# Path: djedi/compat.py
# def patterns(*urls):
#         def parse_bits(parser, bits, params, varargs, varkw, defaults,
#                        takes_context, name):
#     def generic_tag_compiler(parser, token, params, varargs, varkw, defaults,
#                              name, takes_context, node_class):
#         def __init__(self, *args, **kwargs):
#     def get_cache(name):
#     def getargspec(func):
#     class TemplateResponse(BaseTemplateResponse):
# 
# Path: djedi/admin/api.py
# class LoadApi(JSONResponseMixin, APIView):
# 
#     @never_cache
#     def get(self, request, uri):
#         """
#         Load raw node source from storage.
# 
#         JSON Response:
#             {uri: x, data: y}
#         """
#         uri = self.decode_uri(uri)
#         node = cio.load(uri)
#         return self.render_to_json(node)
# 
# class NodeApi(JSONResponseMixin, APIView):
# 
#     @never_cache
#     def get(self, request, uri):
#         """
#         Return published node or specified version.
# 
#         JSON Response:
#             {uri: x, content: y}
#         """
#         uri = self.decode_uri(uri)
#         node = cio.get(uri, lazy=False)
# 
#         if node.content is None:
#             raise Http404
# 
#         return self.render_to_json({
#             'uri': node.uri,
#             'content': node.content
#         })
# 
#     def post(self, request, uri):
#         """
#         Set node data for uri, return rendered content.
# 
#         JSON Response:
#             {uri: x, content: y}
#         """
#         uri = self.decode_uri(uri)
#         data, meta = self.get_post_data(request)
#         meta['author'] = auth.get_username(request)
#         node = cio.set(uri, data, publish=False, **meta)
#         return self.render_to_json(node)
# 
#     def delete(self, request, uri):
#         """
#         Delete versioned uri and return empty text response on success.
#         """
#         uri = self.decode_uri(uri)
#         uris = cio.delete(uri)
# 
#         if uri not in uris:
#             raise Http404
# 
#         return self.render_to_response()
# 
# class NodeEditor(JSONResponseMixin, DjediContextMixin, APIView):
# 
#     @never_cache
#     @xframe_options_exempt
#     def get(self, request, uri):
#         try:
#             uri = self.decode_uri(uri)
#             uri = URI(uri)
#             plugin = plugins.resolve(uri)
#             plugin_context = self.get_context_data(uri=uri)
# 
#             if isinstance(plugin, DjediPlugin):
#                 plugin_context = plugin.get_editor_context(**plugin_context)
# 
#         except UnknownPlugin:
#             raise Http404
#         else:
#             return self.render_plugin(request, plugin_context)
# 
#     @never_cache
#     def post(self, request, uri):
#         uri = self.decode_uri(uri)
#         data, meta = self.get_post_data(request)
#         meta['author'] = auth.get_username(request)
#         node = cio.set(uri, data, publish=False, **meta)
# 
#         context = cio.load(node.uri)
#         context['content'] = node.content
# 
#         if request.is_ajax():
#             return self.render_to_json(context)
#         else:
#             return self.render_plugin(request, context)
# 
#     def render_plugin(self, request, context):
#         return TemplateResponse(request, [
#             'djedi/plugins/%s/editor.html' % context['uri'].ext,
#             'djedi/plugins/base/editor.html'
#         ], self.get_context_data(**context))
# 
# class PublishApi(JSONResponseMixin, APIView):
# 
#     def put(self, request, uri):
#         """
#         Publish versioned uri.
# 
#         JSON Response:
#             {uri: x, content: y}
#         """
#         uri = self.decode_uri(uri)
#         node = cio.publish(uri)
# 
#         if not node:
#             raise Http404
# 
#         return self.render_to_json(node)
# 
# class RenderApi(APIView):
# 
#     def post(self, request, ext):
#         """
#         Render data for plugin and return text response.
#         """
#         try:
#             plugin = plugins.get(ext)
#             data, meta = self.get_post_data(request)
#             data = plugin.load(data)
#         except UnknownPlugin:
#             raise Http404
#         else:
#             content = plugin.render(data)
#             return self.render_to_response(content)
# 
# class RevisionsApi(JSONResponseMixin, APIView):
# 
#     def get(self, request, uri):
#         """
#         List uri revisions.
# 
#         JSON Response:
#             [[uri, state], ...]
#         """
#         uri = self.decode_uri(uri)
#         revisions = cio.revisions(uri)
#         revisions = [list(revision) for revision in revisions]  # Convert tuples to lists
#         return self.render_to_json(revisions)
# 
# Path: djedi/admin/cms.py
# class DjediCMS(DjediContextMixin, View):
# 
#     @xframe_options_exempt
#     def get(self, request):
#         if has_permission(request):
#             return render(request, 'djedi/cms/cms.html', self.get_context_data())
#         else:
#             raise PermissionDenied


from ..compat import include, patterns, url
from .api import LoadApi, NodeApi, NodeEditor, PublishApi, RenderApi, RevisionsApi
from .cms import DjediCMS

app_name = 'djedi'

urlpatterns = patterns(
    url(r'^$', DjediCMS.as_view(), name='cms'),
    url(r'^node/(?P<uri>.+)/editor$', NodeEditor.as_view(), name='cms.editor'),
    url(r'^node/(?P<uri>.+)/load$', LoadApi.as_view(), name='api.load'),

# Path: djedi/compat.py
# def patterns(*urls):
#         def parse_bits(parser, bits, params, varargs, varkw, defaults,
#                        takes_context, name):
#     def generic_tag_compiler(parser, token, params, varargs, varkw, defaults,
#                              name, takes_context, node_class):
#         def __init__(self, *args, **kwargs):
#     def get_cache(name):
#     def getargspec(func):
#     class TemplateResponse(BaseTemplateResponse):
# 
# Path: djedi/admin/api.py
# class LoadApi(JSONResponseMixin, APIView):
# 
#     @never_cache
#     def get(self, request, uri):
#         """
#         Load raw node source from storage.
# 
#         JSON Response:
#             {uri: x, data: y}
#         """
#         uri = self.decode_uri(uri)
#         node = cio.load(uri)
#         return self.render_to_json(node)
# 
# class NodeApi(JSONResponseMixin, APIView):
# 
#     @never_cache
#     def get(self, request, uri):
#         """
#         Return published node or specified version.
# 
#         JSON Response:
#             {uri: x, content: y}
#         """
#         uri = self.decode_uri(uri)
#         node = cio.get(uri, lazy=False)
# 
#         if node.content is None:
#             raise Http404
# 
#         return self.render_to_json({
#             'uri': node.uri,
#             'content': node.content
#         })
# 
#     def post(self, request, uri):
#         """
#         Set node data for uri, return rendered content.
# 
#         JSON Response:
#             {uri: x, content: y}
#         """
#         uri = self.decode_uri(uri)
#         data, meta = self.get_post_data(request)
#         meta['author'] = auth.get_username(request)
#         node = cio.set(uri, data, publish=False, **meta)
#         return self.render_to_json(node)
# 
#     def delete(self, request, uri):
#         """
#         Delete versioned uri and return empty text response on success.
#         """
#         uri = self.decode_uri(uri)
#         uris = cio.delete(uri)
# 
#         if uri not in uris:
#             raise Http404
# 
#         return self.render_to_response()
# 
# class NodeEditor(JSONResponseMixin, DjediContextMixin, APIView):
# 
#     @never_cache
#     @xframe_options_exempt
#     def get(self, request, uri):
#         try:
#             uri = self.decode_uri(uri)
#             uri = URI(uri)
#             plugin = plugins.resolve(uri)
#             plugin_context = self.get_context_data(uri=uri)
# 
#             if isinstance(plugin, DjediPlugin):
#                 plugin_context = plugin.get_editor_context(**plugin_context)
# 
#         except UnknownPlugin:
#             raise Http404
#         else:
#             return self.render_plugin(request, plugin_context)
# 
#     @never_cache
#     def post(self, request, uri):
#         uri = self.decode_uri(uri)
#         data, meta = self.get_post_data(request)
#         meta['author'] = auth.get_username(request)
#         node = cio.set(uri, data, publish=False, **meta)
# 
#         context = cio.load(node.uri)
#         context['content'] = node.content
# 
#         if request.is_ajax():
#             return self.render_to_json(context)
#         else:
#             return self.render_plugin(request, context)
# 
#     def render_plugin(self, request, context):
#         return TemplateResponse(request, [
#             'djedi/plugins/%s/editor.html' % context['uri'].ext,
#             'djedi/plugins/base/editor.html'
#         ], self.get_context_data(**context))
# 
# class PublishApi(JSONResponseMixin, APIView):
# 
#     def put(self, request, uri):
#         """
#         Publish versioned uri.
# 
#         JSON Response:
#             {uri: x, content: y}
#         """
#         uri = self.decode_uri(uri)
#         node = cio.publish(uri)
# 
#         if not node:
#             raise Http404
# 
#         return self.render_to_json(node)
# 
# class RenderApi(APIView):
# 
#     def post(self, request, ext):
#         """
#         Render data for plugin and return text response.
#         """
#         try:
#             plugin = plugins.get(ext)
#             data, meta = self.get_post_data(request)
#             data = plugin.load(data)
#         except UnknownPlugin:
#             raise Http404
#         else:
#             content = plugin.render(data)
#             return self.render_to_response(content)
# 
# class RevisionsApi(JSONResponseMixin, APIView):
# 
#     def get(self, request, uri):
#         """
#         List uri revisions.
# 
#         JSON Response:
#             [[uri, state], ...]
#         """
#         uri = self.decode_uri(uri)
#         revisions = cio.revisions(uri)
#         revisions = [list(revision) for revision in revisions]  # Convert tuples to lists
#         return self.render_to_json(revisions)
# 
# Path: djedi/admin/cms.py
# class DjediCMS(DjediContextMixin, View):
# 
#     @xframe_options_exempt
#     def get(self, request):
#         if has_permission(request):
#             return render(request, 'djedi/cms/cms.html', self.get_context_data())
#         else:
#             raise PermissionDenied


# Path: djedi/admin/urls.py
from ..compat import include, patterns, url
from .api import LoadApi, NodeApi, NodeEditor, PublishApi, RenderApi, RevisionsApi
from .cms import DjediCMS


app_name = 'djedi'

urlpatterns = patterns(
    url(r'^$', DjediCMS.as_view(), name='cms'),
    url(r'^node/(?P<uri>.+)/editor$', NodeEditor.as_view(), name='cms.editor'),
    url(r'^node/(?P<uri>.+)/load$', LoadApi.as_view(), name='api.load'),

    url(r'^node/(?P<uri>.+)/publish$', PublishApi.as_view(), name='api.publish'),