class AdvancedSearch(forms.Form): def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) super(AdvancedSearch, self).__init__(*args, **kwargs) self.fields['country'] = forms.MultipleChoiceField( required=False, widget=FilteredSelectMultiple('Countries', False), choices=([c.code, c.name.title()] for c in Country.objects.order_by('name'))) self.fields['language'] = forms.MultipleChoiceField( required=False, choices=([l.code, l.name] for l in Language.objects.order_by('name')), widget=FilteredSelectMultiple('Languages', False)) if user and user.is_authenticated: self.fields['in_collection'] = forms.ModelMultipleChoiceField( label='', widget=FilteredSelectMultiple('Collections', False), queryset=user.collector.collections.all(), required=False) self.user = user self.fields['in_selected_collection'] = forms.BooleanField( label="Is in the selected collections", required=False, initial=True) target = forms.ChoiceField(choices=[['publisher', 'Publishers'], ['brand_group', 'Publisher Brand Group'], ['brand_emblem', 'Publisher Brand Emblem'], ['indicia_publisher', 'Indicia / Colophon Publisher'], ['series', 'Series'], ['issue', 'Issues'], ['issue_cover', 'Covers for Issues'], ['sequence', 'Stories'], ['cover', 'Covers']], initial='sequence', label='Search For') method_help = "All methods case-insensitive." method = forms.ChoiceField(choices=[ ['iexact', 'Matches Exactly'], ['istartswith', 'Starts With'], ['icontains', 'Contains'], ['exact', 'Matches Exactly (case sensitive)'], ['startswith', 'Starts With (case sensitive)'], ['contains', 'Contains (case sensitive)'], ], initial='icontains', label='Search Method', help_text = method_help) logic_help = "This option applies primarily to the story credit fields." \ "It will eventually be replaced by more powerful options." logic = forms.ChoiceField(choices=[[False, 'AND all fields'], [True, 'OR credits, AND other fields']], initial=False, label='Behavior', help_text=logic_help) keywords = forms.CharField(required=False) order1 = forms.ChoiceField(choices=ORDERINGS, required=False, initial='series', label='First By') order2 = forms.ChoiceField(choices=ORDERINGS, required=False, initial='date', label='Second By') order3 = forms.ChoiceField(choices=ORDERINGS, required=False, label='Third By') start_date = forms.DateField(label='Start Date', required=False, input_formats=DATE_FORMATS) end_date = forms.DateField(label='End Date', required=False, input_formats=DATE_FORMATS) use_on_sale_date = forms.BooleanField(label="Use On-Sale Date", required=False) updated_since = forms.DateField(label='Updated Since', required=False, input_formats=DATE_FORMATS) pub_name = forms.CharField(label='Publisher', required=False) pub_notes = forms.CharField(label='Notes', required=False) brand_group = forms.CharField(required=False) brand_emblem = forms.CharField(required=False) brand_notes = forms.CharField(label='Notes', required=False) indicia_publisher = forms.CharField(label='Indicia / Colophon Publisher', required=False) ind_pub_notes = forms.CharField(label='Notes', required=False) is_surrogate = forms.NullBooleanField(label='Is Surrogate?', required=False, widget=forms.Select(choices=((None, ""), (True, "yes"), (False, "no")))) series = forms.CharField(label='Name', required=False) series_notes = forms.CharField(label='Series Notes', required=False) tracking_notes = forms.CharField(label='Tracking Notes', required=False) not_reserved = forms.BooleanField(label="Not Reserved", required=False) is_current = forms.BooleanField(label="Current", required=False) issue_count = forms.CharField(label='Issue Count', required=False) series_year_began = forms.IntegerField(required=False, label='Series Year Began') is_comics = forms.NullBooleanField(label="Comics Publication, " "i.e. 50+x% comics", required=False, widget=forms.Select(choices=((None, ""), (True, "yes"), (False, "no")))) color = forms.CharField(label='Color', required=False) dimensions = forms.CharField(label='Dimensions', required=False) paper_stock = forms.CharField(label='Paper Stock', required=False) binding = forms.CharField(label='Binding', required=False) publishing_format = forms.CharField(label='Publishing Format', required=False) publication_type = forms.ModelMultipleChoiceField(label='Publication Type', queryset=SeriesPublicationType.objects.all(), required=False) issues = forms.CharField(label='Issues', required=False) volume = forms.CharField(label='Volume', required=False) issue_title = forms.CharField(label='Title', required=False) variant_name = forms.CharField(label='Variant Name', required=False) is_variant = forms.NullBooleanField(label='Is a Variant', required=False, widget=forms.Select(choices=((None, ""), (True, "yes"), (False, "no")))) price = forms.CharField(required=False) issue_pages = forms.CharField(label='Issue Pages', required=False) issue_pages_uncertain = forms.NullBooleanField(\ label='Page count uncertain', required=False, widget=forms.Select(choices=((None, ""), (True, "yes"), (False, "no")))) issue_notes = forms.CharField(label='Issue Notes', required=False) issue_editing = forms.CharField(label='Issue Editing', required=False) issue_date = forms.CharField(label='Cover Date', required=False) isbn = forms.CharField(label='ISBN', required=False) barcode = forms.CharField(required=False) rating = forms.CharField(label="Publisher's Age Guidelines", required=False) indicia_frequency = forms.CharField(label='Indicia Frequency', required=False) issue_reprinted = forms.NullBooleanField(label="Reprinted", required=False, widget=forms.Select(choices=((None, ""), (True, "has issue level sources"), (False, "has issue level targets")))) cover_needed = forms.BooleanField(label="Cover is Needed", required=False) is_indexed = forms.NullBooleanField(label="Is Indexed", required=False, widget=forms.Select(choices=((None, ""), (True, "yes"), (False, "no")))) image_resources = forms.MultipleChoiceField(label='Image Resources', widget=FilteredSelectMultiple('Image Resources', False), choices=(('has_soo', 'Has Statement of Ownership Scan'), ('needs_soo', 'Needs Statement of Ownership Scan'), ('has_indicia', 'Has Indicia Scan'), ('needs_indicia', 'Needs Indicia Scan')), required=False) indexer = forms.ModelMultipleChoiceField(required=False, label='', queryset=Indexer.objects.filter(imps__gt=0).\ order_by('user__first_name', 'user__last_name').select_related('user'), widget=FilteredSelectMultiple('Indexers', False, attrs={'size': '6'})) feature = forms.CharField(required=False) type = forms.ModelMultipleChoiceField(queryset=StoryType.objects\ .exclude(name__in=[i for i in OLD_TYPES]), widget=FilteredSelectMultiple('Story Types', False, attrs={'size' : '6'}), required=False) title = forms.CharField(required=False) pages = forms.CharField(required=False) pages_uncertain = forms.NullBooleanField(label='Page count uncertain', required=False, widget=forms.Select(choices=((None, ""), (True, "yes"), (False, "no")))) script = forms.CharField(required=False) pencils = forms.CharField(required=False) inks = forms.CharField(required=False) colors = forms.CharField(required=False) letters = forms.CharField(required=False) story_editing = forms.CharField(label='Story Editing', required=False) job_number = forms.CharField(label='Job Number', required=False) first_line = forms.CharField(required=False) genre = forms.MultipleChoiceField(required=False, widget=FilteredSelectMultiple('Genres', False), choices=([c, c] for c in GENRES['en'])) characters = forms.CharField(required=False) synopsis = forms.CharField(required=False) reprint_notes = forms.CharField(label='Reprint Notes', required=False) story_reprinted = forms.ChoiceField(label="Reprinted", required=False, choices=[('', ""), ('from', "is a linked reprint"), ('in', "has linked reprints"), ('not', "is not a linked reprint")]) notes = forms.CharField(label='Notes', required=False) alt_country = forms.CharField(label='', required=False, max_length=3) alt_language = forms.CharField(label='', required=False, max_length=3) def clean_pages(self): pages_data = self.cleaned_data['pages'] if pages_data: range_match = match(PAGE_RANGE_REGEXP, pages_data) if not range_match: try: Decimal(pages_data) except InvalidOperation: raise forms.ValidationError( "Page count must be a decimal number or a pair of " "decimal numbers separated by a hyphen.") return pages_data def clean_issue_pages(self): pages_data = self.cleaned_data['issue_pages'] if pages_data: range_match = match(PAGE_RANGE_REGEXP, pages_data) if not range_match: try: Decimal(pages_data) except InvalidOperation: raise forms.ValidationError( "Page count must be a decimal number or a pair of " "decimal numbers separated by a hyphen.") return pages_data def clean_issue_count(self): issue_count_data = self.cleaned_data['issue_count'].strip() if issue_count_data: issue_count_match = (issue_count_data != '-' and match(COUNT_RANGE_REGEXP, issue_count_data)) if not issue_count_match: try: int(issue_count_data) except ValueError: raise forms.ValidationError( "Issue count must be an integer or an integer " "range reparated by a hyphen (e.g. 100-200, " "100-, -200).") return issue_count_data def clean_keywords(self): keywords = self.cleaned_data['keywords'] if keywords != None: not_allowed = False for c in ['<', '>', '{', '}', ':', '/', '\\', '|', '@' , ',']: if c in keywords: not_allowed = True break if not_allowed: raise forms.ValidationError('The following characters are ' 'not allowed in a keyword: < > { } : / \ | @ ,') return keywords def clean_in_collection(self): collections = self.cleaned_data['in_collection'] if collections.exclude(collector=self.user.collector).count(): raise forms.ValidationError( "One cannot search in the collections of other users.") return collections def clean(self): cleaned_data = self.cleaned_data if self.is_valid(): if cleaned_data['cover_needed']: # use of in since after distinction stuff is cleared add series if cleaned_data['target'] not in ['issue', 'series']: raise forms.ValidationError( "Searching for covers which are missing or need to be" " replaced is valid only for issue or series searches.") if cleaned_data['target'] == 'cover' and cleaned_data['type']: if len(cleaned_data['type']) > 1 or StoryType.objects\ .get(name='cover') not in cleaned_data['type']: raise forms.ValidationError( "When searching for covers only type cover can be " "selected.") if cleaned_data['use_on_sale_date']: if cleaned_data['target'] not in ['issue', 'sequence', 'issue_cover']: raise forms.ValidationError( "The on-sale date can only be used in issue or story " "searches.") if cleaned_data['start_date'] or cleaned_data['end_date']: if (cleaned_data['start_date'] and len(self.data['start_date'])<=4) or \ (cleaned_data['end_date'] and len(self.data['end_date'])<=4): if cleaned_data['target'] in ['issue', 'issue_cover', 'sequence', 'cover']: raise forms.ValidationError( "For issue-level search targets please use full " "dates. To get everything from a year/month you need" " to use the last day of the preceding year/month, " "e.g. 1989-12-31 will find all comics we have " "recorded with a publication date 1990 and later.") return cleaned_data
class Meta: model = SharedPagelet fields = ('pagelet', 'area', 'order') widgets = { "area": forms.Select(choices=conf.CONTENT_AREAS), }
class ConfigUIForm(forms.Form): HTTP_SKINS = (('nasLogin', 'NasLogin'), ('basicLogin', 'BasicLogin')) ftp_banner = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '25' }), label="Banner", required=False, initial="FTP server ready") ftp_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="Enable", required=False) ftp_port = forms.IntegerField( widget=forms.NumberInput(attrs={'class': 'form-control'}), label="Port", required=True, initial=21) http_banner = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '25' }), label="Banner", required=False, initial="Apache/2.2.22 (Ubuntu)") http_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="Enable", required=False) http_port = forms.IntegerField( widget=forms.NumberInput(attrs={'class': 'form-control'}), label="Port", required=True, initial=80) http_skin = forms.ChoiceField( widget=forms.Select(attrs={'name': 'httpSkins'}), label="Skins", required=True, choices=HTTP_SKINS) mailserver = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '50' }), label="Mail Server", required=False) mailserverPort = forms.IntegerField( widget=forms.NumberInput(attrs={'class': 'form-control'}), label="Port", required=True, initial=587) fromaddr = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '50' }), label="From Address", required=False) toaddr = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '50' }), label="To Address", required=False) subject = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '50' }), label="Subject", required=False) username = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '50' }), label="USer name", required=False) password = forms.CharField(widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'size': '50' }), label="Password", required=False) #smtp_enabled = forms.BooleanField(widget=forms.CheckboxInput(attrs={'class': 'form-control'}),label = "Enable",required =False) mysql_banner = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '25' }), label="Banner", required=False, initial="5.5.43-0ubuntu0.14.04.1") mysql_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="Enable", required=False) mysql_port = forms.IntegerField( widget=forms.NumberInput(attrs={'class': 'form-control'}), label="Port", required=True, initial=3306) ssh_version = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '25' }), label="Banner", required=False, initial="SSH-2.0-OpenSSH_5.1p1 Debian-4") ssh_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="Enable", required=False) ssh_port = forms.IntegerField( widget=forms.NumberInput(attrs={'class': 'form-control'}), label="Port", required=True, initial=8022) rdp_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="RDP", required=False) sip_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="SIP", required=False) snmp_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="SNMP", required=False) #tftp_enabled = forms.BooleanField(widget=forms.CheckboxInput(attrs={'class': 'form-control'}),label = "TFTP Enable",required =False) mssql_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="MS Sql", required=False) vnc_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="VNC", required=False) telnet_banner = forms.CharField(widget=forms.TextInput(attrs={ 'class': 'form-control', 'size': '25' }), label="Banner", required=False, initial="") telnet_enabled = forms.BooleanField( widget=forms.CheckboxInput(attrs={'class': 'form-control'}), label="Enable", required=False) telnet_port = forms.IntegerField( widget=forms.NumberInput(attrs={'class': 'form-control'}), label="Port", required=True, initial=23)
class DataFilter(django_mongoengine_filter.FilterSet): '''Create the filter form and filter according to its selection :param req: The Http Request :type amount: Http Request :returns: Data Queryset :rtype: Data Queryset ''' #https://pypi.org/project/django-mongoengine-filter/ Country_Region = django_mongoengine_filter.ChoiceFilter(choices=Cache().COUNTRY_CHOICES, widget=forms.Select(attrs={'onchange': 'this.form.submit();', 'class': 'selectpicker', 'data-live-search': 'true'})) Last_Update = django_mongoengine_filter.ChoiceFilter(choices=Cache().DATE_CHOICES, widget=forms.Select(attrs={'onchange': 'this.form.submit();', 'class': 'selectpicker', 'data-live-search': 'true'})) class Meta: model = Data fields = ['Country_Region', 'Last_Update'] """filter_overrides = {
class CreateDealForm(forms.Form): title = forms.CharField(max_length=55, required=True) description = forms.CharField(widget=forms.Textarea, required=True) status = forms.ChoiceField(choices=CATEGORY_CHOICES, label="", initial='', widget=forms.Select(), required=True) price = forms.DecimalField(max_digits=10, decimal_places=2) old_price = forms.DecimalField(max_digits=10, decimal_places=2) featured = forms.BooleanField(required=False) date_start = forms.DateField() date_end = forms.DateField()
class FormGenerarTurno(forms.Form): paciente = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = Paciente.objects.all()) dia = forms.DateField(widget=forms.DateInput(attrs={'class': 'form-control'})) hora = forms.TimeField(widget=forms.TimeInput(attrs={'class': 'form-control'}))
class FormFiltroFecha(forms.Form): filtrar_turnos_por_dia = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset=Turno.objects.all())
class FilterForm(forms.Form): category = forms.ChoiceField(widget=forms.Select(), choices=CATEGORY)
class MaterialForm(forms.Form): material = forms.ChoiceField(widget=forms.Select(), choices=MATERIAL)
class signup_form(forms.Form): name = forms.CharField(widget=forms.TextInput(attrs={ "class": "form-control", "id": "defaultForm-name" })) branch = forms.CharField( widget=forms.Select(choices=CHOICES, attrs={ "class": "multiple", "id": "defaultForm-college" })) #branch=forms.CharField(widget=forms.TextInput(attrs={"class":"form-control","id":"defaultForm-branch"})) contact = forms.DecimalField(widget=forms.NumberInput( attrs={ "class": "form-control", "id": "defaultForm-year" })) year = forms.DecimalField( max_value=3, min_value=1, widget=forms.NumberInput(attrs={ "class": "form-control", "id": "defaultForm-year" })) college = forms.CharField(widget=forms.TextInput( attrs={ "class": "form-control", "id": "defaultForm-college" })) email = forms.EmailField(widget=forms.EmailInput( attrs={ "class": "form-control", "id": "defaultForm-email" })) password = forms.CharField( min_length=8, widget=forms.PasswordInput(attrs={ "class": "form-control", "id": "defaultForm-password" })) confirm_password = forms.CharField(widget=forms.PasswordInput( attrs={ "class": "form-control", "id": "defaultForm-confirm_pass" })) def clean_email(self): email = self.cleaned_data.get("email") qs = User.objects.filter(username=email) if qs.exists(): raise forms.ValidationError("Email Taken !") elif ("@" not in email) or (".com" not in email): raise forms.ValidationError("Please Enter a Valid Email !") return email # def clean(self): # data=self.cleaned_data # password=self.cleaned_data.get("password") # password1=self.cleaned_data.get("confirm_password") # if password1 != password: # raise forms.ValidationError("Password must Match !") # return data def clean_confirm_password(self): data = self.cleaned_data print(data) password = self.cleaned_data.get('password') password1 = self.cleaned_data.get('confirm_password') if password1 != password: raise forms.ValidationError("Password must Match !!") return data
class GenderForm(forms.Form): gender = forms.ChoiceField(widget=forms.Select(), choices=GENDER)
class DonateForm(forms.Form): name = forms.CharField( label=_("NAME"), max_length=100, widget=forms.TextInput(attrs={"class": "form-control"})) email = forms.EmailField( label=_("EMAIL"), widget=forms.EmailInput(attrs={"class": "form-control"})) phone = forms.CharField( label=_("PHONE NUMBER"), widget=forms.TextInput(attrs={"class": "form-control"})) pan = forms.CharField( label=_("PAN NUMBER"), max_length=10, widget=forms.TextInput(attrs={"class": "form-control"}), help_text=_("PAN is required as per government regulations.")) address = forms.CharField( label=_("ADDRESS"), max_length=252, widget=forms.Textarea(attrs={ "class": "form-control", "rows": 2 }), help_text=_("Address is required as per government regulations.")) is_indian = forms.BooleanField(initial=False, label=_("I am a citizen of India*"), widget=forms.CheckboxInput()) payment_method = forms.ChoiceField(choices=DonationOptions.Methods.CHOICES, widget=forms.RadioSelect, label=_('Payment method')) amount = AmountField(choices=DonationOptions.Amount.CHOICES, label=_('AMOUNT'), required=False) frequency = forms.ChoiceField( choices=DonationOptions.Frequency.FORM_CHOICES, widget=forms.RadioSelect, required=False, label=_('TYPE')) term = forms.ChoiceField( choices=DonationOptions.Term.CHOICES, initial=DonationOptions.Term.Y5, widget=forms.Select(attrs={"class": "form-control term-select"}), label=_('DURATION')) def clean_is_indian(self): data = self.cleaned_data["is_indian"] if data != True: raise forms.ValidationError( _("Sorry, we can accept donations " "from Indians only.")) return data def clean_term(self): if self.cleaned_data.get('frequency', '') == DonationOptions.Frequency.Y and \ self.cleaned_data['term'] in (DonationOptions.Term.M6, DonationOptions.Term.Y1): raise forms.ValidationError( _('Term should be at least 2 years for Yearly donation')) return self.cleaned_data['term'] def clean_amount(self): if self.cleaned_data.get('payment_method', '') == DonationOptions.Methods.onlinePayment and \ self.cleaned_data['amount'] in (None, ''): raise forms.ValidationError(_('Please enter amount')) return self.cleaned_data['amount']
class NewsForm(forms.Form): title = forms.CharField(max_length=150, label='Название', widget=forms.TextInput(attrs={"class": "form-control"})) content = forms.CharField(label='Текст', required=False, widget=forms.Textarea(attrs={ "class": "form-control", "rows": 5 })) is_published = forms.BooleanField(label='Опубликовано?', initial=True) category = forms.ModelChoiceField(empty_label='Выберите категорию', label='Категория', queryset=Category.objects.all(), widget=forms.Select(attrs={"class": "form-control"}))
class Meta: model = userDetails fields = '__all__' state_choices = helper_functions.return_states_tuple_list() widgets = {"birthState": forms.Select(choices=state_choices)}
class FormNuevoProductoLente(forms.Form): nombre_lente = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}), max_length=64, label="Nombre lente") precio_lente = forms.DecimalField(widget=forms.NumberInput(attrs={'class': 'form-control'}), decimal_places=2, max_digits=5, min_value=0) lejos_o_cerca = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = LejosCerca.objects.all()) izquierda_o_derecha = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset=IzquierdaDerecha.objects.all()) armazon = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset= Armazon.objects.all())
class DesignForm(forms.Form): design = forms.ChoiceField(widget=forms.Select(), choices=DESIGN)
class FormCrearPaciente(forms.Form): nombre = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}), max_length=64, label ="Nombre") apellido = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}), max_length=64, label ="Apellido") medico_asignado = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = Medico.objects.all())
class ColorForm(forms.Form): color = forms.ChoiceField(widget=forms.Select(), choices=COLOR)
class FormComentarMedico(forms.Form): paciente = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = Paciente.objects.all()) observacion = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
class DecisionForm(forms.Form): """ Form for making a decision on a request. """ # Constants defining options for the quick expiry selection EXPIRES_SIX_MONTHS = 1 EXPIRES_ONE_YEAR = 2 EXPIRES_TWO_YEARS = 3 EXPIRES_THREE_YEARS = 4 EXPIRES_FIVE_YEARS = 5 EXPIRES_TEN_YEARS = 6 EXPIRES_CUSTOM = 7 approved = forms.NullBooleanField( label='Decision', widget=forms.Select( choices=[(None, '---------'), (True, 'APPROVED'), (False, 'REJECTED')])) expires = forms.TypedChoiceField( label='Expiry date', help_text= 'Pick a duration from the dropdown list, or pick a custom expiry date', required=False, choices=[ (0, '---------'), (EXPIRES_SIX_MONTHS, 'Six months from now'), (EXPIRES_ONE_YEAR, 'One year from now'), (EXPIRES_TWO_YEARS, 'Two years from now'), (EXPIRES_THREE_YEARS, 'Three years from now'), (EXPIRES_FIVE_YEARS, 'Five years from now'), (EXPIRES_TEN_YEARS, 'Ten years from now'), (EXPIRES_CUSTOM, 'Custom expiry date'), ], coerce=int, empty_value=0) expires_custom = forms.DateField(label='Custom expiry date', required=False, input_formats=['%Y-%m-%d', '%d/%m/%Y'], widget=forms.DateInput( format='%Y-%m-%d', attrs={'type': 'date'})) user_reason = forms.CharField(label='Reason for rejection (user)', required=False, widget=forms.Textarea(attrs={'rows': 5}), help_text=markdown_allowed()) internal_reason = forms.CharField(label='Reason for rejection (internal)', required=False, widget=forms.Textarea(attrs={'rows': 5}), help_text=markdown_allowed()) def __init__(self, request, approver, *args, **kwargs): self._request = request self._approver = approver super().__init__(*args, **kwargs) def clean_approved(self): approved = self.cleaned_data.get('approved') if approved is None: raise ValidationError('This field is required') return approved def clean_expires(self): approved = self.cleaned_data.get('approved') expires = self.cleaned_data.get('expires') if approved and not expires: raise ValidationError('Please give an expiry date for access') return expires def clean_expires_custom(self): approved = self.cleaned_data.get('approved') expires = self.cleaned_data.get('expires') expires_custom = self.cleaned_data.get('expires_custom') if approved and expires == self.EXPIRES_CUSTOM and not expires_custom: raise ValidationError('Please give an expiry date for access') if expires_custom and expires_custom < date.today(): raise ValidationError('Expiry date must be in the future') return expires_custom def clean_user_reason(self): approved = self.cleaned_data.get('approved') user_reason = self.cleaned_data.get('user_reason') if approved is False and not user_reason: raise ValidationError('Please give a reason for rejection') return user_reason def save(self): # Update the request from the form if self.cleaned_data['approved']: # Get the expiry date expires = self.cleaned_data['expires'] if expires == self.EXPIRES_SIX_MONTHS: expires_date = date.today() + relativedelta(months=6) elif expires == self.EXPIRES_ONE_YEAR: expires_date = date.today() + relativedelta(years=1) elif expires == self.EXPIRES_TWO_YEARS: expires_date = date.today() + relativedelta(years=2) elif expires == self.EXPIRES_THREE_YEARS: expires_date = date.today() + relativedelta(years=3) elif expires == self.EXPIRES_FIVE_YEARS: expires_date = date.today() + relativedelta(years=5) elif expires == self.EXPIRES_TEN_YEARS: expires_date = date.today() + relativedelta(years=10) else: expires_date = self.cleaned_data['expires_custom'] self._request.state = RequestState.APPROVED # If the request was approved, create the grant self._request.grant = Grant.objects.create( role=self._request.role, user=self._request.user, granted_by=self._approver.username, expires=expires_date) # Copy the metadata from the request to the grant self._request.copy_metadata_to(self._request.grant) else: self._request.state = RequestState.REJECTED self._request.user_reason = self.cleaned_data['user_reason'] self._request.internal_reason = self.cleaned_data[ 'internal_reason'] self._request.save() return self._request
class SelfRecordForm(forms.Form): """ actor_name = forms.CharField(required=False, label=_('actor full name'), widget=forms.TextInput(attrs={'readonly':'readonly', 'class':'form-control',}), help_text=_('this is a computed value'),) actor_email = forms.EmailField(required=False, label=_('actor email'), widget=forms.TextInput(attrs={'readonly':'readonly', 'class':'form-control',}), help_text=_('this is a computed value'),) """ actor_name = forms.CharField(widget=forms.HiddenInput()) actor_email = forms.CharField(widget=forms.HiddenInput()) timestamp = forms.DateTimeField( required=True, label=_('timestamp'), input_formats=['%d/%m/%Y %H:%M'], widget=DateTimeWidget(bootstrap_version=3, options=dateTimeOptions, attrs={ 'id': 'timestamp', 'class': 'form-control', }), help_text=_('when the experience occurred; format: dd/mm/yyyy hh:mm')) platform = forms.CharField( required=True, label=_('learning platform'), widget=forms.TextInput(attrs={ 'class': 'form-control', }), help_text=_('can be the name of any activity provider'), ) endpoint = forms.CharField(widget=forms.HiddenInput()) recipe_ids = forms.MultipleChoiceField( required=True, label=_('xAPI recipes'), choices=get_recipe_choices, widget=forms.SelectMultiple( attrs={ 'class': 'form-control', 'onchange': 'javascript: this.form.submit()', }), help_text=_('select one or more, then wait for the form to refresh'), ) verb_id = forms.ChoiceField( required=False, label=_('verb'), choices=get_verb_choices, widget=forms.Select(attrs={ 'class': 'form-control', }), help_text= _('please, choose after selecting the recipe(s); currently the match with the activity type is not checked' ), ) activity_type = forms.ChoiceField( required=False, label=_('activity type'), choices=get_activity_choices, widget=forms.Select(attrs={ 'class': 'form-control', }), help_text= _('please, choose after selecting the recipe(s); currently the match with the verb is not checked' ), ) object_name = forms.CharField( required=True, label=_('activity name'), widget=forms.TextInput(attrs={ 'class': 'form-control', }), help_text= _('the name of the specific activity, distinguishing it among other activities of the same type' ), ) object_id = forms.CharField( required=True, label=_('activity unique identifier'), widget=forms.TextInput(attrs={ 'class': 'form-control', }), help_text=_('can be an URL, a URI, a DOI, an ISBN code or the like'), ) object_description = forms.CharField( required=False, label=_('activity description'), widget=forms.Textarea(attrs={ 'class': 'form-control', 'rows': 2, }), help_text=_('an optional description of the specific activity'), ) object_language = forms.ChoiceField( required=True, label=_('Language of name and description'), choices=xapi_language_codes, widget=forms.Select(attrs={ 'class': 'form-control', }), help_text= _('please, specify the language used for the name and the description of the activity object' ), ) context_activity_type = forms.ChoiceField( required=False, label=_('contextual activity type'), choices=get_contextual_activity_choices, widget=forms.Select(attrs={ 'class': 'form-control', }), help_text=_('the type of a related activity, if any'), ) context_object_name = forms.CharField( required=True, label=_('contextual activity name'), widget=forms.TextInput(attrs={ 'class': 'form-control', }), help_text= _('the name of the related activity, distinguishing it among other activities of the same type' ), ) context_object_id = forms.CharField( required=True, label=_('contextual activity unique identifier'), widget=forms.TextInput(attrs={ 'class': 'form-control', }), help_text= _('the unique id of the related activity; can be an URL, a URI, a DOI, an ISBN code or the like' ), ) context_activity_relationship = forms.ChoiceField( required=False, label=_('contextual activity relationship'), choices=context_activity_relation_choices, widget=forms.Select(attrs={ 'class': 'form-control', }), help_text= _('please, specify how the contextual activity is related to the one being recorded' ), ) """
class Meta: model = Processing exclude = ('materiel_belong', 'GS1', 'GS2', 'GS3', 'GS4', 'GS5', 'GS6', 'GS7', 'GS8', 'GS9', 'GS10', 'GS11', 'GS12') widgets = { "GX1": forms.Select(attrs={"class": "form-control input-mini"}), "GX2": forms.Select(attrs={"class": "form-control input-mini"}), "GX3": forms.Select(attrs={"class": "form-control input-mini"}), "GX4": forms.Select(attrs={"class": "form-control input-mini"}), "GX5": forms.Select(attrs={"class": "form-control input-mini"}), "GX6": forms.Select(attrs={"class": "form-control input-mini"}), "GX7": forms.Select(attrs={"class": "form-control input-mini"}), "GX8": forms.Select(attrs={"class": "form-control input-mini"}), "GX9": forms.Select(attrs={"class": "form-control input-mini"}), "GX10": forms.Select(attrs={"class": "form-control input-mini"}), "GX11": forms.Select(attrs={"class": "form-control input-mini"}), "GX12": forms.Select(attrs={"class": "form-control input-mini"}), }
def get_custom_fields_for_model(content_type, filterable_only=False, bulk_edit=False): """ Retrieve all CustomFields applicable to the given ContentType """ field_dict = OrderedDict() custom_fields = CustomField.objects.filter(obj_type=content_type) if filterable_only: custom_fields = custom_fields.exclude(filter_logic=CF_FILTER_DISABLED) for cf in custom_fields: field_name = 'cf_{}'.format(str(cf.name)) initial = cf.default if not bulk_edit else None # Integer if cf.type == CF_TYPE_INTEGER: field = forms.IntegerField(required=cf.required, initial=initial) # Boolean elif cf.type == CF_TYPE_BOOLEAN: choices = ( (None, '---------'), (1, 'True'), (0, 'False'), ) if initial is not None and initial.lower() in ['true', 'yes', '1']: initial = 1 elif initial is not None and initial.lower() in ['false', 'no', '0']: initial = 0 else: initial = None field = forms.NullBooleanField( required=cf.required, initial=initial, widget=forms.Select(choices=choices) ) # Date elif cf.type == CF_TYPE_DATE: field = forms.DateField(required=cf.required, initial=initial, help_text="Date format: YYYY-MM-DD") # Select elif cf.type == CF_TYPE_SELECT: choices = [(cfc.pk, cfc) for cfc in cf.choices.all()] if not cf.required or bulk_edit or filterable_only: choices = [(None, '---------')] + choices # Check for a default choice default_choice = None if initial: try: default_choice = cf.choices.get(value=initial).pk except ObjectDoesNotExist: pass field = forms.TypedChoiceField(choices=choices, coerce=int, required=cf.required, initial=default_choice) # URL elif cf.type == CF_TYPE_URL: field = LaxURLField(required=cf.required, initial=initial) # Text else: field = forms.CharField(max_length=255, required=cf.required, initial=initial) field.model = cf field.label = cf.label if cf.label else cf.name.replace('_', ' ').capitalize() if cf.description: field.help_text = cf.description field_dict[field_name] = field return field_dict
class FormFiltroSemanaMes(forms.Form): c = [("0", "Ultima semana"), ("1","Ultimo mes")] lapso= forms.ChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), choices=c)
class UserRegisterForm(UserCreationForm): username = forms.CharField(max_length=50) first_name = forms.CharField(required=True, max_length=45, label='First Name', widget=forms.TextInput(attrs={ 'placeholder': 'John', })) last_name = forms.CharField(required=True, max_length=45, label='Last Name', widget=forms.TextInput(attrs={ 'placeholder': 'Woo', })) email = forms.EmailField( required=True, max_length=70, widget=forms.EmailInput(attrs={ 'placeholder': '*****@*****.**', })) phone = forms.CharField( required=False, max_length=45, widget=forms.TextInput(attrs={ 'placeholder': '650-449-7300', })) country = forms.ChoiceField( required=True, choices=COUNTRIES_TUPLES, widget=forms.Select(attrs={'class': 'form-control input-sm'})) gender = forms.ChoiceField( required=True, choices=Gender.values(), widget=forms.Select(attrs={'class': 'form-control input-sm'})) birthday = forms.DateField( # input_formats='%d/%m/%Y', label='Birthday', help_text='month/day/year', required=True, # widget=forms.DateInput(format='%d/%m/%Y') ) class Meta: # create a new user when form validate model = User # field to show on the forms fields = [ 'username', 'first_name', 'last_name', 'phone', 'email', 'gender', 'birthday', 'country', 'password1', 'password2', ]
class FormNuevoPedido(forms.Form): paciente = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = Paciente.objects.all()) producto = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = Producto.objects.all()) cantidad = forms.IntegerField(widget=forms.NumberInput(attrs={'class': 'form-control'}), label="Cantidad", min_value=0, max_value=100) tipo_de_pago = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = FormaDePago.objects.all())
class Meta: model = Client exclude = [ 'user', 'created_by', 'updated_by', 'updated_on', 'company', 'branch' ] widgets = { 'title': forms.Select(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'fullname': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'full_address': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'city': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'zip': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'state': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'phone': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'state_of_origin': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'lga': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'loan_officer': forms.Select(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'gender': forms.Select(attrs={ 'class': 'form-control', 'required': True }), 'dob': forms.DateInput(attrs={ 'class': 'form-control', 'value': '1/1/1994', 'required': True }), 'marital_status': forms.Select(attrs={ 'class': 'form-control', 'required': True }), 'picture': forms.FileInput(attrs={'class': 'form-control'}), 'bio': forms.Textarea(attrs={ 'class': 'form-control', 'value': 'Mr' }), 'current_employer': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'current_salary': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'job_description': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'years_in_workplace': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'state_of_origin': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'vehicles_owned': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'years_at_residence': forms.TextInput(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'residential_status': forms.Select(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'educational_status': forms.Select(attrs={ 'class': 'form-control', 'value': 'Mr', 'required': True }), 'employment_date': forms.DateInput(attrs={ 'class': 'form-control', 'value': 'Mr' }), }
class FormUpdatePedidoTaller(forms.Form): pedido = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = Pedido.objects.all()) estado = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}), queryset = EstadoPedido.objects.filter(nombre = "Finalizado"))
class SearchFormLog(forms.Form): def __init__(self, users, actions, functionalities, *args, **kwargs): super(SearchFormLog, self).__init__(*args, **kwargs) if isinstance(users, list): USER_CHOICES = ( [(user['id_usuario'], (user['nome'] + ' - ' + user['usuario'])) for user in users]) else: USER_CHOICES = ((0, '-'),) ACTION_CHOICES = ([(action, action) for action in actions]) ACTION_CHOICES.insert(0, ('', '-')) if isinstance(functionalities, list): FUNCTIONALITY_CHOICES = ( [(f['f_value'], f['f_name']) for f in functionalities]) else: FUNCTIONALITY_CHOICES = ((0, '-'),) self.fields['user'].choices = USER_CHOICES self.fields['action'].choices = ACTION_CHOICES self.fields['functionality'].choices = FUNCTIONALITY_CHOICES user = forms.ChoiceField(label=u'Usuário', required=False, choices=[('', 'Selecione')], widget=forms.Select( attrs={'style': "width: 300px;"}), error_messages=error_messages) first_date = forms.CharField(label="De", required=False, min_length=3, max_length=80, error_messages=error_messages, widget=forms.TextInput(attrs={"style": "width: 70px"})) start_time = forms.CharField(label="", required=False, min_length=5, max_length=5, initial='00:00', error_messages=error_messages, widget=forms.TextInput(attrs={"style": "width: 40px"})) last_date = forms.CharField(label="Até", required=False, min_length=10, max_length=10, error_messages=error_messages, widget=forms.TextInput(attrs={"style": "width: 70px"})) end_time = forms.CharField(label="", required=False, min_length=5, max_length=5, initial='23:59', error_messages=error_messages, widget=forms.TextInput(attrs={"style": "width: 40px"})) action = forms.ChoiceField(label="Ação", required=False, choices=[( '', 'Selecione'), ], error_messages=error_messages, widget=forms.Select(attrs={"style": "width: 90px"})) functionality = forms.ChoiceField(label="Funcionalidade", required=False, choices=[( '', 'Selecione')], error_messages=error_messages, widget=forms.Select(attrs={"style": "width: 150px"})) parameter = forms.CharField(label="", required=False, min_length=1, max_length=80, error_messages=error_messages, widget=forms.TextInput(attrs={"style": "width: 150px"})) def clean(self): cleaned_data = super(SearchFormLog, self).clean() first_date = cleaned_data.get("first_date") last_date = cleaned_data.get("last_date") start_time = cleaned_data.get("start_time") end_time = cleaned_data.get("end_time") if first_date != '' and last_date != '': start_time = cleaned_data.get("start_time") first_date = first_date + ' ' + start_time + ':00' end_time = cleaned_data.get("end_time") last_date = last_date + ' ' + end_time + ':59' try: first_date = datetime.strptime(first_date, '%d/%m/%Y %H:%M:%S') except ValueError, e: raise forms.ValidationError("Formato de data e hora inválido.") try: last_date = datetime.strptime(last_date, '%d/%m/%Y %H:%M:%S') except ValueError, e: self.log.error(u'Datetime format of %s is invalid.', e.value) raise forms.ValidationError("Formato de data e hora inválido.") if last_date < first_date: raise forms.ValidationError( "A data/hora final não pode ser menor que a data inicial.") if (first_date > datetime.today()): raise forms.ValidationError( "A data/hora inicial não pode ser maior que a data atual.")
class CommunalCouncilAdminForm(forms.ModelForm): ## Rif del consejo comunal rif = RifField() ## Nombre del consejo comunal name = forms.CharField(label=_('Nombre:'), max_length=500, widget=forms.TextInput( attrs={ 'class': 'form-control input-sm', 'data-toggle': 'tooltip', 'title': _('Indique el Nombre del RIF.'), })) ## Estado donde se ecnuetra ubicado el municipio state = forms.ModelChoiceField( label=_('Estado:'), queryset=State.objects.all(), empty_label=_('Seleccione...'), widget=forms.Select( attrs={ 'class': 'form-control select2', 'data-toggle': 'tooltip', 'title': _( 'Seleccione el estado en donde se encuentra ubicada.'), })) ## Municipio donde se encuentra ubicada la parroquia municipality = forms.ModelChoiceField( label=_('Municipio:'), queryset=Municipality.objects.all(), empty_label=_('Seleccione...'), widget=forms.Select( attrs={ 'class': 'form-control select2', 'data-toggle': 'tooltip', 'disabled': 'true', 'title': _('Seleccione el municipio en donde se encuentra ubicada.'), })) ## Parroquia donde se encuentra ubicado el consejo comunal parish = forms.ModelChoiceField( label=_('Parroquia:'), queryset=Parish.objects.all(), empty_label=_('Seleccione...'), widget=forms.Select( attrs={ 'class': 'form-control select2', 'data-toggle': 'tooltip', 'disabled': 'true', 'title': _('Seleccione la parroquia en donde se encuentra ubicada.'), })) class Meta: model = CommunalCouncil fields = ['rif', 'name', 'state', 'municipality', 'parish']