# Path: html5_appcache/views.py
# class ManifestAppCache(TemplateView):
#     """
#     Basic template view.
#     It just get the temlate from AppCacheManager and wrap it in a response
#     """
#     template_name = "html5_appcache/manifest"
#     appcache_update = 0
#     force_empty_manifest = False
# 
#     def _do_update(self, request, appcache_registry):
#         """ Actual update function """
#         if (request.user.is_authenticated() and
#                 request.user.has_perm('html5_appcache.can_update_manifest')):
#             appcache_registry.extract_urls()
#             return appcache_registry.get_manifest(update=True)
#         else:
#             return None
# 
#     def get(self, request, *args, **kwargs):
#         empty_manifest = render_to_string(self.template_name, dictionary={
#             'version': 0, 'date': '-', 'network_urls': ['*']
#         })
#         manifest = None
#         if not get_setting("DISABLE"):
#             appcache_registry.setup(request, self.template_name)
#             if self.appcache_update:
#                 manifest = self._do_update(request, appcache_registry)
#                 if not manifest:
#                     return HttpResponseForbidden(
#                         _("Current user is not authorized for this action"))
#             else:
#                 manifest = appcache_registry.get_manifest()
#         if manifest and request.user.is_authenticated():
#             manifest += "\n# version %s" % "auth"
# 
#         if (not manifest or self.force_empty_manifest or
#                 kwargs.get("parameter", False) == 'empty'):
#             manifest = empty_manifest
#         return HttpResponse(content=manifest, content_type="text/cache-manifest")
# 
# class CacheStatusView(View):
#     icons = ('html5_appcache_dirty', 'html5_appcache_clean')
# 
#     def get(self, request, *args, **kwargs):
#         if (request.user.is_authenticated() and
#                 request.user.has_perm('html5_appcache.can_view_cache_status')):
#             filepath = os.path.join(settings.STATIC_ROOT, "img", "%s.png" % (
#                 self.icons[int(is_manifest_clean())]
#             ))
#             with open(filepath, "rb") as wrapper:
#                 response = HttpResponse(list(wrapper), content_type='text/plain')
#                 response['Content-Length'] = os.path.getsize(filepath)
#                 return response
#         else:
#             return HttpResponseForbidden(
#                 _("Current user is not authorized for this action"))
# 
# class ManifestUpdateView(ManifestAppCache):
#     def get(self, request, *args, **kwargs):
#         if request.is_ajax():
#             appcache_registry.setup(request, self.template_name)
#             manifest = self._do_update(request, appcache_registry)
#             if manifest:
#                 content = {
#                     'text': "OK",
#                     'success': True
#                 }
#             else:
#                 content = {
#                     'text': unicode(_("Current user is not authorized for this action")),
#                     'success': False
#                 }
#             return HttpResponse(content=json.dumps(content), content_type="text/plain")
#         return HttpResponseBadRequest(_("Method not allowed for this view"))


from django.conf.urls import url, patterns
from django.views.decorators.cache import never_cache
from html5_appcache.views import (ManifestAppCache, CacheStatusView,
                                  ManifestUpdateView)
# -*- coding: utf-8 -*-


urlpatterns = patterns(
    '',
    url("^manifest.appcache$",
        never_cache(ManifestAppCache.as_view()),
        name="appcache_manifest"),
    url("^manifest/empty.appcache$",

# Path: html5_appcache/views.py
# class ManifestAppCache(TemplateView):
#     """
#     Basic template view.
#     It just get the temlate from AppCacheManager and wrap it in a response
#     """
#     template_name = "html5_appcache/manifest"
#     appcache_update = 0
#     force_empty_manifest = False
# 
#     def _do_update(self, request, appcache_registry):
#         """ Actual update function """
#         if (request.user.is_authenticated() and
#                 request.user.has_perm('html5_appcache.can_update_manifest')):
#             appcache_registry.extract_urls()
#             return appcache_registry.get_manifest(update=True)
#         else:
#             return None
# 
#     def get(self, request, *args, **kwargs):
#         empty_manifest = render_to_string(self.template_name, dictionary={
#             'version': 0, 'date': '-', 'network_urls': ['*']
#         })
#         manifest = None
#         if not get_setting("DISABLE"):
#             appcache_registry.setup(request, self.template_name)
#             if self.appcache_update:
#                 manifest = self._do_update(request, appcache_registry)
#                 if not manifest:
#                     return HttpResponseForbidden(
#                         _("Current user is not authorized for this action"))
#             else:
#                 manifest = appcache_registry.get_manifest()
#         if manifest and request.user.is_authenticated():
#             manifest += "\n# version %s" % "auth"
# 
#         if (not manifest or self.force_empty_manifest or
#                 kwargs.get("parameter", False) == 'empty'):
#             manifest = empty_manifest
#         return HttpResponse(content=manifest, content_type="text/cache-manifest")
# 
# class CacheStatusView(View):
#     icons = ('html5_appcache_dirty', 'html5_appcache_clean')
# 
#     def get(self, request, *args, **kwargs):
#         if (request.user.is_authenticated() and
#                 request.user.has_perm('html5_appcache.can_view_cache_status')):
#             filepath = os.path.join(settings.STATIC_ROOT, "img", "%s.png" % (
#                 self.icons[int(is_manifest_clean())]
#             ))
#             with open(filepath, "rb") as wrapper:
#                 response = HttpResponse(list(wrapper), content_type='text/plain')
#                 response['Content-Length'] = os.path.getsize(filepath)
#                 return response
#         else:
#             return HttpResponseForbidden(
#                 _("Current user is not authorized for this action"))
# 
# class ManifestUpdateView(ManifestAppCache):
#     def get(self, request, *args, **kwargs):
#         if request.is_ajax():
#             appcache_registry.setup(request, self.template_name)
#             manifest = self._do_update(request, appcache_registry)
#             if manifest:
#                 content = {
#                     'text': "OK",
#                     'success': True
#                 }
#             else:
#                 content = {
#                     'text': unicode(_("Current user is not authorized for this action")),
#                     'success': False
#                 }
#             return HttpResponse(content=json.dumps(content), content_type="text/plain")
#         return HttpResponseBadRequest(_("Method not allowed for this view"))


# Path: html5_appcache/urls.py
from django.conf.urls import url, patterns
from django.views.decorators.cache import never_cache
from html5_appcache.views import (ManifestAppCache, CacheStatusView,
                                  ManifestUpdateView)

# -*- coding: utf-8 -*-


urlpatterns = patterns(
    '',
    url("^manifest.appcache$",
        never_cache(ManifestAppCache.as_view()),
        name="appcache_manifest"),
    url("^manifest/empty.appcache$",

        never_cache(ManifestAppCache.as_view(force_empty_manifest=1)),