added link to PR, some cleaning
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 10 Oct 2011 13:04:48 +0000 (15:04 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 10 Oct 2011 13:04:48 +0000 (15:04 +0200)
apps/api/handlers.py
apps/api/urls.py
wolnelektury/templates/catalogue/book_detail.html

index ce29c61..09370fd 100644 (file)
@@ -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()
index d6f0dbf..c060322 100644 (file)
@@ -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('',  
index 5454800..99bbb39 100644 (file)
                 {% if extra_info.source_url %}
                 <li><a href="{{ extra_info.source_url }}">{% trans "Source of the book" %}</a></li>
                 {% endif %}
+                {% if extra_info.about %}
+                <li><a href="{{ extra_info.about }}">{% trans "Book on the Editor's Platform" %}</a></li>
+                {% endif %}
                 {% if book.gazeta_link %}
                 <li><a href="{{ book.gazeta_link }}">{% trans "Book description on Lektury.Gazeta.pl" %}</a></li>
                 {% endif %}