Snipt: Glitch Edition
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.9 KiB

import hashlib
from accounts.models import UserProfile
from annoying.decorators import ajax_request, render_to
from blogs.views import blog_list
from django.contrib.auth.models import User
from django.db.models import Count
from django.http import HttpResponseRedirect, HttpResponseBadRequest
from snipts.models import Snipt
from snipts.utils import get_lexers_list
from taggit.models import Tag
def homepage(request):
if request.blog_user:
return blog_list(request)
return {
'snipts_count': Snipt.objects.all().count(),
def lexers(request):
lexers = get_lexers_list()
objects = []
for l in lexers:
filters = l[2]
except IndexError:
filters = []
mimetypes = l[3]
except IndexError:
mimetypes = []
{"name": l[0], "lexers": l[1], "filters": filters, "mimetypes": mimetypes}
return {"objects": objects}
def login_redirect(request):
if request.user.is_authenticated():
return HttpResponseRedirect("/" + request.user.username + "/")
return HttpResponseRedirect("/")
def tags(request):
all_tags = Tag.objects.filter(snipt__public=True).order_by("name")
all_tags = all_tags.annotate(count=Count("taggit_taggeditem_items__id"))
popular_tags = Tag.objects.filter(snipt__public=True)
popular_tags = popular_tags.annotate(count=Count("taggit_taggeditem_items__id"))
popular_tags = popular_tags.order_by("-count")[:20]
popular_tags = sorted(popular_tags, key=lambda tag:
return {"all_tags": all_tags, "tags": popular_tags}
def user_api_key(request):
if not request.user.is_authenticated():
return HttpResponseBadRequest()
return {"api_key": request.user.api_key.key}