Working on dash

master
Nick Sergeant 2011-10-12 11:29:21 -04:00
parent 9ac53c88f6
commit 4d1e272577
5 changed files with 34 additions and 13 deletions

View File

@ -7,6 +7,7 @@
-e hg+http://bitbucket.org/dwaiter/django-bcrypt#egg=django-bcrypt
-e hg+ssh://hg@bitbucket.org/nicksergeant/django-registration#egg=django-registration
-e svn+http://django-grappelli.googlecode.com/svn/trunk#egg=django-grappelli
-e svn+http://django-pagination.googlecode.com/svn/trunk#egg=django-pagination
-e hg+https://bitbucket.org/birkenfeld/pygments-main#egg=Pygments
# Deployment

View File

@ -43,6 +43,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'pagination.middleware.PaginationMiddleware',
)
ROOT_URLCONF = 'urls'
@ -62,6 +63,7 @@ INSTALLED_APPS = (
'compressor',
'django_bcrypt',
'south',
'pagination',
'taggit',
'tastypie',

View File

@ -1,20 +1,34 @@
from annoying.decorators import render_to
from snipts.api import PublicSniptResource, PublicTagResource
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):
tr = PublicTagResource()
#tags_queryset = tr.cached_obj_get_list()[:20]
tags_queryset = tr.obj_get_list()[:20]
tags_bundles = (tr.build_bundle(request=request, obj=tag) for tag in tags_queryset)
tags = [tr.full_dehydrate(bundle) for bundle in tags_bundles]
if request.user.is_authenticated():
return home_user(request)
sr = PublicSniptResource()
#snipts_queryset = sr.cached_obj_get_list()[:20]
snipts_queryset = sr.obj_get_list()[:20]
snipts_bundles = (sr.build_bundle(request=request, obj=snipt) for snipt in snipts_queryset)
snipts = [sr.full_dehydrate(bundle) for bundle in snipts_bundles]
tags = Tag.objects.filter(snipt__public=True)
tags = tags.annotate(count=Count('taggit_taggeditem_items__id'))
tags = tags.order_by('-count')[:20]
snipts = Snipt.objects.filter(public=True).order_by('-created')
return {
'snipts': snipts,
'tags': tags,
}
@render_to('home.html')
def home_user(request):
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')
return {
'snipts': snipts,

View File

@ -93,7 +93,7 @@
<ul>
{% for tag in tags %}
<li>
<a href="{{ tag.data.absolute_url }}">{{ tag.data.name }} ({{ tag.data.count }})</a>
<a href="/public/tag/{{ tag.slug }}/">{{ tag.name }} ({{ tag.count }})</a>
</li>
{% endfor %}
</ul>

View File

@ -1,11 +1,15 @@
{% extends "base.html" %}
{% load pagination_tags %}
{% block content %}
<section class="snipts">
{% autopaginate snipts 20 %}
{% for snipt in snipts %}
<article class="snipt">
{{ snipt.data.title }}
{{ snipt.title }}
</article>
{% endfor %}
{% paginate %}
</section>
{% endblock %}