X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/5d33b325a606240f9bcc7d704de1af0152c9bd19..f32577466e18584c0adb9e9845a0f50faa5db777:/forum/views/meta.py diff --git a/forum/views/meta.py b/forum/views/meta.py index be41bd2..97c852f 100644 --- a/forum/views/meta.py +++ b/forum/views/meta.py @@ -1,32 +1,36 @@ +from itertools import groupby from django.shortcuts import render_to_response, get_object_or_404 from django.core.urlresolvers import reverse -from django.template import RequestContext +from django.template import RequestContext, loader from django.http import HttpResponseRedirect, HttpResponse -from django.conf import settings +from forum import settings from forum.forms import FeedbackForm from django.core.urlresolvers import reverse -from django.core.mail import mail_admins from django.utils.translation import ugettext as _ +from django.db.models import Count from forum.utils.forms import get_next_url from forum.models import Badge, Award, User -from forum.badges import ALL_BADGES +from forum.badges.base import BadgesMeta from forum import settings from forum.utils.mail import send_email -from forum.settings.settingsmarkdown import * - import re def favicon(request): return HttpResponseRedirect(str(settings.APP_FAVICON)) -def about(request): - return render_to_response('about.html', {'text': settings.ABOUT_PAGE_TEXT.value }, context_instance=RequestContext(request)) +def static(request, title, content): + return render_to_response('static.html', {'content' : content, 'title': title}, context_instance=RequestContext(request)) + +def markdown_help(request): + # md = markdown.Markdown([SettingsExtension({})]) + # text = md.convert(settings.FAQ_PAGE_TEXT.value) -def faq(request): - md = markdown.Markdown([SettingsExtension({})]) - text = md.convert(settings.FAQ_PAGE_TEXT.value) + return render_to_response('markdown_help.html', context_instance=RequestContext(request)) - return render_to_response('faq.html', {'text' : text}, context_instance=RequestContext(request)) + +def opensearch(request): + return render_to_response('opensearch.html', {'settings' : settings}, context_instance=RequestContext(request)) + def feedback(request): if request.method == "POST": @@ -36,9 +40,9 @@ def feedback(request): if not request.user.is_authenticated: context['email'] = form.cleaned_data.get('email',None) - context['message'] = form.cleaned_data['message'] context['name'] = form.cleaned_data.get('name',None) + context['ip'] = request.META['REMOTE_ADDR'] recipients = [(adm.username, adm.email) for adm in User.objects.filter(is_superuser=True)] @@ -62,42 +66,29 @@ def logout(request): 'next' : get_next_url(request), }, context_instance=RequestContext(request)) -def badges(request):#user status/reputation system - badges = Badge.objects.all().order_by('name') - - badges_dict = dict([(badge.badge, badge.description) for badge in ALL_BADGES]) - - for badge in badges: - if badge.description != badges_dict.get(badge.slug, badge.description): - badge.description = badges_dict[badge.slug] - badge.save() +def badges(request): + badges = [b.ondb for b in sorted(BadgesMeta.by_id.values(), lambda b1, b2: cmp(b1.name, b2.name))] - my_badges = [] if request.user.is_authenticated(): - my_badges = Award.objects.filter(user=request.user).values('badge_id') - #my_badges.query.group_by = ['badge_id'] + my_badges = Award.objects.filter(user=request.user).values('badge_id').distinct() + else: + my_badges = [] return render_to_response('badges.html', { 'badges' : badges, 'mybadges' : my_badges, - 'feedback_faq_url' : reverse('feedback'), }, context_instance=RequestContext(request)) -def badge(request, id): - badge = get_object_or_404(Badge, id=id) - awards = Award.objects.extra( - select={'id': 'auth_user.id', - 'name': 'auth_user.username', - 'rep':'forum_user.reputation', - 'gold': 'forum_user.gold', - 'silver': 'forum_user.silver', - 'bronze': 'forum_user.bronze'}, - tables=['award', 'auth_user', 'forum_user'], - where=['badge_id=%s AND user_id=auth_user.id AND forum_user.user_ptr_id = auth_user.id'], - params=[id] - ).distinct('id') +def badge(request, id, slug): + badge = Badge.objects.get(id=id) + awards = list(Award.objects.filter(badge=badge).order_by('user', 'awarded_at')) + award_count = len(awards) + + awards = sorted([dict(count=len(list(g)), user=k) for k, g in groupby(awards, lambda a: a.user)], + lambda c1, c2: c2['count'] - c1['count']) return render_to_response('badge.html', { + 'award_count': award_count, 'awards' : awards, 'badge' : badge, }, context_instance=RequestContext(request))