def award_points(request, answer_id, queryset=Answer.objects.all()): """ do transfer point from question's author to answerer """ answer = get_object_or_404(queryset, id=answer_id) if request.user == answer.author: raise Http404(_(u'You can not award yourself!')) elif answer.question.author != request.user: raise Http404(_(u'This is not your question!')) elif answer.question.bounty_points: points = answer.question.bounty_points reason=ugettext(u'Award points to answer: %(answer)s') % {'answer': answer } try: UnitPack.consume(request.user, quantity=points, reason=reason) except ValueError, msg: url = construct_main_site_url(reverse('prepaid-index', urlconf=settings.MUACCOUNTS_MAIN_URLCONF)) if request.is_ajax(): data = simplejson.dumps({'not_enough_credits': '1', 'available_credits': UnitPack.get_user_credits(request.user), 'required_credits': points, 'awarded': '0'}) return HttpResponse(data, mimetype="application/json") else: return HttpResponseRedirect(url) else: UnitPack.credit(answer.author, quantity=points, reason=reason) PointAward(answer=answer, points=points).save() if request.is_ajax(): data = simplejson.dumps({'not_enough_credits': '0', 'awarded': '1'}) return HttpResponse(data, mimetype="application/json") else: return redirect(answer)
def signout(request, redirect_field_name=REDIRECT_FIELD_NAME): """ log out then redirect to logout on main site """ redirect_to = request.REQUEST.get(redirect_field_name, None) logout_url = "%s?%s=%s" \ % (construct_main_site_url(getattr(settings, 'LOGOUT_URL', '/accounts/logout/'), False), redirect_field_name, urlquote_plus(request.build_absolute_uri(redirect_to))) data = request.GET.copy() data[redirect_field_name] = logout_url request.GET = data response = sso(request) logout(request) return response
class MainURLNode(template.defaulttags.URLNode): def render(self, context): """ copy of default tag URLNode render method. Just url_conf was changed """ from django.core.urlresolvers import reverse, NoReverseMatch args = [arg.resolve(context) for arg in self.args] kwargs = dict([(smart_str(k, 'ascii'), v.resolve(context)) for k, v in self.kwargs.items()]) # Try to look up the URL twice: once given the view name, and again # relative to what we guess is the "main" app. If they both fail, # re-raise the NoReverseMatch unless we're using the # {% url ... as var %} construct in which cause return nothing. url = '' try: url = reverse(self.view_name, urlconf=settings.MUACCOUNTS_MAIN_URLCONF, args=args, kwargs=kwargs, current_app=context.current_app) except NoReverseMatch, e: if settings.SETTINGS_MODULE: project_name = settings.SETTINGS_MODULE.split('.')[0] try: url = reverse(project_name + '.' + self.view_name, urlconf=settings.MUACCOUNTS_MAIN_URLCONF, args=args, kwargs=kwargs, current_app=context.current_app) except NoReverseMatch: if self.asvar is None: # Re-raise the original exception, not the one with # the path relative to the project. This makes a # better error message. raise e else: if self.asvar is None: raise e url = construct_main_site_url(url) if self.asvar: context[self.asvar] = url return '' else: return url
def signin(request, redirect_field_name=REDIRECT_FIELD_NAME): redirect_to = request.REQUEST.get(redirect_field_name, settings.LOGIN_REDIRECT_URL) if request.user.is_authenticated(): return HttpResponseRedirect(redirect_to) else: sso_url = "%s?%s=%s" \ % (getattr(settings, 'SSO_URL', '/sso/'), redirect_field_name, urlquote_plus(request.get_host() + request.get_full_path()), ) return HttpResponseRedirect("%s?%s=%s&muaccount=%d" \ % (construct_main_site_url(getattr(settings, 'LOGIN_URL', '/accounts/login/'), False), redirect_field_name, urlquote_plus(sso_url), request.muaccount.pk))