示例#1
0
文件: models.py 项目: ella/ella-wiki
 def get_absolute_url(self):
     if self.status == self.STATUS_APPROVED:
         return resolver.reverse(self.wiki, 'wiki-submission', id=self.pk)
     elif self.status == self.STATUS_PENDING:
         return resolver.reverse(self.wiki, 'wiki-queue')
     else:
         return self.wiki.get_absolute_url()
示例#2
0
 def dispatch(self, request, context, *args, **kwargs):
     self.context = context
     self.kwargs = kwargs
     last_step = storage.get_last_step(self.contest, request)
     if last_step is None:
         url = resolver.reverse(self.contest, 'ella-contests-contests-detail', question_number=1)
         return HttpResponseRedirect(url)
     if self.contest.questions_count != last_step:
         url = resolver.reverse(self.contest, 'ella-contests-contests-detail', question_number=last_step + 1)
         return HttpResponseRedirect(url)
     return super(ContestContestantView, self).dispatch(request, context, *args, **kwargs)
示例#3
0
def send_by_email(request, object_info):
    if FORCE_AJAX and not request.is_ajax():
        raise Http404('This page is only reachable by Ajax request. Forced by SEND_BY_EMAIL_FORCE_AJAX setting.')

    context = {}
    object = object_info['object']

    if request.method == 'POST':
        form = SendMailForm(request.POST)

        if form.is_valid():
            cd = form.cleaned_data
            subject = u'%s %s' % (settings.EMAIL_SUBJECT_PREFIX, _('link to `%s`') % unicode(object))
            message = render_to_string('send_email/email.html', {
                'sender': cd['sender'], 'message': cd['message'],
                'site': Site.objects.get_current(), 'url': request.build_absolute_uri(object.get_absolute_url())
            })
            recipients = (form.cleaned_data['recipient'],)
            send_mail(subject, message, settings.SERVER_EMAIL, recipients,
                fail_silently=False)
            publishable_email_sent.send(sender=object, subject=subject,
                message=message, recipients=recipients)
            if request.is_ajax():
                return send_by_email_success(request, object_info)
            else:
                return HttpResponseRedirect(resolver.reverse(object, 'send_by_email_success'))

    else:
        form = SendMailForm()

    context['form'] = form
    context.update(object_info)

    return render_to_response('send_email/form.html', context,
        context_instance=RequestContext(request))
示例#4
0
 def dispatch(self, request, context, *args, **kwargs):
     self.context = context
     self.kwargs = kwargs
     #check if user can see this step else redirect
     last_step = storage.get_last_step(self.contest, request)
     if last_step is None:
         if self.current_page == 1:
             return super(ContestDetailFormView, self).dispatch(request, context, *args, **kwargs)
         url = resolver.reverse(self.contest, 'ella-contests-contests-detail', question_number=1)
         return HttpResponseRedirect(url)
     if self.current_page != last_step + 1:
         if self.next_question:
             url = resolver.reverse(self.contest, 'ella-contests-contests-detail',
                                    question_number=self.next_question.position)
         else:
             url = resolver.reverse(self.contest, 'ella-contests-contests-contestant')
         return HttpResponseRedirect(url)
     return super(ContestDetailFormView, self).dispatch(request, context, *args, **kwargs)
示例#5
0
 def render(self, context):
     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()])
     obj = self.obj.resolve(context)
   
     url = ''
     try:
         url = resolver.reverse(obj, self.view_name, *args, **kwargs)
     except NoReverseMatch, e:
         if self.asvar is None:
             raise e
示例#6
0
 def get_absolute_url(self, reversed=False):
     return '%s?p=%d' % (
             resolver.reverse(self.content_object, 'comments-list'),
             self._comment_list(reversed).page_index(self.pk)
         )
示例#7
0
 def get_default_return_url(self, context):
     return resolver.reverse(context['object'], 'comments-list')
示例#8
0
 def get_success_url(self):
     if self.next_question:
         return self.next_question.get_absolute_url()
     return resolver.reverse(self.contest, 'ella-contests-contests-contestant')
示例#9
0
 def get_success_url(self):
     return resolver.reverse(self.contest, 'ella-contests-contests-result')
示例#10
0
 def get_absolute_url(self):
     return resolver.reverse(self.quiz, 'quiz-result', choice=self.choice)
示例#11
0
 def get_absolute_url(self):
     if self.order == 0:
         return self.gallery.get_absolute_url()
     return resolver.reverse(self.gallery, 'gallery-item-detail', self.get_slug())
示例#12
0
 def get_absolute_url(self, reversed=False):
     return '%s?p=%d' % (
             resolver.reverse(self.content_object, 'comments-list'),
             self._comment_list(reversed).page_index(self.pk)
         )
示例#13
0
 def get_absolute_url(self):
     return resolver.reverse(self.contest, 'ella-contests-contests-detail', question_number=self.position)
示例#14
0
 def get_absolute_url(self):
     if self.order == 0:
         return self.gallery.get_absolute_url()
     return resolver.reverse(self.gallery, 'gallery-item-detail',
                             self.get_slug())
示例#15
0
 def get_absolute_url(self):
     return resolver.reverse(self.quiz, 'quiz-result', choice=self.choice)