Exemple #1
0
    def handle_site(self, request, domain):
        self.site = None

        # we silently fail on errors

        if not request.browserid:
            messages.error(request, 'You are not logged in')
            return

        domain = normalise_site(domain)
        if not domain:
            messages.error(request, "The domain '%s' does not look valid" % domain)
            return

        try:
            self.site = Site.objects.filter(domain=domain).get()
        except ObjectDoesNotExist:
            self.site = Site(domain=domain)
            self.site.save()
            messages.success(request, 'You have voted for %s' % self.site)

        vote = Vote(voter=unicode(request.browserid), website=self.site)

        try:
            vote.save()
        except:
            messages.error(request, 'You have already voted for this site.')
            return
Exemple #2
0
class DemandView(RedirectView):
    def get_redirect_url(self, **kwargs):
        if self.site:
            return self.site.get_absolute_url()
        return '/'

    def handle_site(self, request, domain):
        self.site = None

        # we silently fail on errors

        if not request.browserid:
            messages.error(request, 'You are not logged in')
            return

        domain = normalise_site(domain)
        if not domain:
            messages.error(request, "The domain '%s' does not look valid" % domain)
            return

        try:
            self.site = Site.objects.filter(domain=domain).get()
        except ObjectDoesNotExist:
            self.site = Site(domain=domain)
            self.site.save()
            messages.success(request, 'You have voted for %s' % self.site)

        vote = Vote(voter=unicode(request.browserid), website=self.site)

        try:
            vote.save()
        except:
            messages.error(request, 'You have already voted for this site.')
            return

    def get(self, request, site):
        self.handle_site(request, site)
        return super(DemandView, self).get(request)

    def post(self, request, site=None):
        self.handle_site(request, request.POST.get('site'))
        return super(DemandView, self).get(request)