From: Radek Czajka Date: Mon, 10 Oct 2011 13:04:48 +0000 (+0200) Subject: added link to PR, some cleaning X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/52c28b63e294283d557c9b26d3a2b267a2938a09?ds=sidebyside;hp=-c added link to PR, some cleaning --- 52c28b63e294283d557c9b26d3a2b267a2938a09 diff --git a/apps/api/handlers.py b/apps/api/handlers.py index ce29c61cc..09370fd36 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -5,30 +5,14 @@ from functools import wraps from django.shortcuts import get_object_or_404 -from django.contrib.auth.decorators import login_required, permission_required -from piston.handler import BaseHandler +from piston.handler import AnonymousBaseHandler, BaseHandler from piston.utils import rc, validate from catalogue.models import Book from catalogue.forms import BookImportForm -def method_decorator(function_decorator): - """ - Turns a function(*args, **kwargs) decorator into an - equivalent decorator for method(self, *args, **kwargs). - """ - @wraps(function_decorator) - def decorator(method): - @wraps(method) - def decorated_method(self, *args, **kwargs): - def method_as_function(*fargs, **fkwargs): - return method(self, *fargs, **fkwargs) - return function_decorator(method_as_function)(*args, **kwargs) - return decorated_method - return decorator - -class BookHandler(BaseHandler): +class AnonymousBooksHandler(AnonymousBaseHandler): model = Book fields = ('slug', 'title') @@ -38,8 +22,16 @@ class BookHandler(BaseHandler): else: return Book.objects.all() - @method_decorator(permission_required('catalogue.add_book')) + +class BooksHandler(BaseHandler): + model = Book + fields = ('slug', 'title') + anonymous = AnonymousBooksHandler + def create(self, request): + if not request.user.has_perm('catalogue.add_book'): + return rc.FORBIDDEN + form = BookImportForm(request.POST, request.FILES) if form.is_valid(): form.save() diff --git a/apps/api/urls.py b/apps/api/urls.py index d6f0dbf91..c060322fd 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -3,11 +3,11 @@ from django.conf.urls.defaults import * from piston.resource import Resource from piston.authentication import OAuthAuthentication -from api.handlers import BookHandler +from api.handlers import BooksHandler auth = OAuthAuthentication(realm="Wolne Lektury") -book_resource = Resource(handler=BookHandler, authentication=auth) +book_resource = Resource(handler=BooksHandler, authentication=auth) urlpatterns = patterns('', diff --git a/wolnelektury/templates/catalogue/book_detail.html b/wolnelektury/templates/catalogue/book_detail.html index 54548007e..99bbb39b2 100644 --- a/wolnelektury/templates/catalogue/book_detail.html +++ b/wolnelektury/templates/catalogue/book_detail.html @@ -157,6 +157,9 @@ {% if extra_info.source_url %}
  • {% trans "Source of the book" %}
  • {% endif %} + {% if extra_info.about %} +
  • {% trans "Book on the Editor's Platform" %}
  • + {% endif %} {% if book.gazeta_link %}
  • {% trans "Book description on Lektury.Gazeta.pl" %}
  • {% endif %}