]> git.openstreetmap.org Git - osqa.git/blob - forum/views/meta.py
fixed feedback page
[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 import re
16
17 def favicon(request):
18     return HttpResponseRedirect(str(settings.APP_FAVICON))
19
20 def about(request):
21     return render_to_response('about.html', {'text': settings.ABOUT_PAGE_TEXT.value }, context_instance=RequestContext(request))
22
23 def faq(request):
24     data = {
25         'gravatar_faq_url': reverse('faq') + '#gravatar',
26         #'send_email_key_url': reverse('send_email_key'),
27         'ask_question_url': reverse('ask'),
28     }
29     return render_to_response('faq.html', data, 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             context['message'] = form.cleaned_data['message']
40             context['name'] = form.cleaned_data.get('name',None)
41
42             recipients = [(adm.username, adm.email) for adm in User.objects.filter(is_superuser=True)]
43
44             send_email(settings.EMAIL_SUBJECT_PREFIX + _("Feedback message from %(site_name)s") % {'site_name': settings.APP_SHORT_NAME},
45                        recipients, "notifications/feedback.html", context)
46             
47             msg = _('Thanks for the feedback!')
48             request.user.message_set.create(message=msg)
49             return HttpResponseRedirect(get_next_url(request))
50     else:
51         form = FeedbackForm(initial={'next':get_next_url(request)})
52
53     return render_to_response('feedback.html', {'form': form}, context_instance=RequestContext(request))
54 feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)')
55
56 def privacy(request):
57     return render_to_response('privacy.html', context_instance=RequestContext(request))
58
59 def logout(request):
60     return render_to_response('logout.html', {
61         'next' : get_next_url(request),
62     }, context_instance=RequestContext(request))
63
64 def badges(request):#user status/reputation system
65     badges = Badge.objects.all().order_by('name')
66
67     badges_dict = dict([(badge.badge, badge.description) for badge in ALL_BADGES])
68
69     for badge in badges:
70         if badge.description != badges_dict.get(badge.slug, badge.description):
71             badge.description = badges_dict[badge.slug]
72             badge.save()
73     
74     my_badges = []
75     if request.user.is_authenticated():
76         my_badges = Award.objects.filter(user=request.user).values('badge_id')
77         #my_badges.query.group_by = ['badge_id']
78
79     return render_to_response('badges.html', {
80         'badges' : badges,
81         'mybadges' : my_badges,
82         'feedback_faq_url' : reverse('feedback'),
83     }, context_instance=RequestContext(request))
84
85 def badge(request, id):
86     badge = get_object_or_404(Badge, id=id)
87     awards = Award.objects.extra(
88         select={'id': 'auth_user.id', 
89                 'name': 'auth_user.username', 
90                 'rep':'forum_user.reputation',
91                 'gold': 'forum_user.gold',
92                 'silver': 'forum_user.silver',
93                 'bronze': 'forum_user.bronze'},
94         tables=['award', 'auth_user', 'forum_user'],
95         where=['badge_id=%s AND user_id=auth_user.id AND forum_user.user_ptr_id = auth_user.id'],
96         params=[id]
97     ).distinct('id')
98
99     return render_to_response('badge.html', {
100         'awards' : awards,
101         'badge' : badge,
102     }, context_instance=RequestContext(request))
103