Ejemplo n.º 1
0
 class Meta:
     model = Internship
     fields = (
         'company', 'title', 'description', 'registration_start_date', 'registration_end_date', 'start_date',
         'end_date', 'openings'
     )
     widgets = {
         'registration_start_date': DateTimePicker(options={"format": "%Y-%m-%d %H:%M", }),
         'registration_end_date': DateTimePicker(options={"format": "%Y-%m-%d %H:%M", }),
         'start_date': DateTimePicker(options={"format": "%Y-%m-%d %H:%M", }),
         'end_date': DateTimePicker(options={"format": "%Y-%m-%d %H:%M", }),
     }
Ejemplo n.º 2
0
class Post(models.Model):
    title = models.CharField(max_length=50)
    complete = models.BooleanField(default=False)
    description = models.TextField(max_length=500)
    datetime = models.DateTimeField()
    widget = DateTimePicker()
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.title
Ejemplo n.º 3
0
 def get_form(self, form_class=None):
     if form_class is None:
         form_class = self.get_form_class()
     form = super().get_form(form_class)
     for field in ("starts_at", "ends_at", "publish_at"):
         form.fields[field].widget = DateTimePicker(
             options={
                 'format': '%Y-%m-%d %H:%M',
                 # todo: i18n not working yet, needs to add a static JS
                 # file for translations ?
                 # see https://xdsoft.net/jqplugins/datetimepicker/
                 'lang': self.request.LANGUAGE_CODE[:2],
                 'step': 15,
             })
     return form
Ejemplo n.º 4
0
class UserDetailForm(forms.Form):
    usernameUser = forms.CharField(label='Username', max_length=100, widget=forms.TextInput(attrs={'value': 'Username'}))
    fullnameUser = forms.CharField(label='Fullname', max_length=30)
    dobUser = forms.DateField(label='DOB', widget=DateTimePicker(),)
    addressUSer = forms.CharField(label='Address')
    emailUser = forms.CharField(label='Email')
    phoneUser = forms.CharField(label='Phone', max_length=12)
    def save(self):
        a = User.objects.get(usernameUser=self.cleaned_data['usernameUser'])
        a.fullnameUser = self.cleaned_data['fullnameUser']
        a.dobUser = self.cleaned_data['dobUser']
        a.addressUSer = self.cleaned_data['addressUSer']
        a.emailUser = self.cleaned_data['emailUser']
        a.phoneUser = self.cleaned_data['phoneUser']
        a.save()
Ejemplo n.º 5
0
 class Meta:
     model = gnuhealth_pol
     fields = "__all__"
     page_date = forms.DateTimeField(widget=DateTimePicker(), )
     procedure = ModelMultipleChoiceField(
         queryset=gnuhealth_procedure.objects.values_list('name',
                                                          flat=True),
         widget=Select2MultipleWidget)
     person = ModelMultipleChoiceField(
         queryset=party_party.objects.values_list('name', flat=True),
         widget=Select2MultipleWidget)
     institution = ModelMultipleChoiceField(
         queryset=gnuhealth_institution.objects.values_list('name',
                                                            flat=True),
         widget=Select2MultipleWidget)
     health_condition = ModelMultipleChoiceField(
         queryset=gnuhealth_pathology.objects.values_list('name',
                                                          flat=True),
         widget=Select2MultipleWidget)
Ejemplo n.º 6
0
class DropOffUpdateForm(forms.ModelForm):


    dropoff_at = forms.DateTimeField(
        input_formats=("%a %b %d, %Y %I:%M %p",),
        localize=True,
        label='',
        widget=DateTimePicker(
            options={
                'validateOnBlur': False,
                'twelveHoursFormat': True,
                'format': 'D M d, Y g:i a',
                'language': 'en-us',
            },
        )
    )

    class Meta:
        model = Order
        fields = ('dropoff_at',)
Ejemplo n.º 7
0
def zv_index_view(request):
    n1 = 'CRM'
    n2 = '222'
    nzvn = modelformset_factory(
        zvonok,
        fields=(
            'tel',
            'client_name',
            'subj',
            'cena',
            'status_zvonka',
            'prezvonit',
            'coment',
        ),
        widgets={
            'prezvonit':
            DateTimePicker(options={
                'format': '%Y-%m-%d %H:%M',
                'language': 'ru-ru',
            }),
            'coment':
            Textarea(attrs={
                'rows': 80,
                'cols': 20
            })
        },
        extra=1,
    )
    nzvn_formset = nzvn(queryset=zvonok.objects.all())
    if request.POST:
        nformset = nzvn(request.POST, request.FILES)
        if nformset.is_valid():
            nformset.save()
    return render(request, 'zvonki/index.html', {
        'tn1': n1,
        'tn2': n2,
        'nformset': nzvn_formset
    })
Ejemplo n.º 8
0
class SampleForm(forms.Form):

    datepicker = forms.DateField(widget=DateTimePicker(options={
        "format": "%Y-%m-%d",
        "timepicker": False
    }, ))
    timepicker = forms.TimeField(widget=DateTimePicker(options={
        "format": "%H:%M",
        "datepicker": False
    }, ))
    datetimepicker = forms.DateTimeField(
        widget=DateTimePicker(options={"format": "%Y-%m-%d %H:%M"}, ))

    datepicker_no_script_tag = forms.DateField(widget=DateTimePicker(
        options={
            "format": "%Y-%m-%d",
            "timepicker": False
        },
        script_tag=False,
    ))
    timepicker_no_script_tag = forms.TimeField(widget=DateTimePicker(
        options={
            "format": "%H:%M",
            "datepicker": False
        },
        script_tag=False,
    ))
    datetimepicker_no_script_tag = forms.DateTimeField(widget=DateTimePicker(
        options={"format": "%Y-%m-%d %H:%M"},
        script_tag=False,
    ))

    @property
    def media(self):
        js_urls = js_loader_url(fields=self.fields,
                                input_ids=[
                                    'datepicker_no_script_tag',
                                    'timepicker_no_script_tag',
                                    'datetimepicker_no_script_tag'
                                ])

        form_media = forms.Media(js=js_urls)
        return super(SampleForm, self).media + form_media
Ejemplo n.º 9
0
class PickupForm(forms.ModelForm):
    street = forms.CharField(
        label='',
        max_length=120,
        widget=forms.TextInput(attrs={'placeholder': 'Street*'}))
    apt = forms.CharField(
        label='',
        required=False,
        max_length=50,
        widget=forms.TextInput(
            attrs={
                'placeholder': 'APT/Suite',
                'pattern': '[0-9A-Za-z ]+',
                'title': ' alphanumeric '
                'characters '
                'only '
                'please'
            }))
    city = forms.CharField(
        label='',
        max_length=120,
        widget=forms.TextInput(attrs={'placeholder': 'City*'}))
    MODDED_STATE_CHOICES = list(STATE_CHOICES)
    MODDED_STATE_CHOICES.insert(0, ('', 'Select a State'))
    state = USStateField(label='',
                         widget=forms.Select(choices=MODDED_STATE_CHOICES))

    zip_code = USZipCodeField(
        label='',
        widget=forms.TextInput(
            attrs={
                'placeholder': 'Zip Code*',
                'pattern': '[0-9]+',
                'title': ' numeric '
                'characters '
                'only '
                'please'
            }))
    pickup_at = forms.DateTimeField(input_formats=("%a %b %d, %Y %I:%M %p", ),
                                    localize=True,
                                    label='',
                                    widget=DateTimePicker(
                                        options={
                                            'validateOnBlur': False,
                                            'twelveHoursFormat': True,
                                            'format': 'D M d, Y g:i a',
                                            'formatTime': 'g:i a',
                                            'lang': 'en-us',
                                            'minDate': 0,
                                            'maxDate': '+1970/01/15'
                                        }))

    class Meta:
        model = Address
        fields = '__all__'

    def clean(self):
        cleaned_data = super(PickupForm, self).clean()
        address = usps.Address(name='None',
                               address_2=cleaned_data.get('street'),
                               address_1=cleaned_data.get('apt'),
                               city=cleaned_data.get('city'),
                               state=cleaned_data.get('state'),
                               zipcode=cleaned_data.get('zip_code'))

        try:
            validator = usps.USPSApi('161ALORA3737', test=True)
            validation = validator.validate_address(address)
        except usps.USPSApiError:
            raise forms.ValidationError("Please provide a valid address.")

        address_data = validation.result['AddressValidateResponse']['Address']

        if address_data is not None:
            if 'Error' in address_data:
                error = address_data['Error']

                if error['Description'] == 'Address Not Found.':
                    raise forms.ValidationError(
                        "Please provide a valid address.")

            elif 'ReturnText' in address_data:
                return_text = address_data['ReturnText']

                if 'Default address' in return_text:
                    raise forms.ValidationError(
                        "A valid APT/Suite is required for this address")

            cleaned_data['street'] = address.address_2.title()
            cleaned_data['apt'] = address.address_1
            cleaned_data['city'] = address.city.title()
            cleaned_data['zip_code'] = address.zipcode
        return cleaned_data

    def clean_pickup_at(self):
        cleaned_data = super(PickupForm, self).clean()
        pickup_date = cleaned_data['pickup_at']

        if pickup_date < (now() +
                          datetime.timedelta(days=0, hours=1, minutes=0)):
            raise ValidationError(
                "Pick-up date/time must not be earlier than 1 hour from now.")
        if pickup_date > (now() +
                          datetime.timedelta(days=15, hours=11, minutes=59)):
            raise ValidationError(
                "Pick-up date/time can be at latest 15 days from now")
        return pickup_date
Ejemplo n.º 10
0
class FilterForm(forms.Form):

    search = forms.CharField(
        label=_('search'),
        required=False,
    )
    from_date = forms.DateField(
        error_messages={'invalid': _('please enter a valid start date')},
        label=_('from'),
        required=False,
        widget=DateTimePicker(options={
            "format": settings.DATE_INPUT_FORMATS[0],
            "pickTime": False
        }),
    )
    to_date = forms.DateField(
        error_messages={'invalid': _('please enter a valid end date')},
        label=_('to'),
        required=False,
        widget=DateTimePicker(options={
            "format": settings.DATE_INPUT_FORMATS[0],
            "pickTime": False
        }),
    )

    def __init__(self, *args, **kwargs):
        """
        Dynamically build the fields of the filter forms by the groups and groupings.
        Django uses an ordered dict to store the form fields, in order to ensure the ordering
        when rendering the form fields. We must do the same, otherwise the order of the
        form fields may change when restarting the app.
        """
        calendar = kwargs.pop('calendar', None)
        super(FilterForm, self).__init__(*args, **kwargs)

        # get the groups
        _groups = Group.objects.filter(grouping__calendars=calendar).order_by(
            'grouping__order').distinct()  # The ordering is important here.

        # group the groups by groupings
        _groupings = OrderedDict()
        for group in _groups:
            # if the group was not added before, do it now
            if group.grouping not in _groupings:
                _groupings[group.grouping] = []
            _groupings[group.grouping].append(group)

        # generate choices using the sorted groupings
        _choices = {
            grouping: [(group.pk, group.title)
                       for group in sorted(_groupings[grouping],
                                           key=lambda g: g.title.lower())]
            for grouping in _groupings
        }

        # Now that we have the choices, generate MultipleChoiceFields with them
        _fields = OrderedDict([(grouping.title,
                                forms.MultipleChoiceField(
                                    choices=_choices[grouping],
                                    required=False,
                                    widget=Select2MultipleWidget,
                                )) for grouping in _groupings])

        self.filter_field_names = sorted(_fields.keys())

        self.fields.update(_fields)

        for field in self:
            field.field.widget.attrs['placeholder'] = capfirst(field.label)

    def clean(self):
        cleaned_data = super(FilterForm, self).clean()
        from_date = cleaned_data.get('from_date')
        to_date = cleaned_data.get('to_date')

        if from_date and to_date and from_date > to_date:
            raise forms.ValidationError(
                _('"from date" is greater than "to date"'))

        return cleaned_data

    def grouped_groups(self):
        _groups = {}
        if self.is_valid():
            data = self.clean()
            _groups.update({
                grouping: data.get(grouping)
                for grouping in self.filter_field_names
                if len(data.get(grouping))
            })
        return _groups

    def groups(self):
        _groups = []
        if self.is_valid():
            data = self.clean()
            # get all the primary keys of the groups
            for grouping in self.filter_field_names:
                _groups.extend([int(pk) for pk in data.get(grouping)])
        return _groups

    def date_fields(self):
        return [
            field for field in self if field.name in ['from_date', 'to_date']
        ]  # noqa

    def filter_fields(self):
        return [
            field for field in self if field.name in self.filter_field_names
        ]  # noqa

    def search_fields(self):
        return [field for field in self if field.name in ['search']]

    class Media:
        css = {'all': ('eventary/css/filterform.css', )}
        js = ('eventary/js/filterform.js', )
Ejemplo n.º 11
0
class TimeDateForm(forms.Form):
    start_date = forms.DateField(
        label=_('start date'),
        required=True,
        widget=DateTimePicker(
            attrs={
                'non-recurrence-label': capfirst(_('start date')),
                'recurrence-label':
                capfirst(_('date of the first recurrence')),  # noqa
            },
            options={
                'format': settings.DATE_INPUT_FORMATS[0],
                'pickTime': False
            }))
    end_date = forms.DateField(
        label=_('end date'),
        required=False,
        widget=DateTimePicker(attrs={
            'non-recurrence-label':
            capfirst(_('end date')),
            'recurrence-label':
            capfirst(_('date of the last recurrence')),
        },
                              options={
                                  'format': settings.DATE_INPUT_FORMATS[0],
                                  'pickTime': False
                              }))
    start_time = forms.TimeField(label=_('start time'),
                                 required=False,
                                 widget=DateTimePicker(options={
                                     'format': '%H:%M',
                                     'pickDate': False
                                 }))
    end_time = forms.TimeField(label=_('end time'),
                               required=False,
                               widget=DateTimePicker(options={
                                   'format': '%H:%M',
                                   'pickDate': False
                               }))

    def clean(self):
        cleaned_data = super(TimeDateForm, self).clean()
        start_date = cleaned_data.get('start_date')
        end_date = cleaned_data.get('end_date')
        start_time = cleaned_data.get('start_time')
        end_time = cleaned_data.get('end_time')

        def _consistent(start=None, end=None):
            return not end or start and end and start <= end

        # the start date should not be greater than the end date
        if not _consistent(start_date, end_date):
            raise forms.ValidationError(
                _('"start date" cannot be greater than "end date"'))

        # you can't know the ending if you don't know the starting
        if end_time and not start_time:
            raise forms.ValidationError(
                _('"start time" cannot be left blank if "end time" is set'))

        # check time consistency (end time after start time) on single dates
        if not end_date and not _consistent(start_time, end_time):
            raise forms.ValidationError(
                _('"start time" is greater than "end time"'))

        return cleaned_data
Ejemplo n.º 12
0
class SampleForm(forms.Form):

    datetime = forms.DateTimeField(widget=DateTimePicker(), )
Ejemplo n.º 13
0
 class Meta:
     model = Student
     fields = '__all__'
     widgets = {'my_date': forms.DateTimeField(widget=DateTimePicker())}
Ejemplo n.º 14
0
def zv_index_view(request):
    n1 = 'CRM'
    tel_form = new_zvn_form()
    nzvnCount = zvonok.objects.filter(status_zvonka='Новый').count()
    allform1 = modelformset_factory(
        zvonok,
        fields=(
            'tel',
            'client_name',
            'raion',
            'subj',
            'cena',
            'status_zvonka',
            'prezvonit',
            'coment',
        ),
        widgets={
            'prezvonit':
            DateTimePicker(options={
                'format': '%Y-%m-%d %H:%M',
                'language': 'ru-ru',
            }),
            'coment':
            Textarea(attrs={
                'rows': 80,
                'cols': 20
            })
        },
        extra=0,
    )
    Fallform1 = modelformset_factory(
        zvonok,
        fields=(
            'tel',
            'client_name',
            'raion',
            'subj',
            'cena',
            'status_zvonka',
            'prezvonit',
            'coment',
        ),
        widgets={
            'prezvonit':
            DateTimePicker(options={
                'format': '%Y-%m-%d %H:%M',
                'language': 'ru-ru',
            }),
            'coment':
            Textarea(attrs={
                'rows': 80,
                'cols': 20
            })
        },
        extra=1,
    )
    allform = allform1(queryset=zvonok.objects.filter(status_zvonka='Новый'))
    Fallform = Fallform1(queryset=zvonok.objects.none())
    perezv_call = zvonok.objects.filter(
        status_zvonka='Перезвонить', auth=request.user).order_by('-prezvonit')
    perezv_call_count = zvonok.objects.filter(
        status_zvonka='Перезвонить',
        auth=request.user).order_by('-prezvonit').count()
    nd_call = zvonok.objects.filter(status_zvonka='Недозвонился',
                                    auth=request.user).order_by('-date_sozd')
    nd_call_count = zvonok.objects.filter(
        status_zvonka='Недозвонился',
        auth=request.user).order_by('-date_sozd').count()
    work_call = zvonok.objects.filter(status_zvonka='В работе',
                                      auth=request.user).order_by('-date_sozd')
    work_call_count = zvonok.objects.filter(
        status_zvonka='В работе',
        auth=request.user).order_by('-date_sozd').count()
    arh_call = zvonok.objects.filter(status_zvonka='Архив',
                                     auth=request.user).order_by('-date_sozd')
    arh_call_count = zvonok.objects.filter(
        status_zvonka='Архив',
        auth=request.user).order_by('-date_sozd').count()
    all_call = zvonok.objects.filter(status_zvonka='В общем доступе',
                                     auth=request.user).order_by('-date_sozd')
    all_call_count = zvonok.objects.filter(
        status_zvonka='В общем доступе',
        auth=request.user).order_by('-date_sozd').count()
    n2='Все звонки:'+' Перезвонить:'+str(perezv_call_count)+'/ Недозвонился:'+str(nd_call_count)+'/ Недозвонился:'\
                                    +str(arh_call_count)+'/ В общем доступе:'+str(all_call_count)

    if request.POST:
        formset = allform1(request.POST, queryset=allform)
        if formset.is_valid():
            formset.save()

    return render(
        request, 'zvonki/index.html', {
            'tn1': n1,
            'tn2': n2,
            't_per_cl': perezv_call,
            'tpcount': perezv_call_count,
            't_nd_cl': nd_call,
            'tndcount': nd_call_count,
            't_wk_cl': work_call,
            'twcount': work_call_count,
            't_arh_cl': arh_call,
            'tarhcount': arh_call_count,
            't_all_cl': all_call,
            'tallcount': all_call_count,
            'tAllForm': allform,
            'tFAllForm': Fallform,
            'tnzvncount': nzvnCount,
            'tTelForm': tel_form
        })