# Path: sveedocuments/models.py
# DOCUMENTS_PAGE_TEMPLATES_CHOICES = [(k,v[1]) for k,v in settings.DOCUMENTS_PAGE_TEMPLATES.items()]
# DOCUMENTS_VISIBILTY_CHOICES = (
#     (True, _('Visible')),
#     (False, _('Hidden')),
# )
# IMAGE_MIMETYPES = (
#     'image/gif',
#     'image/jpeg',
#     'image/png',
#     #'image/tiff',
#     'image/svg+xml',
# )
# ATTACH_FILE_UPLOADTO = lambda x,y: content_file_name('pages/attachments/%Y/%m/%d', x, y)
#     ATTACHMENTS_WITH_SENDFILE = False
#     ATTACHMENT_FS_STORAGE = FileSystemStorage(location=settings.MEDIA_ROOT, base_url=settings.MEDIA_URL)
#     ATTACHMENTS_WITH_SENDFILE = True
#     ATTACHMENT_FS_STORAGE = FileSystemStorage(location=settings.SENDFILE_ROOT, base_url=settings.SENDFILE_URL)
# class Insert(models.Model):
#     class Meta:
# class PageModelBase(models.Model):
#     class Meta:
# class Page(PageModelBase):
#     class Meta:
# class PageRevision(PageModelBase):
#     class Meta:
# class Attachment(models.Model):
#     class Meta:
#     def __unicode__(self):
#     def get_render_cache_key(self, **kwargs):
#     def get_toc_cache_key(self, **kwargs):
#     def save(self, *args, **kwargs):
#     def delete(self, using=None):
#     def clear_cache(self):
#     def __unicode__(self):
#     def get_template(self):
#     def get_absolute_url(self):
#     def get_render_cache_key(self, **kwargs):
#     def get_toc_cache_key(self, **kwargs):
#     def clear_cache(self):
#     def _get_current_revision(self):
#     def save(self, *args, **kwargs):
#     def delete(self, using=None):
#     def __unicode__(self):
#     def is_image(self):
#     def save(self, *args, **kwargs):
# 
# Path: sveedocuments/utils/braces_addons.py
# class DownloadMixin(object):
#     """
#     Simple Mixin to send a downloadable content
#     
#     Inherits must have :
#     
#     * Filled the ``self.content_type`` attribute with the content content_type to send;
#     * Implementation of ``get_filename()`` that return the filename to use in response 
#       headers;
#     * Implementation of ``get_content()`` that return the content to send as downloadable.
#     
#     If the content is a not a string, it is assumed to be a fileobject to send as 
#     the content with its ``read()`` method.
#     
#     Optionnaly implement a ``close_content()`` to close specifics objects linked to 
#     content fileobject, if it does not exists a try will be made on a close() method 
#     on the content fileobject;
#     
#     A "get_filename_timestamp" method is implemented to return a timestamp to use in your 
#     filename if needed, his date format is defined in "timestamp_format" attribute (in a 
#     suitable way to use with strftime on a datetime object).
#     """
#     content_type = None
#     timestamp_format = "%Y-%m-%d"
#     
#     def get_filename_timestamp(self):
#         return datetime.datetime.now().strftime(self.timestamp_format)
#     
#     def get_filename(self, context):
#         raise ImproperlyConfigured("DownloadMixin requires an implementation of 'get_filename()' to return the filename to use in headers")
#     
#     def get_content(self, context):
#         raise ImproperlyConfigured("DownloadMixin requires an implementation of 'get_content()' to return the downloadable content")
#     
#     def render_to_response(self, context, **response_kwargs):
#         if getattr(self, 'content_type', None) is None:
#             raise ImproperlyConfigured("DownloadMixin requires a definition of 'content_type' attribute")
#         # Needed headers
#         response = HttpResponse(content_type=self.content_type, **response_kwargs)
#         response['Content-Disposition'] = 'attachment; filename={0}'.format(self.get_filename(context))
#         # Read the content file object or string, append it to response and close it
#         content = self.get_content(context)
#         if isinstance(content, basestring):
#             response.write(content)
#         else:
#             response.write(content.read())
#         # Conditionnal closing content object
#         if hasattr(self, 'close_content'):
#             self.close_content(context, content)
#         elif hasattr(content, 'close'):
#             content.close()
#             
#         return response
# 
#     def get_context_data(self, **kwargs):
#         return {
#             'params': kwargs
#         }
# 
#     def get(self, request, *args, **kwargs):
#         context = self.get_context_data(**kwargs)
#         return self.render_to_response(context)


import json, os
from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponse, Http404
from django.views import generic
from mptt.templatetags.mptt_tags import cache_tree_children
from braces.views import LoginRequiredMixin
from rstview.parser import SourceParser
from sveedocuments import models
from sveedocuments.utils.braces_addons import DownloadMixin
        
        context = {'content' : SourceParser(content, silent=False)}
        return self.render_to_response(context)


class PageDetailsMixin(object):
    """
    Page view
    """
    model = models.Page
    context_object_name = "page_instance"
    template_name = "sveedocuments/page_details/page_default.html"
    
    def get_object(self, *args, **kwargs):
        """
        Memorize object to avoid multiple database access when using ``get_object()`` 
        method
        """
        cache_key = "_cache_get_object"
        if not hasattr(self, cache_key):
            setattr(self, cache_key, super(PageDetailsMixin, self).get_object(*args, **kwargs))
        return getattr(self, cache_key)
    
    def get_attachments(self):
        return self.object.attachment.all()
        
    def get_context_data(self, **kwargs):
        context = super(PageDetailsMixin, self).get_context_data(**kwargs)
        context.update({
            'attachments': self.get_attachments(),

# Path: sveedocuments/models.py
# DOCUMENTS_PAGE_TEMPLATES_CHOICES = [(k,v[1]) for k,v in settings.DOCUMENTS_PAGE_TEMPLATES.items()]
# DOCUMENTS_VISIBILTY_CHOICES = (
#     (True, _('Visible')),
#     (False, _('Hidden')),
# )
# IMAGE_MIMETYPES = (
#     'image/gif',
#     'image/jpeg',
#     'image/png',
#     #'image/tiff',
#     'image/svg+xml',
# )
# ATTACH_FILE_UPLOADTO = lambda x,y: content_file_name('pages/attachments/%Y/%m/%d', x, y)
#     ATTACHMENTS_WITH_SENDFILE = False
#     ATTACHMENT_FS_STORAGE = FileSystemStorage(location=settings.MEDIA_ROOT, base_url=settings.MEDIA_URL)
#     ATTACHMENTS_WITH_SENDFILE = True
#     ATTACHMENT_FS_STORAGE = FileSystemStorage(location=settings.SENDFILE_ROOT, base_url=settings.SENDFILE_URL)
# class Insert(models.Model):
#     class Meta:
# class PageModelBase(models.Model):
#     class Meta:
# class Page(PageModelBase):
#     class Meta:
# class PageRevision(PageModelBase):
#     class Meta:
# class Attachment(models.Model):
#     class Meta:
#     def __unicode__(self):
#     def get_render_cache_key(self, **kwargs):
#     def get_toc_cache_key(self, **kwargs):
#     def save(self, *args, **kwargs):
#     def delete(self, using=None):
#     def clear_cache(self):
#     def __unicode__(self):
#     def get_template(self):
#     def get_absolute_url(self):
#     def get_render_cache_key(self, **kwargs):
#     def get_toc_cache_key(self, **kwargs):
#     def clear_cache(self):
#     def _get_current_revision(self):
#     def save(self, *args, **kwargs):
#     def delete(self, using=None):
#     def __unicode__(self):
#     def is_image(self):
#     def save(self, *args, **kwargs):
# 
# Path: sveedocuments/utils/braces_addons.py
# class DownloadMixin(object):
#     """
#     Simple Mixin to send a downloadable content
#     
#     Inherits must have :
#     
#     * Filled the ``self.content_type`` attribute with the content content_type to send;
#     * Implementation of ``get_filename()`` that return the filename to use in response 
#       headers;
#     * Implementation of ``get_content()`` that return the content to send as downloadable.
#     
#     If the content is a not a string, it is assumed to be a fileobject to send as 
#     the content with its ``read()`` method.
#     
#     Optionnaly implement a ``close_content()`` to close specifics objects linked to 
#     content fileobject, if it does not exists a try will be made on a close() method 
#     on the content fileobject;
#     
#     A "get_filename_timestamp" method is implemented to return a timestamp to use in your 
#     filename if needed, his date format is defined in "timestamp_format" attribute (in a 
#     suitable way to use with strftime on a datetime object).
#     """
#     content_type = None
#     timestamp_format = "%Y-%m-%d"
#     
#     def get_filename_timestamp(self):
#         return datetime.datetime.now().strftime(self.timestamp_format)
#     
#     def get_filename(self, context):
#         raise ImproperlyConfigured("DownloadMixin requires an implementation of 'get_filename()' to return the filename to use in headers")
#     
#     def get_content(self, context):
#         raise ImproperlyConfigured("DownloadMixin requires an implementation of 'get_content()' to return the downloadable content")
#     
#     def render_to_response(self, context, **response_kwargs):
#         if getattr(self, 'content_type', None) is None:
#             raise ImproperlyConfigured("DownloadMixin requires a definition of 'content_type' attribute")
#         # Needed headers
#         response = HttpResponse(content_type=self.content_type, **response_kwargs)
#         response['Content-Disposition'] = 'attachment; filename={0}'.format(self.get_filename(context))
#         # Read the content file object or string, append it to response and close it
#         content = self.get_content(context)
#         if isinstance(content, basestring):
#             response.write(content)
#         else:
#             response.write(content.read())
#         # Conditionnal closing content object
#         if hasattr(self, 'close_content'):
#             self.close_content(context, content)
#         elif hasattr(content, 'close'):
#             content.close()
#             
#         return response
# 
#     def get_context_data(self, **kwargs):
#         return {
#             'params': kwargs
#         }
# 
#     def get(self, request, *args, **kwargs):
#         context = self.get_context_data(**kwargs)
#         return self.render_to_response(context)


# Path: sveedocuments/views/page.py
import json, os
from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponse, Http404
from django.views import generic
from mptt.templatetags.mptt_tags import cache_tree_children
from braces.views import LoginRequiredMixin
from rstview.parser import SourceParser
from sveedocuments import models
from sveedocuments.utils.braces_addons import DownloadMixin

        
        context = {'content' : SourceParser(content, silent=False)}
        return self.render_to_response(context)


class PageDetailsMixin(object):
    """
    Page view
    """
    model = models.Page
    context_object_name = "page_instance"
    template_name = "sveedocuments/page_details/page_default.html"
    
    def get_object(self, *args, **kwargs):
        """
        Memorize object to avoid multiple database access when using ``get_object()`` 
        method
        """
        cache_key = "_cache_get_object"
        if not hasattr(self, cache_key):
            setattr(self, cache_key, super(PageDetailsMixin, self).get_object(*args, **kwargs))
        return getattr(self, cache_key)
    
    def get_attachments(self):
        return self.object.attachment.all()
        
    def get_context_data(self, **kwargs):
        context = super(PageDetailsMixin, self).get_context_data(**kwargs)
        context.update({
            'attachments': self.get_attachments(),

            'ATTACHMENTS_WITH_SENDFILE': models.ATTACHMENTS_WITH_SENDFILE,