Python django.forms.HiddenInput() Examples
The following are 30
code examples of django.forms.HiddenInput().
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
, or try the search function
.
Example #1
Source File: views.py From InvenTree with MIT License | 6 votes |
def get_form(self): """ Get form for StockItem editing. Limit the choices for supplier_part """ form = super(AjaxUpdateView, self).get_form() item = self.get_object() # If the part cannot be purchased, hide the supplier_part field if not item.part.purchaseable: form.fields['supplier_part'].widget = HiddenInput() else: query = form.fields['supplier_part'].queryset query = query.filter(part=item.part.id) form.fields['supplier_part'].queryset = query if not item.part.trackable or not item.serialized: form.fields.pop('serial') return form
Example #2
Source File: detail.py From StormOnline with Apache License 2.0 | 6 votes |
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, extra_context=None, **kwargs): super(ShowField, self).render(form, form_style, context, template_pack, extra_context, **kwargs) if extra_context is None: extra_context = {} if hasattr(self, 'wrapper_class'): extra_context['wrapper_class'] = self.wrapper_class if self.attrs: if 'detail-class' in self.attrs: extra_context['input_class'] = self.attrs['detail-class'] elif 'class' in self.attrs: extra_context['input_class'] = self.attrs['class'] html = '' for field, result in self.results: extra_context['result'] = result if field in form.fields: if form.fields[field].widget != forms.HiddenInput: extra_context['field'] = form[field] html += loader.render_to_string(self.template, extra_context) else: extra_context['field'] = field html += loader.render_to_string(self.template, extra_context) return html
Example #3
Source File: forms.py From coursys with GNU General Public License v3.0 | 6 votes |
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=':', empty_permitted=False, instance=None, offering=None, userid=None, enforced_prep_min=0): super(TUGForm, self).__init__(data, files, auto_id, prefix, initial, error_class, label_suffix, empty_permitted, instance) # see old revisions (git id 1d1d2f9) for a dropdown if userid is not None and offering is not None: member = Member.objects.exclude(role='DROP').get(person__userid=userid, offering=offering) elif instance is not None: member = instance.member else: assert False self.enforced_prep_min = enforced_prep_min self.initial['member'] = member self.fields['member'].widget = forms.widgets.HiddenInput() self.subforms = self.__construct_subforms(data, initial, instance)
Example #4
Source File: detail.py From django_OA with GNU General Public License v3.0 | 6 votes |
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, extra_context=None, **kwargs): super(ShowField, self).render(form, form_style, context, template_pack, extra_context, **kwargs) if extra_context is None: extra_context = {} if hasattr(self, 'wrapper_class'): extra_context['wrapper_class'] = self.wrapper_class if self.attrs: if 'detail-class' in self.attrs: extra_context['input_class'] = self.attrs['detail-class'] elif 'class' in self.attrs: extra_context['input_class'] = self.attrs['class'] html = '' for field, result in self.results: extra_context['result'] = result if field in form.fields: if form.fields[field].widget != forms.HiddenInput: extra_context['field'] = form[field] html += loader.render_to_string(self.template, extra_context) else: extra_context['field'] = field html += loader.render_to_string(self.template, extra_context) return html
Example #5
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def new_student(request, userid): person = get_object_or_404(Person, find_userid_or_emplid(userid)) semester = Semester.next_starting() semesterconfig = SemesterConfig.get_config(request.units, semester) student = get_object_or_404(Person, find_userid_or_emplid(userid)) initial = {'person': student.emplid, 'start_date': semesterconfig.start_date(), 'end_date': semesterconfig.end_date(), 'hours': 80 } scholarship_choices, hiring_faculty_choices, unit_choices, project_choices, account_choices, program_choices = \ _appointment_defaults(request.units, emplid=student.emplid) gss = GradStudent.objects.filter(person=student) if gss: gradstudent = gss[0] initial['sin'] = gradstudent.person.sin() raform = RAForm(initial=initial) raform.fields['person'] = forms.CharField(widget=forms.HiddenInput()) raform.fields['scholarship'].choices = scholarship_choices raform.fields['hiring_faculty'].choices = hiring_faculty_choices raform.fields['unit'].choices = unit_choices raform.fields['project'].choices = project_choices raform.fields['account'].choices = account_choices raform.fields['program'].choices = program_choices return render(request, 'ra/new.html', { 'raform': raform, 'person': person }) #Edit RA Appointment
Example #6
Source File: forms.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_image_form(model): fields = model.admin_form_fields if 'collection' not in fields: # force addition of the 'collection' field, because leaving it out can # cause dubious results when multiple collections exist (e.g adding the # document to the root collection where the user may not have permission) - # and when only one collection exists, it will get hidden anyway. fields = list(fields) + ['collection'] return modelform_factory( model, form=BaseImageForm, fields=fields, formfield_callback=formfield_for_dbfield, # set the 'file' widget to a FileInput rather than the default ClearableFileInput # so that when editing, we don't get the 'currently: ...' banner which is # a bit pointless here widgets={ 'tags': widgets.AdminTagWidget, 'file': forms.FileInput(), 'focal_point_x': forms.HiddenInput(attrs={'class': 'focal_point_x'}), 'focal_point_y': forms.HiddenInput(attrs={'class': 'focal_point_y'}), 'focal_point_width': forms.HiddenInput(attrs={'class': 'focal_point_width'}), 'focal_point_height': forms.HiddenInput(attrs={'class': 'focal_point_height'}), })
Example #7
Source File: factory.py From django-djangui with GNU General Public License v3.0 | 6 votes |
def get_master_form(self, model=None, pk=None): pk = int(pk) if pk is not None else pk if pk is not None and pk in self.djangui_forms: if 'master' in self.djangui_forms[pk]: return copy.deepcopy(self.djangui_forms[pk]['master']) master_form = DjanguiForm() params = ScriptParameter.objects.filter(script=model).order_by('pk') # set a reference to the object type for POST methods to use pk = model.pk script_id_field = forms.CharField(widget=forms.HiddenInput) master_form.fields['djangui_type'] = script_id_field master_form.fields['djangui_type'].initial = pk for param in params: field = self.get_field(param) master_form.fields[param.slug] = field try: self.djangui_forms[pk]['master'] = master_form except KeyError: self.djangui_forms[pk] = {'master': master_form} # create the group forms while we have the model if 'groups' not in self.djangui_forms[pk]: self.get_group_forms(model=model, pk=pk) return master_form
Example #8
Source File: helper.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
def render_layout(self, form, context, template_pack=TEMPLATE_PACK): """ Copy any field label to the ``placeholder`` attribute. Note, this method is called when :attr:`layout` is defined. """ # Writing the label values into the field placeholders. # This is done at rendering time, so the Form.__init__() could update any labels before. # Django 1.11 no longer lets EmailInput or URLInput inherit from TextInput, # so checking for `Input` instead while excluding `HiddenInput`. for field in form.fields.values(): if field.label and \ isinstance(field.widget, (Input, forms.Textarea)) and \ not isinstance(field.widget, forms.HiddenInput): field.widget.attrs['placeholder'] = u"{0}:".format(field.label) return super(CompactLabelsCommentFormHelper, self).render_layout(form, context, template_pack=template_pack)
Example #9
Source File: forms.py From fermentrack with MIT License | 6 votes |
def set_choices(self, family): # There's probably a better way of doing this board_choices = [(brd.id, brd.name) for brd in Board.objects.filter(family=family)] self.fields['board_type'].choices = board_choices # class GuidedDeviceFlashForm(forms.Form): # DEVICE_FAMILY_CHOICES = GuidedDeviceSelectForm.DEVICE_FAMILY_CHOICES # # device_family = forms.ChoiceField(label="Device Family", # widget=forms.Select(attrs={'class': 'form-control', # 'data-toggle': 'select'}), # choices=DEVICE_FAMILY_CHOICES, required=True) # should_flash_device = forms.BooleanField(widget=forms.HiddenInput, required=False, initial=False) # #
Example #10
Source File: views.py From tom_base with GNU General Public License v3.0 | 6 votes |
def get_form(self): form = super().get_form() form.fields['facility'].widget = forms.HiddenInput() form.fields['observation_id'].widget = forms.HiddenInput() if self.request.method == 'GET': target_id = self.request.GET.get('target_id') elif self.request.method == 'POST': target_id = self.request.POST.get('target_id') cancel_url = reverse('home') if target_id: cancel_url = reverse('tom_targets:detail', kwargs={'pk': target_id}) form.helper.layout = Layout( HTML('''<p>An observation record already exists in your TOM for this combination of observation ID, facility, and target. Are you sure you want to create this record?</p>'''), 'target_id', 'facility', 'observation_id', 'confirm', FormActions( Submit('confirm', 'Confirm'), HTML(f'<a class="btn btn-outline-primary" href={cancel_url}>Cancel</a>') ) ) return form
Example #11
Source File: detail.py From CTF_AWD_Platform with MIT License | 6 votes |
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, extra_context=None, **kwargs): super(ShowField, self).render(form, form_style, context, template_pack, extra_context, **kwargs) if extra_context is None: extra_context = {} if hasattr(self, 'wrapper_class'): extra_context['wrapper_class'] = self.wrapper_class if self.attrs: if 'detail-class' in self.attrs: extra_context['input_class'] = self.attrs['detail-class'] elif 'class' in self.attrs: extra_context['input_class'] = self.attrs['class'] html = '' for field, result in self.results: extra_context['result'] = result if field in form.fields: if form.fields[field].widget != forms.HiddenInput: extra_context['field'] = form[field] html += loader.render_to_string(self.template, extra_context) else: extra_context['field'] = field html += loader.render_to_string(self.template, extra_context) return html
Example #12
Source File: views.py From tom_base with GNU General Public License v3.0 | 6 votes |
def get_context_data(self, *args, **kwargs): """ Adds the ``DataProductUploadForm`` to the context and prepopulates the hidden fields. :returns: context object :rtype: dict """ context = super().get_context_data(*args, **kwargs) observing_strategy_form = RunStrategyForm(initial={'target': self.get_object()}) if any(self.request.GET.get(x) for x in ['observing_strategy', 'cadence_strategy', 'cadence_frequency']): initial = {'target': self.object} initial.update(self.request.GET) observing_strategy_form = RunStrategyForm( initial=initial ) observing_strategy_form.fields['target'].widget = HiddenInput() context['observing_strategy_form'] = observing_strategy_form return context
Example #13
Source File: detail.py From myblog with GNU Affero General Public License v3.0 | 6 votes |
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, extra_context=None, **kwargs): super(ShowField, self).render(form, form_style, context, template_pack, extra_context, **kwargs) if extra_context is None: extra_context = {} if hasattr(self, 'wrapper_class'): extra_context['wrapper_class'] = self.wrapper_class if self.attrs: if 'detail-class' in self.attrs: extra_context['input_class'] = self.attrs['detail-class'] elif 'class' in self.attrs: extra_context['input_class'] = self.attrs['class'] html = '' for field, result in self.results: extra_context['result'] = result if field in form.fields: if form.fields[field].widget != forms.HiddenInput: extra_context['field'] = form[field] html += loader.render_to_string(self.template, extra_context) else: extra_context['field'] = field html += loader.render_to_string(self.template, extra_context) return html
Example #14
Source File: detail.py From weibo-analysis-system with MIT License | 6 votes |
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, extra_context=None, **kwargs): super(ShowField, self).render(form, form_style, context, template_pack, extra_context, **kwargs) if extra_context is None: extra_context = {} if hasattr(self, 'wrapper_class'): extra_context['wrapper_class'] = self.wrapper_class if self.attrs: if 'detail-class' in self.attrs: extra_context['input_class'] = self.attrs['detail-class'] elif 'class' in self.attrs: extra_context['input_class'] = self.attrs['class'] html = '' for field, result in self.results: extra_context['result'] = result if field in form.fields: if form.fields[field].widget != forms.HiddenInput: extra_context['field'] = form[field] html += loader.render_to_string(self.template, extra_context) else: extra_context['field'] = field html += loader.render_to_string(self.template, extra_context) return html
Example #15
Source File: views.py From InvenTree with MIT License | 6 votes |
def get_form(self): """ Create form for editing a BuildItem. - Limit the StockItem options to items that match the part """ build_item = self.get_object() form = super(BuildItemEdit, self).get_form() query = StockItem.objects.all() if build_item.stock_item: part_id = build_item.stock_item.part.id query = query.filter(part=part_id) form.fields['stock_item'].queryset = query form.fields['build'].widget = HiddenInput() return form
Example #16
Source File: auth.py From myblog with GNU Affero General Public License v3.0 | 5 votes |
def get_field_attrs(self, __, db_field, **kwargs): if self.user_fields and db_field.name in self.user_fields: return {'widget': forms.HiddenInput} return __()
Example #17
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self, *args, **kwargs): form = super().get_form(*args, **kwargs) # If the order is specified, hide the widget order_id = form['order'].value() if SalesOrder.objects.filter(id=order_id).exists(): form.fields['order'].widget = HiddenInput() return form
Example #18
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): form = super().get_form() form.fields['part'].widget = HiddenInput() return form
Example #19
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): form = super(AjaxUpdateView, self).get_form() order = self.get_object() # Prevent user from editing supplier if there are already lines in the order if order.lines.count() > 0 or not order.status == PurchaseOrderStatus.PENDING: form.fields['supplier'].widget = HiddenInput() return form
Example #20
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): """ Limit choice options based on the selected order, etc """ form = super().get_form() # Limit the available to orders to ones that are PENDING query = form.fields['order'].queryset query = query.filter(status=PurchaseOrderStatus.PENDING) form.fields['order'].queryset = query order_id = form['order'].value() try: order = PurchaseOrder.objects.get(id=order_id) query = form.fields['part'].queryset # Only allow parts from the selected supplier query = query.filter(supplier=order.supplier.id) exclude = [] for line in order.lines.all(): if line.part and line.part.id not in exclude: exclude.append(line.part.id) # Remove parts that are already in the order query = query.exclude(id__in=exclude) form.fields['part'].queryset = query form.fields['order'].widget = HiddenInput() except (ValueError, PurchaseOrder.DoesNotExist): pass return form
Example #21
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): form = super(AjaxUpdateView, self).get_form() # Hide the 'order' field form.fields['order'].widget = HiddenInput() return form
Example #22
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): """ Hide the 'order' field """ form = super().get_form() form.fields['order'].widget = HiddenInput() return form
Example #23
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): """ Create a form to upload a new PurchaseOrderAttachment - Hide the 'order' field """ form = super(AjaxCreateView, self).get_form() form.fields['order'].widget = HiddenInput() return form
Example #24
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): form = super().get_form() # Prevent user from editing customer form.fields['customer'].widget = HiddenInput() return form
Example #25
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): form = super(AjaxCreateView, self).get_form() form.fields['part'].widget = HiddenInput() return form
Example #26
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): form = super(AjaxUpdateView, self).get_form() form.fields['part'].widget = HiddenInput() return form
Example #27
Source File: edit_handlers.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #28
Source File: dashboard.py From myblog with GNU Affero General Public License v3.0 | 5 votes |
def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == 'widget_type': widgets = widget_manager.get_widgets(self.request.GET.get('page_id', '')) form_widget = WidgetTypeSelect(widgets) return forms.ChoiceField(choices=[(w.widget_type, w.description) for w in widgets], widget=form_widget, label=_('Widget Type')) if 'page_id' in self.request.GET and db_field.name == 'page_id': kwargs['widget'] = forms.HiddenInput field = super( UserWidgetAdmin, self).formfield_for_dbfield(db_field, **kwargs) return field
Example #29
Source File: collections.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def empty_form(self): empty_form = super().empty_form empty_form.fields['DELETE'].widget = forms.HiddenInput() return empty_form
Example #30
Source File: views.py From InvenTree with MIT License | 5 votes |
def get_form(self): form = super().get_form() line_id = form['line'].value() # If a line item has been specified, reduce the queryset for the stockitem accordingly try: line = SalesOrderLineItem.objects.get(pk=line_id) queryset = form.fields['item'].queryset # Ensure the part reference matches queryset = queryset.filter(part=line.part) # Exclude StockItem which are already allocated to this order allocated = [allocation.item.pk for allocation in line.allocations.all()] queryset = queryset.exclude(pk__in=allocated) form.fields['item'].queryset = queryset # Hide the 'line' field form.fields['line'].widget = HiddenInput() except (ValueError, SalesOrderLineItem.DoesNotExist): pass return form