From: Radek Czajka Date: Mon, 17 Dec 2018 20:08:43 +0000 (+0100) Subject: Prevent model loading too early, remove some unused code. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/d5e836566b0bbff5242de33acc264ca94ad11f49?hp=bad0ebfd2747e44e647b743e866a5cb42994d16e Prevent model loading too early, remove some unused code. --- diff --git a/src/api/handlers.py b/src/api/handlers.py index d32981e04..eb18e0502 100644 --- a/src/api/handlers.py +++ b/src/api/handlers.py @@ -19,8 +19,8 @@ from api.models import BookUserData from catalogue.forms import BookImportForm from catalogue.models import Book, Tag, BookMedia, Fragment, Collection from catalogue.models.tag import prefetch_relations -from catalogue.utils import is_subscribed from librarian.cover import WLCover +from paypal.rest import user_is_subscribed from picture.models import Picture from picture.forms import PictureImportForm from social.utils import likes @@ -330,7 +330,7 @@ class BooksHandler(BookDetailHandler): class EpubHandler(BookDetailHandler): def read(self, request, slug): - if not is_subscribed(request.user): + if not user_is_subscribed(request.user): return rc.FORBIDDEN try: book = Book.objects.get(slug=slug) @@ -730,7 +730,7 @@ class UserDataHandler(BaseHandler): if not request.user.is_authenticated(): return rc.FORBIDDEN if slug is None: - return {'username': request.user.username, 'premium': is_subscribed(request.user)} + return {'username': request.user.username, 'premium': user_is_subscribed(request.user)} try: book = Book.objects.get(slug=slug) except Book.DoesNotExist: diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py index 6906f605d..5efdb05e6 100644 --- a/src/catalogue/templatetags/catalogue_tags.py +++ b/src/catalogue/templatetags/catalogue_tags.py @@ -18,7 +18,7 @@ from ssify import ssi_variable from catalogue.helpers import get_audiobook_tags from catalogue.models import Book, BookMedia, Fragment, Tag, Source from catalogue.constants import LICENSES -from catalogue.utils import is_subscribed +from paypal.rest import user_is_subscribed from picture.models import Picture register = template.Library() @@ -498,7 +498,7 @@ def strip_tag(html, tag_name): def status(book, user): if not book.preview: return 'open' - elif is_subscribed(user): + elif user_is_subscribed(user): return 'preview' else: return 'closed' diff --git a/src/catalogue/tests/test_visit.py b/src/catalogue/tests/test_visit.py index 5e640adad..e6a83edd0 100644 --- a/src/catalogue/tests/test_visit.py +++ b/src/catalogue/tests/test_visit.py @@ -72,7 +72,6 @@ class VisitTest(WLTestCase): prefix = '/katalog/' for expected_status, urls in url_map.items(): for url in urls: - print(url) status = self.client.get(prefix + url).status_code self.assertEqual( status, expected_status, diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index 9878a70f2..1c188418e 100644 --- a/src/catalogue/utils.py +++ b/src/catalogue/utils.py @@ -20,7 +20,6 @@ from django.core.files.uploadedfile import UploadedFile from django.http import HttpResponse from django.utils.encoding import force_unicode -from paypal.rest import user_is_subscribed from reporting.utils import read_chunks # Use the system (hardware-based) random number generator if it exists. @@ -356,6 +355,3 @@ def gallery_path(slug): def gallery_url(slug): return '%s%s%s/' % (settings.MEDIA_URL, settings.IMAGE_DIR, slug) - -def is_subscribed(user): - return user_is_subscribed(user) diff --git a/src/catalogue/views.py b/src/catalogue/views.py index dc6de7b77..f6d6cd5eb 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -20,13 +20,14 @@ from django.utils.translation import ugettext as _, ugettext_lazy from ajaxable.utils import AjaxableFormView from pdcounter import views as pdcounter_views +from paypal.rest import user_is_subscribed from picture.models import Picture, PictureArea from ssify import ssi_included, ssi_expect, SsiVariable as Var from catalogue import constants from catalogue import forms from catalogue.helpers import get_top_level_related_tags from catalogue.models import Book, Collection, Tag, Fragment -from catalogue.utils import split_tags, is_subscribed +from catalogue.utils import split_tags from catalogue.models.tag import prefetch_relations from wolnelektury.utils import is_crawler @@ -140,15 +141,7 @@ def object_list(request, objects, fragments=None, related_tags=None, tags=None, def literature(request): books = Book.objects.filter(parent=None) - - # last_published = Book.objects.exclude(cover_thumb='').filter(parent=None).order_by('-created_at')[:20] - # most_popular = Book.objects.exclude(cover_thumb='')\ - # .order_by('-popularity__count', 'sort_key_author', 'sort_key')[:20] return object_list(request, books, related_tags=get_top_level_related_tags([])) - # extra={ - # 'last_published': last_published, - # 'most_popular': most_popular, - # }) def gallery(request): @@ -306,7 +299,7 @@ def player(request, slug): def book_text(request, slug): book = get_object_or_404(Book, slug=slug) - if book.preview and not is_subscribed(request.user): + if book.preview and not user_is_subscribed(request.user): return HttpResponseRedirect(book.get_absolute_url()) if not book.has_html_file(): @@ -361,7 +354,7 @@ def embargo_link(request, format_, slug): media_file = book.get_media(format_) if not book.preview: return HttpResponseRedirect(media_file.url) - if not is_subscribed(request.user): + if not user_is_subscribed(request.user): return HttpResponseRedirect(book.get_absolute_url()) return HttpResponse(media_file, content_type=constants.EBOOK_CONTENT_TYPES[format_]) @@ -395,7 +388,7 @@ class CustomPDFFormView(AjaxableFormView): def validate_object(self, obj, request): book = obj - if book.preview and not is_subscribed(request.user): + if book.preview and not user_is_subscribed(request.user): return HttpResponseRedirect(book.get_absolute_url()) return super(CustomPDFFormView, self).validate_object(obj, request) diff --git a/src/paypal/models.py b/src/paypal/models.py index 80aa357a6..426688231 100644 --- a/src/paypal/models.py +++ b/src/paypal/models.py @@ -19,10 +19,6 @@ class BillingAgreement(models.Model): active = models.BooleanField(max_length=32) token = models.CharField(max_length=32) - def get_agreement(self): - from .rest import get_agreement - return get_agreement(self.agreement_id) - def check_agreement(self): from .rest import check_agreement return check_agreement(self.agreement_id) diff --git a/src/paypal/nvp_soap.py b/src/paypal/nvp_soap.py deleted file mode 100644 index 09f8f62f3..000000000 --- a/src/paypal/nvp_soap.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- 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. -# -# UNUSED -import requests -import urlparse -from django.conf import settings - -DESC = 'Wolne Lektury subscription' - - -def paypal_request(data): - request_data = { - 'USER': settings.PAYPAL['user'], - 'PWD': settings.PAYPAL['password'], - 'SIGNATURE': settings.PAYPAL['signature'], - 'SUBJECT': settings.PAYPAL['email'], - 'VERSION': 93, - } - request_data.update(data) - - response = requests.post(settings.PAYPAL['api-url'], data=request_data) - return dict(urlparse.parse_qsl(response.text)) - - -def set_express_checkout(amount): - response = paypal_request({ - 'METHOD': 'SetExpressCheckout', - 'PAYMENTREQUEST_0_PAYMENTACTION': 'SALE', - 'PAYMENTREQUEST_0_AMT': amount, - 'PAYMENTREQUEST_0_CURRENCYCODE': 'PLN', - 'L_BILLINGTYPE0': 'RecurringPayments', - 'L_BILLINGAGREEMENTDESCRIPTION0': DESC, - 'RETURNURL': settings.PAYPAL['return-url'], - 'CANCELURL': settings.PAYPAL['cancel-url'], - }) - return response.get('TOKEN') - - -def create_profile(token, amount): - response = paypal_request({ - 'METHOD': 'CreateRecurringPaymentsProfile', - 'TOKEN': token, - 'PROFILESTARTDATE': '2011-03-11T00:00:00Z', - 'DESC': DESC, - 'MAXFAILEDPAYMENTS': 3, - 'AUTOBILLAMT': 'AddToNextBilling', - 'BILLINGPERIOD': 'Month', # or 30 Days? - 'BILLINGFREQUENCY': 1, - 'AMT': amount, - 'CURRENCYCODE': 'PLN', - 'L_PAYMENTREQUEST_0_ITEMCATEGORY0': 'Digital', - 'L_PAYMENTREQUEST_0_NAME0': 'Subskrypcja Wolnych Lektur', - 'L_PAYMENTREQUEST_0_AMT0': amount, - 'L_PAYMENTREQUEST_0_QTY0': 1, - }) - return response.get('PROFILEID') - - -# min amount: 10, max amount: 30000