From: Radek Czajka Date: Tue, 12 Nov 2013 11:57:43 +0000 (+0100) Subject: Merge branch 'master' into rwd X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/7f0caf88dd3aac2e4d5bb4ee064137e03ecd4f03?hp=9f4f697f0c6fe9a9d55bb45aaa93c804992f3339 Merge branch 'master' into rwd Conflicts: apps/wolnelektury_core/templates/superbase.html --- diff --git a/apps/api/handlers.py b/apps/api/handlers.py index 7f74c19e7..da5c0ed27 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -105,10 +105,6 @@ class BookMediaHandler(BaseHandler): class BookDetails(object): """Custom fields used for representing Books.""" - @classmethod - def author(cls, book): - return ",".join(t[0] for t in book.related_info()['tags'].get('author', [])) - @classmethod def href(cls, book): """ Returns an URI for a Book in the API. """ @@ -168,7 +164,12 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails): """ allowed_methods = ('GET',) model = Book - fields = ['author', 'href', 'title', 'url', 'cover'] + fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb'] + + @classmethod + def genres(cls, book): + """ Returns all media for a book. """ + return book.tags.filter(category='genre') @piwik_track def read(self, request, tags, top_level=False, @@ -214,7 +215,7 @@ class AnonymousBooksHandler(AnonymousBaseHandler, BookDetails): class BooksHandler(BookDetailHandler): allowed_methods = ('GET', 'POST') model = Book - fields = ['author', 'href', 'title', 'url'] + fields = book_tag_categories + ['href', 'title', 'url', 'cover', 'cover_thumb'] anonymous = AnonymousBooksHandler def create(self, request, *args, **kwargs): @@ -240,8 +241,14 @@ def _tags_getter(category): def get_tags(cls, book): return book.tags.filter(category=category) return get_tags +def _tag_getter(category): + @classmethod + def get_tag(cls, book): + return ", ".join(t[0] for t in book.related_info()['tags'].get(category, [])) + return get_tag for plural, singular in category_singular.items(): setattr(BookDetails, plural, _tags_getter(singular)) + setattr(BookDetails, singular, _tag_getter(singular)) # add fields for files in Book def _file_getter(format): diff --git a/apps/catalogue/locale/pl/LC_MESSAGES/django.mo b/apps/catalogue/locale/pl/LC_MESSAGES/django.mo index 62671f116..6c1e2b692 100644 Binary files a/apps/catalogue/locale/pl/LC_MESSAGES/django.mo and b/apps/catalogue/locale/pl/LC_MESSAGES/django.mo differ diff --git a/apps/catalogue/locale/pl/LC_MESSAGES/django.po b/apps/catalogue/locale/pl/LC_MESSAGES/django.po index a2d12acae..1ecf8316d 100644 --- a/apps/catalogue/locale/pl/LC_MESSAGES/django.po +++ b/apps/catalogue/locale/pl/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-06-19 14:10+0200\n" -"PO-Revision-Date: 2013-06-19 14:10+0100\n" +"POT-Creation-Date: 2013-08-07 12:31+0200\n" +"PO-Revision-Date: 2013-08-07 12:32+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" @@ -98,7 +98,7 @@ msgstr "Błąd podczas importowania pliku: %r" msgid "Download custom PDF" msgstr "Stwórz własny PDF" -#: views.py:557 templates/catalogue/book_short.html:92 +#: views.py:557 templates/catalogue/book_short.html:96 #: templates/catalogue/book_text.html:27 templates/catalogue/book_wide.html:63 msgid "Download" msgstr "Pobierz" @@ -272,7 +272,7 @@ msgstr "" "Możecie z niej korzystać bezpłatnie i bez ograniczeń.\n" "Audiobooki nagrywają znani aktorzy, wśród nich Danuta Stenka i Jan Peszek." -#: templates/catalogue/book_detail.html:20 +#: templates/catalogue/book_detail.html:21 #: templates/catalogue/tagged_object_list.html:74 #: templates/catalogue/tagged_object_list.html:104 msgid "See also" @@ -303,7 +303,7 @@ msgid "" "Commons Attribution-ShareAlike 3.0\n" " license." msgstr "" -"Ten utwór nie jest chroniony prawem autorskim i znajduje się w " +"Ten utwór nie jest objęty majątkowym prawem autorskim i znajduje się w " "domenie publicznej, co oznacza że możesz go swobodnie wykorzystywać, " "publikować i rozpowszechniać. Jeśli utwór opatrzony jest dodatkowymi " "materiałami (przypisy, motywy literackie etc.), które podlegają prawu " @@ -320,6 +320,10 @@ msgid "Edited and annotated by:" msgstr "Opracowanie redakcyjne i przypisy:" #: templates/catalogue/book_info.html:33 +msgid "Publication funded by:" +msgstr "Publikację ufundowali i ufundowały:" + +#: templates/catalogue/book_info.html:41 msgid "Cover image by:" msgstr "Ilustracja na okładce:" @@ -331,53 +335,53 @@ msgstr "Spis wszystkich utworów" msgid "Table of Content" msgstr "Spis treści" -#: templates/catalogue/book_list.html:30 +#: templates/catalogue/book_list.html:31 msgid "↑ top ↑" msgstr "↑ góra ↑" -#: templates/catalogue/book_short.html:59 +#: templates/catalogue/book_short.html:61 #: templates/catalogue/picture_detail.html:54 msgid "Epoch" msgstr "Epoka" -#: templates/catalogue/book_short.html:66 +#: templates/catalogue/book_short.html:69 #: templates/catalogue/picture_detail.html:60 msgid "Kind" msgstr "Rodzaj" -#: templates/catalogue/book_short.html:73 +#: templates/catalogue/book_short.html:77 msgid "Genre" msgstr "Gatunek" -#: templates/catalogue/book_short.html:88 +#: templates/catalogue/book_short.html:92 msgid "Read online" msgstr "Czytaj online" -#: templates/catalogue/book_short.html:95 +#: templates/catalogue/book_short.html:99 #: templates/catalogue/book_text.html:40 msgid "to print" msgstr "do druku" -#: templates/catalogue/book_short.html:98 +#: templates/catalogue/book_short.html:102 msgid "for an e-book reader" msgstr "na czytnik e-booków" -#: templates/catalogue/book_short.html:101 +#: templates/catalogue/book_short.html:105 #: templates/catalogue/book_text.html:46 msgid "for Kindle" msgstr "na Kindle" -#: templates/catalogue/book_short.html:104 +#: templates/catalogue/book_short.html:108 #: templates/catalogue/book_text.html:49 msgid "FictionBook" msgstr "FictionBook" -#: templates/catalogue/book_short.html:107 +#: templates/catalogue/book_short.html:111 #: templates/catalogue/book_text.html:52 msgid "for advanced usage" msgstr "do zadań specjalnych" -#: templates/catalogue/book_short.html:113 +#: templates/catalogue/book_short.html:117 #: templates/catalogue/book_text.html:30 msgid "Listen" msgstr "Słuchaj" @@ -456,6 +460,7 @@ msgid "Mix this book" msgstr "Miksuj treść utworu" #: templates/catalogue/catalogue.html:6 templates/catalogue/catalogue.html:11 +#: templates/catalogue/menu.html:5 msgid "Catalogue" msgstr "Katalog" @@ -495,7 +500,7 @@ msgstr "Epoki" msgid "Themes and topics" msgstr "Motywy i tematy" -#: templates/catalogue/catalogue.html:34 templates/catalogue/menu.html:16 +#: templates/catalogue/catalogue.html:34 templates/catalogue/menu.html:20 msgid "Collections" msgstr "Kolekcje" @@ -539,19 +544,23 @@ msgstr "Zwiń fragment" msgid "See full category" msgstr "Zobacz całą kategorię" -#: templates/catalogue/menu.html:9 templates/catalogue/menu.html.py:18 +#: templates/catalogue/menu.html:4 +msgid "Catalogue of the library" +msgstr "" + +#: templates/catalogue/menu.html:13 templates/catalogue/menu.html.py:22 msgid "Please wait…" msgstr "Proszę czekać…" -#: templates/catalogue/menu.html:24 +#: templates/catalogue/menu.html:28 msgid "All books" msgstr "Wszystkie utwory" -#: templates/catalogue/menu.html:28 +#: templates/catalogue/menu.html:32 msgid "Audiobooks" msgstr "Audiobooki" -#: templates/catalogue/menu.html:32 +#: templates/catalogue/menu.html:36 msgid "DAISY" msgstr "DAISY" diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index e80b8af73..d69cf2aca 100644 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -75,7 +75,7 @@ class Book(models.Model): self.sort_key = sortify(self.title) - ret = super(Book, self).save(force_insert, force_update) + ret = super(Book, self).save(force_insert, force_update, **kwargs) if reset_short_html: self.reset_short_html() @@ -511,10 +511,11 @@ class Book(models.Model): """ # get relevant books and their tags objects = cls.tagged.with_all(tags) + parents = objects.filter(html_file='').only('slug') # eliminate descendants l_tags = Tag.objects.filter(category='book', - slug__in=[book.book_tag_slug() for book in objects.iterator()]) - descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).iterator()] + slug__in=[book.book_tag_slug() for book in parents.iterator()]) + descendants_keys = [book.pk for book in cls.tagged.with_any(l_tags).only('pk').iterator()] if descendants_keys: objects = objects.exclude(pk__in=descendants_keys) diff --git a/apps/catalogue/models/listeners.py b/apps/catalogue/models/listeners.py index cb106166e..373a2fcc8 100644 --- a/apps/catalogue/models/listeners.py +++ b/apps/catalogue/models/listeners.py @@ -40,6 +40,14 @@ def _pre_delete_handler(sender, instance, **kwargs): pre_delete.connect(_pre_delete_handler) +def _post_delete_handler(sender, instance, **kwargs): + """ refresh Book on BookMedia delete """ + if sender == Collection: + permanent_cache.delete('catalogue.collection:%s' % instance.slug) + permanent_cache.delete('catalogue.catalogue') +post_delete.connect(_post_delete_handler) + + def _post_save_handler(sender, instance, **kwargs): """ refresh all the short_html stuff on BookMedia update """ if sender == BookMedia: @@ -48,6 +56,7 @@ def _post_save_handler(sender, instance, **kwargs): 'catalogue.audiobook_list', 'catalogue.daisy_list']) elif sender == Collection: permanent_cache.delete('catalogue.collection:%s' % instance.slug) + permanent_cache.delete('catalogue.catalogue') post_save.connect(_post_save_handler) @@ -63,9 +72,5 @@ if not settings.NO_SEARCH_INDEX: """ remove the book from search index, when it is deleted.""" import search idx = search.Index() - idx.open(timeout=10000) # 10 seconds timeout. - try: - idx.remove_book(instance) - idx.index_tags() - finally: - idx.close() + idx.remove_book(instance) + idx.index_tags() diff --git a/apps/catalogue/templates/catalogue/book_info.html b/apps/catalogue/templates/catalogue/book_info.html index c5006f1ed..a90ccdc87 100755 --- a/apps/catalogue/templates/catalogue/book_info.html +++ b/apps/catalogue/templates/catalogue/book_info.html @@ -29,6 +29,12 @@ {% all_editors book.extra_info %}.

{% endif %} +{% if book.extra_info.funders %} +

{% trans "Publication funded by:" %} + {% for funder in book.extra_info.funders %}{{ funder }}{% if not forloop.last %}, {% else %}.{% endif %}{% endfor %} +

+{% endif %} + {% if book.extra_info.cover_by %}

{% trans "Cover image by:" %} diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index d69e5428c..e9b1465dd 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -186,7 +186,7 @@ def tagged_object_list(request, tags=''): # get related tags from `tag_counter` and `theme_counter` related_counts = {} tags_pks = [tag.pk for tag in tags] - for book in objects.iterator(): + for book in objects: for tag_pk, value in itertools.chain(book.tag_counter.iteritems(), book.theme_counter.iteritems()): if tag_pk in tags_pks: continue diff --git a/apps/dictionary/templates/dictionary/note_list.html b/apps/dictionary/templates/dictionary/note_list.html index 097457eda..5bf9e3f4c 100755 --- a/apps/dictionary/templates/dictionary/note_list.html +++ b/apps/dictionary/templates/dictionary/note_list.html @@ -35,7 +35,7 @@ {% blocktrans count object_list.count as c %}{{c}} footnote found{% plural %}{{c}} footnotes found{% endblocktrans %}

-{% if object_list %} +{% if object_list.exists %} {% autopaginate object_list 100 %} {% paginate %} diff --git a/apps/funding/__init__.py b/apps/funding/__init__.py index e69de29bb..9e81e9ec3 100644 --- a/apps/funding/__init__.py +++ b/apps/funding/__init__.py @@ -0,0 +1,17 @@ +# -*- 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 django.conf import settings as settings +from catalogue.utils import AppSettings + + +class Settings(AppSettings): + """Default settings for funding app.""" + DEFAULT_LANGUAGE = u'pl' + DEFAULT_AMOUNT = 20 + MIN_AMOUNT = 1 + DAYS_NEAR = 2 + + +app_settings = Settings('FUNDING') diff --git a/apps/funding/admin.py b/apps/funding/admin.py index 66cff10f7..d70aef66a 100644 --- a/apps/funding/admin.py +++ b/apps/funding/admin.py @@ -1,23 +1,62 @@ +# -*- 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 django.utils.translation import ugettext_lazy as _ from django.contrib import admin from .models import Offer, Perk, Funding, Spent class OfferAdmin(admin.ModelAdmin): model = Offer - list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end', 'due'] + list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end'] search_fields = ['title', 'author'] readonly_fields = ('cover_img_tag',) class PerkAdmin(admin.ModelAdmin): model = Perk + search_fields = ['name', 'long_name'] list_display = ['name', 'long_name', 'price', 'end_date', 'offer'] + list_filter = ['offer'] + + + +class PayedFilter(admin.SimpleListFilter): + title = _('payment complete') + parameter_name = 'payed' + def lookups(self, request, model_admin): + return ( + ('yes', _('Yes')), + ('no', _('No')), + ) + def queryset(self, request, queryset): + if self.value() == 'yes': + return queryset.exclude(payed_at=None) + elif self.value() == 'no': + return queryset.filter(payed_at=None) + +class PerksFilter(admin.SimpleListFilter): + title = _('perks') + parameter_name = 'perks' + def lookups(self, request, model_admin): + return ( + ('yes', _('Yes')), + ('no', _('No')), + ) + def queryset(self, request, queryset): + if self.value() == 'yes': + return queryset.exclude(perks=None) + elif self.value() == 'no': + return queryset.filter(perks=None) class FundingAdmin(admin.ModelAdmin): model = Funding - list_display = ['payed_at', 'offer', 'amount', 'name', 'email'] + list_display = ['payed_at', 'offer', 'amount', 'name', 'email', 'perk_names'] search_fields = ['name', 'email', 'offer__title', 'offer__author'] + list_filter = [PayedFilter, 'offer', PerksFilter] + class SpentAdmin(admin.ModelAdmin): diff --git a/apps/funding/forms.py b/apps/funding/forms.py index dc0e6236d..64cceb6ad 100644 --- a/apps/funding/forms.py +++ b/apps/funding/forms.py @@ -1,9 +1,13 @@ -from django.conf import settings +# -*- 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 django import forms from django.utils import formats from django.utils.translation import ugettext_lazy as _, ugettext, get_language from .models import Funding from .widgets import PerksAmountWidget +from . import app_settings class FundingForm(forms.Form): @@ -14,8 +18,9 @@ class FundingForm(forms.Form): name = forms.CharField(label=_("Name"), required=False, help_text=_("Optional name for public list of contributors")) email = forms.EmailField(label=_("Contact e-mail"), - help_text=_("We'll use it to contact you about your perks and fundraiser status and payment updates.
" - "Won't be publicised."), required=False) + help_text=_("We'll use it to contact you about the details needed for your perks,
" + "and to send you updates about your payment and the fundraiser status (which you can always turn off).
" + "Your e-mail won't be publicised."), required=False) def __init__(self, offer, *args, **kwargs): self.offer = offer @@ -23,10 +28,10 @@ class FundingForm(forms.Form): self.fields['amount'].widget.form_instance = self def clean_amount(self): - if self.cleaned_data['amount'] < settings.FUNDING_MIN_AMOUNT: - min_amount = settings.FUNDING_MIN_AMOUNT - if isinstance(settings.FUNDING_MIN_AMOUNT, float): - min_amount = formats.number_format(settings.FUNDING_MIN_AMOUNT, 2) + if self.cleaned_data['amount'] < app_settings.MIN_AMOUNT: + min_amount = app_settings.MIN_AMOUNT + if isinstance(min_amount, float): + min_amount = formats.number_format(min_amount, 2) raise forms.ValidationError( ugettext("The minimum amount is %(amount)s PLN.") % { 'amount': min_amount}) diff --git a/apps/funding/locale/pl/LC_MESSAGES/django.mo b/apps/funding/locale/pl/LC_MESSAGES/django.mo index a2ca35f45..9f86a860d 100644 Binary files a/apps/funding/locale/pl/LC_MESSAGES/django.mo and b/apps/funding/locale/pl/LC_MESSAGES/django.mo differ diff --git a/apps/funding/locale/pl/LC_MESSAGES/django.po b/apps/funding/locale/pl/LC_MESSAGES/django.po index 716871916..9b4e03449 100644 --- a/apps/funding/locale/pl/LC_MESSAGES/django.po +++ b/apps/funding/locale/pl/LC_MESSAGES/django.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-06-26 15:26+0200\n" -"PO-Revision-Date: 2013-06-26 15:32+0100\n" +"POT-Creation-Date: 2013-08-02 14:02+0200\n" +"PO-Revision-Date: 2013-08-02 14:00+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: LANGUAGE \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -18,199 +19,220 @@ msgstr "" "|| n%100>=20) ? 1 : 2);\n" "X-Generator: Poedit 1.5.4\n" -#: forms.py:12 templates/funding/wlfund.html:27 +#: admin.py:26 +msgid "payment complete" +msgstr "płatność doszła do skutku" + +#: admin.py:30 admin.py:44 +msgid "Yes" +msgstr "Tak" + +#: admin.py:31 admin.py:45 +msgid "No" +msgstr "Nie" + +#: admin.py:40 models.py:197 models.py:215 +msgid "perks" +msgstr "prezenty" + +#: forms.py:16 templates/funding/wlfund.html:27 msgid "Amount" msgstr "Kwota" -#: forms.py:14 +#: forms.py:18 msgid "Name" msgstr "Imię i nazwisko na listę darczyńców" -#: forms.py:15 +#: forms.py:19 msgid "Optional name for public list of contributors" -msgstr "Opcjonalnie imię i nazwisko lub pseudonim do listy darczyńców." +msgstr "" +"Opcjonalnie imię i nazwisko lub pseudonim do publicznej listy darczyńców." -#: forms.py:16 +#: forms.py:20 msgid "Contact e-mail" msgstr "E-mail kontaktowy" -#: forms.py:17 +#: forms.py:21 msgid "" -"We'll use it to contact you about your perks and fundraiser status and " -"payment updates.
Won't be publicised." +"We'll use it to contact you about the details needed for your perks,
and to send you updates about your payment and the fundraiser " +"status (which you can always turn off).
Your e-mail won't be publicised." msgstr "" -"Użyjemy go do kontaktu w sprawie prezentów i informacji o zmianach statusu " -"zbiórki i kolejnych akcjach.
Nie będzie publikowany." +"Użyjemy go do kontaktu w sprawie danych potrzebnych do realizacji " +"prezentów
i do informowania Cię o zmianach statusu płatności i " +"zbiórki (z czego zawsze możesz zrezygnować).
Twój adres e-mail nie " +"będzie upubliczniony." -#: forms.py:28 +#: forms.py:36 #, python-format msgid "The minimum amount is %(amount)s PLN." msgstr "Minimalna kwota wpłaty to %(amount)s zł." -#: forms.py:34 +#: forms.py:42 msgid "This offer is out of date." msgstr "Ta zbiórka jest już nieaktywna." -#: models.py:19 +#: models.py:23 msgid "author" msgstr "autor" -#: models.py:20 +#: models.py:24 msgid "title" msgstr "tytuł" -#: models.py:21 +#: models.py:25 msgid "slug" msgstr "slug" -#: models.py:22 +#: models.py:26 msgid "description" msgstr "opis" -#: models.py:23 +#: models.py:27 msgid "target" msgstr "kwota docelowa" -#: models.py:24 +#: models.py:28 msgid "start" msgstr "początek" -#: models.py:25 +#: models.py:29 msgid "end" msgstr "koniec" -#: models.py:26 -msgid "due" -msgstr "data publikacji" - -#: models.py:27 -msgid "When will it be published if the money is raised." -msgstr "Kiedy książka zostanie opublikowana, jeśli uda się zebrać pieniądze." - -#: models.py:28 +#: models.py:30 msgid "redakcja URL" msgstr "URL na Redakcji" -#: models.py:30 +#: models.py:32 msgid "Published book." msgstr "Opublikowana książka." -#: models.py:31 +#: models.py:33 msgid "Cover" msgstr "Okładka" -#: models.py:32 +#: models.py:34 msgid "Poll" msgstr "Ankieta" #: models.py:36 +msgid "Near-end notifications sent" +msgstr "Wysłano powiadomienia przed końcem" + +#: models.py:37 +msgid "End notifications sent" +msgstr "Wysłano powiadomienia o zakończeniu" + +#: models.py:41 msgid "Cover preview" msgstr "Podgląd okładki" -#: models.py:40 models.py:114 models.py:135 +#: models.py:45 models.py:189 models.py:210 msgid "offer" msgstr "zbiórka" -#: models.py:41 +#: models.py:46 msgid "offers" msgstr "zbiórki" -#: models.py:115 +#: models.py:144 +msgid "The fundraiser has ended!" +msgstr "Zbiórka dobiegła końca!" + +#: models.py:160 +msgid "The fundraiser will end soon!" +msgstr "Zbiórka niedługo się zakończy!" + +#: models.py:174 +msgid "The book you helped fund has been published." +msgstr "Książka, którą pomogłeś/-aś ufundować, została opublikowana." + +#: models.py:190 msgid "price" msgstr "cena" -#: models.py:116 models.py:136 +#: models.py:191 models.py:211 msgid "name" msgstr "nazwa" -#: models.py:117 +#: models.py:192 msgid "long name" msgstr "długa nazwa" -#: models.py:118 +#: models.py:193 msgid "end date" msgstr "data końcowa" -#: models.py:121 +#: models.py:196 msgid "perk" msgstr "prezent" -#: models.py:122 models.py:140 -msgid "perks" -msgstr "prezenty" - -#: models.py:137 +#: models.py:212 msgid "email" msgstr "e-mail" -#: models.py:138 models.py:168 +#: models.py:213 models.py:293 msgid "amount" msgstr "kwota" -#: models.py:139 +#: models.py:214 msgid "payed at" msgstr "data wpłaty" -#: models.py:151 +#: models.py:217 +msgid "notifications" +msgstr "powiadomienia" + +#: models.py:221 msgid "funding" msgstr "wpłata" -#: models.py:152 +#: models.py:222 templates/admin/funding/offer/change_form.html:22 msgid "fundings" msgstr "wpłaty" -#: models.py:169 +#: models.py:294 msgid "when" msgstr "kiedy" -#: models.py:172 +#: models.py:297 msgid "money spent on a book" msgstr "pieniądze wydane na książkę" -#: models.py:173 +#: models.py:298 msgid "money spent on books" msgstr "pieniądze wydane na książki" -#: models.py:203 templates/funding/thanks.html:6 +#: models.py:324 templates/funding/thanks.html:6 #: templates/funding/thanks.html.py:13 msgid "Thank you for your support!" msgstr "Dziękujemy za Twoje wsparcie!" -#: templates/funding/email.txt:3 -msgid "Hi" -msgstr "Cześć" - -#: templates/funding/email.txt:5 -msgid "" -"Thank you for your support - thanks to you we will set another book free." -msgstr "Dziękujemy za wsparcie - dzięki Tobie uwolnimy kolejną książkę." +#: templates/funding/disable_notifications.html:5 +#: templates/funding/no_thanks.html:5 templates/funding/no_thanks.html.py:9 +msgid "Payment failed" +msgstr "Płatność nie doszła do skutku" -#: templates/funding/email.txt:7 -msgid "The book will be supplemented with your name as a donor." -msgstr "" -"Twoje imię i nazwisko lub pseudonim zostaną dodane do listy darczyńców przy " -"opublikowanej książce." +#: templates/funding/disable_notifications.html:9 +#: templates/funding/disable_notifications.html:16 +msgid "Disable notifications" +msgstr "Wyłącz powiadomienia" -#: templates/funding/email.txt:9 -msgid "" -"We will contact you to keep you informed about your perks,\n" -"status changes to this fundraiser and the incoming ones that we plan to " -"launch." -msgstr "" -"Skontaktujemy się Tobą w sprawie prezentów i informacji o zmianach statusu " -"zbiórki oraz kolejnych akcjach." +#: templates/funding/disable_notifications.html:14 +#, python-format +msgid "Are you sure you want to disable notifications for address %(e)s?" +msgstr "Czy na pewno chcesz wyłączyć powiadomienia dla adresu %(e)s?" -#: templates/funding/email.txt:12 -msgid "" -"Cheers,\n" -"Wolne Lektury team" -msgstr "" -"Pozdrawiamy,\n" -"zespół Wolnych Lektur" +#: templates/funding/disable_notifications.html:21 +#, python-format +msgid "Notifications for address %(e)s have been successfully disabled." +msgstr "Powiadomienia dla adresu %(e)s zostały wyłączone." -#: templates/funding/no_thanks.html:5 templates/funding/no_thanks.html.py:9 -msgid "Payment failed" -msgstr "Płatność nie doszła do skutku" +#: templates/funding/disable_notifications.html:27 +#, python-format +msgid "Return to the
current fundraiser." +msgstr "Wróć do aktualnej zbiórki." #: templates/funding/no_thanks.html:12 msgid "You're support has not been processed successfully." @@ -225,13 +247,13 @@ msgstr "" "Wróć do aktualnej zbiórki i spróbuj ponownie lub " "użyj innej metody płatności." -#: templates/funding/offer_detail.html:32 templates/funding/offer_list.html:29 +#: templates/funding/offer_detail.html:32 templates/funding/offer_list.html:31 #: templates/funding/tags/funding.html:20 #: templates/funding/tags/funding.html:46 msgid "Help free the book!" msgstr "Pomóż uwolnić książkę!" -#: templates/funding/offer_detail.html:36 templates/funding/thanks.html:29 +#: templates/funding/offer_detail.html:36 templates/funding/thanks.html:33 #: templates/funding/wlfund.html:17 templates/funding/tags/funding.html:12 msgid "Learn more" msgstr "Dowiedz się więcej" @@ -240,27 +262,27 @@ msgstr "Dowiedz się więcej" msgid "Support the publication" msgstr "Wesprzyj publikację" -#: templates/funding/offer_detail.html:51 +#: templates/funding/offer_detail.html:50 msgid "Donate!" msgstr "Wpłać!" -#: templates/funding/offer_detail.html:59 templates/funding/thanks.html:35 +#: templates/funding/offer_detail.html:58 templates/funding/thanks.html:39 msgid "Tell your friends!" msgstr "Powiedz swoim znajomym!" -#: templates/funding/offer_detail.html:60 +#: templates/funding/offer_detail.html:59 msgid "Support Wolne Lektury!" msgstr "Wesprzyj Wolne Lektury!" -#: templates/funding/offer_detail.html:63 +#: templates/funding/offer_detail.html:62 msgid "See all fundraisers." msgstr "Zobacz wszystkie zbiórki." -#: templates/funding/offer_detail.html:68 +#: templates/funding/offer_detail.html:67 msgid "Supporters" msgstr "Wpłaty" -#: templates/funding/offer_detail.html:82 +#: templates/funding/offer_detail.html:81 msgid "Anonymous" msgstr "Anonim" @@ -268,11 +290,15 @@ msgstr "Anonim" msgid "All fundraisers" msgstr "Wszystkie zbiórki" -#: templates/funding/offer_list.html:20 +#: templates/funding/offer_list.html:17 msgid "Current fundraiser:" msgstr "Aktualna zbiórka:" -#: templates/funding/offer_list.html:22 templates/funding/offer_list.html:37 +#: templates/funding/offer_list.html:23 +msgid "No fundraiser is currently running." +msgstr "Obecnie nie jest aktywna żadna zbiórka." + +#: templates/funding/offer_list.html:24 templates/funding/offer_list.html:39 msgid "Previous fundraisers:" msgstr "Poprzednie zbiórki:" @@ -280,38 +306,44 @@ msgstr "Poprzednie zbiórki:" msgid "Thank you!" msgstr "Dziękujemy!" -#: templates/funding/thanks.html:16 -#: templates/funding/tags/offer_status.html:22 +#: templates/funding/thanks.html:14 +msgid "We will contact you if you qualify for perks." +msgstr "Skontaktujemy się z Tobą w sprawie prezentów, które wybrałeś/-aś." + +#: templates/funding/thanks.html:17 +#: templates/funding/tags/offer_status.html:24 msgid "Full amount was successfully raised!" msgstr "Udało się zebrać pełną kwotę!" -#: templates/funding/thanks.html:18 templates/funding/tags/offer_status.html:6 +#: templates/funding/thanks.html:19 #, python-format msgid "" -"The fundraiser\n" -" ends on %(end)s. The book will be published by %(due)s." -msgstr "Zbiórka kończy się %(end)s. Książka zostanie opublikowana do %(due)s." +"Your donation will be spent on digitizing, compiling and\n" +" publishing the book %(b)s in multiple formats." +msgstr "" +"Wpłacone przez Ciebie pieniądze przeznaczymy na digitalizację, opracowanie i " +"udostępnienie książki %(b)s w bibliotece w wielu formatach." -#: templates/funding/thanks.html:22 +#: templates/funding/thanks.html:24 #, python-format msgid "" -"Your donation will be spent on digitizing, compiling and\n" -" publishing the book %(b)s in multiple formats. We will contact you " -"if you qualify for perks." +"If the full amount needed is raised,\n" +" your donation will be spent on digitizing, compiling and\n" +" publishing the book %(b)s in multiple formats." msgstr "" -"Pieniądze przez Ciebie wpłacone przeznaczymy na digitalizację, opracowanie " -"i udostępnienie książki %(b)s w serwisie w wielu formatach. Jeśli wybrałeś/-" -"aś nagrody, skontaktujemy się z Tobą mailowo." +"Jeśli uda się zebrać pełną kwotę, wpłacone przez Ciebie pieniądze " +"przeznaczymy na digitalizację, opracowanie i udostępnienie książki %(b)s w " +"bibliotece w wielu formatach." -#: templates/funding/thanks.html:32 +#: templates/funding/thanks.html:36 msgid "Go back to the current fundraiser." msgstr "Wróć do aktualnej zbiórki." -#: templates/funding/thanks.html:36 +#: templates/funding/thanks.html:40 msgid "I support Wolne Lektury." msgstr "Wspieram Wolne Lektury" -#: templates/funding/thanks.html:39 +#: templates/funding/thanks.html:43 msgid "Vote for a book for the next fundraiser" msgstr "Pomóż wybrać następną książkę, na którą będziemy zbierać pieniądze" @@ -357,6 +389,158 @@ msgstr "Pieniądze przeznaczone na opublikowanie książki" msgid "Money remaining from the fundraiser for" msgstr "Pieniądze pozostałe ze zbiórki na" +#: templates/funding/wlfund.html:53 +msgid "There are no previous fundraisers to show yet." +msgstr "Nie ma jeszcze żadnych zakończonych zbiórek." + +#: templates/funding/email/base.txt:1 +msgid "Hi" +msgstr "Cześć" + +#: templates/funding/email/base.txt:4 +msgid "" +"Cheers,\n" +"Wolne Lektury team" +msgstr "" +"Pozdrawiamy\n" +"zespół Wolnych Lektur" + +#: templates/funding/email/base.txt:8 +msgid "If you don't want to receive any more updates, please visit this page:" +msgstr "Jeśli nie chcesz otrzymywać kolejnych powiadomień, odwiedź tę stronę:" + +#: templates/funding/email/end.txt:6 +msgid "" +"we succesfully collected the full amount needed\n" +"for the book you contributed to:" +msgstr "udało nam się zebrać pełną kwotę na książkę, którą wsparłeś/-aś:" + +#: templates/funding/email/end.txt:12 +msgid "" +"We will now digitize it, develop and publish it in the library,\n" +"in various formats, free for everyone." +msgstr "" +"Teraz ją zdigitalizujemy, opracujemy i bezpłatnie udostępnimy w bibliotece w " +"wielu formatach." + +#: templates/funding/email/end.txt:15 +msgid "" +"Your name will be included on the list of contributors, irrespectively\n" +"of the amount of your contribution." +msgstr "" +"Zostaniesz umieszczony/-a na liście darczyńców, niezależnie od wysokości " +"wpłaty." + +#: templates/funding/email/end.txt:18 +msgid "" +"We will contact you again about details needed\n" +"to deliver your perks." +msgstr "Skontaktujemy się z Tobą w sprawie prezentów, które wybrałeś/-aś." + +#: templates/funding/email/end.txt:21 +#, python-format +msgid "" +"All of the money remaining after this fundraiser (%(r)s PLN)\n" +"will be spent on liberating other books still waiting for publication." +msgstr "" +"Wszystkie dodatkowe pieniądze pozostałe z tej zbiórki (%(r)s PLN)\n" +"zostaną przeznaczone na uwolnienie innych książek czekających na publikację." + +#: templates/funding/email/end.txt:23 templates/funding/email/end.txt.py:34 +msgid "You can see how we're spending these funds on this page:" +msgstr "Możesz zobaczyć, jak wydajemy te środki, na tej stronie:" + +#: templates/funding/email/end.txt:26 +msgid "" +"unfortunately, we were unable to collect the full amount needed\n" +"for the book you contributed to:" +msgstr "" +"niestety, nie udało nam się zebrać pełnej kwoty na książkę, którą wsparłeś/-" +"aś:" + +#: templates/funding/email/end.txt:32 +#, python-format +msgid "" +"All of the money we collected in this fundraiser (%(x)s PLN)\n" +"will be spent on liberating other books still waiting for publication." +msgstr "" +"Wszystkie pieniądze z tej zbiórki (%(x)s PLN)\n" +"zostaną przeznaczone na uwolnienie innych książek czekających na publikację." + +#: templates/funding/email/end.txt:37 templates/funding/email/published.txt:12 +msgid "" +"If you'd like to help liberate another book, or invite your friends\n" +"to do so, we're currently raising money for:" +msgstr "" +"Jeśli chcesz pomóc uwolnić kolejną książkę, albo zachęcić do tego\n" +"swoich znajomych, to aktualnie zbieramy na:" + +#: templates/funding/email/near.txt:5 +#, python-format +msgid "there's only %(d)s day left until the end of the fundraiser for:\n" +msgid_plural "" +"There're only %(d)s days left until the end of the fundraiser for:\n" +msgstr[0] "został jeden dzień do końca zbiórki na:\n" +msgstr[1] "zostały %(d)s dni do końca zbiórki na:\n" +msgstr[2] "zostało %(d)s dni do końca zbiórki na:\n" + +#: templates/funding/email/near.txt:10 +#, python-format +msgid "We managed to collect %(x)s PLN so far." +msgstr "Dotąd udało nam się zebrać %(x)s PLN." + +#: templates/funding/email/near.txt:12 +msgid "" +"The fundraiser is a success already, but the more money\n" +"we collect, the more other books we'll publish." +msgstr "" +"Zbiórka już osiągnęła sukces, ale im więcej pieniędzy\n" +"zbierzemy, tym więcej opublikujemy książek." + +#: templates/funding/email/near.txt:14 +#, python-format +msgid "We still need %(x)s PLN more." +msgstr "Nadal potrzebujemy %(x)s PLN." + +#: templates/funding/email/near.txt:16 +msgid "There's still time to let your friends know about the fundraiser!" +msgstr "Jest jeszcze czas, by poinformować o zbiórce Twoich znajomych!" + +#: templates/funding/email/published.txt:4 +msgid "we have just published the book you contributed to:" +msgstr "właśnie opublikowaliśmy książkę, którą wsparłeś/-aś:" + +#: templates/funding/email/published.txt:9 +msgid "" +"Thanks to you, it is now available for free,\n" +"in various formats, to everyone." +msgstr "" +"Dzięki Tobie jest teraz dostępna bezpłatnie\n" +"dla wszystkich w wielu formatach." + +#: templates/funding/email/thanks.txt:6 +msgid "" +"Thank you for your support - thanks to you we will set another book free." +msgstr "Dziękujemy za wsparcie - dzięki Tobie uwolnimy kolejną książkę." + +#: templates/funding/email/thanks.txt:8 +msgid "The book will be supplemented with your name as a donor." +msgstr "" +"Twoje imię i nazwisko lub pseudonim zostaną dodane do listy darczyńców przy " +"opublikowanej książce." + +#: templates/funding/email/thanks.txt:10 +msgid "We will contact you about details needed for your perks." +msgstr "Skontaktujemy się z Tobą w sprawie prezentów, które wybrałeś/-aś." + +#: templates/funding/email/thanks.txt:12 +msgid "" +"We will keep you informed about status changes to this fundraiser\n" +"and the upcoming ones that we plan to launch." +msgstr "" +"Będziemy Cię informować o zmianach statusu tej zbiórki\n" +"i o kolejnych, które planujemy rozpocząć." + #: templates/funding/snippets/any_remaining.html:4 #, python-format msgid "" @@ -390,7 +574,18 @@ msgstr "potrzebujemy" msgid "until fundraiser end" msgstr "do końca zbiórki" -#: templates/funding/tags/offer_status.html:11 +#: templates/funding/tags/offer_status.html:6 +#, python-format +msgid "" +"The fundraiser\n" +" ends on %(end)s. The full amount has been successfully\n" +" raised, but you can still contribute and help liberate\n" +" more books." +msgstr "" +"Zbiórka kończy się %(end)s. Pełna kwota została już zebrana,\n" +" ale ciągle możesz dołożyć się i pomóc uwolnić więcej książek." + +#: templates/funding/tags/offer_status.html:13 #, python-format msgid "" "W need %(target)s zł to digitize it,\n" @@ -399,7 +594,7 @@ msgstr "" "Potrzebujemy %(target)s zł, by ją zdigitalizować, opracować i bezpłatnie " "udostępnić w serwisie w wielu formatach." -#: templates/funding/tags/offer_status.html:15 +#: templates/funding/tags/offer_status.html:17 #, python-format msgid "" "If we raise enought money before %(end)s we will\n" @@ -408,7 +603,7 @@ msgstr "" "Jeśli do %(end)s uda się zebrać pełną kwotę, opublikujemy ją i będzie " "dostępna dla wszystkich." -#: templates/funding/tags/offer_status.html:26 +#: templates/funding/tags/offer_status.html:28 msgid "The amount needed was not raised." msgstr "Nie udało się zebrać pełnej kwoty." @@ -425,14 +620,7 @@ msgstr "" "Książka\n" " %(bt)s została opublikowana." -#: templates/funding/tags/offer_status_more.html:15 -#, python-format -msgid "" -"The book\n" -" will be published by %(due)s." -msgstr "Książka zostanie opublikowana do %(due)s." - -#: templates/funding/tags/offer_status_more.html:18 +#: templates/funding/tags/offer_status_more.html:16 #, python-format msgid "" "You can follow\n" @@ -442,3 +630,21 @@ msgstr "Możesz śledzić prace na Platformie Redakcyjnej. #: templates/funding/widgets/amount.html:13 msgid "Other amount" msgstr "Inna kwota" + +#~ msgid "due" +#~ msgstr "data publikacji" + +#~ msgid "When will it be published if the money is raised." +#~ msgstr "" +#~ "Kiedy książka zostanie opublikowana, jeśli uda się zebrać pieniądze." + +#~ msgid "" +#~ "The fundraiser\n" +#~ " ends on %(end)s. The book will be published by %(due)s." +#~ msgstr "" +#~ "Zbiórka kończy się %(end)s. Książka zostanie opublikowana do %(due)s." + +#~ msgid "" +#~ "The book\n" +#~ " will be published by %(due)s." +#~ msgstr "Książka zostanie opublikowana do %(due)s." diff --git a/apps/funding/management/__init__.py b/apps/funding/management/__init__.py new file mode 100755 index 000000000..e69de29bb diff --git a/apps/funding/management/commands/__init__.py b/apps/funding/management/commands/__init__.py new file mode 100755 index 000000000..e69de29bb diff --git a/apps/funding/management/commands/funding_notify.py b/apps/funding/management/commands/funding_notify.py new file mode 100755 index 000000000..a583b2785 --- /dev/null +++ b/apps/funding/management/commands/funding_notify.py @@ -0,0 +1,35 @@ +# -*- 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 optparse import make_option +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option('-q', '--quiet', action='store_false', dest='verbose', default=True, + help='Suppress output'), + ) + help = 'Sends relevant funding notifications.' + + def handle(self, **options): + + from datetime import date, timedelta + from funding.models import Offer + from funding import app_settings + + verbose = options['verbose'] + + for offer in Offer.past().filter(notified_end=None): + if verbose: + print 'Notify end:', offer + offer.notify_end() + + current = Offer.current() + if (current is not None and + current.end <= date.today() + timedelta(app_settings.DAYS_NEAR - 1) and + not current.notified_near): + if verbose: + print 'Notify near:', current + current.notify_near() diff --git a/apps/funding/migrations/0015_auto__add_field_funding_notifications__add_field_funding_notify_key.py b/apps/funding/migrations/0015_auto__add_field_funding_notifications__add_field_funding_notify_key.py new file mode 100644 index 000000000..dd9a41eb2 --- /dev/null +++ b/apps/funding/migrations/0015_auto__add_field_funding_notifications__add_field_funding_notify_key.py @@ -0,0 +1,117 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'Funding.notifications' + db.add_column(u'funding_funding', 'notifications', + self.gf('django.db.models.fields.BooleanField')(default=True, db_index=True), + keep_default=False) + + # Adding field 'Funding.notify_key' + db.add_column(u'funding_funding', 'notify_key', + self.gf('django.db.models.fields.CharField')(default='x', max_length=32), + keep_default=False) + + # Adding index on 'Funding', fields ['email'] + db.create_index(u'funding_funding', ['email']) + + + def backwards(self, orm): + # Removing index on 'Funding', fields ['email'] + db.delete_index(u'funding_funding', ['email']) + + # Deleting field 'Funding.notifications' + db.delete_column(u'funding_funding', 'notifications') + + # Deleting field 'Funding.notify_key' + db.delete_column(u'funding_funding', 'notify_key') + + + models = { + 'catalogue.book': { + 'Meta': {'ordering': "('sort_key',)", 'object_name': 'Book'}, + '_related_info': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}), + 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'common_slug': ('django.db.models.fields.SlugField', [], {'max_length': '120'}), + 'cover': ('catalogue.fields.EbookField', [], {'max_length': '100', 'null': 'True', 'format_name': "'cover'", 'blank': 'True'}), + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'epub_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'epub'", 'blank': 'True'}), + 'extra_info': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + 'fb2_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'fb2'", 'blank': 'True'}), + 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'html_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'html'", 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.CharField', [], {'default': "'pol'", 'max_length': '3', 'db_index': 'True'}), + 'mobi_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'mobi'", 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}), + 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pdf_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'pdf'", 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}), + 'txt_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'txt'", 'blank': 'True'}), + 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'xml_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'xml'", 'blank': 'True'}) + }, + u'funding.funding': { + 'Meta': {'ordering': "['-payed_at']", 'object_name': 'Funding'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'email': ('django.db.models.fields.EmailField', [], {'db_index': 'True', 'max_length': '75', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language_code': ('django.db.models.fields.CharField', [], {'max_length': '2', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '127', 'blank': 'True'}), + 'notifications': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}), + 'notify_key': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['funding.Offer']"}), + 'payed_at': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'perks': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['funding.Perk']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'funding.offer': { + 'Meta': {'ordering': "['-end']", 'object_name': 'Offer'}, + 'author': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']", 'null': 'True', 'blank': 'True'}), + 'cover': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}), + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'due': ('django.db.models.fields.DateField', [], {}), + 'end': ('django.db.models.fields.DateField', [], {'db_index': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'poll': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['polls.Poll']", 'null': 'True', 'on_delete': 'models.SET_NULL', 'blank': 'True'}), + 'redakcja_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}), + 'start': ('django.db.models.fields.DateField', [], {'db_index': 'True'}), + 'target': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + u'funding.perk': { + 'Meta': {'ordering': "['-price']", 'object_name': 'Perk'}, + 'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'long_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['funding.Offer']", 'null': 'True', 'blank': 'True'}), + 'price': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}) + }, + u'funding.spent': { + 'Meta': {'ordering': "['-timestamp']", 'object_name': 'Spent'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'timestamp': ('django.db.models.fields.DateField', [], {}) + }, + u'polls.poll': { + 'Meta': {'object_name': 'Poll'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'open': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'question': ('django.db.models.fields.TextField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + } + } + + complete_apps = ['funding'] \ No newline at end of file diff --git a/apps/funding/migrations/0016_auto__del_field_offer_due.py b/apps/funding/migrations/0016_auto__del_field_offer_due.py new file mode 100644 index 000000000..13351005f --- /dev/null +++ b/apps/funding/migrations/0016_auto__del_field_offer_due.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Deleting field 'Offer.due' + db.delete_column(u'funding_offer', 'due') + + + def backwards(self, orm): + + # User chose to not deal with backwards NULL issues for 'Offer.due' + raise RuntimeError("Cannot reverse this migration. 'Offer.due' and its values cannot be restored.") + + models = { + 'catalogue.book': { + 'Meta': {'ordering': "('sort_key',)", 'object_name': 'Book'}, + '_related_info': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}), + 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'common_slug': ('django.db.models.fields.SlugField', [], {'max_length': '120'}), + 'cover': ('catalogue.fields.EbookField', [], {'max_length': '100', 'null': 'True', 'format_name': "'cover'", 'blank': 'True'}), + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'epub_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'epub'", 'blank': 'True'}), + 'extra_info': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + 'fb2_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'fb2'", 'blank': 'True'}), + 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'html_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'html'", 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.CharField', [], {'default': "'pol'", 'max_length': '3', 'db_index': 'True'}), + 'mobi_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'mobi'", 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}), + 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pdf_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'pdf'", 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}), + 'txt_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'txt'", 'blank': 'True'}), + 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'xml_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'xml'", 'blank': 'True'}) + }, + u'funding.funding': { + 'Meta': {'ordering': "['-payed_at']", 'object_name': 'Funding'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'email': ('django.db.models.fields.EmailField', [], {'db_index': 'True', 'max_length': '75', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language_code': ('django.db.models.fields.CharField', [], {'max_length': '2', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '127', 'blank': 'True'}), + 'notifications': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}), + 'notify_key': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['funding.Offer']"}), + 'payed_at': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'perks': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['funding.Perk']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'funding.offer': { + 'Meta': {'ordering': "['-end']", 'object_name': 'Offer'}, + 'author': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']", 'null': 'True', 'blank': 'True'}), + 'cover': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}), + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'end': ('django.db.models.fields.DateField', [], {'db_index': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'poll': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['polls.Poll']", 'null': 'True', 'on_delete': 'models.SET_NULL', 'blank': 'True'}), + 'redakcja_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}), + 'start': ('django.db.models.fields.DateField', [], {'db_index': 'True'}), + 'target': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + u'funding.perk': { + 'Meta': {'ordering': "['-price']", 'object_name': 'Perk'}, + 'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'long_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['funding.Offer']", 'null': 'True', 'blank': 'True'}), + 'price': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}) + }, + u'funding.spent': { + 'Meta': {'ordering': "['-timestamp']", 'object_name': 'Spent'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'timestamp': ('django.db.models.fields.DateField', [], {}) + }, + u'polls.poll': { + 'Meta': {'object_name': 'Poll'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'open': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'question': ('django.db.models.fields.TextField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + } + } + + complete_apps = ['funding'] \ No newline at end of file diff --git a/apps/funding/migrations/0017_auto__add_field_offer_notified_near__add_field_offer_notified_end.py b/apps/funding/migrations/0017_auto__add_field_offer_notified_near__add_field_offer_notified_end.py new file mode 100644 index 000000000..4f12e4d9f --- /dev/null +++ b/apps/funding/migrations/0017_auto__add_field_offer_notified_near__add_field_offer_notified_end.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding field 'Offer.notified_near' + db.add_column(u'funding_offer', 'notified_near', + self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), + keep_default=False) + + # Adding field 'Offer.notified_end' + db.add_column(u'funding_offer', 'notified_end', + self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Offer.notified_near' + db.delete_column(u'funding_offer', 'notified_near') + + # Deleting field 'Offer.notified_end' + db.delete_column(u'funding_offer', 'notified_end') + + + models = { + 'catalogue.book': { + 'Meta': {'ordering': "('sort_key',)", 'object_name': 'Book'}, + '_related_info': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}), + 'changed_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'db_index': 'True', 'blank': 'True'}), + 'common_slug': ('django.db.models.fields.SlugField', [], {'max_length': '120'}), + 'cover': ('catalogue.fields.EbookField', [], {'max_length': '100', 'null': 'True', 'format_name': "'cover'", 'blank': 'True'}), + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'db_index': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'epub_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'epub'", 'blank': 'True'}), + 'extra_info': ('jsonfield.fields.JSONField', [], {'default': "'{}'"}), + 'fb2_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'fb2'", 'blank': 'True'}), + 'gazeta_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'html_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'html'", 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language': ('django.db.models.fields.CharField', [], {'default': "'pol'", 'max_length': '3', 'db_index': 'True'}), + 'mobi_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'mobi'", 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['catalogue.Book']"}), + 'parent_number': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pdf_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'pdf'", 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '120'}), + 'sort_key': ('django.db.models.fields.CharField', [], {'max_length': '120', 'db_index': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '120'}), + 'txt_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'txt'", 'blank': 'True'}), + 'wiki_link': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'xml_file': ('catalogue.fields.EbookField', [], {'default': "''", 'max_length': '100', 'format_name': "'xml'", 'blank': 'True'}) + }, + u'funding.funding': { + 'Meta': {'ordering': "['-payed_at']", 'object_name': 'Funding'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'email': ('django.db.models.fields.EmailField', [], {'db_index': 'True', 'max_length': '75', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'language_code': ('django.db.models.fields.CharField', [], {'max_length': '2', 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '127', 'blank': 'True'}), + 'notifications': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}), + 'notify_key': ('django.db.models.fields.CharField', [], {'max_length': '32'}), + 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['funding.Offer']"}), + 'payed_at': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'perks': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['funding.Perk']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'funding.offer': { + 'Meta': {'ordering': "['-end']", 'object_name': 'Offer'}, + 'author': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']", 'null': 'True', 'blank': 'True'}), + 'cover': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}), + 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'end': ('django.db.models.fields.DateField', [], {'db_index': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'notified_end': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'notified_near': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'poll': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['polls.Poll']", 'null': 'True', 'on_delete': 'models.SET_NULL', 'blank': 'True'}), + 'redakcja_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}), + 'start': ('django.db.models.fields.DateField', [], {'db_index': 'True'}), + 'target': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + }, + u'funding.perk': { + 'Meta': {'ordering': "['-price']", 'object_name': 'Perk'}, + 'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'long_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'offer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['funding.Offer']", 'null': 'True', 'blank': 'True'}), + 'price': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}) + }, + u'funding.spent': { + 'Meta': {'ordering': "['-timestamp']", 'object_name': 'Spent'}, + 'amount': ('django.db.models.fields.DecimalField', [], {'max_digits': '10', 'decimal_places': '2'}), + 'book': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['catalogue.Book']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'timestamp': ('django.db.models.fields.DateField', [], {}) + }, + u'polls.poll': { + 'Meta': {'object_name': 'Poll'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'open': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'question': ('django.db.models.fields.TextField', [], {}), + 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}) + } + } + + complete_apps = ['funding'] \ No newline at end of file diff --git a/apps/funding/models.py b/apps/funding/models.py index 8c3312ee8..de52ac9d8 100644 --- a/apps/funding/models.py +++ b/apps/funding/models.py @@ -3,15 +3,19 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from datetime import date, datetime +from urllib import urlencode from django.core.urlresolvers import reverse from django.core.mail import send_mail from django.conf import settings from django.template.loader import render_to_string from django.db import models -from django.utils.translation import ugettext_lazy as _, ugettext as __, override +from django.utils.translation import ugettext_lazy as _, ugettext, override import getpaid from catalogue.models import Book +from catalogue.utils import get_random_hash from polls.models import Poll +from django.contrib.sites.models import Site +from . import app_settings class Offer(models.Model): @@ -23,14 +27,15 @@ class Offer(models.Model): target = models.DecimalField(_('target'), decimal_places=2, max_digits=10) start = models.DateField(_('start'), db_index=True) end = models.DateField(_('end'), db_index=True) - due = models.DateField(_('due'), - help_text=_('When will it be published if the money is raised.')) redakcja_url = models.URLField(_('redakcja URL'), blank=True) book = models.ForeignKey(Book, 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) + def cover_img_tag(self): return u'' % self.cover.url cover_img_tag.short_description = _('Cover preview') @@ -47,8 +52,17 @@ class Offer(models.Model): def get_absolute_url(self): return reverse('funding_offer', args=[self.slug]) + def save(self, *args, **kw): + published_now = (self.book_id is not None and + self.pk is not None and + type(self).objects.values('book').get(pk=self.pk)['book'] != self.book_id) + retval = super(Offer, self).save(*args, **kw) + if published_now: + self.notify_published() + return retval + def is_current(self): - return self.start <= date.today() <= self.end + return self.start <= date.today() <= self.end and self == self.current() def is_win(self): return self.sum() >= self.target @@ -63,9 +77,16 @@ class Offer(models.Model): @classmethod def current(cls): - """ Returns current fundraiser or None. """ + """ Returns current fundraiser or None. + + Current fundraiser is the one that: + - has already started, + - hasn't yet ended, + - if there's more than one of those, it's the one that ends last. + + """ today = date.today() - objects = cls.objects.filter(start__lte=today, end__gte=today) + objects = cls.objects.filter(start__lte=today, end__gte=today).order_by('-end') try: return objects[0] except IndexError: @@ -73,9 +94,12 @@ class Offer(models.Model): @classmethod def past(cls): - """ QuerySet for all current and past fundraisers. """ - today = date.today() - return cls.objects.filter(end__lt=today) + """ QuerySet for all past fundraisers. """ + objects = cls.public() + current = cls.current() + if current is not None: + objects = objects.exclude(pk=current.pk) + return objects @classmethod def public(cls): @@ -100,10 +124,61 @@ class Offer(models.Model): """ QuerySet for all completed payments for the offer. """ return Funding.payed().filter(offer=self) + def funders(self): + return self.funding_payed().order_by('-amount', 'payed_at') + def sum(self): """ The money gathered. """ return self.funding_payed().aggregate(s=models.Sum('amount'))['s'] or 0 + def notify_all(self, subject, template_name, extra_context=None): + Funding.notify_funders( + subject, template_name, extra_context, + query_filter=models.Q(offer=self) + ) + + def notify_end(self, force=False): + if not force and self.notified_end: return + assert not self.is_current() + self.notify_all( + _('The fundraiser has ended!'), + 'funding/email/end.txt', { + 'offer': self, + 'is_win': self.is_win(), + 'remaining': self.remaining(), + 'current': self.current(), + }) + self.notified_end = datetime.now() + self.save() + + def notify_near(self, force=False): + if not force and self.notified_near: return + assert self.is_current() + sum_ = self.sum() + need = self.target - sum_ + self.notify_all( + _('The fundraiser will end soon!'), + 'funding/email/near.txt', { + 'days': (self.end - date.today()).days + 1, + 'offer': self, + 'is_win': self.is_win(), + 'sum': sum_, + 'need': need, + }) + self.notified_near = datetime.now() + self.save() + + def notify_published(self): + assert self.book is not None + self.notify_all( + _('The book you helped fund has been published.'), + 'funding/email/published.txt', { + 'offer': self, + 'book': self.book, + 'author': ", ".join(a[0] for a in self.book.related_info()['tags']['author']), + 'current': self.current(), + }) + class Perk(models.Model): """ A perk offer. @@ -134,30 +209,80 @@ class Funding(models.Model): """ offer = models.ForeignKey(Offer, verbose_name=_('offer')) name = models.CharField(_('name'), max_length=127, blank=True) - email = models.EmailField(_('email'), blank=True) + email = models.EmailField(_('email'), blank=True, db_index=True) amount = models.DecimalField(_('amount'), decimal_places=2, max_digits=10) payed_at = models.DateTimeField(_('payed at'), null=True, blank=True, db_index=True) perks = models.ManyToManyField(Perk, verbose_name=_('perks'), 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) - # Any additional info needed for perks? + class Meta: + verbose_name = _('funding') + verbose_name_plural = _('fundings') + ordering = ['-payed_at'] @classmethod def payed(cls): """ QuerySet for all completed payments. """ return cls.objects.exclude(payed_at=None) - class Meta: - verbose_name = _('funding') - verbose_name_plural = _('fundings') - ordering = ['-payed_at'] - def __unicode__(self): 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) + return super(Funding, self).save(*args, **kwargs) + + @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), + getattr(settings, 'CONTACT_EMAIL', 'wolnelektury@nowoczesnapolska.org.pl'), + [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') @@ -195,15 +320,8 @@ def payment_status_changed_listener(sender, instance, old_status, new_status, ** instance.order.payed_at = datetime.now() instance.order.save() if instance.order.email: - send_thank_you_email(instance.order.name, instance.order.email, instance.order.language_code) + instance.order.notify( + _('Thank you for your support!'), + 'funding/email/thanks.txt' + ) getpaid.signals.payment_status_changed.connect(payment_status_changed_listener) - -def send_thank_you_email(name, address, language_code): - with override(language_code or 'pl'): - send_mail(_('Thank you for your support!'), - render_to_string('funding/email.txt', dict(name = name)), - getattr(settings, 'CONTACT_EMAIL', 'wolnelektury@nowoczesnapolska.org.pl'), - [address], - fail_silently=False - ) - diff --git a/apps/funding/templates/admin/funding/offer/change_form.html b/apps/funding/templates/admin/funding/offer/change_form.html new file mode 100755 index 000000000..292d0dfeb --- /dev/null +++ b/apps/funding/templates/admin/funding/offer/change_form.html @@ -0,0 +1,31 @@ +{% extends "admin/change_form.html" %} +{% load i18n %} + +{% block extrahead %} +{{ block.super }} + +{% endblock %} + + + +{% block pretitle %} + + +↓ {% trans "fundings" %} ↓ + +{{ block.super }} +{% endblock %} diff --git a/apps/funding/templates/funding/disable_notifications.html b/apps/funding/templates/funding/disable_notifications.html new file mode 100755 index 000000000..9123310d9 --- /dev/null +++ b/apps/funding/templates/funding/disable_notifications.html @@ -0,0 +1,34 @@ +{% extends "base.html" %} +{% load i18n %} +{% load fnp_share %} + +{% block titleextra %}{% trans "Payment failed" %}{% endblock %} + +{% block body %} + +

{% trans "Disable notifications" %}

+
+ +{% if view.object.notifications %} + +

{% blocktrans with e=view.object.email %}Are you sure you want to disable notifications for address {{e}}?{% endblocktrans %}

+
+ +
+ +{% else %} + +

{% blocktrans with e=view.object.email %}Notifications for address {{e}} have been successfully disabled.{% endblocktrans %}

+ +{% endif %} + +{% url 'funding_current' as current %} +

+{% blocktrans with current=current %}Return to the current fundraiser.{% endblocktrans %} +

+ + +
+ + +{% endblock %} diff --git a/apps/funding/templates/funding/email.txt b/apps/funding/templates/funding/email.txt deleted file mode 100644 index e5487671d..000000000 --- a/apps/funding/templates/funding/email.txt +++ /dev/null @@ -1,13 +0,0 @@ -{% load i18n %} - -{% trans 'Hi' %}{% if name %} {{name}}{% endif %}, - -{% trans 'Thank you for your support - thanks to you we will set another book free.' %}{% if name %} - -{% trans 'The book will be supplemented with your name as a donor.' %}{% endif %} - -{% blocktrans %}We will contact you to keep you informed about your perks, -status changes to this fundraiser and the incoming ones that we plan to launch.{% endblocktrans %} - -{% blocktrans %}Cheers, -Wolne Lektury team{% endblocktrans %} diff --git a/apps/funding/templates/funding/email/base.txt b/apps/funding/templates/funding/email/base.txt new file mode 100755 index 000000000..1129549ce --- /dev/null +++ b/apps/funding/templates/funding/email/base.txt @@ -0,0 +1,10 @@ +{% autoescape off %}{% load i18n %}{% trans 'Hi' %}{% if funding.name %} {{ funding.name }}{% endif %}, +{% block body %} +{% endblock %} +{% blocktrans %}Cheers, +Wolne Lektury team{% endblocktrans %} + +-- +{% blocktrans %}If you don't want to receive any more updates, please visit this page:{% endblocktrans %} +http://{{site.domain}}{{ funding.get_disable_notifications_url }} +{% endautoescape %} diff --git a/apps/funding/templates/funding/email/end.txt b/apps/funding/templates/funding/email/end.txt new file mode 100755 index 000000000..023d34427 --- /dev/null +++ b/apps/funding/templates/funding/email/end.txt @@ -0,0 +1,42 @@ +{% extends "funding/email/base.txt" %} +{% load i18n %} + + +{% block body %}{% if is_win %} +{% blocktrans %}we succesfully collected the full amount needed +for the book you contributed to:{% endblocktrans %} + + {{ offer.author }} – {{ offer.title }} + http://{{ site.domain }}{{ offer.get_absolute_url }} + +{% blocktrans %}We will now digitize it, develop and publish it in the library, +in various formats, free for everyone.{% endblocktrans %} +{% if funding.name %} +{% blocktrans %}Your name will be included on the list of contributors, irrespectively +of the amount of your contribution.{% endblocktrans %} +{% endif %}{# funding.name #}{% if funding.perks.exists %} +{% blocktrans %}We will contact you again about details needed +to deliver your perks.{% endblocktrans %} +{% endif %}{# funding.perks.exists #}{% if remaining %} +{% blocktrans with r=remaining %}All of the money remaining after this fundraiser ({{ r }} PLN) +will be spent on liberating other books still waiting for publication.{% endblocktrans %} +{% blocktrans %}You can see how we're spending these funds on this page:{% endblocktrans %} +http://{{ site.domain }}{% url 'funding_wlfund' %} +{% endif %}{# remaining #}{% else %}{# !is_win #} +{% blocktrans %}unfortunately, we were unable to collect the full amount needed +for the book you contributed to:{% endblocktrans %} + + {{ offer.author }} – {{ offer.title }} + http://{{ site.domain }}{{ offer.get_absolute_url }} +{% if remaining %} +{% blocktrans with x=remaining %}All of the money we collected in this fundraiser ({{ x }} PLN) +will be spent on liberating other books still waiting for publication.{% endblocktrans %} +{% blocktrans %}You can see how we're spending these funds on this page:{% endblocktrans %} +http://{{ site.domain }}{% url 'funding_wlfund' %} +{% endif %}{# remaining #}{% endif %}{# is_win #}{% if current %} +{% blocktrans %}If you'd like to help liberate another book, or invite your friends +to do so, we're currently raising money for:{% endblocktrans %} + + {{ current.author }} – {{ current.title }} + http://{{ site.domain }}{% url 'funding_current' %} +{% endif %}{% endblock %} diff --git a/apps/funding/templates/funding/email/near.txt b/apps/funding/templates/funding/email/near.txt new file mode 100755 index 000000000..47537c129 --- /dev/null +++ b/apps/funding/templates/funding/email/near.txt @@ -0,0 +1,18 @@ +{% extends "funding/email/base.txt" %} +{% load i18n %} + +{% block body %} +{% blocktrans count days as d %}there's only {{ d }} day left until the end of the fundraiser for: +{% plural %}There're only {{ d }} days left until the end of the fundraiser for: +{% endblocktrans %} + {{ offer.author }} – {{ offer.title }} + +{% blocktrans with x=sum %}We managed to collect {{x}} PLN so far.{% endblocktrans %} +{% if is_win %} +{% blocktrans %}The fundraiser is a success already, but the more money +we collect, the more other books we'll publish.{% endblocktrans %} +{% else %}{% blocktrans with x=need %}We still need {{ x }} PLN more.{% endblocktrans %} +{% endif %} +{% trans "There's still time to let your friends know about the fundraiser!" %} +http://{{ site.domain }}{% url 'funding_current' %} +{% endblock %} diff --git a/apps/funding/templates/funding/email/published.txt b/apps/funding/templates/funding/email/published.txt new file mode 100755 index 000000000..672efa2ae --- /dev/null +++ b/apps/funding/templates/funding/email/published.txt @@ -0,0 +1,17 @@ +{% extends "funding/email/base.txt" %} +{% load i18n %} +{% block body %} +{% blocktrans %}we have just published the book you contributed to:{% endblocktrans %} + + {{ author }} – {{ offer.book.title }} + http://{{ site.domain }}{{ offer.book.get_absolute_url }} + +{% blocktrans %}Thanks to you, it is now available for free, +in various formats, to everyone.{% endblocktrans %} +{% if current %} +{% blocktrans %}If you'd like to help liberate another book, or invite your friends +to do so, we're currently raising money for:{% endblocktrans %} + + {{ current.author }} – {{ current.title }} + http://{{ site.domain }}{% url 'funding_current' %} +{% endif %}{% endblock %} diff --git a/apps/funding/templates/funding/email/thanks.txt b/apps/funding/templates/funding/email/thanks.txt new file mode 100644 index 000000000..2ded0bd9d --- /dev/null +++ b/apps/funding/templates/funding/email/thanks.txt @@ -0,0 +1,14 @@ +{% extends "funding/email/base.txt" %} +{% load i18n %} + + +{% block body %} +{% trans 'Thank you for your support - thanks to you we will set another book free.' %}{% if funding.name %} + +{% trans 'The book will be supplemented with your name as a donor.' %}{% endif %} +{% if funding.perks.exists %} +{% blocktrans %}We will contact you about details needed for your perks.{% endblocktrans %} +{% endif %}{# funding.perks.exists #} +{% blocktrans %}We will keep you informed about status changes to this fundraiser +and the upcoming ones that we plan to launch.{% endblocktrans %} +{% endblock %} diff --git a/apps/funding/templates/funding/no_thanks.html b/apps/funding/templates/funding/no_thanks.html old mode 100755 new mode 100644 diff --git a/apps/funding/templates/funding/offer_detail.html b/apps/funding/templates/funding/offer_detail.html old mode 100755 new mode 100644 index c5631b086..aef4d28af --- a/apps/funding/templates/funding/offer_detail.html +++ b/apps/funding/templates/funding/offer_detail.html @@ -43,7 +43,6 @@

{% trans "Support the publication" %}

- {% csrf_token %} {{ form.as_table }} {% endif %} + {% empty %} + {% endfor %}
diff --git a/apps/funding/templates/funding/offer_list.html b/apps/funding/templates/funding/offer_list.html old mode 100755 new mode 100644 index 0770b100e..feb175d7f --- a/apps/funding/templates/funding/offer_list.html +++ b/apps/funding/templates/funding/offer_list.html @@ -13,12 +13,14 @@ {% autopaginate object_list 10 %} +{% if page_obj.number == 1 %} +

{% trans "Current fundraiser:" %}

+{% endif %} + {% for offer in object_list %} {% with is_win=offer.is_win is_current=offer.is_current %} - - {% if is_current %} -

{% trans "Current fundraiser:" %}

- {% elif forloop.is_first %} + {% if not is_current and forloop.first and page_obj.number == 1 %} +

{% trans "No fundraiser is currently running." %}

{% trans "Previous fundraisers:" %}

{% endif %} @@ -33,7 +35,7 @@ {% offer_status_more offer %} - {% if is_current and not forloop.is_last %} + {% if is_current and not forloop.last %}

{% trans "Previous fundraisers:" %}

{% endif %} diff --git a/apps/funding/templates/funding/tags/offer_status.html b/apps/funding/templates/funding/tags/offer_status.html index 1c140686f..5828ce41c 100755 --- a/apps/funding/templates/funding/tags/offer_status.html +++ b/apps/funding/templates/funding/tags/offer_status.html @@ -3,8 +3,10 @@ {% if offer.is_current %} {% if offer.is_win %}

- {% blocktrans with due=offer.due end=offer.end %}The fundraiser - ends on {{ end }}. The book will be published by {{ due }}.{% endblocktrans %} + {% blocktrans with end=offer.end %}The fundraiser + ends on {{ end }}. The full amount has been successfully + raised, but you can still contribute and help liberate + more books.{% endblocktrans %}

{% else %}

diff --git a/apps/funding/templates/funding/tags/offer_status_more.html b/apps/funding/templates/funding/tags/offer_status_more.html index 5c6efb1ee..c94c9a801 100755 --- a/apps/funding/templates/funding/tags/offer_status_more.html +++ b/apps/funding/templates/funding/tags/offer_status_more.html @@ -12,9 +12,7 @@ {% blocktrans with bu=offer.book.get_absolute_url bt=offer.book %}The book {{ bt }} has been already published.{% endblocktrans %} {% else %} - {% blocktrans with due=offer.due %}The book - will be published by {{ due }}.{% endblocktrans %} - {% if offer.redakcja_link %} + {% if offer.redakcja_url %} {% blocktrans with r=offer.redakcja_url %}You can follow the work on the Editorial Platform.{% endblocktrans %} {% endif %} diff --git a/apps/funding/templates/funding/thanks.html b/apps/funding/templates/funding/thanks.html old mode 100755 new mode 100644 index efff200dc..10e680f15 --- a/apps/funding/templates/funding/thanks.html +++ b/apps/funding/templates/funding/thanks.html @@ -10,20 +10,24 @@

{% trans "Thank you!" %}

-{% trans "Thank you for your support!" %} +

{% trans "Thank you for your support!" %}

+

{% blocktrans %}We will contact you if you qualify for perks.{% endblocktrans %}

{% if offer.is_win %}

{% trans "Full amount was successfully raised!" %}

-

{% blocktrans with due=offer.due end=offer.end %}The fundraiser - ends on {{ end }}. The book will be published by {{ due }}.{% endblocktrans %}

+

{% blocktrans with b=offer.title %}Your donation will be spent on digitizing, compiling and + publishing the book {{ b }} in multiple formats.{% endblocktrans %}

+ {% else %} -

- {% blocktrans with b=offer.title %}Your donation will be spent on digitizing, compiling and - publishing the book {{ b }} in multiple formats. We will contact you if you qualify for perks.{% endblocktrans %} -

+ +

{% blocktrans with b=offer.title %}If the full amount needed is raised, + your donation will be spent on digitizing, compiling and + publishing the book {{ b }} in multiple formats.{% endblocktrans %}

+ {% endif %} +

{% include "funding/snippets/any_remaining.html" %} {% trans "Learn more" %}.

diff --git a/apps/funding/templates/funding/wlfund.html b/apps/funding/templates/funding/wlfund.html old mode 100755 new mode 100644 index adffe7bfd..bb8a2bea2 --- a/apps/funding/templates/funding/wlfund.html +++ b/apps/funding/templates/funding/wlfund.html @@ -48,7 +48,12 @@ from successful fundraisers.{% endblocktrans %}
{{ entry.total }} zł
+ {% trans "There are no previous fundraisers to show yet." %} +
+ {% endblock %} diff --git a/apps/funding/templatetags/funding_tags.py b/apps/funding/templatetags/funding_tags.py index eb60601ad..5c6544a8f 100755 --- a/apps/funding/templatetags/funding_tags.py +++ b/apps/funding/templatetags/funding_tags.py @@ -8,6 +8,10 @@ register = template.Library() def funding(context, offer=None, link=False, closeable=False, show_title=True, show_title_calling = True, add_class=""): if offer is None and context.get('funding_no_show_current') is None: offer = Offer.current() + is_current = True + elif offer is not None: + is_current = offer.is_current() + if offer is None: return {} @@ -15,7 +19,7 @@ def funding(context, offer=None, link=False, closeable=False, show_title=True, s return { 'offer': offer, 'sum': offer_sum, - 'is_current': offer.is_current(), + 'is_current': is_current, 'is_win': offer_sum >= offer.target, 'missing': offer.target - offer_sum, 'percentage': 100 * offer_sum / offer.target, diff --git a/apps/funding/tests.py b/apps/funding/tests.py index c9438a878..30583f11f 100644 --- a/apps/funding/tests.py +++ b/apps/funding/tests.py @@ -2,27 +2,75 @@ # 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, timedelta from django.test import TestCase from .models import Offer, Perk, Funding -class FundTest(TestCase): +class PerksTest(TestCase): def setUp(self): + self.today = date.today() self.offer1 = Offer.objects.create( author='author1', title='title1', slug='slug1', - target=100, start='2013-03-01', end='2013-03-31') + target=100, start=self.today, end=self.today) def test_perks(self): perk = Perk.objects.create(price=20, name='Perk 20') perk1 = Perk.objects.create(offer=self.offer1, price=50, name='Perk 50') offer2 = Offer.objects.create( author='author2', title='title2', slug='slug2', - target=100, start='2013-02-01', end='2013-02-20') + target=100, start=self.today-timedelta(1), end=self.today-timedelta(1)) perk2 = Perk.objects.create(offer=offer2, price=1, name='Perk 1') self.assertEqual( - set(self.offer1.fund('Tester', 'test@example.com', 10).perks.all()), + set(self.offer1.get_perks(10)), set()) self.assertEqual( - set(self.offer1.fund('Tester', 'test@example.com', 70).perks.all()), + set(self.offer1.get_perks(70)), set([perk, perk1])) + + +class FundingTest(TestCase): + def setUp(self): + self.today = date.today() + self.offer_past = Offer.objects.create( + author='an-author', title='past', slug='past', + target=100, start=self.today-timedelta(1), end=self.today-timedelta(1)) + self.offer_current = Offer.objects.create( + author='an-author', title='current', slug='current', + target=100, start=self.today, end=self.today) + self.offer_future = Offer.objects.create( + author='an-author', title='future', slug='future', + target=100, start=self.today+timedelta(1), end=self.today+timedelta(1)) + + def test_current(self): + self.assertTrue(self.offer_current.is_current()) + self.assertFalse(self.offer_past.is_current()) + self.assertEqual(Offer.current(), self.offer_current) + self.assertEqual( + set(Offer.past()), + set([self.offer_past]) + ) + self.assertEqual( + set(Offer.public()), + set([self.offer_past, self.offer_current]) + ) + + def test_interrupt(self): + # A new offer starts, ending the previously current one. + offer_interrupt = Offer.objects.create( + author='an-author', title='interrupt', slug='interrupt', + target=100, start=self.today-timedelta(1), end=self.today+timedelta(1)) + + self.assertTrue(offer_interrupt.is_current()) + self.assertFalse(self.offer_current.is_current()) + self.assertEqual(Offer.current(), offer_interrupt) + self.assertEqual( + set(Offer.past()), + set([self.offer_past, self.offer_current]) + ) + self.assertEqual( + set(Offer.public()), + set([self.offer_past, self.offer_current, offer_interrupt]) + ) + diff --git a/apps/funding/urls.py b/apps/funding/urls.py index e92704d71..3e55ba4b4 100644 --- a/apps/funding/urls.py +++ b/apps/funding/urls.py @@ -6,12 +6,13 @@ from django.conf.urls import patterns, url, include from .models import Offer from .views import (WLFundView, OfferDetailView, OfferListView, - ThanksView, NoThanksView, CurrentView) + ThanksView, NoThanksView, CurrentView, DisableNotifications) urlpatterns = patterns('', url(r'^$', CurrentView.as_view(), name='funding_current'), + url(r'^teraz/$', CurrentView.as_view()), url(r'^teraz/(?P[^/]+)/$', CurrentView.as_view(), name='funding_current'), url(r'^lektura/$', OfferListView.as_view(), name='funding'), url(r'^lektura/(?P[^/]+)/$', OfferDetailView.as_view(), name='funding_offer'), @@ -19,6 +20,8 @@ urlpatterns = patterns('', url(r'^dziekujemy/$', ThanksView.as_view(), name='funding_thanks'), url(r'^niepowodzenie/$', NoThanksView.as_view(), name='funding_nothanks'), + + url(r'^wylacz_email/$', DisableNotifications.as_view(), name='funding_disable_notifications'), url(r'^getpaid/', include('getpaid.urls')), ) diff --git a/apps/funding/views.py b/apps/funding/views.py index bf2a073dc..dbbe21986 100644 --- a/apps/funding/views.py +++ b/apps/funding/views.py @@ -4,13 +4,14 @@ # from datetime import date from django.views.decorators.cache import never_cache -from django.conf import settings from django.core.urlresolvers import reverse from django.http import Http404 from django.shortcuts import redirect, get_object_or_404 +from django.views.decorators.csrf import csrf_exempt from django.views.generic import TemplateView, FormView, DetailView, ListView import getpaid.backends.payu from getpaid.models import Payment +from . import app_settings from .forms import FundingForm from .models import Offer, Spent, Funding @@ -76,6 +77,7 @@ class OfferDetailView(FormView): template_name = "funding/offer_detail.html" backend = 'getpaid.backends.payu' + @csrf_exempt def dispatch(self, request, slug=None): if getattr(self, 'object', None) is None: if slug: @@ -90,7 +92,7 @@ class OfferDetailView(FormView): if self.request.method == 'POST': return form_class(self.object, self.request.POST) else: - return form_class(self.object, initial={'amount': settings.FUNDING_DEFAULT}) + return form_class(self.object, initial={'amount': app_settings.DEFAULT_AMOUNT}) def get_context_data(self, *args, **kwargs): ctx = super(OfferDetailView, self).get_context_data(*args, **kwargs) @@ -109,10 +111,11 @@ class OfferDetailView(FormView): class CurrentView(OfferDetailView): + @csrf_exempt def dispatch(self, request, slug=None): self.object = Offer.current() if self.object is None: - raise Http404 + return redirect(reverse('funding')) elif slug != self.object.slug: return redirect(reverse('funding_current', args=[self.object.slug])) return super(CurrentView, self).dispatch(request, slug) @@ -136,5 +139,20 @@ class ThanksView(TemplateView): ctx['funding_no_show_current'] = True return ctx + class NoThanksView(TemplateView): template_name = "funding/no_thanks.html" + + +class DisableNotifications(TemplateView): + template_name = "funding/disable_notifications.html" + + @csrf_exempt + def dispatch(self, request): + self.object = get_object_or_404(Funding, + email=request.GET.get('email'), notify_key=request.GET.get('key')) + return super(DisableNotifications, self).dispatch(request) + + def post(self, *args, **kwargs): + self.object.disable_notifications() + return redirect(self.request.get_full_path()) diff --git a/apps/oai/handlers.py b/apps/oai/handlers.py index eabb59c9f..4e3fefcb2 100644 --- a/apps/oai/handlers.py +++ b/apps/oai/handlers.py @@ -15,6 +15,8 @@ from django.contrib.sites.models import Site from django.utils import timezone +make_time_naive = lambda d: timezone.localtime(d).replace(tzinfo=None) + WL_DC_READER_XPATH = '(.|*)/rdf:RDF/rdf:Description/%s/text()' wl_dc_reader = metadata.MetadataReader( fields={ @@ -92,12 +94,12 @@ class Catalogue(common.ResumptionOAIPMH): identifier = self.slug_to_identifier(book.slug) if isinstance(book, Book): # setSpec = map(self.tag_to_setspec, book.tags.filter(category__in=self.TAG_CATEGORIES)) - header = common.Header(identifier, book.changed_at, [], False) + header = common.Header(identifier, make_time_naive(book.changed_at), [], False) if not headers_only: meta = common.Metadata(self.metadata(book)) about = None elif isinstance(book, Deleted): - header = common.Header(identifier, book.deleted_at, [], True) + header = common.Header(identifier, make_time_naive(book.deleted_at), [], True) if not headers_only: meta = common.Metadata({}) about = None @@ -111,7 +113,7 @@ class Catalogue(common.ResumptionOAIPMH): '%s/oaipmh' % WL_BASE, # generate '2.0', # version [m[1] for m in settings.MANAGERS], # adminEmails - self.earliest_datestamp, # earliest datestamp of any change + make_time_naive(self.earliest_datestamp), # earliest datestamp of any change 'persistent', # deletedRecord 'YYYY-MM-DDThh:mm:ssZ', # granularity ['identity'], # compression diff --git a/apps/pdcounter/models.py b/apps/pdcounter/models.py index 50eb43e1f..1e441ac64 100644 --- a/apps/pdcounter/models.py +++ b/apps/pdcounter/models.py @@ -91,13 +91,8 @@ class BookStub(models.Model): if not settings.NO_SEARCH_INDEX: def update_index(sender, instance, **kwargs): import search - print "update pd index %s [update %s]" % (instance, 'created' in kwargs) idx = search.Index() - idx.open() - try: - idx.index_tags(instance, remove_only=not 'created' in kwargs) - finally: - idx.close() + idx.index_tags(instance, remove_only=not 'created' in kwargs) post_delete.connect(update_index, Author) post_delete.connect(update_index, BookStub) diff --git a/apps/pdcounter/views.py b/apps/pdcounter/views.py index 8fb1b13fa..3e2092e47 100644 --- a/apps/pdcounter/views.py +++ b/apps/pdcounter/views.py @@ -11,7 +11,8 @@ from suggest.forms import PublishingSuggestForm def book_stub_detail(request, slug): book = get_object_or_404(models.BookStub, slug=slug) - pd_counter = datetime(book.pd, 1, 1) + if book.pd and not book.in_pd(): + pd_counter = datetime(book.pd, 1, 1) form = PublishingSuggestForm( initial={"books": u"%s — %s, \n" % (book.author, book.title)}) @@ -22,7 +23,8 @@ def book_stub_detail(request, slug): def author_detail(request, slug): author = get_object_or_404(models.Author, slug=slug) - pd_counter = datetime(author.goes_to_pd(), 1, 1) + if not author.alive(): + pd_counter = datetime(author.goes_to_pd(), 1, 1) form = PublishingSuggestForm(initial={"books": author.name + ", \n"}) diff --git a/apps/search/index.py b/apps/search/index.py index 85bcb616d..f9a3c89ae 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -163,7 +163,7 @@ class Index(SolrIndex): q_id_cat = self.index.Q(q_id & q_cat) tag_qs.append(q_id_cat) - self.delete_query(tag_qs) + self.delete_query(*tag_qs) else: # all q = self.index.Q(tag_id__any=True) self.delete_query(q) diff --git a/apps/wolnelektury_core/static/opensearch.xml b/apps/wolnelektury_core/static/opensearch.xml index 8ccdd269b..1bf2aeb5f 100644 --- a/apps/wolnelektury_core/static/opensearch.xml +++ b/apps/wolnelektury_core/static/opensearch.xml @@ -3,7 +3,7 @@ xmlns:atom="http://www.w3.org/2005/Atom" xmlns:moz="http://www.mozilla.org/2006/browser/search/"> Wolne Lektury - WolneLektury.pl, szkolna biblioteka internetowa. + Biblioteka internetowa WolneLektury.pl UTF-8 lektury Fundacja Nowoczesna Polska diff --git a/apps/wolnelektury_core/templates/superbase.html b/apps/wolnelektury_core/templates/superbase.html index 65b9e0a82..9ee206f57 100644 --- a/apps/wolnelektury_core/templates/superbase.html +++ b/apps/wolnelektury_core/templates/superbase.html @@ -28,6 +28,7 @@ {% block bodycontent %} + {% funding link=1 closeable=1 add_class="funding-top-header" %}