我们从Python开源项目中,提取了以下35个代码示例,用于说明如何使用django.forms.widgets.HiddenInput()。
def test_edit_attachments_cannot_set_mount_point(self): volume = self.cinder_volumes.first() servers = [s for s in self.servers.list() if s.tenant_id == self.request.user.tenant_id] cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume) api.nova.server_list(IsA(http.HttpRequest)).AndReturn([servers, False]) self.mox.ReplayAll() url = reverse('horizon:project:volumes:volumes:attach', args=[volume.id]) res = self.client.get(url) # Assert the device field is hidden. form = res.context['form'] self.assertIsInstance(form.fields['device'].widget, widgets.HiddenInput)
def test_launch_form_instance_device_name_hidden(self): self._test_launch_form_instance_show_device_name( u'', widgets.HiddenInput, { 'name': 'device_name', 'value': '', 'attrs': {'id': 'id_device_name'}} )
def __init__(self, *args, **kwargs): self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput) self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput) # MIN_NUM_FORM_COUNT and MAX_NUM_FORM_COUNT are output with the rest of # the management form, but only for the convenience of client-side # code. The POST value of them returned from the client is not checked. self.base_fields[MIN_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput) self.base_fields[MAX_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput) super(ManagementForm, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): super(PageForm, self).__init__(*args, **kwargs) self.fields['parent'].widget = HiddenInput() self.fields['site'].widget = HiddenInput() self.fields['template'].widget = HiddenInput() self.fields['language'].widget = HiddenInput() if not self.fields['site'].initial: self.fields['site'].initial = Site.objects.get_current().pk site_id = self.fields['site'].initial languages = get_language_tuple(site_id) self.fields['language'].choices = languages if not self.fields['language'].initial: self.fields['language'].initial = get_language() if 'page_type' in self.fields: try: type_root = Page.objects.get(publisher_is_draft=True, reverse_id=PAGE_TYPES_ID, site=site_id) except Page.DoesNotExist: type_root = None if type_root: language = self.fields['language'].initial type_ids = type_root.get_descendants().values_list('pk', flat=True) titles = Title.objects.filter(page__in=type_ids, language=language) choices = [('', '----')] for title in titles: choices.append((title.page_id, title.title)) self.fields['page_type'].choices = choices
def __init__(self, *args, **kwargs): # Dates are not language dependent, so let's just fake the language to # make the ModelAdmin happy super(PublicationDatesForm, self).__init__(*args, **kwargs) self.fields['language'].widget = HiddenInput() self.fields['site'].widget = HiddenInput() site_id = self.fields['site'].initial languages = get_language_tuple(site_id) self.fields['language'].choices = languages if not self.fields['language'].initial: self.fields['language'].initial = get_language()
def __init__(self, *args, request=None, allow_clicked_position=False, **kwargs): self.request = request super().__init__(*args, **kwargs) GraphNode = self.request.changeset.wrap_model('GraphNode') graph_node_qs = GraphNode.objects.all() self.fields['active_node'] = ModelChoiceField(graph_node_qs, widget=HiddenInput(), required=False) self.fields['clicked_node'] = ModelChoiceField(graph_node_qs, widget=HiddenInput(), required=False) if allow_clicked_position: self.fields['clicked_position'] = CharField(widget=HiddenInput(), required=False) Space = self.request.changeset.wrap_model('Space') space_qs = Space.objects.all() self.fields['goto_space'] = ModelChoiceField(space_qs, widget=HiddenInput(), required=False)
def __init__(self, *args, **kwargs): self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput) self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput) # MAX_NUM_FORM_COUNT is output with the rest of the management form, # but only for the convenience of client-side code. The POST # value of MAX_NUM_FORM_COUNT returned from the client is not checked. self.base_fields[MAX_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput) super(ManagementForm, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): super(AdvancedSettingsForm, self).__init__(*args, **kwargs) self.fields['language'].widget = HiddenInput() self.fields['site'].widget = HiddenInput() site_id = self.fields['site'].initial languages = get_language_tuple(site_id) self.fields['language'].choices = languages if not self.fields['language'].initial: self.fields['language'].initial = get_language() if 'navigation_extenders' in self.fields: self.fields['navigation_extenders'].widget = forms.Select( {}, [('', "---------")] + menu_pool.get_menus_by_attribute( "cms_enabled", True)) if 'application_urls' in self.fields: # Prepare a dict mapping the apps by class name ('PollApp') to # their app_name attribute ('polls'), if any. app_namespaces = {} app_configs = {} for hook in apphook_pool.get_apphooks(): app = apphook_pool.get_apphook(hook[0]) if app.app_name: app_namespaces[hook[0]] = app.app_name if app.app_config: app_configs[hook[0]] = app self.fields['application_urls'].widget = AppHookSelect( attrs={'id': 'application_urls'}, app_namespaces=app_namespaces ) self.fields['application_urls'].choices = [('', "---------")] + apphook_pool.get_apphooks() page_data = self.data if self.data else self.initial if app_configs: self.fields['application_configs'].widget = ApplicationConfigSelect( attrs={'id': 'application_configs'}, app_configs=app_configs) if page_data.get('application_urls', False) and page_data['application_urls'] in app_configs: self.fields['application_configs'].choices = [(config.pk, force_text(config)) for config in app_configs[page_data['application_urls']].get_configs()] apphook = page_data.get('application_urls', False) try: config = apphook_pool.get_apphook(apphook).get_configs().get(namespace=self.initial['application_namespace']) self.fields['application_configs'].initial = config.pk except ObjectDoesNotExist: # Provided apphook configuration doesn't exist (anymore), # just skip it # The user will choose another value anyway pass else: # If app_config apphook is not selected, drop any value # for application_configs to avoid the field data from # being validated by the field itself try: del self.data['application_configs'] except KeyError: pass if 'redirect' in self.fields: self.fields['redirect'].widget.language = self.fields['language'].initial
def __init__(self, article, request, *args, **kwargs): self.article = article self.user = request.user self.request = request kwargs['instance'] = article kwargs['initial'] = {'locked': article.current_revision.locked} super(PermissionsForm, self).__init__(*args, **kwargs) self.can_change_groups = False self.can_assign = False if permissions.can_assign(article, request.user): self.can_assign = True self.can_change_groups = True self.fields['group'].queryset = Group.objects.all() elif permissions.can_assign_owner(article, request.user): self.fields['group'].queryset = Group.objects.filter( user=request.user) self.can_change_groups = True else: # Quick-fix... # Set the group dropdown to readonly and with the current # group as only selectable option self.fields['group'] = forms.ModelChoiceField( queryset=Group.objects.filter( id=self.instance.group.id) if self.instance.group else Group.objects.none(), empty_label=_('(none)'), required=False, widget=SelectWidgetBootstrap( disabled=True) if settings.USE_BOOTSTRAP_SELECT_WIDGET else forms.Select( attrs={'disabled': True})) self.fields['group_read'].widget = forms.HiddenInput() self.fields['group_write'].widget = forms.HiddenInput() if not self.can_assign: self.fields['owner_username'].widget = forms.TextInput( attrs={ 'readonly': 'true'}) self.fields['recursive'].widget = forms.HiddenInput() self.fields['recursive_group'].widget = forms.HiddenInput() self.fields['recursive_owner'].widget = forms.HiddenInput() self.fields['locked'].widget = forms.HiddenInput() self.fields['owner_username'].initial = getattr( article.owner, User.USERNAME_FIELD) if article.owner else ""