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
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)
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:
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()
def status(book, user):
if not book.preview:
return 'open'
- elif is_subscribed(user):
+ elif user_is_subscribed(user):
return 'preview'
else:
return 'closed'
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,
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.
def gallery_url(slug):
return '%s%s%s/' % (settings.MEDIA_URL, settings.IMAGE_DIR, slug)
-
-def is_subscribed(user):
- return user_is_subscribed(user)
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
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):
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():
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_])
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)
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)
+++ /dev/null
-# -*- 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