fix
[wolnelektury.git] / src / api / emitters.py
index 40cc717..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
@@ -41,10 +42,11 @@ class SsiQS(object):
 
 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 SsiQS(self.data)
         else:
-            return super(SsiEmitterMixin, self).construct()  # WTF
+            return super(SsiEmitterMixin, self).construct()
 
 
 class SsiJsonEmitter(SsiEmitterMixin, JSONEmitter):
 
 
 class SsiJsonEmitter(SsiEmitterMixin, JSONEmitter):
@@ -67,3 +69,11 @@ class SsiXmlEmitter(SsiEmitterMixin, XMLEmitter):
                 '</resource><resource>'.join(self.construct().get_ssis('xml'))
 
 Emitter.register('xml', SsiXmlEmitter, 'text/xml; charset=utf-8')
                 '</resource><resource>'.join(self.construct().get_ssis('xml'))
 
 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')