Working on templates and views
parent
48882238b2
commit
c3c01cfc10
|
@ -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 %}
|
|
@ -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 %}
|
|
@ -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>
|
|
@ -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 »</a>
|
||||||
|
</section>
|
|
@ -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>
|
|
@ -5,4 +5,5 @@ from snipts import views
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^$', views.home, name='home'),
|
url(r'^$', views.home, name='home'),
|
||||||
|
url(r'^(?P<user>[^/]+/)?$', views.list_user, name='list-user'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
from snipts.api import PublicSniptResource, PublicTagResource
|
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 annoying.decorators import render_to
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from snipts.models import Snipt
|
from snipts.models import Snipt
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
|
|
||||||
@render_to('home.html')
|
|
||||||
def home(request):
|
def home(request):
|
||||||
|
|
||||||
if request.user.is_authenticated():
|
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 = Tag.objects.filter(snipt__public=True)
|
||||||
tags = tags.annotate(count=Count('taggit_taggeditem_items__id'))
|
tags = tags.annotate(count=Count('taggit_taggeditem_items__id'))
|
||||||
|
@ -21,16 +26,28 @@ def home(request):
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
}
|
}
|
||||||
|
|
||||||
@render_to('home.html')
|
@render_to('snipts/list-user.html')
|
||||||
def home_user(request):
|
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.annotate(count=Count('taggit_taggeditem_items__id'))
|
||||||
tags = tags.order_by('-count')[:20]
|
tags = tags.order_by('-count')
|
||||||
|
snipts = snipts.order_by('-created')
|
||||||
snipts = Snipt.objects.filter(public=True).order_by('-created')
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'snipts': snipts,
|
'snipts': snipts,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
|
'user': user,
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,10 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="/signup/">Sign up</a>
|
<a href="/signup/">Sign up</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li>
|
||||||
|
<a href="/">My snipts</a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -88,17 +92,7 @@
|
||||||
Ads by Yoggrt
|
Ads by Yoggrt
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="tags">
|
{% block tags %}{% endblock %}
|
||||||
<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 »</a>
|
|
||||||
</section>
|
|
||||||
<nav class="footer">
|
<nav class="footer">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="api">
|
<li class="api">
|
||||||
|
|
|
@ -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 %}
|
|
Loading…
Reference in New Issue