

def _hack_inline_formset_initial(self, revision_view, formset):
    'Hacks the given formset to contain the correct initial data.'
    initial = []
    related_versions = self.get_related_versions(revision_view.org_obj, revision_view.version, formset)
    formset.related_versions = related_versions
    for related_obj in formset.queryset:
        if (unicode(related_obj.pk) in related_versions):
            initial.append(related_versions.pop(unicode(related_obj.pk)).field_dict)
        else:
            initial_data = model_to_dict(related_obj)
            initial_data['DELETE'] = True
            initial.append(initial_data)
    for related_version in related_versions.values():
        initial_row = related_version.field_dict
        pk_name = ContentType.objects.get_for_id(related_version.content_type_id).model_class()._meta.pk.name
        del initial_row[pk_name]
        initial.append(initial_row)
    formset.initial = initial
    formset.forms = [formset._construct_form(n) for n in xrange(len(initial))]

    def get_changed_data(form):
        return [field.name for field in form.fields]
    for form in formset.forms:
        form.has_changed = (lambda : True)
        form._get_changed_data = partial(get_changed_data, form=form)

    def total_form_count_hack(count):
        return (lambda : count)
    formset.total_form_count = total_form_count_hack(len(initial))
    if ((self.request.method == 'GET') and formset.helper and formset.helper.layout):
        helper = formset.helper
        helper.filter(basestring).wrap(InlineDiffField)
        fake_admin_class = type(str(('%s%sFakeAdmin' % (self.opts.app_label, self.opts.model_name))), (object,), {
            'model': self.model,
        })
        for form in formset.forms:
            instance = form.instance
            if instance.pk:
                form.detail = self.get_view(DetailAdminUtil, fake_admin_class, instance)

dataset/ETHPy150Open sshwsfc/xadmin/xadmin/plugins/xversion.py InlineRevisionPlugin._hack_inline_formset_initial/original