]> git.openstreetmap.org Git - osqa.git/blob - forum/views/meta.py
It is now possable for users to add tags like "REP_TO_VOTE_UP" to the faq page and...
[osqa.git] / forum / views / meta.py
1 from django.shortcuts import render_to_response, get_object_or_404
2 from django.core.urlresolvers import reverse
3 from django.template import RequestContext
4 from django.http import HttpResponseRedirect, HttpResponse
5 from django.conf import settings
6 from forum.forms import FeedbackForm
7 from django.core.urlresolvers import reverse
8 from django.core.mail import mail_admins
9 from django.utils.translation import ugettext as _
10 from forum.utils.forms import get_next_url
11 from forum.models import Badge, Award, User
12 from forum.badges import ALL_BADGES
13 from forum import settings
14 from forum.utils.mail import send_email
15 from forum.settings.settingsmarkdown import *
16
17 import re
18
19 def favicon(request):
20     return HttpResponseRedirect(str(settings.APP_FAVICON))
21
22 def about(request):
23     return render_to_response('about.html', {'text': settings.ABOUT_PAGE_TEXT.value }, context_instance=RequestContext(request))
24
25 def faq(request):
26     md = markdown.Markdown([SettingsExtension({})])
27     text = md.convert(settings.FAQ_PAGE_TEXT.value)
28
29     return render_to_response('faq.html', {'text' : text}, context_instance=RequestContext(request))
30
31 def feedback(request):
32     if request.method == "POST":
33         form = FeedbackForm(request.POST)
34         if form.is_valid():
35             context = {'user': request.user}
36
37             if not request.user.is_authenticated:
38                 context['email'] = form.cleaned_data.get('email',None)
39             
40             context['message'] = form.cleaned_data['message']
41             context['name'] = form.cleaned_data.get('name',None)
42
43             recipients = [(adm.username, adm.email) for adm in User.objects.filter(is_superuser=True)]
44
45             send_email(settings.EMAIL_SUBJECT_PREFIX + _("Feedback message from %(site_name)s") % {'site_name': settings.APP_SHORT_NAME},
46                        recipients, "notifications/feedback.html", context)
47             
48             msg = _('Thanks for the feedback!')
49             request.user.message_set.create(message=msg)
50             return HttpResponseRedirect(get_next_url(request))
51     else:
52         form = FeedbackForm(initial={'next':get_next_url(request)})
53
54     return render_to_response('feedback.html', {'form': form}, context_instance=RequestContext(request))
55 feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)')
56
57 def privacy(request):
58     return render_to_response('privacy.html', context_instance=RequestContext(request))
59
60 def logout(request):
61     return render_to_response('logout.html', {
62         'next' : get_next_url(request),
63     }, context_instance=RequestContext(request))
64
65 def badges(request):#user status/reputation system
66     badges = Badge.objects.all().order_by('name')
67
68     badges_dict = dict([(badge.badge, badge.description) for badge in ALL_BADGES])
69
70     for badge in badges:
71         if badge.description != badges_dict.get(badge.slug, badge.description):
72             badge.description = badges_dict[badge.slug]
73             badge.save()
74     
75     my_badges = []
76     if request.user.is_authenticated():
77         my_badges = Award.objects.filter(user=request.user).values('badge_id')
78         #my_badges.query.group_by = ['badge_id']
79
80     return render_to_response('badges.html', {
81         'badges' : badges,
82         'mybadges' : my_badges,
83         'feedback_faq_url' : reverse('feedback'),
84     }, context_instance=RequestContext(request))
85
86 def badge(request, id):
87     badge = get_object_or_404(Badge, id=id)
88     awards = Award.objects.extra(
89         select={'id': 'auth_user.id', 
90                 'name': 'auth_user.username', 
91                 'rep':'forum_user.reputation',
92                 'gold': 'forum_user.gold',
93                 'silver': 'forum_user.silver',
94                 'bronze': 'forum_user.bronze'},
95         tables=['award', 'auth_user', 'forum_user'],
96         where=['badge_id=%s AND user_id=auth_user.id AND forum_user.user_ptr_id = auth_user.id'],
97         params=[id]
98     ).distinct('id')
99
100     return render_to_response('badge.html', {
101         'awards' : awards,
102         'badge' : badge,
103     }, context_instance=RequestContext(request))
104