Пример #1
0
class HoursForm(ModelForm):
	open = TimeField(required=False, help_text=HOURS_HELP_TEXT)
	close = TimeField(required=False, help_text=HOURS_HELP_TEXT)
	lunch_start = TimeField(required=False, help_text=HOURS_HELP_TEXT)
	lunch_duration = IntegerField(required=False, help_text=LUNCH_DURATION_HELP_TEXT)

	class Meta:
		model = PracticeHours
		exclude = ['practice_location']

	def clean(self):
		if(not 'open' in self.cleaned_data or
		   not 'close' in self.cleaned_data or
		   not 'lunch_start' in self.cleaned_data or
		   not 'lunch_duration' in self.cleaned_data):
			if(open in self.cleaned_data and not self.cleaned_data['open']):
				self._errors = {}
			return self.cleaned_data

		if not self.cleaned_data['open']:
			self.cleaned_data['close'] = '17:00'
			self.cleaned_data['lunch_start'] = '12:00'
			self.cleaned_data['lunch_duration'] = '0'
		else:
			if(not self.cleaned_data['close']):
				self._errors['close'] = self.error_class([REQUIRED_ERROR])
			#'and duration != 0' is required because the first half evaluates to False in that case
			if(not self.cleaned_data['lunch_duration'] and self.cleaned_data['lunch_duration'] != 0):
				self._errors['lunch_duration'] = self.error_class([REQUIRED_ERROR])
			if (not self.cleaned_data['lunch_start'] and self.cleaned_data['lunch_duration'] == 0):
				self.cleaned_data['lunch_start'] = '12:00'
			elif (not self.cleaned_data['lunch_start']):
				self._errors['lunch_start'] = self.error_class([REQUIRED_ERROR])

		return self.cleaned_data
Пример #2
0
	def formfield_for_dbfield(self, db_field, **kwargs):
		field = super(EntryAdmin, self).formfield_for_dbfield(db_field, **kwargs)
		if db_field.name == 'hours':
			field = TimeField (
				input_formats=('%H','%H.%M','%H:%M'), 
				widget = TimeInput(format='%H:%M'),
				help_text=db_field.help_text,
			)
		elif db_field.name == 'message':
			field.widget = Textarea(attrs={'cols': 60, 'rows': 2})
		return field
Пример #3
0
class AlertForm(CremeModelForm):
    trigger_time = TimeField(label=_('Hour'), required=False)

    class Meta(CremeModelForm.Meta):
        model = Alert
        widgets = {'trigger_date': CalendarWidget}

    def __init__(self, entity, *args, **kwargs):
        super().__init__(*args, **kwargs)
        instance = self.instance
        instance.creme_entity = entity

        trigger_date = instance.trigger_date

        if trigger_date:
            local_trigger_date = localtime(trigger_date)
            self.fields['trigger_time'].initial = time(
                hour=local_trigger_date.hour,
                minute=local_trigger_date.minute,
            )

    def clean(self):
        cleaned_data = super().clean()

        if not self._errors:
            trigger_time = cleaned_data.get('trigger_time')

            if trigger_time:
                cleaned_data['trigger_date'] = make_aware_dt(
                    datetime.combine(cleaned_data['trigger_date'],
                                     trigger_time), )

        return cleaned_data
Пример #4
0
class ActionForm(CremeModelWithUserForm):
    deadline_time = TimeField(label=_(u'Hour'), required=False)

    class Meta(CremeModelWithUserForm.Meta):
        model = Action
        widgets = {'deadline': CalendarWidget}

    def __init__(self, entity, *args, **kwargs):
        # super(ActionForm, self).__init__(*args, **kwargs)
        super().__init__(*args, **kwargs)
        instance = self.instance
        instance.creme_entity = entity

        deadline = instance.deadline

        if deadline:
            local_deadline = localtime(deadline)
            self.fields['deadline_time'].initial = time(hour=local_deadline.hour,
                                                        minute=local_deadline.minute,
                                                       )

    def clean(self):
        # cdata = super(ActionForm, self).clean()
        cdata = super().clean()

        if not self._errors:
            deadline_time = cdata.get('deadline_time')

            if deadline_time:
                cdata['deadline'] = make_aware_dt(datetime.combine(cdata['deadline'],
                                                                   deadline_time
                                                                  )
                                                 )

        return cdata
    def __init__(self, input_time_formats=None, *args, **kwargs):
        errors = self.default_error_messages.copy()
        if 'error_messages' in kwargs:
            errors.update(kwargs['error_messages'])
        localize = kwargs.get('localize', False)
        fields = (
            TimeField(input_formats=input_time_formats,
                      error_messages={'invalid': errors['invalid_time']},
                      localize=localize),
            TimeZoneFormField(error_messages={'invalid': errors['invalid_time']},
                      localize=localize, initial="Australia/Sydney"),

        )
        super(SplitTimeTimeZoneField, self).__init__(fields, *args, **kwargs)
Пример #6
0
 def __init__(self, input_date_formats=None, input_time_formats=None, *args, **kwargs):
     errors = self.default_error_messages.copy()
     if 'error_messages' in kwargs:
         errors.update(kwargs['error_messages'])
     localize = kwargs.get('localize', False)
     fields = (
         JalaliDateField(input_formats=input_date_formats,
                         error_messages={'invalid': errors['invalid_date']},
                         localize=localize),
         TimeField(input_formats=input_time_formats,
                   error_messages={'invalid': errors['invalid_time']},
                   localize=localize),
     )
     super(SplitDateTimeField, self).__init__(fields, *args, **kwargs)
Пример #7
0
 def __init__(self, input_date_formats=None, input_time_formats=None, *args, **kwargs):
     errors = self.default_error_messages.copy()
     if 'error_messages' in kwargs:
         errors.update(kwargs['error_messages'])
     self.localize = kwargs.get('localize', True)
     fields = (
         DateField(input_formats=input_date_formats,
                   error_messages={'invalid': errors['invalid_date']},
                   localize=self.localize),
         TimeField(input_formats=input_time_formats,
                   error_messages={'invalid': errors['invalid_time']},
                   localize=self.localize),
         TimeZoneField(error_messages={'invalid': errors['invalid_timezone']})
     )
     dw = kwargs.pop('date_widget', fields[0].widget)
     tw = kwargs.pop('time_widget', fields[1].widget)
     tzw = kwargs.pop('timezone_widget', fields[2].widget)
     if isinstance(self.widget, type):
         self.widget = self.widget((dw, tw, tzw))
     super(SplitLocalizedDateTimeField, self).__init__(fields, *args, **kwargs)
Пример #8
0
    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'