Python django.forms.formsets.DELETION_FIELD_NAME Examples

The following are 24 code examples of django.forms.formsets.DELETION_FIELD_NAME(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.forms.formsets , or try the search function .
Example #1
Source File: inline.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #2
Source File: inline_form_views.py    From django-is-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_formset(self):
        fields = self.generate_fields()
        readonly_fields = self.generate_readonly_fields()

        if self.request.POST:
            formset = self.get_formset_factory(fields, readonly_fields)(data=self.request.POST,
                                                                        files=self.request.FILES,
                                                                        instance=self.parent_instance,
                                                                        queryset=self.get_queryset(),
                                                                        prefix=self.get_prefix())
        else:
            formset = self.get_formset_factory(fields, readonly_fields)(instance=self.parent_instance,
                                                                        queryset=self.get_queryset(),
                                                                        initial=self.get_initial(),
                                                                        prefix=self.get_prefix())

        formset.can_add = self.get_can_add()
        for form in formset.all_forms():
            form.class_names = self.form_class_names(form)
            form._is_readonly = self.is_form_readonly(form)
            if not self.readonly and form._is_readonly:
                if formset.can_delete:
                    form.readonly_fields = set(form.fields.keys()) - {'id', DELETION_FIELD_NAME}
                else:
                    form.readonly_fields = set(form.fields.keys()) - {'id'}

            if formset.can_delete and form.instance.pk and not self.can_form_delete(form):
                form.fields[DELETION_FIELD_NAME] = EmptyReadonlyField(
                    required=form.fields[DELETION_FIELD_NAME].required,
                    label=form.fields[DELETION_FIELD_NAME].label
                )
                form.readonly_fields |= {DELETION_FIELD_NAME}

            self.init_form(form)

        for i in range(self.get_min_num()):
            formset.forms[i].empty_permitted = False
        return formset 
Example #3
Source File: inline_form_views.py    From django-is-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_fromset_fields(self, formset):
        fields = list(self.generate_fields() or formset.form.base_fields.keys())
        if formset.can_delete:
            fields.append(DELETION_FIELD_NAME)
        return fields 
Example #4
Source File: inline.py    From ImitationTmall_Django with GNU General Public License v3.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #5
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def add_fields(self, form, index):
        super().add_fields(form, index)
        self.can_delete = True
        if DELETION_FIELD_NAME in form.fields:
            del form.fields[DELETION_FIELD_NAME] 
Example #6
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def add_fields(self, form, index):
        super().add_fields(form, index)
        self.can_delete = True
        if DELETION_FIELD_NAME in form.fields:
            del form.fields[DELETION_FIELD_NAME] 
Example #7
Source File: forms.py    From wagtail-review with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def add_fields(self, form, index):
        super().add_fields(form, index)
        form.fields[DELETION_FIELD_NAME].widget = forms.HiddenInput() 
Example #8
Source File: inline.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #9
Source File: inline.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #10
Source File: inline.py    From devops with MIT License 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #11
Source File: inline.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #12
Source File: helpers.py    From python2017 with MIT License 5 votes vote down vote up
def deletion_field(self):
        from django.forms.formsets import DELETION_FIELD_NAME
        return AdminField(self.form, DELETION_FIELD_NAME, False) 
Example #13
Source File: inline.py    From StormOnline with Apache License 2.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #14
Source File: forms.py    From eventoL with GNU General Public License v3.0 5 votes vote down vote up
def clean(self):
        super().clean()
        if any(self.errors):
            return

        dates = []

        for form in self.forms:
            if form.cleaned_data:
                date = form.cleaned_data['date']
                delete = form.cleaned_data[DELETION_FIELD_NAME]
                if date and not delete:
                    self.validate_date(date, dates)
                    dates.append(date) 
Example #15
Source File: helpers.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def deletion_field(self):
        from django.forms.formsets import DELETION_FIELD_NAME
        return AdminField(self.form, DELETION_FIELD_NAME, False) 
Example #16
Source File: helpers.py    From python with Apache License 2.0 5 votes vote down vote up
def deletion_field(self):
        from django.forms.formsets import DELETION_FIELD_NAME
        return AdminField(self.form, DELETION_FIELD_NAME, False) 
Example #17
Source File: edit_handlers.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def on_form_bound(self):
        self.formset = self.form.formsets[self.relation_name]

        self.children = []
        for subform in self.formset.forms:
            # override the DELETE field to have a hidden input
            subform.fields[DELETION_FIELD_NAME].widget = forms.HiddenInput()

            # ditto for the ORDER field, if present
            if self.formset.can_order:
                subform.fields[ORDERING_FIELD_NAME].widget = forms.HiddenInput()

            child_edit_handler = self.get_child_edit_handler()
            self.children.append(child_edit_handler.bind_to(
                instance=subform.instance, request=self.request, form=subform))

        # if this formset is valid, it may have been re-ordered; respect that
        # in case the parent form errored and we need to re-render
        if self.formset.can_order and self.formset.is_valid():
            self.children.sort(
                key=lambda child: child.form.cleaned_data[ORDERING_FIELD_NAME] or 1)

        empty_form = self.formset.empty_form
        empty_form.fields[DELETION_FIELD_NAME].widget = forms.HiddenInput()
        if self.formset.can_order:
            empty_form.fields[ORDERING_FIELD_NAME].widget = forms.HiddenInput()

        self.empty_child = self.get_child_edit_handler()
        self.empty_child = self.empty_child.bind_to(
            instance=empty_form.instance, request=self.request, form=empty_form) 
Example #18
Source File: helpers.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def deletion_field(self):
        from django.forms.formsets import DELETION_FIELD_NAME
        return AdminField(self.form, DELETION_FIELD_NAME, False) 
Example #19
Source File: inline.py    From django_OA with GNU General Public License v3.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #20
Source File: inline.py    From CTF_AWD_Platform with MIT License 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #21
Source File: inline.py    From myblog with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #22
Source File: inline.py    From weibo-analysis-system with MIT License 5 votes vote down vote up
def get_attrs(self):
        fields = []
        readonly_fields = []
        if len(self.formset):
            fields = [f for k, f in self.formset[0].fields.items() if k != DELETION_FIELD_NAME]
            readonly_fields = [f for f in getattr(self.formset[0], 'readonly_fields', [])]
        return {
            'fields': fields,
            'readonly_fields': readonly_fields
        } 
Example #23
Source File: helpers.py    From bioforum with MIT License 5 votes vote down vote up
def deletion_field(self):
        from django.forms.formsets import DELETION_FIELD_NAME
        return AdminField(self.form, DELETION_FIELD_NAME, False) 
Example #24
Source File: helpers.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def deletion_field(self):
        from django.forms.formsets import DELETION_FIELD_NAME
        return AdminField(self.form, DELETION_FIELD_NAME, False)