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
12 from forum.badges import ALL_BADGES
13 from forum import settings
16 return HttpResponseRedirect(str(settings.APP_FAVICON))
19 return render_to_response('about.html', {'text': settings.ABOUT_PAGE_TEXT.value }, context_instance=RequestContext(request))
23 'gravatar_faq_url': reverse('faq') + '#gravatar',
24 #'send_email_key_url': reverse('send_email_key'),
25 'ask_question_url': reverse('ask'),
27 return render_to_response('faq.html', data, context_instance=RequestContext(request))
29 def feedback(request):
32 if request.method == "POST":
33 form = FeedbackForm(request.POST)
35 if not request.user.is_authenticated:
36 data['email'] = form.cleaned_data.get('email',None)
37 data['message'] = form.cleaned_data['message']
38 data['name'] = form.cleaned_data.get('name',None)
39 message = render_to_response('feedback_email.txt',data,context_instance=RequestContext(request))
40 mail_admins(_('Q&A forum feedback'), message)
41 msg = _('Thanks for the feedback!')
42 request.user.message_set.create(message=msg)
43 return HttpResponseRedirect(get_next_url(request))
45 form = FeedbackForm(initial={'next':get_next_url(request)})
48 return render_to_response('feedback.html', data, context_instance=RequestContext(request))
49 feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)')
52 return render_to_response('privacy.html', context_instance=RequestContext(request))
54 def logout(request):#refactor/change behavior?
55 #currently you click logout and you get
56 #to this view which actually asks you again - do you really want to log out?
57 #I guess rationale was to tell the user that s/he may be still logged in
58 #through their external login sytem and we'd want to remind them about it
59 #however it might be a little annoying
60 #why not just show a message: you are logged out of osqa, but
61 #if you really want to log out -> go to your openid provider
62 return render_to_response('logout.html', {
63 'next' : get_next_url(request),
64 }, context_instance=RequestContext(request))
66 def badges(request):#user status/reputation system
67 badges = Badge.objects.all().order_by('name')
69 badges_dict = dict([(badge.badge, badge.description) for badge in ALL_BADGES])
72 if badge.description != badges_dict.get(badge.slug, badge.description):
73 badge.description = badges_dict[badge.slug]
77 if request.user.is_authenticated():
78 my_badges = Award.objects.filter(user=request.user).values('badge_id')
79 #my_badges.query.group_by = ['badge_id']
81 return render_to_response('badges.html', {
83 'mybadges' : my_badges,
84 'feedback_faq_url' : reverse('feedback'),
85 }, context_instance=RequestContext(request))
87 def badge(request, id):
88 badge = get_object_or_404(Badge, id=id)
89 awards = Award.objects.extra(
90 select={'id': 'auth_user.id',
91 'name': 'auth_user.username',
92 'rep':'forum_user.reputation',
93 'gold': 'forum_user.gold',
94 'silver': 'forum_user.silver',
95 'bronze': 'forum_user.bronze'},
96 tables=['award', 'auth_user', 'forum_user'],
97 where=['badge_id=%s AND user_id=auth_user.id AND forum_user.user_ptr_id = auth_user.id'],
101 return render_to_response('badge.html', {
104 }, context_instance=RequestContext(request))