Skip to content

Commit e0732e9

Browse files
committed
Refactoring sorting code to use models instead of JSON data, refactored a bunch of other stuff to make it work.
1 parent af07d24 commit e0732e9

File tree

33 files changed

+104
-80
lines changed

33 files changed

+104
-80
lines changed

content/gsoc-2019/contents.lr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ body:
66

77
Creative Commons is applying to be a mentoring organization for [Google Summer of Code 2019](https://summerofcode.withgoogle.com/).
88

9-
Check out our [Project Ideas](/gsoc-2019/project-ideas) and [Application Instructions](/gsoc-2019/application-instructions)!
9+
Check out our [Project Ideas](/gsoc-2019/project-ideas/all) and [Application Instructions](/gsoc-2019/application-instructions)!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_model: project-ideas-collection
2+
---
3+
_hidden: yes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
_model: project-ideas
2+
---
3+
nav_label: All Projects
4+
---
5+
field:
6+
---
7+
value:
8+
---
9+
order: 1
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
_model: project-ideas
1+
_model: redirect
22
---
3-
title: GSoC 2019: Project Ideas
3+
target: /gsoc-2019/project-ideas/all/
4+
---
5+
_discoverable: no
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
_model: project-ideas
22
---
3-
title: GSoC 2019: Project Ideas
3+
nav_label: Difficulty: Easy
4+
---
5+
field: difficulty
6+
---
7+
value: Easy
8+
---
9+
order: 2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
_model: project-ideas
22
---
3-
title: GSoC 2019: Project Ideas
3+
nav_label: Difficulty: Hard
4+
---
5+
field: difficulty
6+
---
7+
value: Hard
8+
---
9+
order: 4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
_model: project-ideas
22
---
3-
title: GSoC 2019: Project Ideas
3+
nav_label: Difficulty: Medium
4+
---
5+
field: difficulty
6+
---
7+
value: Medium
8+
---
9+
order: 3

content/gsoc-2019/project-ideas/project-ideas-list/contents.lr

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
_model: project-ideas
22
---
3-
title: GSoC 2019: Project Ideas
3+
nav_label: Skill: JavaScript
4+
---
5+
field: recommended_skill
6+
---
7+
value: JavaScript
8+
---
9+
order: 5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
_model: project-ideas
22
---
3-
title: GSoC 2019: Project Ideas
3+
nav_label: Skill: Python
4+
---
5+
field: recommended_skill
6+
---
7+
value: Python
8+
---
9+
order: 6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
_model: project-ideas
22
---
3-
title: GSoC 2019: Project Ideas
3+
nav_label: Skill: WordPress
4+
---
5+
field: recommended_skill
6+
---
7+
value: WordPress
8+
---
9+
order: 7

databags/project-filters.json

-44
This file was deleted.

models/project-ideas-list.ini renamed to models/project-ideas-collection.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[model]
2-
name = Project Ideas
2+
name = Project Ideas List
33
label = {{ this.title }}
44
hidden = yes
55
protected = yes

models/project-ideas.ini

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
[model]
2-
name = Project Ideas Page
2+
name = Project Ideas
33
label = {{ this.title }}
44
hidden = yes
55
protected = yes
66

7+
[children]
8+
model = project-idea
9+
order_by = title
10+
11+
[fields.nav_label]
12+
label = Filter Navigation Label
13+
type = string
14+
15+
[fields.field]
16+
label = Filter Field
17+
type = string
18+
19+
[fields.value]
20+
label = Filter Value
21+
type = string
22+
723
[fields.title]
824
label = Title
925
type = string
26+
27+
[fields.order]
28+
label = Sort Key
29+
type = sort_key

models/redirect.ini

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[model]
2+
name = Redirect
3+
4+
[fields.target]
5+
label = Redirect Target
6+
type = string
7+
description = Target is of type 'string' to allow relative paths. Converted to url in the template

templates/layout.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<a class="nav-link" href="/gsoc-2019/" id="navbarDropdown" role="button">Google Summer of Code 2019</a>
3434
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
3535
{% for href, title in [
36-
['/gsoc-2019/project-ideas', 'Project Ideas'],
36+
['/gsoc-2019/project-ideas/all', 'Project Ideas'],
3737
['/gsoc-2019/application-instructions', 'Application Instructions'],
3838
] %}
3939
<a class="dropdown-item" href="{{ href|url }}">{{ title }}</a>
@@ -49,7 +49,7 @@
4949
<div class="row justify-content-md-center">
5050
<div class="col-9 content-wrap">
5151
<div class="page py-3">
52-
<h2 class="pb-2"><strong>{{ this.title }}</strong></h2>
52+
<h2 class="pb-2"><strong>{% block header %}{{ this.title }}{% endblock %}</strong></h2>
5353
{% block body %}{% endblock %}
5454
</div>
5555
</div>

templates/project-ideas.html

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
{% extends "layout.html" %}
22
{% block title %}Project Ideas for GSoC 2019{% endblock %}
33

4+
{% block header %}GSoC 2019: Project Ideas{% endblock %}
45
{% block body %}
56
<p class="text-muted">This is the project idea list for the <a href="/gsoc-2019">Google Summer of Code 2019</a> program. We have a mix of projects that are meant to be installed widely (such as plugins for other software) and projects that are more focused on improving user experience for users of Creative Commons licenses. Regardless of scope, these projects all have a broad and positive community impact.</p>
67
<a name="ideas-top"></a>
78
<hr/>
89
<!-- We display all ideas by default. -->
9-
{% set ideas = site.query('/gsoc-2019/project-ideas/project-ideas-list').include_undiscoverable(true) %}
10-
<!-- The following code filters the ideas to display based on the current URL. These mappings are defined in the "databags" folder.
11-
Jinja does not support changing values of variables inside loops, so we have to use namespace objects.
12-
See "Scoping Behavior" here: http://jinja.pocoo.org/docs/2.10/templates/#assignments -->
13-
{% set ns = namespace(field=None, value=None) %}
14-
{% for slug, data in bag('project-filters').iteritems() %}
15-
{% if this._slug == slug %}
16-
{% set ns.field = data['field'] %}
17-
{% set ns.value = data['value'] %}
18-
{% endif %}
19-
{% endfor %}
20-
{% if ns.field == 'difficulty' %}
21-
{% set ideas = ideas.filter(F.difficulty == ns.value) %}
22-
{% endif %}
23-
{% if ns.field == 'skill' %}
24-
{% set ideas = ideas.filter(F.skills_recommended.contains(ns.value)) %}
10+
{% set ideas = site.query('/gsoc-2019/project-ideas-collection').include_undiscoverable(true) %}
11+
{% set filters = site.query('/gsoc-2019/project-ideas').include_undiscoverable(true).order_by('order') %}
12+
{% set current_filter = filters.filter(F._slug == this._slug).first() %}
13+
<!-- The following code filters the ideas to display based on the current URL. -->
14+
{% if current_filter.field == 'difficulty' %}
15+
{% set ideas = ideas.filter(F.difficulty == current_filter.value) %}
16+
{% elif current_filter.field == 'recommended_skill' %}
17+
{% set ideas = ideas.filter(F.skills_recommended.contains(current_filter.value)) %}
2518
{% endif %}
2619
<div class="mt-4">
2720
<div>
28-
{% for slug, data in bag('project-filters').iteritems() %}
29-
<a href="{{ data['path'] }}">
30-
<button type="button" class="btn btn-sm {% if this._path == data['path'] %}btn-dark{% else %}btn-primary{% endif %}" {% if this._path == data['path'] %}disabled{% endif %}>
31-
{{ data['nav_label'] }}
21+
{% for filter in filters %}
22+
<a href="{{ filter.url_path }}">
23+
<button type="button" class="m-1 btn btn-sm {% if this._slug == filter._slug %}btn-dark{% else %}btn-primary{% endif %}" {% if this._slug == filter._slug %}disabled{% endif %}>
24+
{{ filter.nav_label }}
3225
</button>
3326
</a>
3427
{% endfor %}

templates/redirect.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<meta http-equiv="refresh" content="0; URL='{{ this.target|url }}'" />

0 commit comments

Comments
 (0)