Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
moved fetching channels to an assignment tag, removed channels args f…
Browse files Browse the repository at this point in the history
…rom views.
  • Loading branch information
dhedegaard committed Jul 6, 2015
1 parent 57a7d60 commit ed8cf6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions youtube/templates/youtube/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
{% load static %}
{% load youtubetags %}
<html lang="en">
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -42,6 +43,7 @@
</div>
{% endif %}
<ul class="nav navbar-nav">
{% visible_channels as channels %}
{% if channels %}
<li class="dropdown{% if page == 'channel' %} active{% endif %}">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"
Expand Down
10 changes: 10 additions & 0 deletions youtube/templatetags/youtubetags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django import template

from ..models import Channel

register = template.Library()


@register.assignment_tag
def visible_channels():
return Channel.objects.filter(hidden=False).order_by('title')
7 changes: 0 additions & 7 deletions youtube/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ def index(request):
filter(uploader__hidden=False).
exclude_deleted().
prefetch_related('uploader')),
'channels': (Channel.objects.
filter(hidden=False).
order_by('title')),
})


Expand All @@ -27,17 +24,13 @@ def channel(request, author):
filter(hidden=False), author=author)
return render(request, 'youtube/index.html', {
'videos': channel.videos.exclude_deleted(),
'channels': Channel.objects.filter(hidden=False).order_by('title'),
})


@login_required
def admin(request):
form = AddChannelForm(request.POST or None)
return render(request, 'youtube/admin.html', {
'channels': (Channel.objects.
filter(hidden=False).
order_by('title')),
'admin_channels': (Channel.objects.
prefetch_related('videos').
order_by('hidden', 'title')),
Expand Down

0 comments on commit ed8cf6d

Please sign in to comment.