2 from itertools import groupby
3 from django.shortcuts import render_to_response, get_object_or_404
4 from django.core.urlresolvers import reverse
5 from django.template import RequestContext, loader
6 from django.http import HttpResponseRedirect, HttpResponse
7 from django.views.static import serve
8 from forum import settings
9 from forum.forms import FeedbackForm
10 from django.core.urlresolvers import reverse
11 from django.utils.translation import ugettext as _
12 from django.db.models import Count
13 from forum.utils.forms import get_next_url
14 from forum.models import Badge, Award, User
15 from forum.badges.base import BadgesMeta
16 from forum import settings
17 from forum.utils.mail import send_email
21 return HttpResponseRedirect(str(settings.APP_FAVICON))
23 def static(request, title, content):
24 return render_to_response('static.html', {'content' : content, 'title': title}, context_instance=RequestContext(request))
26 def media(request, skin, path):
27 return serve(request, "%s/media/%s" % (skin, path),
28 document_root=os.path.join(os.path.dirname(os.path.dirname(__file__)),'skins').replace('\\','/'))
30 def markdown_help(request):
31 # md = markdown.Markdown([SettingsExtension({})])
32 # text = md.convert(settings.FAQ_PAGE_TEXT.value)
34 return render_to_response('markdown_help.html', context_instance=RequestContext(request))
37 def opensearch(request):
38 return render_to_response('opensearch.html', {'settings' : settings}, context_instance=RequestContext(request))
41 def feedback(request):
42 if request.method == "POST":
43 form = FeedbackForm(request.POST)
45 context = {'user': request.user}
47 if not request.user.is_authenticated:
48 context['email'] = form.cleaned_data.get('email',None)
49 context['message'] = form.cleaned_data['message']
50 context['name'] = form.cleaned_data.get('name',None)
51 context['ip'] = request.META['REMOTE_ADDR']
53 recipients = [(adm.username, adm.email) for adm in User.objects.filter(is_superuser=True)]
55 send_email(settings.EMAIL_SUBJECT_PREFIX + _("Feedback message from %(site_name)s") % {'site_name': settings.APP_SHORT_NAME},
56 recipients, "notifications/feedback.html", context)
58 msg = _('Thanks for the feedback!')
59 request.user.message_set.create(message=msg)
60 return HttpResponseRedirect(get_next_url(request))
62 form = FeedbackForm(initial={'next':get_next_url(request)})
64 return render_to_response('feedback.html', {'form': form}, context_instance=RequestContext(request))
65 feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)')
68 return render_to_response('privacy.html', context_instance=RequestContext(request))
71 return render_to_response('logout.html', {
72 'next' : get_next_url(request),
73 }, context_instance=RequestContext(request))
76 badges = [b.ondb for b in sorted(BadgesMeta.by_id.values(), lambda b1, b2: cmp(b1.name, b2.name))]
78 if request.user.is_authenticated():
79 my_badges = Award.objects.filter(user=request.user).values('badge_id').distinct()
83 return render_to_response('badges.html', {
85 'mybadges' : my_badges,
86 }, context_instance=RequestContext(request))
88 def badge(request, id, slug):
89 badge = Badge.objects.get(id=id)
90 awards = list(Award.objects.filter(badge=badge).order_by('user', 'awarded_at'))
91 award_count = len(awards)
93 awards = sorted([dict(count=len(list(g)), user=k) for k, g in groupby(awards, lambda a: a.user)],
94 lambda c1, c2: c2['count'] - c1['count'])
96 return render_to_response('badge.html', {
97 'award_count': award_count,
100 }, context_instance=RequestContext(request))