X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0679f997bb4e0583f2425b0abd07186e44c26915..c0a7799619e217e2eac724b1a688ad37f0182253:/src/funding/models.py?ds=inline diff --git a/src/funding/models.py b/src/funding/models.py index b126c7681..2b4372fe1 100644 --- a/src/funding/models.py +++ b/src/funding/models.py @@ -1,16 +1,15 @@ -# -*- 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 @@ -31,7 +30,7 @@ class Offer(models.Model): 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) @@ -48,7 +47,7 @@ class Offer(models.Model): 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): @@ -207,7 +206,7 @@ class Perk(models.Model): 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) @@ -218,7 +217,7 @@ class Perk(models.Model): 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 "") @@ -228,7 +227,7 @@ class Funding(models.Model): 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) @@ -248,8 +247,8 @@ class Funding(models.Model): """ 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]) @@ -309,7 +308,7 @@ getpaid.register_to_payment(Funding, unique=False, related_name='payment') 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')) @@ -318,8 +317,8 @@ class Spent(models.Model): 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)