Prevent model loading too early, remove some unused code.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 17 Dec 2018 20:08:43 +0000 (21:08 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 19 Dec 2018 20:42:27 +0000 (21:42 +0100)
src/api/handlers.py
src/catalogue/templatetags/catalogue_tags.py
src/catalogue/tests/test_visit.py
src/catalogue/utils.py
src/catalogue/views.py
src/paypal/models.py
src/paypal/nvp_soap.py [deleted file]

index d32981e..eb18e05 100644 (file)
@@ -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:
index 6906f60..5efdb05 100644 (file)
@@ -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'
index 5e640ad..e6a83ed 100644 (file)
@@ -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,
index 9878a70..1c18841 100644 (file)
@@ -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)
index dc6de7b..f6d6cd5 100644 (file)
@@ -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)
 
index 80aa357..4266882 100644 (file)
@@ -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 (file)
index 09f8f62..0000000
+++ /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