-# -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from datetime import date, datetime
-from urllib import urlencode
+from urllib.parse import urlencode
from django.conf import settings
from django.contrib.sites.models import Site
-from django.core.urlresolvers import reverse
from django.core.mail import send_mail
from django.db import models
from django.dispatch import receiver
from django.template.loader import render_to_string
+from django.urls import reverse
from django.utils.timezone import utc
from django.utils.translation import ugettext_lazy as _, override
import getpaid
start = models.DateField(_('start'), db_index=True)
end = models.DateField(_('end'), db_index=True)
redakcja_url = models.URLField(_('redakcja URL'), blank=True)
- book = models.ForeignKey(Book, null=True, blank=True, help_text=_('Published book.'))
+ book = models.ForeignKey(Book, models.PROTECT, null=True, blank=True, help_text=_('Published book.'))
cover = models.ImageField(_('Cover'), upload_to='funding/covers')
poll = models.ForeignKey(Poll, help_text=_('Poll'), null=True, blank=True, on_delete=models.SET_NULL)
verbose_name_plural = _('offers')
ordering = ['-end']
- def __unicode__(self):
+ def __str__(self):
return u"%s - %s" % (self.author, self.title)
def get_absolute_url(self):
If no attached to a particular Offer, applies to all.
"""
- offer = models.ForeignKey(Offer, verbose_name=_('offer'), null=True, blank=True)
+ offer = models.ForeignKey(Offer, models.CASCADE, verbose_name=_('offer'), null=True, blank=True)
price = models.DecimalField(_('price'), decimal_places=2, max_digits=10)
name = models.CharField(_('name'), max_length=255)
long_name = models.CharField(_('long name'), max_length=255)
verbose_name_plural = _('perks')
ordering = ['-price']
- def __unicode__(self):
+ def __str__(self):
return "%s (%s%s)" % (self.name, self.price, u" for %s" % self.offer if self.offer else "")
The payment was completed if and only if payed_at is set.
"""
- offer = models.ForeignKey(Offer, verbose_name=_('offer'))
+ offer = models.ForeignKey(Offer, models.PROTECT, verbose_name=_('offer'))
name = models.CharField(_('name'), max_length=127, blank=True)
email = models.EmailField(_('email'), blank=True, db_index=True)
amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10)
""" QuerySet for all completed payments. """
return cls.objects.exclude(payed_at=None)
- def __unicode__(self):
- return unicode(self.offer)
+ def __str__(self):
+ return str(self.offer)
def get_absolute_url(self):
return reverse('funding_funding', args=[self.pk])
class Spent(models.Model):
""" Some of the remaining money spent on a book. """
- book = models.ForeignKey(Book)
+ book = models.ForeignKey(Book, models.PROTECT)
amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10)
timestamp = models.DateField(_('when'))
verbose_name_plural = _('money spent on books')
ordering = ['-timestamp']
- def __unicode__(self):
- return u"Spent: %s" % unicode(self.book)
+ def __str__(self):
+ return u"Spent: %s" % str(self.book)
@receiver(getpaid.signals.new_payment_query)