X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/08e687e53ba84afd39646185142e59c6bfe77783..HEAD:/src/funding/models.py diff --git a/src/funding/models.py b/src/funding/models.py index 838d2ab35..5afdc2259 100644 --- a/src/funding/models.py +++ b/src/funding/models.py @@ -1,5 +1,5 @@ -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # from datetime import date, datetime from urllib.parse import urlencode @@ -12,7 +12,7 @@ from django.template.loader import render_to_string from django.urls import reverse from django.utils.html import mark_safe from django.utils.timezone import utc -from django.utils.translation import gettext_lazy as _, override +from django.utils.translation import override from catalogue.models import Book from catalogue.utils import get_random_hash from polls.models import Poll @@ -24,28 +24,28 @@ from . import utils class Offer(models.Model): """ A fundraiser for a particular book. """ - author = models.CharField(_('author'), max_length=255) - title = models.CharField(_('title'), max_length=255) - slug = models.SlugField(_('slug')) - description = models.TextField(_('description'), blank=True) - target = models.DecimalField(_('target'), decimal_places=2, max_digits=10) - 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, 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) - - notified_near = models.DateTimeField(_('Near-end notifications sent'), blank=True, null=True) - notified_end = models.DateTimeField(_('End notifications sent'), blank=True, null=True) + author = models.CharField('autor', max_length=255) + title = models.CharField('tytuł', max_length=255) + slug = models.SlugField('slug') + description = models.TextField('opis', blank=True) + target = models.DecimalField('kwota docelowa', decimal_places=2, max_digits=10) + start = models.DateField('początek', db_index=True) + end = models.DateField('koniec', db_index=True) + redakcja_url = models.URLField('URL na Redakcji', blank=True) + book = models.ForeignKey(Book, models.PROTECT, null=True, blank=True, help_text='Opublikowana książka.') + cover = models.ImageField('Okładka', upload_to='funding/covers') + poll = models.ForeignKey(Poll, help_text='Ankieta', null=True, blank=True, on_delete=models.SET_NULL) + + notified_near = models.DateTimeField('Wysłano powiadomienia przed końcem', blank=True, null=True) + notified_end = models.DateTimeField('Wysłano powiadomienia o zakończeniu', blank=True, null=True) def cover_img_tag(self): return mark_safe('' % self.cover.url) - cover_img_tag.short_description = _('Cover preview') + cover_img_tag.short_description = 'Podgląd okładki' class Meta: - verbose_name = _('offer') - verbose_name_plural = _('offers') + verbose_name = 'zbiórka' + verbose_name_plural = 'zbiórki' ordering = ['-end'] def __str__(self): @@ -69,7 +69,6 @@ class Offer(models.Model): def clear_cache(self): clear_cached_renders(self.top_bar) - clear_cached_renders(self.list_bar) clear_cached_renders(self.detail_bar) clear_cached_renders(self.status) clear_cached_renders(self.status_more) @@ -155,7 +154,7 @@ class Offer(models.Model): return assert not self.is_current() self.notify_all( - _('The fundraiser has ended!'), + _('Zbiórka dobiegła końca!'), 'funding/email/end.txt', { 'offer': self, 'is_win': self.is_win(), @@ -172,7 +171,7 @@ class Offer(models.Model): sum_ = self.sum() need = self.target - sum_ self.notify_all( - _('The fundraiser will end soon!'), + _('Zbiórka niedługo się zakończy!'), 'funding/email/near.txt', { 'days': (self.end - date.today()).days + 1, 'offer': self, @@ -186,7 +185,7 @@ class Offer(models.Model): def notify_published(self): assert self.book is not None self.notify_all( - _('The book you helped fund has been published.'), + _('Książka, którą pomogłeś/-aś ufundować, została opublikowana.'), 'funding/email/published.txt', { 'offer': self, 'book': self.book, @@ -202,12 +201,20 @@ class Offer(models.Model): 'is_current': self.is_current(), 'is_win': offer_sum >= self.target, 'missing': self.target - offer_sum, - 'percentage': 100 * offer_sum / self.target, + 'percentage': min(100, 100 * offer_sum / self.target), 'show_title': True, 'show_title_calling': True, } + @cached_render('funding/includes/offer_status.html') + def status(self): + return {'offer': self} + + @cached_render('funding/includes/offer_status_more.html') + def status_more(self): + return {'offer': self} + @cached_render('funding/includes/funding.html') def top_bar(self): ctx = self.basic_info() @@ -218,15 +225,6 @@ class Offer(models.Model): }) return ctx - @cached_render('funding/includes/funding.html') - def list_bar(self): - ctx = self.basic_info() - ctx.update({ - 'link': True, - 'show_title_calling': False, - }) - return ctx - @cached_render('funding/includes/funding.html') def detail_bar(self): ctx = self.basic_info() @@ -235,14 +233,6 @@ class Offer(models.Model): }) return ctx - @cached_render('funding/includes/offer_status.html') - def status(self): - return {'offer': self} - - @cached_render('funding/includes/offer_status_more.html') - def status_more(self): - return {'offer': self} - class Perk(models.Model): """ A perk offer. @@ -250,15 +240,15 @@ class Perk(models.Model): If no attached to a particular Offer, applies to all. """ - 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) - end_date = models.DateField(_('end date'), null=True, blank=True) + offer = models.ForeignKey(Offer, models.CASCADE, verbose_name='zbiórka', null=True, blank=True) + price = models.DecimalField('cena', decimal_places=2, max_digits=10) + name = models.CharField('nazwa', max_length=255) + long_name = models.CharField('długa nazwa', max_length=255) + end_date = models.DateField('data końcowa', null=True, blank=True) class Meta: - verbose_name = _('perk') - verbose_name_plural = _('perks') + verbose_name = 'prezent' + verbose_name_plural = 'prezenty' ordering = ['-price'] def __str__(self): @@ -271,21 +261,21 @@ class Funding(club.payu.models.Order): The payment was completed if and only if completed_at is set. """ - offer = models.ForeignKey(Offer, models.PROTECT, verbose_name=_('offer')) - customer_ip = models.GenericIPAddressField(_('customer IP'), null=True) + offer = models.ForeignKey(Offer, models.PROTECT, verbose_name='zbiórka') + customer_ip = models.GenericIPAddressField('adres IP', null=True, blank=True) - name = models.CharField(_('name'), max_length=127, blank=True) - email = models.EmailField(_('email'), blank=True, db_index=True) + name = models.CharField('nazwa', max_length=127, blank=True) + email = models.EmailField('e-mail', blank=True, db_index=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, models.SET_NULL, blank=True, null=True) - amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10) - perks = models.ManyToManyField(Perk, verbose_name=_('perks'), blank=True) + amount = models.DecimalField('kwota', decimal_places=2, max_digits=10) + perks = models.ManyToManyField(Perk, verbose_name='prezenty', blank=True) language_code = models.CharField(max_length=2, null=True, blank=True) - notifications = models.BooleanField(_('notifications'), default=True, db_index=True) - notify_key = models.CharField(max_length=32) + notifications = models.BooleanField('powiadomienia', default=True, db_index=True) + notify_key = models.CharField(max_length=32, blank=True) class Meta: - verbose_name = _('funding') - verbose_name_plural = _('fundings') + verbose_name = 'wpłata' + verbose_name_plural = 'wpłaty' ordering = ['-completed_at', 'pk'] @classmethod @@ -382,15 +372,31 @@ class PayUNotification(club.payu.models.Notification): class Spent(models.Model): """ Some of the remaining money spent on a book. """ - book = models.ForeignKey(Book, models.PROTECT) - amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10) - timestamp = models.DateField(_('when')) + book = models.ForeignKey( + Book, models.PROTECT, null=True, blank=True, + verbose_name='książka', + help_text='Książka, na którą zostały wydatkowane środki. ' + 'Powinny tu być uwzględnione zarówno książki na które zbierano środki, jak i dodatkowe książki ' + 'sfinansowane z nadwyżek ze zbiórek.' + ) + link = models.URLField( + blank=True, + help_text="Jeśli wydatek nie dotyczy pojedynczej książki, to zamiast pola „Książka” " + "powinien zostać uzupełniony link do sfinansowanego obiektu (np. kolekcji)." + ) + amount = models.DecimalField('kwota', decimal_places=2, max_digits=10) + timestamp = models.DateField('kiedy') + annotation = models.CharField( + 'adnotacja', max_length=255, blank=True, + help_text="Adnotacja pojawi się w nawiasie w rozliczeniu, by wyjaśnić sytuację w której " + "do tej samej książki może być przypisany więcej niż jeden wydatek. " + "Np. osobny wydatek na audiobook może mieć adnotację „audiobook”.") class Meta: - verbose_name = _('money spent on a book') - verbose_name_plural = _('money spent on books') + verbose_name = 'pieniądze wydane na książkę' + verbose_name_plural = 'pieniądze wydane na książki' ordering = ['-timestamp'] def __str__(self): - return "Spent: %s" % str(self.book) + return "Wydane na: %s" % str(self.book or self.link)