'name': docid } for docid in lib.documents() ]
return {'documents' : document_list}
+
class LibraryHandler(BaseHandler):
allowed_methods = ('GET', 'POST')
'url': reverse('document_view', args=[docid]),
'name': docid } for docid in lib.documents() ]
- return {'documents' : document_list }
+ return {'documents' : document_list }
@validate_form(forms.DocumentUploadForm, 'POST')
def create(self, request, form):
return result
+ def update(self, request, docid):
+ """Update information about the document, like display not"""
+ return
+
#
# Document Text View
#
elif self._mime == MIME_JSON:
data = json.dumps(body, default=lambda o: repr(o) )
else:
- data = u"%s\n%s" % (self.MESSAGE, unicode(self._info))
+ data = u"%s\n%s" % (self.MESSAGE, unicode(body))
data = data.encode('utf-8')
return HttpResponse(content=data, status=self._code, \
def django_response(self):
return ResponseObject.django_response(self, body=None)
-
#
# Client errors
#
ResponseObject.__init__(self, 409, **kwargs)
+#
+# Server side errors
+#
+class NotImplemented(ResponseObject):
+
+ def __init__(self, **kwargs):
+ ResponseObject.__init__(self, 501, **kwargs)
+
def validate_form(formclass, source='GET'):
from functools import wraps
--- /dev/null
+from django.conf import settings
+
+MAINTENANCE_MODE = getattr(settings, 'MAINTENANCE_MODE', False)
\ No newline at end of file
--- /dev/null
+__all__ = ['handler503']
+
+handler503 = 'maintenancemode.views.defaults.temporary_unavailable'
\ No newline at end of file
--- /dev/null
+from django.http import HttpResponse
+
+class HttpResponseTemporaryUnavailable(HttpResponse):
+ status_code = 503
--- /dev/null
+from django.conf import settings
+from django.core import urlresolvers
+
+# This is django-maintancemode v. 0.9.2
+
+from django.conf.urls import defaults
+defaults.handler503 = 'maintenancemode.views.defaults.temporary_unavailable'
+defaults.__all__.append('handler503')
+
+from maintenancemode.conf.settings import MAINTENANCE_MODE
+
+class MaintenanceModeMiddleware(object):
+ def process_request(self, request):
+ # Allow access if middleware is not activated
+ if not MAINTENANCE_MODE:
+ return None
+
+ # Allow access if remote ip is in INTERNAL_IPS
+ if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
+ return None
+
+ # Allow acess if the user doing the request is logged in and a
+ # staff member.
+ if hasattr(request, 'user') and request.user.is_staff:
+ return None
+
+ # Otherwise show the user the 503 page
+ resolver = urlresolvers.get_resolver(None)
+
+ callback, param_dict = resolver._resolve_special('503')
+ return callback(request, **param_dict)
\ No newline at end of file
--- /dev/null
+from django.template import Context, loader
+
+from maintenancemode import http
+
+def temporary_unavailable(request, template_name='503.html'):
+ """
+ Default 503 handler, which looks for the requested URL in the redirects
+ table, redirects if found, and displays 404 page if not redirected.
+
+ Templates: `503.html`
+ Context:
+ request_path
+ The path of the requested URL (e.g., '/app/pages/bad_page/')
+ """
+ t = loader.get_template(template_name) # You need to create a 503.html template.
+ return http.HttpResponseTemporaryUnavailable(t.render(Context({})))
\ No newline at end of file
'django.contrib.auth.middleware.AuthenticationMiddleware',
'explorer.middleware.EditorSettingsMiddleware',
'django.middleware.doc.XViewMiddleware',
+
+ 'maintenancemode.middleware.MaintenanceModeMiddleware',
)
ROOT_URLCONF = 'urls'