class ToDoForm(forms.Form): title = forms.CharField( label='일정 제목', max_length=20, widget=forms.TextInput(attrs={'class': 'todo_form'})) date = forms.DateField(label='날짜', widget=forms.SelectDateWidget, initial=timezone.now().date()) start_time = forms.TimeField(label='시작 시각', widget=AdminTimeWidget( format="%H:%M", attrs={'placeholder': "HH:MM"}), initial=timezone.now().time()) end_time = forms.TimeField(label='끝 시각', widget=AdminTimeWidget( format="%H:%M", attrs={'placeholder': "HH:MM"}), initial=timezone.now().time()) repetition = forms.BooleanField(label='매주 반복', required=False) repetition_start = forms.DateField(label='반복 시작 날짜', widget=forms.SelectDateWidget, initial=timezone.now().date()) repetition_end = forms.DateField(label='반복 끝 날짜', widget=forms.SelectDateWidget, initial=timezone.now().date())
class Meta: model = TeacherFreeTimes fields = [ 'date', 'start', 'end', 'student_capacity', ] widgets = { 'date': AdminDateWidget(), 'start': AdminTimeWidget(), 'end': AdminTimeWidget(), 'student_capacity': AdminIntegerFieldWidget(), } error_messages = { 'end': { 'invalid': 'زمان پایان وارد شده معتبر نمیباشد' }, 'start': { 'invalid': 'زمان شروع وارد شده معتبر نمیباشد' }, 'date': { 'invalid': 'تاریخ وارد شده معتبر نمیباشد' }, }
class Meta: model = meeting fields = 'title', 'date', 'start_time', 'end_time', 'participants', 'link' widgets = { 'start_time': AdminTimeWidget(), 'end_time': AdminTimeWidget(), 'date': AdminDateWidget(), }
class CabinetTermsForm(forms.ModelForm): time_on = forms.CharField(widget=AdminTimeWidget(), required=False) time_off = forms.CharField(widget=AdminTimeWidget(), required=False) class Meta: model = Hotel fields = ('payment_method', 'time_on', 'time_off') def __init__(self, *args, **kwargs): super(CabinetTermsForm, self).__init__(*args, **kwargs) if get_language() == 'ru': booking_terms = self.instance.booking_terms condition_cancellation = self.instance.condition_cancellation paid_services = self.instance.paid_services else: booking_terms = self.instance.booking_terms_en condition_cancellation = self.instance.condition_cancellation_en paid_services = self.instance.paid_services_en self.fields['booking_terms'] = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'class': 'wide', 'rows': '5' }), initial=booking_terms) self.fields['condition_cancellation'] = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'class': 'wide', 'rows': '5' }), initial=condition_cancellation) self.fields['paid_services'] = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'class': 'wide', 'rows': '5' }), initial=paid_services) def save(self, commit=True): if get_language() == 'ru': self.instance.booking_terms = self.cleaned_data['booking_terms'] self.instance.condition_cancellation = self.cleaned_data[ 'condition_cancellation'] self.instance.paid_services = self.cleaned_data['paid_services'] else: self.instance.booking_terms_en = self.cleaned_data['booking_terms'] self.instance.condition_cancellation_en = self.cleaned_data[ 'condition_cancellation'] self.instance.paid_services_en = self.cleaned_data['paid_services'] return super(CabinetTermsForm, self).save(commit=commit)
class CabinetInfoForm(UserFromRequestForm, LocaleNamedForm): time_on = forms.CharField(widget=AdminTimeWidget(), required=False) time_off = forms.CharField(widget=AdminTimeWidget(), required=False) class Meta: model = Hotel fields = ('option', 'time_on', 'time_off') def __init__(self, *args, **kwargs): super(CabinetInfoForm, self).__init__(*args, **kwargs) if get_language() == 'ru': schema_transit = self.instance.schema_transit paid_services = self.instance.paid_services else: schema_transit = self.instance.schema_transit_en paid_services = self.instance.paid_services_en self.fields['schema_transit'] = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'class': 'wide', 'rows': '5' }), initial=schema_transit) self.fields['paid_services'] = forms.CharField( required=False, widget=forms.Textarea(attrs={ 'class': 'wide', 'rows': '5' }), initial=paid_services) if not self._user.is_superuser: self.fields['name'].widget.attrs['readonly'] = True def clean_name(self): if self._user.is_superuser: return self.cleaned_data['name'] if get_language() == 'ru': return self.instance.name else: return self.instance.name_en def save(self, commit=True): if get_language() == 'ru': self.instance.schema_transit = self.cleaned_data['schema_transit'] self.instance.paid_services = self.cleaned_data['paid_services'] else: self.instance.schema_transit_en = self.cleaned_data[ 'schema_transit'] self.instance.paid_services_en = self.cleaned_data['paid_services'] return super(CabinetInfoForm, self).save(commit=commit)
def __init__(self, *args, **kwargs): super(account_find_slum, self).__init__(*args, **kwargs) self.fields['account_slumname'] = forms.ModelChoiceField( queryset=Slum.objects.all(), widget=ForeignKeyRawIdWidget(rel=ManyToOneRel( Slum._meta.get_field('id'), Slum, 'id'), admin_site=admin.site)) self.fields['account_cityname'] = forms.ModelChoiceField( queryset=City.objects.all()) self.fields['account_slumname'].widget.attrs.update( {'class': 'customized-form'}) self.fields['account_slumname'].widget.attrs.update({ 'name': 'account_slumname', 'id': 'id_account_slumname' }) self.fields['account_slumname'].label = "Select slum" self.fields['account_cityname'].widget.attrs.update( {'class': 'customized-form'}) self.fields['account_cityname'].widget.attrs.update({ 'name': 'account_cityname', 'id': 'account_cityname' }) self.fields['account_cityname'].label = "Select city" self.fields['account_start_date'] = forms.DateField( widget=AdminTimeWidget()) self.fields['account_start_date'].label = "From" self.fields['account_start_date'].widget.attrs.update({ 'name': 'account_start_date', 'class': 'datepicker', 'style': 'width:80px;' }) self.fields['account_end_date'] = forms.DateField( widget=AdminTimeWidget()) #extras.SelectDateWidget()) self.fields['account_end_date'].label = "To" self.fields['account_end_date'].widget.attrs.update({ 'name': 'account_end_date', 'class': 'datepicker', 'style': 'width:80px;' })
class approve_appointment(forms.ModelForm): # day1 = DateField(widget=forms.TextInput(attrs={'readonly': 'readonly'})) # day2 = DateField(widget=forms.TextInput(attrs={'readonly': 'readonly'})) # day3 = DateField(widget=forms.TextInput(attrs={'readonly': 'readonly'})) # patient = CharField(widget=forms.TextInput(attrs={'readonly': 'readonly'})) # message = CharField(widget=forms.TextInput(attrs={'readonly': 'readonly'})) approved_time = CharField(widget=AdminTimeWidget( attrs={'placeholder': 'hh:mm XM'})) approved_for = forms.ChoiceField(choices=( ('1', 'day 1'), ('2', 'day 2'), ('3', 'day 3'), ), label="Approved for day: ") # def __init__(self, ap_id, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None): # super().__init__(data=data, files=files, auto_id=auto_id, prefix=prefix, initial=initial, error_class=error_class, label_suffix=label_suffix, empty_permitted=empty_permitted, instance=instance, use_required_attribute=use_required_attribute, renderer=renderer) # def __init__(self, ap_id, *args, **kwargs): # approved_for = forms.ModelChoiceField(ap_id) # accountid = kwargs.pop('accountid', None) # super(approve_appointment, self).__init__(*args, **kwargs) class Meta: model = Appointment fields = ('approved_for', 'approved_time')
class Meta: model = Post fields = ( 'title', 'sdate', 'starttime', 'endtime', 'content', 'available', ) widgets = { 'sdate': SelectDateWidget(years=YEAR_CHOICES, months=MONTH_CHOICES), 'starttime': AdminTimeWidget(format='%H:%M'), 'endtime': AdminTimeWidget(format='%H:%M'), }
def __init__(self, *args, **kwargs): field_name = kwargs.pop('field_name') super(TimeRangeForm, self).__init__(*args, **kwargs) self.fields['%s%s__gte' % (FILTER_PREFIX, field_name)] = forms.TimeField( label='', widget=AdminTimeWidget( attrs={'placeholder': _('From time')}), localize=True, required=False) self.fields['%s%s__lte' % (FILTER_PREFIX, field_name)] = forms.TimeField( label='', widget=AdminTimeWidget( attrs={'placeholder': _('To time')}), localize=True, required=False, )
def __init__(self, *args, **kwargs): super(EventForm, self).__init__(*args, **kwargs) # since we override the widget, we need to set the queryset again" self.fields['event_type'].widget = SelectWithPop(self.user) self.fields['event_type'].queryset = Event_Type.objects.filter( author__username__exact=self.user) self.fields['experiment'].widget = SelectWithPop(self.user) self.fields['experiment'].queryset = Experiment.objects.filter( author__username__exact=self.user) self.fields['date'].widget = AdminDateWidget() self.fields['time'].widget = AdminTimeWidget()
class VisitForm(forms.ModelForm): filter_shop = forms.ChoiceField(widget=widgets.Select(), required=False, choices=CHOICE_ALPH) visitTime = forms.CharField(max_length=8, widget=AdminTimeWidget()) def __init__(self, *args, **kwargs): super(VisitForm, self).__init__(*args, **kwargs) if kwargs.__contains__('initial'): agent = Agent.objects.get(id=kwargs['initial']['agent_id']) self.fields['shop'].queryset = agent.available_shops() if not kwargs['initial']['enabled']: for field in self.fields: self.fields[field].widget.attrs['disabled'] = 'disabled' def save(self, *args, **kwargs): return super(VisitForm, self).save(*args, **kwargs) class Meta: model = Visit fields = ('id', 'visitDate', 'shop', 'note', 'visitTime', 'filter_shop') help_texts = { 'id': '', 'visitDate': '', 'shop': '', 'note': '', } widgets = { 'note': forms.Textarea( attrs={ 'class': 'form-control', 'cols': 10, 'rows': 4, 'style': 'width:98%' }), 'visitDate': widgets.SelectDateWidget(), 'shop': widgets.Select(attrs={ 'choice': Agent.objects.none(), 'style': 'width:98%' }) }
class TimeForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(TimeForm, self).__init__(*args, **kwargs) self.fields['start'].initial = self.get_initial_start() def get_initial_start(self): try: return TimeBackup.objects.first().start except: return start = forms.TimeField(label='Время бекапа', initial=None, widget=AdminTimeWidget(format='%H:%M')) class Meta: model = TimeBackup fields = ('start', )
class ScheduleJobForm(forms.ModelForm): class Meta: model = RepeatableJob fields = [ 'name', 'interval_unit', 'interval', 'scheduled_time', 'starting_date', 'callable', 'queue' ] scheduled_time = forms.TimeField(widget=AdminTimeWidget( attrs={'type': 'time'})) starting_date = forms.DateField( widget=AdminDateWidget(attrs={'type': 'date'}), required=False) def clean_scheduled_time(self): # Convertir la hora a un datetime apropiado clean_datetime = timezone.localtime() scheduled_time = self.cleaned_data['scheduled_time'] clean_datetime = clean_datetime.replace(hour=scheduled_time.hour, minute=scheduled_time.minute, second=0, microsecond=0) # Si la hora está en el pasado, lo programo para el día siguiente if clean_datetime < timezone.localtime(): clean_datetime = clean_datetime + timedelta(days=1) return clean_datetime def clean(self): cleaned_data = super(ScheduleJobForm, self).clean() interval_unit = cleaned_data.get('interval_unit') if interval_unit == 'weeks': starting_date = cleaned_data.get('starting_date') if not starting_date: self.add_error('starting_date', 'This is a required field') return cleaned_data scheduled_time = self.cleaned_data.get('scheduled_time') scheduled_time = scheduled_time.replace(year=starting_date.year, month=starting_date.month, day=starting_date.day) if scheduled_time < timezone.localtime(): self.add_error('starting_date', 'Date cannot be in the past') cleaned_data['scheduled_time'] = scheduled_time return cleaned_data
class SynchroForm(forms.Form): name = forms.CharField(max_length=50) WEEK_DAYS = 'week days' DAILY = 'every day' FREQUENCY_CHOICES = ( (DAILY, DAILY), (WEEK_DAYS, WEEK_DAYS), ) frequency = forms.ChoiceField(choices=FREQUENCY_CHOICES) scheduled_time = forms.TimeField( widget=AdminTimeWidget(attrs={'type': 'time'})) MON = strings.MON TUE = strings.TUE WED = strings.WED THU = strings.THU FRI = strings.FRI SAT = strings.SAT SUN = strings.SUN WEEK_DAY_CHOICES = ( (MON, 'Monday'), (TUE, 'Tuesday'), (WED, 'Wednesday'), (THU, 'Thursday'), (FRI, 'Friday'), (SAT, 'Saturday'), (SUN, 'Sunday'), ) week_days = forms.MultipleChoiceField(choices=WEEK_DAY_CHOICES, required=False) def clean(self): cleaned_data = super(SynchroForm, self).clean() days = cleaned_data['week_days'] frequency = cleaned_data['frequency'] if frequency == self.WEEK_DAYS and not days: self.add_error('week_days', 'Days of week not selected')
class DTForm(forms.Form): your_name = forms.CharField(max_length=64) date_input = forms.DateField(widget=AdminDateWidget()) time_input = forms.DateField(widget=AdminTimeWidget()) date_time_input = forms.DateField(widget=AdminSplitDateTime())
def __init__(self, attrs=None): widgets = [ AdminDateWidget, AdminTimeWidget(attrs=None, format='%I:%M %p') ] forms.MultiWidget.__init__(self, widgets, attrs)
def get_field(self): field = super(AdaptorTimeField, self).get_field() field.field.widget = AdminTimeWidget() return field
class PostFlightForm(forms.Form): transport_date = forms.DateField( input_formats=['%Y-%m-%d'], label='Transport Date', widget=forms.TextInput(attrs={'id': 'datepicker'})) flight_num = forms.CharField(label="Flight Number") base = forms.CharField(label="", widget=forms.Select(choices=BASE_CHOICES)) transport_type = forms.CharField( label='', widget=forms.Select(choices=AIRFRAME_CHOICES)) tail_num = forms.CharField(label='', widget=forms.Select(choices=TAILNUM_CHOICES)) med_crew_1 = forms.ModelChoiceField(queryset=Account.objects.all().exclude( job_title="dispatcher").exclude(job_title="pilot").exclude( job_title="programmer").exclude(job_title="mechanic").exclude( job_title="flightMedic")) med_crew_2 = forms.ModelChoiceField(queryset=Account.objects.all().exclude( job_title="dispatcher").exclude(job_title="pilot").exclude( job_title="programmer").exclude(job_title="mechanic")) pilot = forms.ModelChoiceField(queryset=Account.objects.all().exclude( job_title="dispatcher").exclude(job_title="flightNurse").exclude( job_title="programmer").exclude(job_title="mechanic").exclude( job_title="flightMedic")) dispatcher = forms.ModelChoiceField(queryset=Account.objects.all().exclude( job_title="pilot").exclude(job_title="flightNurse").exclude( job_title="programmer").exclude(job_title="mechanic").exclude( job_title="flightMedic")) activity_flight = forms.CharField( label='', widget=forms.Select( choices=[('', 'Select the Activity of the transport'), ('Completed', 'Completed By Air'), ('Completed', 'Completed By Ground'), ('Completed', 'Aborted Flight, Completed by Ground' ), ('Completed', 'Patient Care Only, No Transport' ), ('Aborted', 'Aborted Flight, No Patient Contact')])) scene_hosp = forms.CharField( label='Transport Type', widget=forms.RadioSelect( choices=[('Scene', 'Scene'), ('Interfacility', 'Interfacility')])) start_time = forms.TimeField(widget=AdminTimeWidget(format='%H:%M')) lift_time = forms.TimeField(widget=AdminTimeWidget(format='%H:%M')) at_recieving_time = forms.TimeField(widget=AdminTimeWidget(format='%H:%M')) at_patient_time = forms.TimeField(widget=AdminTimeWidget(format='%H:%M')) depart_recieving_time = forms.TimeField(widget=AdminTimeWidget( format='%H:%M')) ifr_vfr = forms.CharField( label='', widget=forms.RadioSelect(choices=[('IFR', 'IFR'), ('VFR', 'VFR')])) weather_issues = forms.CharField( label='Weather Issues', widget=forms.RadioSelect(choices=[('Yes', 'Yes'), ('No', 'No')]), initial='No') aviation_issues = forms.CharField( label='Aviation Issues', widget=forms.RadioSelect(choices=[('Yes', 'Yes'), ('No', 'No')]), initial='No') maintenance_issues = forms.CharField( label='Maintenance Issues', widget=forms.RadioSelect(choices=[('Yes', 'Yes'), ('No', 'No')]), initial='No') aviation_issues_comments = forms.CharField(widget=forms.Textarea(attrs={ 'cols': 80, 'rows': 10 })) priority_level = forms.CharField(widget=forms.RadioSelect( choices=[('1', 'Priority 1'), ('2', 'Priority 2'), ('NoIssues', 'No Issues')])) def __init__(self, *args, **kwargs): super(forms.Form, self).__init__(*args, **kwargs)
class Meta: model = Hotel widgets = { 'time_on': AdminTimeWidget(), 'time_off': AdminTimeWidget() }
class Meta: model = Hotel fields = '__all__' widgets = {'time_on': AdminTimeWidget(), 'time_off': AdminTimeWidget()}
class BusinessLocationAdminForm(forms.ModelForm): class Meta: model = BusinessLocation fields = '__all__' about = forms.Textarea() location_field = forms.CharField(max_length=255) mon_open = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) mon_close = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) tue_open = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) tue_close = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) wed_open = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) wed_close = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) thu_open = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) thu_close = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) fri_open = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) fri_close = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) sat_open = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) sat_close = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) sun_open = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) sun_close = forms.TimeField(widget=AdminTimeWidget(format='%I:%M %p'), input_formats=('%I:%M %p', ), required=False) def __init__(self, *args, **kwargs): super(BusinessLocationAdminForm, self).__init__(*args, **kwargs) self.fields['location_email'].required = True self.fields['phone'].required = True self.fields['location_field'].required = False
def get_form(self, form_class=None): form = super(Task, self).get_form() form.fields['start_time'].widget = AdminTimeWidget() form.fields['end_time'].widget = AdminTimeWidget() return form
class DishAdmin(admin.ModelAdmin): formfield_overrides = { models.TimeField: { 'widget': AdminTimeWidget(format='%H:%M') }, }
def __init__(self, attrs=None): widgets = ( forms.widgets.CheckboxInput(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), forms.widgets.CheckboxInput(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), forms.widgets.CheckboxInput(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), forms.widgets.CheckboxInput(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), forms.widgets.CheckboxInput(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), forms.widgets.CheckboxInput(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), forms.widgets.CheckboxInput(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), AdminTimeWidget(), ) super(OrariFormWidget, self).__init__(widgets, attrs)