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 test_normalise(self): self.assertEqual(normalise_site("www.heroku.com"), "heroku.com") self.assertEqual(normalise_site("https://secure.gaug.es"), "gaug.es") self.assertEqual(normalise_site("http://get.gaug.es/bla"), "gaug.es") self.assertEqual(normalise_site("github.com/kylef"), "github.com")