class SearchJourneyForm(forms.Form): """Form to search journeys.""" position = forms.CharField(widget=forms.HiddenInput()) distance = forms.CharField(widget=forms.HiddenInput()) departure_date = forms.DateField( label=_("Fecha de salida"), widget=floppyforms.DateInput(attrs={"class": "form-control"})) departure_time = forms.TimeField( label=_("Hora de salida"), widget=floppyforms.DateInput(attrs={"class": "form-control"})) search_by_time = forms.BooleanField(required=False, widget=forms.CheckboxInput()) time_window = forms.IntegerField( label=_("Margen de tiempo, en minutos"), initial=30, widget=forms.NumberInput(attrs={"class": "form-control"})) def clean_position(self): position = self.cleaned_data["position"] position_point = GEOSGeometry(position, srid=DEFAULT_GOOGLE_MAPS_SRID) position_projected_point = make_point( position_point, origin_coord_srid=DEFAULT_GOOGLE_MAPS_SRID, destiny_coord_srid=DEFAULT_PROJECTED_SRID) return position_projected_point def clean_distance(self): distance = self.cleaned_data["distance"] return float(distance) def clean_departure_time(self): departure_date = self.cleaned_data["departure_date"] departure_time = self.cleaned_data["departure_time"] departure_datetime = make_aware( datetime.datetime.combine(departure_date, departure_time), pytz.timezone("Europe/Madrid")) time_zone = pytz.timezone("UTC") departure_datetime = timezone.localtime(departure_datetime, time_zone) return departure_datetime.time() def search(self, user): position = self.cleaned_data["position"] distance = self.cleaned_data["distance"] departure_date = self.cleaned_data["departure_date"] departure_time = self.cleaned_data["departure_time"] departure = make_aware(datetime.datetime.combine( departure_date, departure_time), timezone=pytz.timezone("UTC")) search_by_time = self.cleaned_data.get("search_by_time", False) time_window = self.cleaned_data["time_window"] return Journey.objects.search(user=user, position=position, distance=distance, departure=departure, time_window=time_window, search_by_time=search_by_time)
class GradebookFilterForm(forms.Form): cohort = forms.ModelChoiceField( queryset=None, widget=forms.Select( attrs={'onchange': 'submit_filter_form(this.form)'}), required=False) marking_period = forms.ModelChoiceField( queryset=None, widget=forms.Select( attrs={'onchange': 'submit_filter_form(this.form)'}), required=False) benchmark = forms.ModelMultipleChoiceField( queryset=None, required=False, widget=forms.SelectMultiple(attrs={'class': 'simple_multiselect'})) category = forms.ModelChoiceField( queryset=None, widget=forms.Select( attrs={'onchange': 'submit_filter_form(this.form)'}), required=False) assignment_type = forms.ModelChoiceField( queryset=None, widget=forms.Select( attrs={'onchange': 'submit_filter_form(this.form)'}), required=False) name = forms.CharField(required=False) date_begin = forms.DateField( required=False, widget=forms.DateInput(attrs={'placeholder': 'Later than'}), validators=settings.DATE_VALIDATORS) date_end = forms.DateField( required=False, widget=forms.DateInput(attrs={'placeholder': 'Earlier than'}), validators=settings.DATE_VALIDATORS) def update_querysets(self, course_section): self.fields['cohort'].queryset = Cohort.objects.filter( Q(percoursesectioncohort=None, student__coursesection=course_section) | Q(percoursesectioncohort__coursesection=course_section) ).distinct().order_by('name') self.fields['marking_period'].queryset = MarkingPeriod.objects.filter( coursesection=course_section).distinct() self.fields['benchmark'].queryset = Benchmark.objects.filter( item__course_section=course_section).distinct() self.fields[ 'assignment_type'].queryset = AssignmentType.objects.filter( item__course_section=course_section).distinct() self.fields['category'].queryset = Category.objects.filter( item__course_section=course_section).distinct()
class BZURLField(forms.URLField): def __init__(self, *args, **kwargs): super(BZURLField, self).__init__(*args, **kwargs) if self.label is None: self.label = u'Bugzilla URL' self.widget = forms.URLInput( attrs={ 'placeholder': 'https://bugzilla.mozilla.org/...', }) self.validators.append(validate_bzurl) date5 = forms.DateInput(attrs={ 'placeholder': 'YYYY-MM-DD', }) class SlugInput(forms.TextInput): def get_context_data(self): self.attrs['pattern'] = "[-.\w]+" return super(SlugInput, self).get_context_data() class ProjectForm(forms.ModelForm): template_title = 'Project' class Meta: model = Project widgets = {
class SettingsForm(forms.ModelForm): start = forms.DateField(input_formats=('%d.%m.%Y',), error_messages=RU_ERRORS, widget=forms.DateInput(attrs={'class': 'input-small form-control'})) finish = forms.DateField(input_formats=('%d.%m.%Y',), error_messages=RU_ERRORS, widget=forms.DateInput(attrs={'class': 'input-small form-control'})) time = forms.TimeField(input_formats=('%H:%M',), error_messages=RU_ERRORS, widget=forms.TimeInput(attrs={'class': 'form-control', 'id': 'alert-time-display', 'value': '12:00'})) email = forms.EmailField(required=False, error_messages=RU_ERRORS, widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': u'Укажите email для оповещений'})) phone = forms.RegexField(r'^\+79\d{9}$', '^\+79\d{9}$', required=False, error_messages=RU_ERRORS, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': u'+79123456789'})) user_time = forms.CharField(widget=forms.HiddenInput()) class Meta: model = Alert widgets = { 'alert_email': forms.CheckboxInput(attrs={'id': 'email-alert'}), 'alert_sms': forms.CheckboxInput(attrs={'id': 'sms-alert'}), 'period': forms.Select(attrs={'class': 'form-control'}), } exclude = ['user', 'alert_server_time'] def clean(self): cleaned_data = super(SettingsForm, self).clean() if cleaned_data.get('alert_email') and cleaned_data.get('email') == '': raise forms.ValidationError(u'Введите email') if cleaned_data.get('alert_sms') and cleaned_data.get('phone') == '': raise forms.ValidationError(u'Введите номер телефона') return cleaned_data
def __init__(self, path, user, *args, **kwargs): super(DynForm, self).__init__(*args, **kwargs) pathComplete = str(path) elements = pathComplete.split("/") studyName = elements[2] stageName = elements[3] for study in Study.objects.filter(studyName=str(studyName)): tempEntity = [] for entity in Patient.objects.filter( studyId__idStudy=study.idStudy, userOwner=user): tempLabel = str(entity).split(" ") patientLabel = tempLabel[0] + ". ID: " + tempLabel[1] tempEntity.append((patientLabel, patientLabel)) choiceEnt = tuple(tempEntity) self.fields['Paciente'] = ChoiceField( tempEntity, initial=tempEntity[len(tempEntity) - 1]) self.fields['Paciente'].widget.attrs['class'] = 'form-control' for stage in Stage.objects.filter(studyId=study.idStudy): if stage.stageType == str(stageName): questionList = [] for questionGroups in Question_Groups.objects.filter( groupStage__idStage=stage.idStage).order_by( 'order'): for question in questionGroups.idQuestions.all(): questionList.append(question) for question in questionList: if question.questionsType == 'Char': self.fields['%s' % question] = CharField( max_length=255, required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control' if question.questionsType == 'Int': self.fields['%s' % question] = IntegerField( widget=forms.NumberInput(), required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control' self.fields['%s' % question].widget.attrs[ 'min'] = question.questionMin self.fields['%s' % question].widget.attrs[ 'max'] = question.questionMax self.fields['%s' % question].widget.attrs['step'] = 1 if question.questionsType == 'Real': self.fields['%s' % question] = FloatField( widget=forms.NumberInput(), required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control' self.fields['%s' % question].widget.attrs[ 'min'] = question.questionMin self.fields['%s' % question].widget.attrs[ 'max'] = question.questionMax self.fields[ '%s' % question].widget.attrs['step'] = 0.1 if question.questionsType == 'Date': self.fields['%s' % question] = DateField( widget=forms.DateInput(), required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control' if question.questionsType == 'Time': self.fields['%s' % question] = TimeField( widget=forms.TimeInput(), required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control' if question.questionsType == 'Bool': self.fields[ '%s' % question] = NullBooleanField( widget=forms.NullBooleanSelect(), required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs.update({ 'onclick': "toggle_id_%s()" % question, }) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control' if question.questionsType == 'Img': self.fields['%s' % question] = FileField( required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control' if question.questionsType == 'Enum': choices = Choices.objects.filter( questionId__questionsId=question. questionsId) list_of_choices = [] for choice in choices: list_of_choices.append((choice, choice)) tuple_of_choices = tuple(list_of_choices) self.fields['%s' % question] = ChoiceField( widget=forms.Select(), choices=tuple_of_choices, required=False) self.fields['%s' % question].label = str( question.questionsLabel) self.fields['%s' % question].help_text = str( question.questionHelp) self.fields['%s' % question].widget.attrs.update({ 'onchange': "toggle_id_%s()" % question, }) self.fields['%s' % question].widget.attrs[ 'class'] = 'form-control'
class IndividualAssignForm(forms.Form): date_suggested = forms.DateField( initial=datetime.date.today, required=True, widget=forms.DateInput(attrs={'data-js-widget': 'datepicker'})) time_suggested = forms.TimeField(initial='18:00')