- return (patterns('',
- url(r'^$', self.index, name='index'),
- url(r'^css.css$', self.css, name='css'),
- url(r'^api.js$', self.api, name='api'),
- url(r'^router/?$', self.router, name='router'),
- url(r'^models/(?P<app_label>\w+)/?$', self.router, name='models'),
- url(r'^plugins/(?P<plugin_name>\w+)/?$', self.router, name='plugins'),
- url(r'^login$', self.router, name='login'),
- ), self.app_name, self.namespace)
-
- def request_context(self, request, extra_context=None):
- from django.template import RequestContext
- context = RequestContext(request, current_app=self.namespace)
- context.update(extra_context or {})
- context.update({'gilbert': self, 'user': request.user, 'logged_in': self.has_permission(request)})
- return context
-
- def index(self, request, extra_context=None):
- return render_to_response('gilbert/index.html', context_instance=self.request_context(request, extra_context))
-
- def css(self, request, extra_context=None):
- return render_to_response('gilbert/css.css', context_instance=self.request_context(request, extra_context), mimetype='text/css')
-
- def api(self, request, extra_context=None):
- return render_to_response('gilbert/api.js', context_instance=self.request_context(request, extra_context), mimetype='text/javascript')
-
- def router(self, request, app_label=None, plugin_name=None, extra_context=None):
- submitted_form = False
- if request.META['CONTENT_TYPE'].startswith('application/x-www-form-urlencoded'):
- submitted_form = True
-
- if submitted_form:
- post_dict = dict(request.POST)
- ext_request = {
- 'action': post_dict.pop('extAction'),
- 'method': post_dict.pop('extMethod'),
- 'type': post_dict.pop('extType'),
- 'tid': post_dict.pop('extTID'),
- 'data': None,
- 'kwdata': post_dict,
- }
- if 'extUpload' in request.POST:
- ext_request['upload'] = request.POST['extUpload']
- else:
- ext_request = json.loads(request.raw_post_data)
- ext_request['kwdata'] = None
+ urlpatterns = patterns('',
+ url(r'^$', self.protected_view(self.index), name='index'),
+ url(r'^api.js$', self.protected_view(self.api, login_page=False), name='api'),
+ url(r'^icons.css$', self.protected_view(self.icons, login_page=False), name='icons'),
+ url(r'^router$', self.protected_view(self.router, login_page=False), name='router'),
+ url(r'^router/models/(?P<app_label>\w+)$', self.protected_view(self.router, login_page=False), name='model_router'),
+ )
+ return (urlpatterns, self.app_name, self.namespace)
+
+ def login(self, request):
+ context = {
+ 'gilbert': self,
+ 'form_url': request.get_full_path(),
+ }
+ context.update(csrf(request))