Working on templates and views

master
Nick Sergeant 2011-10-12 16:34:01 -04:00
parent 48882238b2
commit c3c01cfc10
10 changed files with 104 additions and 49 deletions

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% load pagination_tags %}
{% block tags %}
{% include "snipts/tags-public.html" %}
{% endblock %}
{% block content %}
<section class="snipts">
{% autopaginate snipts 20 %}
{% for snipt in snipts %}
{% include "snipts/snipt-list.html" %}
{% endfor %}
{% paginate %}
</section>
{% endblock %}

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% load pagination_tags %}
{% block tags %}
{% include "snipts/tags-user.html" %}
{% endblock %}
{% block content %}
<section class="snipts">
{% autopaginate snipts 20 %}
{% for snipt in snipts %}
{% include "snipts/snipt-list.html" %}
{% endfor %}
{% paginate %}
</section>
{% endblock %}

View File

@ -0,0 +1,17 @@
<article class="snipt group">
<div class="container">
<header class="group">
<h2>{{ snipt.lexer }}</h2>
<h1>{{ snipt.title }}</h1>
</header>
<section class="code">
<br /><br /><br /><br /><br /><br /><br /><br />
</section>
</div>
<aside>
</aside>
<footer>
</footer>
</article>

View File

@ -0,0 +1,11 @@
<section class="tags">
<h1>Popular public tags</h1>
<ul>
{% for tag in tags %}
<li>
<a href="/public/tag/{{ tag.slug }}/">{{ tag.name }} ({{ tag.count }})</a>
</li>
{% endfor %}
</ul>
<a href="/public/tags/" class="view-all">View all &raquo;</a>
</section>

View File

@ -0,0 +1,10 @@
<section class="tags">
<h1>{{ user.username }}'s tags</h1>
<ul>
{% for tag in tags %}
<li>
<a href="/{{ user.username }}/tag/{{ tag.slug }}/">{{ tag.name }} ({{ tag.count }})</a>
</li>
{% endfor %}
</ul>
</section>

View File

@ -5,4 +5,5 @@ from snipts import views
urlpatterns = patterns('',
url(r'^$', views.home, name='home'),
url(r'^(?P<user>[^/]+/)?$', views.list_user, name='list-user'),
)

View File

@ -1,14 +1,19 @@
from snipts.api import PublicSniptResource, PublicTagResource
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User
from annoying.decorators import render_to
from django.db.models import Count
from snipts.models import Snipt
from taggit.models import Tag
@render_to('home.html')
def home(request):
if request.user.is_authenticated():
return home_user(request)
return list_user(request, user=request.user)
else:
return list_public(request)
@render_to('snipts/list-public.html')
def list_public(request):
tags = Tag.objects.filter(snipt__public=True)
tags = tags.annotate(count=Count('taggit_taggeditem_items__id'))
@ -21,16 +26,28 @@ def home(request):
'tags': tags,
}
@render_to('home.html')
def home_user(request):
@render_to('snipts/list-user.html')
def list_user(request, user):
if type(user) == unicode:
user = get_object_or_404(User, username=user.strip('/'))
tags = Tag.objects
snipts = Snipt.objects
if user == request.user:
tags = tags.filter(snipt__user=user)
snipts = snipts.filter(user=user)
else:
tags = tags.filter(snipt__user=user, snipt__public=True)
snipts = snipts.filter(user=user, public=True)
tags = Tag.objects.filter(snipt__user=request.user)
tags = tags.annotate(count=Count('taggit_taggeditem_items__id'))
tags = tags.order_by('-count')[:20]
snipts = Snipt.objects.filter(public=True).order_by('-created')
tags = tags.order_by('-count')
snipts = snipts.order_by('-created')
return {
'snipts': snipts,
'tags': tags,
'user': user,
}

View File

@ -68,6 +68,10 @@
<li>
<a href="/signup/">Sign up</a>
</li>
{% else %}
<li>
<a href="/">My snipts</a>
</li>
{% endif %}
</ul>
</nav>
@ -88,17 +92,7 @@
Ads by Yoggrt
</div>
</section>
<section class="tags">
<h1>Popular public tags</h1>
<ul>
{% for tag in tags %}
<li>
<a href="/public/tag/{{ tag.slug }}/">{{ tag.name }} ({{ tag.count }})</a>
</li>
{% endfor %}
</ul>
<a href="/public/tags/" class="view-all">View all &raquo;</a>
</section>
{% block tags %}{% endblock %}
<nav class="footer">
<ul>
<li class="api">

View File

@ -1,29 +0,0 @@
{% extends "base.html" %}
{% load pagination_tags %}
{% block content %}
<section class="snipts">
{% autopaginate snipts 20 %}
{% for snipt in snipts %}
<article class="snipt group">
<div class="container">
<header class="group">
<h2>Javascript</h2>
<h1>{{ snipt.title }}</h1>
</header>
<section class="code">
<br /><br /><br /><br /><br /><br /><br /><br />
</section>
</div>
<aside>
Aside
</aside>
<footer>
Footer
</footer>
</article>
{% endfor %}
{% paginate %}
</section>
{% endblock %}