Skip to content

Commit

Permalink
Show old and current projects in navigation
Browse files Browse the repository at this point in the history
- This change adds the two navigation points below
  the "Projects" entry in the navigation
  - "Current projects"
  - "Old projects"

It also refactors some of the not so pretty code
  • Loading branch information
Knut Hühne committed Jul 6, 2016
1 parent 91d7ec0 commit 19b35f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
22 changes: 13 additions & 9 deletions foundation/organisation/menu.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
from menus.base import NavigationNode
from menus.menu_pool import menu_pool
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from cms.menu_bases import CMSAttachMenu
from .models import Project, Theme, NetworkGroup
from .models import Theme, NetworkGroup


class ProjectMenu(CMSAttachMenu):

name = _("Projects")

def get_nodes(self, request):
nodes = []
for project in Project.objects.all():
node = NavigationNode(
project.name,
project.get_absolute_url(),
project.pk,
)
nodes.append(node)
current_projects = NavigationNode(
'Current projects',
reverse('projects'),
1337,
)
old_projects = NavigationNode(
'Old projects',
reverse('projects_old'),
1338,
)
nodes = [current_projects, old_projects]
return nodes

menu_pool.register_menu(ProjectMenu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

{% block blurb %}{% static_placeholder "projects blurb" %}{% endblock %}


{% block main %}
<div class="row">
{% static_placeholder "projects intro" %}
Expand Down Expand Up @@ -94,11 +93,7 @@ <h4>Sourcecode:</h4>
</div>
{% endfor %}

{% if not old_projects %}
<a href="/projects/?show_old=True">Old projects </a>
{% else %}
<a href="/projects">Current projects </a>
{% endif %}


{% with timeless=True %}
{% include "includes/pager.html" %}
Expand Down
1 change: 1 addition & 0 deletions foundation/organisation/urls/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
urlpatterns = patterns(
'',
url(r'^$', ProjectListView.as_view(), name='projects'),
url(r'^old$', ProjectListView.as_view(), name='projects_old'),
url(r'^(?P<slug>[^/]+)/$', ProjectDetailView.as_view(), name='project'),
)
3 changes: 1 addition & 2 deletions foundation/organisation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProjectListView(ListView):

def get_queryset(self):
# Do we want to show old projects?
show_old = self.request.GET.get('show_old', False)
show_old = self.request.path.endswith("old")
if show_old:
return Project.objects.filter(old_project=True)

Expand All @@ -49,7 +49,6 @@ def get_context_data(self, **kwargs):
context = super(ProjectListView, self).get_context_data(**kwargs)
context['themes'] = Theme.objects.all()
context['projecttypes'] = ProjectType.objects.all()
context['old_projects'] = self.request.GET.get('show_old', False)
return context


Expand Down

0 comments on commit 19b35f7

Please sign in to comment.