# Path: dockit/forms/forms.py
# class DocumentForm(BaseDocumentForm):
#     """ The document form object """
#     __metaclass__ = DocumentFormMetaClass
# 
# def documentform_factory(document, form=DocumentForm, fields=None, exclude=None,
#                              formfield_callback=None, schema=None, dotpath=None):
#     meta = UserMeta(document=document,
#                     fields=fields,
#                     exclude=exclude,
#                     formfield_callback=formfield_callback,
#                     schema=schema,
#                     dotpath=dotpath,)
#     class FactoryForm(form):
#         Meta = meta
#     
#     return FactoryForm


from django.forms.formsets import BaseFormSet, formset_factory
from django.utils.translation import ugettext_lazy as _, ugettext
from dockit.forms.forms import DocumentForm, documentform_factory
    
    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



# Path: dockit/forms/forms.py
# class DocumentForm(BaseDocumentForm):
#     """ The document form object """
#     __metaclass__ = DocumentFormMetaClass
# 
# def documentform_factory(document, form=DocumentForm, fields=None, exclude=None,
#                              formfield_callback=None, schema=None, dotpath=None):
#     meta = UserMeta(document=document,
#                     fields=fields,
#                     exclude=exclude,
#                     formfield_callback=formfield_callback,
#                     schema=schema,
#                     dotpath=dotpath,)
#     class FactoryForm(form):
#         Meta = meta
#     
#     return FactoryForm


# Path: dockit/forms/formsets.py
from django.forms.formsets import BaseFormSet, formset_factory
from django.utils.translation import ugettext_lazy as _, ugettext
from dockit.forms.forms import DocumentForm, documentform_factory

    
    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,