# Path: feincms/contents.py

# 
# Path: feincms/module/medialibrary/contents.py
# class MediaFileContent(ContentWithMediaFile):
#     """
#     Rehashed, backwards-incompatible media file content which does not contain
#     the problems from v1 anymore.
# 
#     Create a media file content as follows::
# 
#         from feincms.content.medialibrary.models import MediaFileContent
#         Page.create_content_type(MediaFileContent, TYPE_CHOICES=(
#             ('default', _('Default')),
#             ('lightbox', _('Lightbox')),
#             ('whatever', _('Whatever')),
#             ))
# 
#     For a media file of type 'image' and type 'lightbox', the following
#     templates are tried in order:
# 
#     * content/mediafile/image_lightbox.html
#     * content/mediafile/image.html
#     * content/mediafile/lightbox.html
#     * content/mediafile/default.html
# 
#     The context contains ``content`` and ``request`` (if available).
#     """
# 
#     feincms_item_editor_inline = MediaFileContentInline
# 
#     class Meta:
#         abstract = True
#         verbose_name = _("media file")
#         verbose_name_plural = _("media files")
# 
#     @classmethod
#     def initialize_type(cls, TYPE_CHOICES=None):
#         if TYPE_CHOICES is None:
#             raise ImproperlyConfigured(
#                 "You have to set TYPE_CHOICES when" " creating a %s" % cls.__name__
#             )
# 
#         cls.add_to_class(
#             "type",
#             models.CharField(
#                 _("type"),
#                 max_length=20,
#                 choices=TYPE_CHOICES,
#                 default=TYPE_CHOICES[0][0],
#             ),
#         )
# 
#     def render(self, **kwargs):
#         return (
#             [
#                 f"content/mediafile/{self.mediafile.type}_{self.type}.html",
#                 "content/mediafile/%s.html" % self.mediafile.type,
#                 "content/mediafile/%s.html" % self.type,
#                 "content/mediafile/default.html",
#             ],
#             {"content": self},
#         )
# 
# Path: feincms/module/medialibrary/models.py
# class MediaFile(MediaFileBase):
#     class Meta:
#         app_label = "medialibrary"
# 
# Path: feincms/module/page/models.py
# class Page(BasePage):
#     class Meta:
#         ordering = ["tree_id", "lft"]
#         verbose_name = _("page")
#         verbose_name_plural = _("pages")
#         app_label = "page"
#         # not yet # permissions = (("edit_page", _("Can edit page metadata")),)


from django.contrib.auth.models import User
from django.core.files import File as DjangoFile
from django.core.management.base import NoArgsCommand
from filer.models import File, Image
from feincms.contents import FilerFileContent, FilerImageContent
from feincms.module.medialibrary.contents import MediaFileContent
from feincms.module.medialibrary.models import MediaFile
from feincms.module.page.models import Page



PageMediaFileContent = Page.content_type_for(MediaFileContent)
PageFilerFileContent = Page.content_type_for(FilerFileContent)
PageFilerImageContent = Page.content_type_for(FilerImageContent)


assert all(
    (PageMediaFileContent, PageFilerFileContent, PageFilerImageContent)
), "Not all required models available"


class Command(NoArgsCommand):
    help = "Migrate the medialibrary and contents to django-filer"

    def handle_noargs(self, **options):
        user = User.objects.order_by("pk")[0]

        count = MediaFile.objects.count()


# Path: feincms/contents.py

# 
# Path: feincms/module/medialibrary/contents.py
# class MediaFileContent(ContentWithMediaFile):
#     """
#     Rehashed, backwards-incompatible media file content which does not contain
#     the problems from v1 anymore.
# 
#     Create a media file content as follows::
# 
#         from feincms.content.medialibrary.models import MediaFileContent
#         Page.create_content_type(MediaFileContent, TYPE_CHOICES=(
#             ('default', _('Default')),
#             ('lightbox', _('Lightbox')),
#             ('whatever', _('Whatever')),
#             ))
# 
#     For a media file of type 'image' and type 'lightbox', the following
#     templates are tried in order:
# 
#     * content/mediafile/image_lightbox.html
#     * content/mediafile/image.html
#     * content/mediafile/lightbox.html
#     * content/mediafile/default.html
# 
#     The context contains ``content`` and ``request`` (if available).
#     """
# 
#     feincms_item_editor_inline = MediaFileContentInline
# 
#     class Meta:
#         abstract = True
#         verbose_name = _("media file")
#         verbose_name_plural = _("media files")
# 
#     @classmethod
#     def initialize_type(cls, TYPE_CHOICES=None):
#         if TYPE_CHOICES is None:
#             raise ImproperlyConfigured(
#                 "You have to set TYPE_CHOICES when" " creating a %s" % cls.__name__
#             )
# 
#         cls.add_to_class(
#             "type",
#             models.CharField(
#                 _("type"),
#                 max_length=20,
#                 choices=TYPE_CHOICES,
#                 default=TYPE_CHOICES[0][0],
#             ),
#         )
# 
#     def render(self, **kwargs):
#         return (
#             [
#                 f"content/mediafile/{self.mediafile.type}_{self.type}.html",
#                 "content/mediafile/%s.html" % self.mediafile.type,
#                 "content/mediafile/%s.html" % self.type,
#                 "content/mediafile/default.html",
#             ],
#             {"content": self},
#         )
# 
# Path: feincms/module/medialibrary/models.py
# class MediaFile(MediaFileBase):
#     class Meta:
#         app_label = "medialibrary"
# 
# Path: feincms/module/page/models.py
# class Page(BasePage):
#     class Meta:
#         ordering = ["tree_id", "lft"]
#         verbose_name = _("page")
#         verbose_name_plural = _("pages")
#         app_label = "page"
#         # not yet # permissions = (("edit_page", _("Can edit page metadata")),)


# Path: feincms/management/commands/medialibrary_to_filer.py
from django.contrib.auth.models import User
from django.core.files import File as DjangoFile
from django.core.management.base import NoArgsCommand
from filer.models import File, Image
from feincms.contents import FilerFileContent, FilerImageContent
from feincms.module.medialibrary.contents import MediaFileContent
from feincms.module.medialibrary.models import MediaFile
from feincms.module.page.models import Page




PageMediaFileContent = Page.content_type_for(MediaFileContent)
PageFilerFileContent = Page.content_type_for(FilerFileContent)
PageFilerImageContent = Page.content_type_for(FilerImageContent)


assert all(
    (PageMediaFileContent, PageFilerFileContent, PageFilerImageContent)
), "Not all required models available"


class Command(NoArgsCommand):
    help = "Migrate the medialibrary and contents to django-filer"

    def handle_noargs(self, **options):
        user = User.objects.order_by("pk")[0]

        count = MediaFile.objects.count()


        for i, mediafile in enumerate(MediaFile.objects.order_by("pk")):