# Path: textplusstuff/models.py
# class TextPlusStuffDraft(models.Model):
#     """
#     A simple model used to hold 'drafts' of TextPlusStuffField
#     content.
#     """
#     title = models.CharField(
#         _('Draft Title'),
#         max_length=100
#     )
#     user = models.ForeignKey(
#         'auth.User',
#         verbose_name=_('User'),
#         help_text=_(
#             'The user who created this draft.'
#         ),
#         null=True,
#         on_delete=models.SET_NULL,
#     )
#     date_created = models.DateTimeField(
#         _('Date Created'),
#         auto_now_add=True,
#         help_text=_('The date this draft was originally created.')
#     )
#     date_modified = models.DateTimeField(
#         _('Date Modified'),
#         auto_now=True,
#         help_text=_('The date this draft was updated.')
#     )
#     content = TextPlusStuffField(
#         _('Content'),
#         blank=True
#     )
#     content_ported = models.BooleanField(
#         _('Content Ported'),
#         default=False,
#         help_text=_(
#             'Signifies whether or not this draft has been used to populate '
#             'a TextPlusStuffField on another model.'
#         )
#     )
# 
#     class Meta:
#         verbose_name = _('Text Plus Stuff Draft')
#         verbose_name_plural = _('Text Plus Stuff Drafts')
# 
# Path: textplusstuff/registry.py
# def get_modelstuff_renditions(model_instance):
#     """
#     Build out a dict of the available MODELSTUFF renditions
#     for a particular model instance
#     """
#     stuff_config, groups = stuff_registry._registry.get(
#         model_instance._meta.model, (None, None)
#     )
#     if stuff_config is not None:
#         return dict(
#             (
#                 short_name,
#                 {
#                     'verbose_name': rendition.verbose_name,
#                     'description': rendition.description,
#                     'token': (
#                         "{{% textplusstuff 'MODELSTUFF__{app}:{model}:"
#                         "{pk}:{rend}' %}}"
#                     ).format(
#                         app=model_instance._meta.app_label,
#                         model=model_instance._meta.model_name,
#                         pk=model_instance.pk,
#                         rend=short_name
#                     ),
#                     'path_to_template': rendition.path_to_template,
#                     'type': rendition.rendition_type
# 
#                 }
#             )
#             for short_name, rendition in stuff_config._renditions.items()
#         )


from django.contrib import admin
from .models import TextPlusStuffDraft
from .registry import get_modelstuff_renditions
from __future__ import unicode_literals




class TextPlusStuffRegisteredModelAdmin(admin.ModelAdmin):
    change_form_template = 'textplusstuff/change_form_with_renditions.html'

    def change_view(self, request, object_id, form_url='', extra_context=None):
        obj = self.get_object(request, admin.utils.unquote(object_id))

# Path: textplusstuff/models.py
# class TextPlusStuffDraft(models.Model):
#     """
#     A simple model used to hold 'drafts' of TextPlusStuffField
#     content.
#     """
#     title = models.CharField(
#         _('Draft Title'),
#         max_length=100
#     )
#     user = models.ForeignKey(
#         'auth.User',
#         verbose_name=_('User'),
#         help_text=_(
#             'The user who created this draft.'
#         ),
#         null=True,
#         on_delete=models.SET_NULL,
#     )
#     date_created = models.DateTimeField(
#         _('Date Created'),
#         auto_now_add=True,
#         help_text=_('The date this draft was originally created.')
#     )
#     date_modified = models.DateTimeField(
#         _('Date Modified'),
#         auto_now=True,
#         help_text=_('The date this draft was updated.')
#     )
#     content = TextPlusStuffField(
#         _('Content'),
#         blank=True
#     )
#     content_ported = models.BooleanField(
#         _('Content Ported'),
#         default=False,
#         help_text=_(
#             'Signifies whether or not this draft has been used to populate '
#             'a TextPlusStuffField on another model.'
#         )
#     )
# 
#     class Meta:
#         verbose_name = _('Text Plus Stuff Draft')
#         verbose_name_plural = _('Text Plus Stuff Drafts')
# 
# Path: textplusstuff/registry.py
# def get_modelstuff_renditions(model_instance):
#     """
#     Build out a dict of the available MODELSTUFF renditions
#     for a particular model instance
#     """
#     stuff_config, groups = stuff_registry._registry.get(
#         model_instance._meta.model, (None, None)
#     )
#     if stuff_config is not None:
#         return dict(
#             (
#                 short_name,
#                 {
#                     'verbose_name': rendition.verbose_name,
#                     'description': rendition.description,
#                     'token': (
#                         "{{% textplusstuff 'MODELSTUFF__{app}:{model}:"
#                         "{pk}:{rend}' %}}"
#                     ).format(
#                         app=model_instance._meta.app_label,
#                         model=model_instance._meta.model_name,
#                         pk=model_instance.pk,
#                         rend=short_name
#                     ),
#                     'path_to_template': rendition.path_to_template,
#                     'type': rendition.rendition_type
# 
#                 }
#             )
#             for short_name, rendition in stuff_config._renditions.items()
#         )


# Path: textplusstuff/admin.py
from django.contrib import admin
from .models import TextPlusStuffDraft
from .registry import get_modelstuff_renditions

from __future__ import unicode_literals




class TextPlusStuffRegisteredModelAdmin(admin.ModelAdmin):
    change_form_template = 'textplusstuff/change_form_with_renditions.html'

    def change_view(self, request, object_id, form_url='', extra_context=None):
        obj = self.get_object(request, admin.utils.unquote(object_id))

        rendition_dict = get_modelstuff_renditions(obj) or {}