app redirect for paypal
[wolnelektury.git] / src / api / emitters.py
index 2f6f7e7..531ae19 100644 (file)
@@ -9,6 +9,7 @@ When outputting a queryset of selected models, instead of returning
 XML or JSON stanzas, SSI include statements are returned.
 
 """
 XML or JSON stanzas, SSI include statements are returned.
 
 """
+from django.conf import settings
 from django.core.urlresolvers import reverse
 from django.db.models.query import QuerySet
 from piston.emitters import Emitter, XMLEmitter, JSONEmitter
 from django.core.urlresolvers import reverse
 from django.db.models.query import QuerySet
 from piston.emitters import Emitter, XMLEmitter, JSONEmitter
@@ -27,21 +28,22 @@ class SsiQS(object):
 
     def get_ssis(self, emitter_format):
         """Yields SSI include statements for the queryset."""
 
     def get_ssis(self, emitter_format):
         """Yields SSI include statements for the queryset."""
-        url_pattern = reverse('api_include',
-                kwargs={'model': self.queryset.model.__name__.lower(),
-                    'pk': '0000',
-                    'emitter_format': emitter_format,
-                    'lang': get_language(),
-                    })
+        url_pattern = reverse(
+            'api_include',
+            kwargs={
+                'model': self.queryset.model.__name__.lower(),
+                'pk': '0000',
+                'emitter_format': emitter_format,
+                'lang': get_language(),
+            })
         for instance in self.queryset:
         for instance in self.queryset:
-            yield "<!--#include file='%s'-->" % url_pattern.replace('0000',
-                    str(instance.pk))
+            yield "<!--#include file='%s'-->" % url_pattern.replace('0000', str(instance.pk))
 
 
 class SsiEmitterMixin(object):
     def construct(self):
 
 
 class SsiEmitterMixin(object):
     def construct(self):
-        if isinstance(self.data, QuerySet) and self.data.model in (Book,
-                Fragment, Tag):
+        ssify_api = getattr(settings, 'SSIFY_API', True)
+        if ssify_api and isinstance(self.data, QuerySet) and self.data.model in (Book, Fragment, Tag):
             return SsiQS(self.data)
         else:
             return super(SsiEmitterMixin, self).construct()
             return SsiQS(self.data)
         else:
             return super(SsiEmitterMixin, self).construct()
@@ -68,3 +70,10 @@ class SsiXmlEmitter(SsiEmitterMixin, XMLEmitter):
 
 Emitter.register('xml', SsiXmlEmitter, 'text/xml; charset=utf-8')
 
 
 Emitter.register('xml', SsiXmlEmitter, 'text/xml; charset=utf-8')
 
+
+# hack
+class EpubEmitter(Emitter):
+    def render(self, request):
+        return self.data
+
+Emitter.register('epub', EpubEmitter, 'application/epub+zip')