예제 #1
0
파일: options.py 프로젝트: whit/ella
 def __iter__(self):
     for form, original in zip(self.formset.initial_forms,
                               self.formset.get_queryset()):
         yield InlineAdminForm(self.formset,
                               form,
                               self.fieldsets,
                               self.opts.prepopulated_fields,
                               original,
                               self.readonly_fields,
                               model_admin=self.opts)
     for form in self.formset.extra_forms:
         yield InlineAdminForm(self.formset,
                               form,
                               self.fieldsets,
                               self.opts.prepopulated_fields,
                               None,
                               self.readonly_fields,
                               model_admin=self.opts)
예제 #2
0
    def __iter__(self):
        if self.has_change_permission:
            readonly_fields_for_editing = self.readonly_fields
        else:
            readonly_fields_for_editing = self.readonly_fields + flatten_fieldsets(
                self.fieldsets)

        for form in self.formset.initial_forms:
            original = None
            if form.instance.pk is not None:
                original = form.instance
            view_on_site_url = self.opts.get_view_on_site_url(original)

            yield InlineAdminForm(
                self.formset,
                form,
                self.fieldsets,
                self.prepopulated_fields,
                original,
                readonly_fields_for_editing,
                model_admin=self.opts,
                view_on_site_url=view_on_site_url,
            )
        for form in self.formset.extra_forms:
            yield InlineAdminForm(
                self.formset,
                form,
                self.fieldsets,
                self.prepopulated_fields,
                None,
                self.readonly_fields,
                model_admin=self.opts,
            )
        if self.has_add_permission:
            yield InlineAdminForm(
                self.formset,
                self.formset.empty_form,
                self.fieldsets,
                self.prepopulated_fields,
                None,
                self.readonly_fields,
                model_admin=self.opts,
            )
예제 #3
0
 def test_original_content_type_id_deprecated(self):
     """
     #23444 -- Verify a warning is raised when accessing
     `original_content_type_id` attribute of `InlineAdminForm` object.
     """
     iaf = InlineAdminForm(None, None, {}, {}, None)
     poll = Poll.objects.create(name="poll")
     iaf2 = InlineAdminForm(None, None, {}, {}, poll)
     poll_ct = ContentType.objects.get_for_model(Poll)
     with warnings.catch_warnings(record=True) as recorded:
         with self.assertRaises(AttributeError):
             iaf.original_content_type_id
         msg = force_text(recorded.pop().message)
         self.assertEqual(
             msg,
             'InlineAdminForm.original_content_type_id is deprecated and will be '
             'removed in Django 2.0. If you were using this attribute to construct '
             'the "view on site" URL, use the `absolute_url` attribute instead.'
         )
         self.assertEqual(iaf2.original_content_type_id, poll_ct.id)
예제 #4
0
    def test_immutable_content_type(self):
        """Regression for #9362
        The problem depends only on InlineAdminForm and its "original"
        argument, so we can safely set the other arguments to None/{}. We just
        need to check that the content_type argument of Child isn't altered by
        the internals of the inline form."""

        sally = Teacher.objects.create(name='Sally')
        john = Parent.objects.create(name='John')
        joe = Child.objects.create(name='Joe', teacher=sally, parent=john)

        iaf = InlineAdminForm(None, None, {}, {}, joe)
        parent_ct = ContentType.objects.get_for_model(Parent)
        self.assertEqual(iaf.original.content_type, parent_ct)
예제 #5
0
 def pk_field(self):
     # if there is no pk field then it's an embedded form so return none
     if hasattr(self.formset, "_pk_field"):
         return DjangoInlineAdminForm.pk_field(self)
     else:
         return None