# Path: sveedocuments/models.py
# class Page(PageModelBase):
#     """
#     Full page document
#     """
#     modified = models.DateTimeField(_('last edit'), auto_now=True)
#     slug = models.SlugField(_('slug'), unique=True, max_length=75, help_text=_("Unique slug used in URL, should be automatically filled with sluggified title."))
#     
#     @models.permalink
#     def get_absolute_url(self):
#         return ('documents-page-details', [self.slug])
#     
#     def get_render_cache_key(self, **kwargs):
#         """
#         Get the cache key for the content render with according to the given settings
#         """
#         return settings.PAGE_RENDER_CACHE_KEY_NAME.format(id=self.id, **kwargs)
#     
#     def get_toc_cache_key(self, **kwargs):
#         """
#         Get the cache key for the content TOC with according to the given settings
#         """
#         return settings.PAGE_TOC_CACHE_KEY_NAME.format(id=self.id, **kwargs)
#     
#     def clear_cache(self):
#         """
#         Invalidate all possible cache keys
#         """
#         keys = _get_cache_keyset(settings.PAGE_RENDER_CACHE_KEY_NAME, **{
#             'id': self.id,
#             'setting': RSTVIEW_PARSER_FILTER_SETTINGS.keys(),
#         })
#         keys += _get_cache_keyset(settings.PAGE_TOC_CACHE_KEY_NAME, **{
#             'id': self.id,
#             'setting': RSTVIEW_PARSER_FILTER_SETTINGS.keys(),
#         })
#         # Drop cache for knowed pages slugs used in the ``page`` rest role
#         cache.delete_many([settings.PAGE_SLUGS_CACHE_KEY_NAME]+keys)
#         return keys
#     
#     def _get_current_revision(self):
#         return (self.revision.all().aggregate(models.Max('revision')).get('revision__max') or 0)+1
#     current_revision = property(_get_current_revision)
#     
#     def save(self, *args, **kwargs):
#         # First create
#         if not self.created:
#             self.created = datetime.now()
#         # Creating a new revision archive
#         elif settings.DOCUMENTS_PAGE_ARCHIVED:
#             old = Page.objects.get(pk=self.id)
#             PageRevision(
#                 page=self,
#                 created=self.modified,
#                 parent=old.parent,
#                 author=old.author,
#                 title=old.title,
#                 published=old.published,
#                 slug=old.slug,
#                 template=old.template,
#                 order=old.order,
#                 visible=old.visible,
#                 content=old.content,
#                 revision=self.current_revision,
#                 comment=old.comment,
#             ).save()
#         
#         # Fill in the published date with the created date if empty
#         if not self.published:
#             self.published = self.created
#         # Invalidate all caches on edit
#         if self.modified:
#             self.clear_cache()
#         
#         super(Page, self).save(*args, **kwargs)
#     
#     def delete(self, using=None):
#         self.clear_cache()
#         super(Page, self).delete(using=using)
#     
#     class Meta:
#         verbose_name = _("page")
#         verbose_name_plural = _("pages")


import os, json, StringIO
from optparse import OptionValueError, make_option
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
from django.contrib.auth.models import User
from sveedocuments.models import Page
            _cfg = default.copy()
            _cfg.update(entry)
            items.append(_cfg)
        
        return items

    def proceed(self):
        """
        Proceed to the entry action 
        """
        for i, entry in enumerate(self.configs, start=1):
            if hasattr(self, "do_{0}".format(entry["kind"])):
                getattr(self, "do_{0}".format(entry["kind"]))(entry)
            else:
                raise CommandError("{0} : Command method for kind '{1}' does not exist.".format(entry["name"], entry["kind"]))

    def do_import(self, entry):
        """
        Import documents from their file destination to their database object
        """
        if self.verbosity > 0:
            print "=== Import '{0}' ===".format(entry["name"])
        
        for i, item in enumerate(entry['items'], start=1):
            # Get the content to import
            fp = open(item["filepath"], 'r')
            new_content = fp.read()
            fp.close()
            author = entry.get("author") or self.default_author
            if item["object"] is None and self.smart:

# Path: sveedocuments/models.py
# class Page(PageModelBase):
#     """
#     Full page document
#     """
#     modified = models.DateTimeField(_('last edit'), auto_now=True)
#     slug = models.SlugField(_('slug'), unique=True, max_length=75, help_text=_("Unique slug used in URL, should be automatically filled with sluggified title."))
#     
#     @models.permalink
#     def get_absolute_url(self):
#         return ('documents-page-details', [self.slug])
#     
#     def get_render_cache_key(self, **kwargs):
#         """
#         Get the cache key for the content render with according to the given settings
#         """
#         return settings.PAGE_RENDER_CACHE_KEY_NAME.format(id=self.id, **kwargs)
#     
#     def get_toc_cache_key(self, **kwargs):
#         """
#         Get the cache key for the content TOC with according to the given settings
#         """
#         return settings.PAGE_TOC_CACHE_KEY_NAME.format(id=self.id, **kwargs)
#     
#     def clear_cache(self):
#         """
#         Invalidate all possible cache keys
#         """
#         keys = _get_cache_keyset(settings.PAGE_RENDER_CACHE_KEY_NAME, **{
#             'id': self.id,
#             'setting': RSTVIEW_PARSER_FILTER_SETTINGS.keys(),
#         })
#         keys += _get_cache_keyset(settings.PAGE_TOC_CACHE_KEY_NAME, **{
#             'id': self.id,
#             'setting': RSTVIEW_PARSER_FILTER_SETTINGS.keys(),
#         })
#         # Drop cache for knowed pages slugs used in the ``page`` rest role
#         cache.delete_many([settings.PAGE_SLUGS_CACHE_KEY_NAME]+keys)
#         return keys
#     
#     def _get_current_revision(self):
#         return (self.revision.all().aggregate(models.Max('revision')).get('revision__max') or 0)+1
#     current_revision = property(_get_current_revision)
#     
#     def save(self, *args, **kwargs):
#         # First create
#         if not self.created:
#             self.created = datetime.now()
#         # Creating a new revision archive
#         elif settings.DOCUMENTS_PAGE_ARCHIVED:
#             old = Page.objects.get(pk=self.id)
#             PageRevision(
#                 page=self,
#                 created=self.modified,
#                 parent=old.parent,
#                 author=old.author,
#                 title=old.title,
#                 published=old.published,
#                 slug=old.slug,
#                 template=old.template,
#                 order=old.order,
#                 visible=old.visible,
#                 content=old.content,
#                 revision=self.current_revision,
#                 comment=old.comment,
#             ).save()
#         
#         # Fill in the published date with the created date if empty
#         if not self.published:
#             self.published = self.created
#         # Invalidate all caches on edit
#         if self.modified:
#             self.clear_cache()
#         
#         super(Page, self).save(*args, **kwargs)
#     
#     def delete(self, using=None):
#         self.clear_cache()
#         super(Page, self).delete(using=using)
#     
#     class Meta:
#         verbose_name = _("page")
#         verbose_name_plural = _("pages")


# Path: sveedocuments/management/commands/extractor.py
import os, json, StringIO
from optparse import OptionValueError, make_option
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
from django.contrib.auth.models import User
from sveedocuments.models import Page

            _cfg = default.copy()
            _cfg.update(entry)
            items.append(_cfg)
        
        return items

    def proceed(self):
        """
        Proceed to the entry action 
        """
        for i, entry in enumerate(self.configs, start=1):
            if hasattr(self, "do_{0}".format(entry["kind"])):
                getattr(self, "do_{0}".format(entry["kind"]))(entry)
            else:
                raise CommandError("{0} : Command method for kind '{1}' does not exist.".format(entry["name"], entry["kind"]))

    def do_import(self, entry):
        """
        Import documents from their file destination to their database object
        """
        if self.verbosity > 0:
            print "=== Import '{0}' ===".format(entry["name"])
        
        for i, item in enumerate(entry['items'], start=1):
            # Get the content to import
            fp = open(item["filepath"], 'r')
            new_content = fp.read()
            fp.close()
            author = entry.get("author") or self.default_author
            if item["object"] is None and self.smart:

                item["object"] = Page(title=item["slug"], slug=item["slug"], author=author, content=new_content)