Skip to content

Commit

Permalink
Add context processors to list services
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorfs committed Mar 9, 2018
1 parent f589218 commit ea24360
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions woid/apps/core/templatetags/startswith.py
Expand Up @@ -7,6 +7,7 @@

@register.filter('startswith')
def startswith(text, starts):
starts = '/%s/' % starts
if isinstance(text, basestring):
return text.startswith(starts)
return False
6 changes: 6 additions & 0 deletions woid/apps/services/context_processors.py
@@ -0,0 +1,6 @@
from .models import Service

def services(request):
return {
'services_slugs': Service.objects.values_list('slug', flat=True).order_by('id')
}
2 changes: 2 additions & 0 deletions woid/settings.py
Expand Up @@ -68,6 +68,8 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',

'woid.apps.services.context_processors.services',
],
},
},
Expand Down
9 changes: 3 additions & 6 deletions woid/templates/includes/menu.html
Expand Up @@ -2,10 +2,7 @@

<ul class="menu-services">
<li><a href="{% url 'front_page' %}"{% if request.path = '/' %} class="active"{% endif %}>front page</a></li>
<li><a href="{% url 'services:index' 'hn' %}"{% if request.path|startswith:'/hn/' %} class="active"{% endif %}>hn</a></li>
<li><a href="{% url 'services:index' 'reddit' %}"{% if request.path|startswith:'/reddit/' %} class="active"{% endif %}>reddit</a></li>
<li><a href="{% url 'services:index' 'github' %}"{% if request.path|startswith:'/github/' %} class="active"{% endif %}>github</a></li>
<li><a href="{% url 'services:index' 'medium' %}"{% if request.path|startswith:'/medium/' %} class="active"{% endif %}>medium</a></li>
<li><a href="{% url 'services:index' 'nytimes' %}"{% if request.path|startswith:'/nytimes/' %} class="active"{% endif %}>nytimes</a></li>
<li><a href="{% url 'services:index' 'producthunt' %}"{% if request.path|startswith:'/producthunt/' %} class="active"{% endif %}>product hunt</a></li>
{% for slug in services_slugs %}
<li><a href="{% url 'services:index' slug %}"{% if request.path|startswith:slug %} class="active"{% endif %}>{{ slug }}</a></li>
{% endfor %}
</ul>

0 comments on commit ea24360

Please sign in to comment.