# Path: dockit/forms/formsets.py
# class BaseInlineFormSet(BaseDocumentFormSet): #simply merge as one?
#     """A formset for child objects related to a parent."""
#     def __init__(self, data=None, files=None, instance=None,
#                  save_as_new=False, prefix=None, dotpath=None):
#         self.instance = instance
#         self.save_as_new = save_as_new
#         self.dotpath = dotpath or self.form._meta.dotpath
#         self.singleton = False
#         # is there a better way to get the object descriptor?
#         qs = self.instance.dot_notation(self.base_dotpath) or []
#         if not isinstance(qs, (list, set)):
#             qs = [qs]
#             self.singleton = True
#         super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix,
#                                                 queryset=qs)
#     
#     @property
#     def base_dotpath(self):
#         return self.dotpath.rsplit('.', 1)[0]
#     
#     def initial_form_count(self):
#         if self.save_as_new:
#             return 0
#         return super(BaseInlineFormSet, self).initial_form_count()
# 
#     def _construct_form(self, i, **kwargs):
#         if self.singleton:
#             kwargs['dotpath'] = self.base_dotpath
#         else:
#             kwargs['dotpath'] = '%s.%i' % (self.base_dotpath, i)
#         kwargs['instance'] = self.instance
#         form = super(BaseDocumentFormSet, self)._construct_form(i, **kwargs)
#         if self.save_as_new:
#             # Remove the primary key from the form's data, we are only
#             # creating new instances
#             #form.data[form.add_prefix(self._pk_field.name)] = None
# 
#             # Remove the foreign key from the form's data
#             #form.data[form.add_prefix(self.fk.name)] = None
#             pass
# 
#         # Set the fk value here so that the form can do it's validation.
#         #?????
#         #setattr(form.instance, self.fk.get_attname(), self.instance.pk)
#         return form
# 
#     #def get_default_prefix(self):
#     #    return self.dotpath.rsplit('.', 1)[-1]
#     #get_default_prefix = classmethod(get_default_prefix)
#     
#     def save_new(self, form, commit=True):
#         """Saves and returns a new model instance for the given form."""
#         return form._inner_save()
# 
#     def save_existing(self, form, instance, commit=True):
#         """Saves and returns an existing model instance for the given form."""
#         return form._inner_save()
#     
#     def save(self, commit=True, instance=None):
#         """Saves model instances for every form, adding and changing instances
#         as necessary, and returns the list of instances.
#         """
#         if instance:
#             self.instance = instance
#         if not commit:
#             self.saved_forms = []
#             def save_m2m():
#                 for form in self.saved_forms:
#                     form.save_m2m()
#             self.save_m2m = save_m2m
#         new_list = self.save_existing_objects(commit) + self.save_new_objects(commit)
#         if commit:
#             if self.singleton:
#                 self.instance.dot_notation_set_value(self.base_dotpath, new_list[0])
#             else:
#                 self.instance.dot_notation_set_value(self.base_dotpath, new_list)
#         return new_list
# 
# def inlinedocumentformset_factory(document, dotpath, form=DocumentForm,
#                           formset=BaseInlineFormSet,
#                           fields=None, exclude=None, schema=None,
#                           extra=3, can_order=False, can_delete=True, max_num=None,
#                           formfield_callback=None):
#     """
#     Returns an ``InlineFormSet`` for the given kwargs.
# 
#     You must provide ``fk_name`` if ``model`` has more than one ``ForeignKey``
#     to ``parent_model``.
#     """
#     kwargs = {
#         'form': form,
#         'formfield_callback': formfield_callback,
#         'formset': formset,
#         'extra': extra,
#         'can_delete': can_delete,
#         'can_order': can_order,
#         'fields': fields,
#         'exclude': exclude,
#         'max_num': max_num,
#         'schema': schema,
#         'dotpath': dotpath + '.*',
#     }
#     FormSet = documentformset_factory(document, **kwargs)
#     #FormSet.fk = fk
#     return FormSet


from documentadmin import SchemaAdmin
from django import forms
from django.contrib.admin.util import flatten_fieldsets
from django.utils.functional import curry
from dockit.forms.formsets import BaseInlineFormSet, inlinedocumentformset_factory
        from django.conf import settings
        from fields import DotPathField



class InlineSchemaAdmin(SchemaAdmin):
    schema = None
    formset = BaseInlineFormSet
    extra = 1
    max_num = None
    template = None
    verbose_name = None
    verbose_name_plural = None
    can_delete = True

    def __init__(self, model, admin_site, schema=None, documentadmin=None, dotpath=None, **kwargs):
        super(InlineSchemaAdmin, self).__init__(model, admin_site, schema or self.schema, documentadmin)

# Path: dockit/forms/formsets.py
# class BaseInlineFormSet(BaseDocumentFormSet): #simply merge as one?
#     """A formset for child objects related to a parent."""
#     def __init__(self, data=None, files=None, instance=None,
#                  save_as_new=False, prefix=None, dotpath=None):
#         self.instance = instance
#         self.save_as_new = save_as_new
#         self.dotpath = dotpath or self.form._meta.dotpath
#         self.singleton = False
#         # is there a better way to get the object descriptor?
#         qs = self.instance.dot_notation(self.base_dotpath) or []
#         if not isinstance(qs, (list, set)):
#             qs = [qs]
#             self.singleton = True
#         super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix,
#                                                 queryset=qs)
#     
#     @property
#     def base_dotpath(self):
#         return self.dotpath.rsplit('.', 1)[0]
#     
#     def initial_form_count(self):
#         if self.save_as_new:
#             return 0
#         return super(BaseInlineFormSet, self).initial_form_count()
# 
#     def _construct_form(self, i, **kwargs):
#         if self.singleton:
#             kwargs['dotpath'] = self.base_dotpath
#         else:
#             kwargs['dotpath'] = '%s.%i' % (self.base_dotpath, i)
#         kwargs['instance'] = self.instance
#         form = super(BaseDocumentFormSet, self)._construct_form(i, **kwargs)
#         if self.save_as_new:
#             # Remove the primary key from the form's data, we are only
#             # creating new instances
#             #form.data[form.add_prefix(self._pk_field.name)] = None
# 
#             # Remove the foreign key from the form's data
#             #form.data[form.add_prefix(self.fk.name)] = None
#             pass
# 
#         # Set the fk value here so that the form can do it's validation.
#         #?????
#         #setattr(form.instance, self.fk.get_attname(), self.instance.pk)
#         return form
# 
#     #def get_default_prefix(self):
#     #    return self.dotpath.rsplit('.', 1)[-1]
#     #get_default_prefix = classmethod(get_default_prefix)
#     
#     def save_new(self, form, commit=True):
#         """Saves and returns a new model instance for the given form."""
#         return form._inner_save()
# 
#     def save_existing(self, form, instance, commit=True):
#         """Saves and returns an existing model instance for the given form."""
#         return form._inner_save()
#     
#     def save(self, commit=True, instance=None):
#         """Saves model instances for every form, adding and changing instances
#         as necessary, and returns the list of instances.
#         """
#         if instance:
#             self.instance = instance
#         if not commit:
#             self.saved_forms = []
#             def save_m2m():
#                 for form in self.saved_forms:
#                     form.save_m2m()
#             self.save_m2m = save_m2m
#         new_list = self.save_existing_objects(commit) + self.save_new_objects(commit)
#         if commit:
#             if self.singleton:
#                 self.instance.dot_notation_set_value(self.base_dotpath, new_list[0])
#             else:
#                 self.instance.dot_notation_set_value(self.base_dotpath, new_list)
#         return new_list
# 
# def inlinedocumentformset_factory(document, dotpath, form=DocumentForm,
#                           formset=BaseInlineFormSet,
#                           fields=None, exclude=None, schema=None,
#                           extra=3, can_order=False, can_delete=True, max_num=None,
#                           formfield_callback=None):
#     """
#     Returns an ``InlineFormSet`` for the given kwargs.
# 
#     You must provide ``fk_name`` if ``model`` has more than one ``ForeignKey``
#     to ``parent_model``.
#     """
#     kwargs = {
#         'form': form,
#         'formfield_callback': formfield_callback,
#         'formset': formset,
#         'extra': extra,
#         'can_delete': can_delete,
#         'can_order': can_order,
#         'fields': fields,
#         'exclude': exclude,
#         'max_num': max_num,
#         'schema': schema,
#         'dotpath': dotpath + '.*',
#     }
#     FormSet = documentformset_factory(document, **kwargs)
#     #FormSet.fk = fk
#     return FormSet


# Path: dockit/admin/inlines.py
from documentadmin import SchemaAdmin
from django import forms
from django.contrib.admin.util import flatten_fieldsets
from django.utils.functional import curry
from dockit.forms.formsets import BaseInlineFormSet, inlinedocumentformset_factory
        from django.conf import settings
        from fields import DotPathField




class InlineSchemaAdmin(SchemaAdmin):
    schema = None
    formset = BaseInlineFormSet
    extra = 1
    max_num = None
    template = None
    verbose_name = None
    verbose_name_plural = None
    can_delete = True

    def __init__(self, model, admin_site, schema=None, documentadmin=None, dotpath=None, **kwargs):
        super(InlineSchemaAdmin, self).__init__(model, admin_site, schema or self.schema, documentadmin)

        self.model = self.schema