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