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 forum.forms import FeedbackForm
6 from django.core.urlresolvers import reverse
7 from django.core.mail import mail_admins
8 from django.utils.translation import ugettext as _
9 from forum.utils.forms import get_next_url
10 from forum.models import Badge, Award
13 return render_to_response('about.html', context_instance=RequestContext(request))
17 'gravatar_faq_url': reverse('faq') + '#gravatar',
18 #'send_email_key_url': reverse('send_email_key'),
19 'ask_question_url': reverse('ask'),
21 return render_to_response('faq.html', data, context_instance=RequestContext(request))
23 def feedback(request):
26 if request.method == "POST":
27 form = FeedbackForm(request.POST)
29 if not request.user.is_authenticated:
30 data['email'] = form.cleaned_data.get('email',None)
31 data['message'] = form.cleaned_data['message']
32 data['name'] = form.cleaned_data.get('name',None)
33 message = render_to_response('feedback_email.txt',data,context_instance=RequestContext(request))
34 mail_admins(_('Q&A forum feedback'), message)
35 msg = _('Thanks for the feedback!')
36 request.user.message_set.create(message=msg)
37 return HttpResponseRedirect(get_next_url(request))
39 form = FeedbackForm(initial={'next':get_next_url(request)})
42 return render_to_response('feedback.html', data, context_instance=RequestContext(request))
43 feedback.CANCEL_MESSAGE=_('We look forward to hearing your feedback! Please, give it next time :)')
46 return render_to_response('privacy.html', context_instance=RequestContext(request))
48 def logout(request):#refactor/change behavior?
49 #currently you click logout and you get
50 #to this view which actually asks you again - do you really want to log out?
51 #I guess rationale was to tell the user that s/he may be still logged in
52 #through their external login sytem and we'd want to remind them about it
53 #however it might be a little annoying
54 #why not just show a message: you are logged out of osqa, but
55 #if you really want to log out -> go to your openid provider
56 return render_to_response('logout.html', {
57 'next' : get_next_url(request),
58 }, context_instance=RequestContext(request))
60 def badges(request):#user status/reputation system
61 badges = Badge.objects.all().order_by('name')
63 if request.user.is_authenticated():
64 my_badges = Award.objects.filter(user=request.user).values('badge_id')
65 #my_badges.query.group_by = ['badge_id']
67 return render_to_response('badges.html', {
69 'mybadges' : my_badges,
70 'feedback_faq_url' : reverse('feedback'),
71 }, context_instance=RequestContext(request))
73 def badge(request, id):
74 badge = get_object_or_404(Badge, id=id)
75 awards = Award.objects.extra(
76 select={'id': 'auth_user.id',
77 'name': 'auth_user.username',
78 'rep':'auth_user.reputation',
79 'gold': 'auth_user.gold',
80 'silver': 'auth_user.silver',
81 'bronze': 'auth_user.bronze'},
82 tables=['award', 'auth_user'],
83 where=['badge_id=%s AND user_id=auth_user.id'],
87 return render_to_response('badge.html', {
90 }, context_instance=RequestContext(request))