if not self.preview:
return True
Membership = apps.get_model('club', 'Membership')
- return Membership.is_active_for(user)
+ if Membership.is_active_for(user):
+ return True
+ Funding = apps.get_model('funding', 'Funding')
+ if Funding.objects.filter(user=user, offer__book=self):
+ return True
+ return False
def save(self, force_insert=False, force_update=False, **kwargs):
from sortify import sortify
def status(book, user):
if not book.preview:
return 'open'
- elif Membership.is_active_for(user):
+ elif book.is_accessible_to(user):
return 'preview'
else:
return 'closed'
from ajaxable.utils import AjaxableFormView
from club.forms import ScheduleForm
-from club.models import Club, Membership
+from club.models import Club
from annoy.models import DynamicTextInsert
from pdcounter import views as pdcounter_views
from picture.models import Picture, PictureArea
def book_text(request, slug):
book = get_object_or_404(Book, slug=slug)
- if book.preview and not Membership.is_active_for(request.user):
+ if not book.is_accessible_to(request.user):
return HttpResponseRedirect(book.get_absolute_url())
if not book.has_html_file():
def validate_object(self, obj, request):
book = obj
- if book.preview and not Membership.is_active_for(request.user):
+ if not book.is_accessible_to(request.user):
return HttpResponseRedirect(book.get_absolute_url())
return super(CustomPDFFormView, self).validate_object(obj, request)
list_display = ['payed_at', 'offer', 'amount', 'name', 'email', 'perk_names']
search_fields = ['name', 'email', 'offer__title', 'offer__author']
list_filter = [PayedFilter, 'offer', PerksFilter]
+ search_fields = ['user']
actions = [export_as_csv_action(
fields=[
'id', 'offer', 'name', 'email', 'amount', 'payed_at',
W przypadku podania danych zostaną one wykorzystane w sposób podany powyżej, a w przypadku wyrażenia dodatkowej zgody
adres e-mail zostanie wykorzystany także w celu przesyłania newslettera Wolnych Lektur.'''
- def __init__(self, offer, *args, **kwargs):
+ def __init__(self, request, offer, *args, **kwargs):
self.offer = offer
+ self.user = request.user if request.user.is_authenticated else None
super(FundingForm, self).__init__(*args, **kwargs)
self.fields['amount'].widget.form_instance = self
email=self.cleaned_data['email'],
amount=self.cleaned_data['amount'],
language_code=get_language(),
+ user=self.user,
)
funding.perks.set(funding.offer.get_perks(funding.amount))
return funding
--- /dev/null
+# Generated by Django 2.2.27 on 2022-04-07 08:38
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('funding', '0005_auto_20210120_1358'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='funding',
+ name='user',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
+ ),
+ ]
offer = models.ForeignKey(Offer, models.PROTECT, verbose_name=_('offer'))
name = models.CharField(_('name'), max_length=127, blank=True)
email = models.EmailField(_('email'), blank=True, db_index=True)
+ user = models.ForeignKey(settings.AUTH_USER_MODEL, models.SET_NULL, blank=True, null=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)
{% block body %}
{% endblock %}{% get_current_language as LANGUAGE_CODE %}
{% if LANGUAGE_CODE == 'pl' %}Chcesz wiedzieć więcej o działaniach realizowanych w ramach projektu Wolne Lektury?
-Zapisz się na nasz newsletter http://{{ site.domain }}{% url 'subscribe' %}, a już nigdy nie przegapisz żadnej publikacji nowej książki czy kolejnej zbiórki.{% endif %}
+Zapisz się na nasz newsletter https://{{ site.domain }}{% url 'subscribe' %}, a już nigdy nie przegapisz żadnej publikacji nowej książki czy kolejnej zbiórki.{% endif %}
{% 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 }}
+https://{{site.domain}}{{ funding.get_disable_notifications_url }}
{% endautoescape %}
{% blocktrans %}we have just published the book you contributed to:{% endblocktrans %}
{{ author }} – {{ offer.book.title }}
- http://{{ site.domain }}{{ offer.book.get_absolute_url }}
+ https://{{ site.domain }}{{ offer.book.get_absolute_url }}
+{% if book.preview %}
+Dzięki Tobie, niedługo będzie bezpłatnie dla wszystkich w wielu formatach. Tymczasem możesz przeczytać ją już teraz jako prapremierę.
+{% if funding.user %}Wystarczy, że zalogujesz się na Wolnych Lekturach (jako {{ funding.user.username }}).
+{% else %}Wystarczy, że zalogujesz się na Wolnych Lekturach i wejdziesz pod ten adres, aby uzyskać wcześniejszy dostęp:
+https://{{ site.domain }}{% url 'funding_claim' funding.notify_key %}
+{% endif %}
+{% else %}
{% blocktrans %}Thanks to you, it is now available for free,
in various formats, to everyone.{% endblocktrans %}
+{% endif %}
+
{% 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' %}
+ https://{{ site.domain }}{% url 'funding_current' %}
{% endif %}{% endblock %}
path('niepowodzenie/', banner_exempt(views.NoThanksView.as_view()), name='funding_nothanks'),
path('wylacz_email/', banner_exempt(views.DisableNotifications.as_view()), name='funding_disable_notifications'),
+ path('przylacz/<key>/', banner_exempt(views.claim), name='funding_claim'),
path('getpaid/', include('getpaid.urls')),
]
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
-from django.http import Http404
+from django.http import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
+from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView, FormView, ListView
from getpaid.models import Payment
if form_class is None:
form_class = self.get_form_class()
if self.request.method == 'POST':
- return form_class(self.object, self.request.POST)
+ return form_class(self.request, self.object, self.request.POST)
else:
- return form_class(self.object, initial={'amount': app_settings.DEFAULT_AMOUNT})
+ return form_class(self.request, self.object, initial={'amount': app_settings.DEFAULT_AMOUNT})
def get_context_data(self, **kwargs):
ctx = super(OfferDetailView, self).get_context_data(**kwargs)
def post(self, *args, **kwargs):
self.object.disable_notifications()
return redirect(self.request.get_full_path())
+
+
+@login_required
+def claim(request, key):
+ funding = get_object_or_404(Funding, notify_key=key)
+ if funding.user is None:
+ funding.user = request.user
+ funding.save()
+ return HttpResponseRedirect(
+ funding.offer.book.get_absolute_url() if funding.offer.book is not None
+ else funding.offer.get_absolute_url()
+ )
+