+ return unicode(self.offer)
+
+ def get_absolute_url(self):
+ return reverse('funding_funding', args=[self.pk])
+
+ def perk_names(self):
+ return ", ".join(perk.name for perk in self.perks.all())
+
+ def get_disable_notifications_url(self):
+ return "%s?%s" % (reverse("funding_disable_notifications"),
+ urlencode({
+ 'email': self.email,
+ 'key': self.notify_key,
+ }))
+
+ def save(self, *args, **kwargs):
+ if self.email and not self.notify_key:
+ self.notify_key = get_random_hash(self.email)
+ ret = super(Funding, self).save(*args, **kwargs)
+ self.offer.flush_includes()
+ return ret
+
+ @classmethod
+ def notify_funders(cls, subject, template_name, extra_context=None,
+ query_filter=None, payed_only=True):
+ funders = cls.objects.exclude(email="").filter(notifications=True)
+ if payed_only:
+ funders = funders.exclude(payed_at=None)
+ if query_filter is not None:
+ funders = funders.filter(query_filter)
+ emails = set()
+ for funder in funders:
+ if funder.email in emails:
+ continue
+ emails.add(funder.email)
+ funder.notify(subject, template_name, extra_context)
+
+ def notify(self, subject, template_name, extra_context=None):
+ context = {
+ 'funding': self,
+ 'site': Site.objects.get_current(),
+ }
+ if extra_context:
+ context.update(extra_context)
+ with override(self.language_code or app_settings.DEFAULT_LANGUAGE):
+ send_mail(subject,
+ render_to_string(template_name, context),
+ settings.CONTACT_EMAIL,
+ [self.email],
+ fail_silently=False
+ )
+
+ def disable_notifications(self):
+ """Disables all notifications for this e-mail address."""
+ type(self).objects.filter(email=self.email).update(notifications=False)
+
+
+# Register the Funding model with django-getpaid for payments.
+getpaid.register_to_payment(Funding, unique=False, related_name='payment')