Пример #1
0
class DateRangeForm(forms.Form):
  REPORT_FILTER_CHOICES = (
    #("", "<Default>"),
    ("week", "This Week"),
    ("last-week", "Last Week"),
    ("month", "This month"),
    ("last-month", "Last month"),
    ("year", "Year-to-date"),
    ("custom", "Select date range"),
  )
  date_range = forms.ChoiceField(label="Filter by Date Range", required=False, choices=REPORT_FILTER_CHOICES) #choices=REPORT_FILTER_CHOICES, initial="custom")
  range_from = forms.DateField(label="From", required=False, widget=BootstrapDateInput())
  range_to = forms.DateField(label="To", required=False, widget=BootstrapDateInput())
  
  def __init__(self, *args, **kwargs):
    super(DateRangeForm, self).__init__(*args, **kwargs)
    #self.initial['date_range'] = 'custom'  #default selection

    self.helper = FormHelper()
    self.form_tag = False
    self.disable_csrf = True
    self.helper.form_class = 'form-inline'
    self.helper.field_template = 'bootstrap3/layout/inline_field.html'
    self.helper.layout = Layout(
        Div(
          HTML (
            '<h3>Select date range</h3>'
          ),
          'date_range',
          'range_from',
          'range_to',
          Submit('submit', 'Filter', css_class='btn-default'),
          css_class = 'well'
        )
    )
Пример #2
0
class MoteDetailInterval(forms.Form):
    id = forms.IntegerField(label='Mote ID',
                            required=True,
                            help_text='Id of mote to detail')
    startDate = forms.DateTimeField(label='Initial period',
                                    required=True,
                                    widget=BootstrapDateInput())
    finalDate = forms.DateTimeField(label='Final period',
                                    initial=datetime.datetime.now(),
                                    required=True,
                                    widget=BootstrapDateInput())
Пример #3
0
 def __init__(self, widgets=None, *args, **kwargs):
     widgets = (BootstrapDateInput(
         attrs={
             'class': 'form-control glyphicon glyphicon-list',
             'placeholder': 'Starting after'
         }),
                BootstrapDateInput(
                    attrs={
                        'class': 'form-control glyphicon glyphicon-list',
                        'placeholder': 'Ending before'
                    }))
     super(DateRangeWidget, self).__init__(widgets, *args, **kwargs)
Пример #4
0
class StudentForm(ModelForm):

    date_enrolled = forms.DateField(widget=BootstrapDateInput(),)

    class Meta:
        model = Student
        fields = ['first_name', 'last_name', 'am', 'date_enrolled', 'semester', 'undergraduate']
Пример #5
0
 class Meta:
     model = Whois
     fields = ('date_from', 'contact', 'address1', 'address2')
     attrs = {
         'date_from': {
             'label': 'Whois registration date',
             'widget': BootstrapDateInput(attrs={'disabled': True}),
         },
         'contact': {
             'label':
             'Whois contact',
             'widget':
             Uneditable(value_calback=lambda qs, selected: ', '.join(
                 filter(None, selected))),
         },
         'address1': {
             'label':
             'Whois address (city)',
             'widget':
             Uneditable(value_calback=lambda qs, selected: ', '.join(
                 filter(None, selected))),
         },
         'address2': {
             'label':
             'Whois address (country code)',
             'widget':
             Uneditable(value_calback=lambda qs, selected: ', '.join(
                 filter(None, selected))),
         },
     }
Пример #6
0
 class Meta:
     model = SIteContent
     fields = ('site', 'last_update', 'shipment', 'type', 'links')
     attrs = {
         'site': {
             'widget': HiddenInput(),
         },
         'last_update': {
             'label':
             'Last updated',
             'widget':
             BootstrapDateInput(attrs={
                 'class': 'datepicker',
                 'data-provide': 'datepicker-inline'
             }),
         },
         'shipment': {
             'label': 'Shipment method',
             'help_text': '',
         },
         'type': {
             'label': 'Shop type',
             'empty_label': 'Select shop type'
         },
         'links': {
             'label': 'Links to other sites',
             'help_text': '',
         },
     }
Пример #7
0
    def __init__(self, *args, **kwargs):
        if not 'user' in kwargs:
            raise Exception('missing user')
        self.user = kwargs.pop('user')
        self.view_only = kwargs.pop('view_only', False)

        if not 'customer' in kwargs:
            raise Exception('missing customer')
        self.customer = kwargs.pop('customer')

        if 'exclude_list' in kwargs:
            exclude_list = kwargs.pop('exclude_list')
        else:
            exclude_list = []

        if not 'is_stuff' in kwargs or not kwargs.pop('is_stuff'):
            exclude_list = list(
                set(exclude_list + settings.TICKET_NON_PUBLIC_FIELDS))

            super(TicketsForm, self).__init__(*args, **kwargs)

            if self.fields.get('customer'):
                self.fields['customer'].queryset = self.fields[
                    'customer'].queryset.filter(pk=self.customer)
        else:
            super(TicketsForm, self).__init__(*args, **kwargs)

        for field in exclude_list:
            del self.fields[field]

        for field in self.fields:
            if type(self.fields[field]) is forms.fields.DateField:
                self.fields[field].widget = BootstrapDateInput()

        # remove fields after close
        if not self.instance.pk is None and self.instance.closed and not self.view_only:
            available_fields = []
            for field in self.fields:
                available_fields.append(str(field))

            for field in available_fields:
                if str(field
                       ) not in settings.TICKET_EDITABLE_FIELDS_AFTER_CLOSE:
                    del self.fields[str(field)]

        # disallow non state
        if 'state' in self.fields:
            self.fields['state'].empty_label = None

            # only allow possible states
            if not self.instance.pk is None and not self.view_only:
                flows = list(
                    ticket_flow_edges.objects.select_related('next').filter(
                        now=self.instance.state).exclude(
                            next__type=2).values_list('next', flat=True))
                flows.append(self.instance.state_id)
                self.fields['state'].queryset = self.fields[
                    'state'].queryset.filter(id__in=flows)
Пример #8
0
class BRWRYForm(forms.Form):
    date = forms.DateField(
        widget=BootstrapDateInput(),
    )
    title = forms.CharField(
        max_length=100,
        help_text=u'This is the standard text input',
    )
    disabled = forms.CharField(
        max_length=100,
        help_text=u'I am read only',
        widget=forms.TextInput(attrs={
            'disabled': 'disabled'
        })
    )
    content = forms.ChoiceField(
        choices=(
            ("text", "Plain text"),
            ("html", "HTML"),
        ),
        help_text=u'Pick your choice',
    )
    email = forms.EmailField()
    like = forms.BooleanField(required=False)
    fruits = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple,
        choices=(
            ("apple", "Apple"),
            ("pear", "Pear"),
        ),
        help_text=u'As you can see, multiple checkboxes work too',
    )
    veggies = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple(attrs={
            'inline': True,
        }),
        choices=(
            ("broccoli", "Broccoli"),
            ("carrots", "Carrots"),
            ("turnips", "Turnips"),
        ),
        help_text=u'And can be inline',
    )
    color = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=(
            ("#f00", "red"),
            ("#0f0", "green"),
            ("#00f", "blue"),
        ),
        help_text=u'And we have <i>radiosets</i>',
    )

    def clean(self):
        cleaned_data = super(BRWRYForm, self).clean()
        raise forms.ValidationError("This error was added to show the non field errors styling.")
        return cleaned_data
Пример #9
0
class InformationForm(forms.ModelForm):
    class Meta:
        model = Information
        exclude = ('owner', 'heat', 'ischeck', 'istimeout')

    end_date = forms.DateField(widget=BootstrapDateInput())

    def clean_description(self):
        description = self.cleaned_data['description']
        if len(description) <= 8:
            raise forms.ValidationError("字数不够")
        return description
Пример #10
0
class DynamicViewForm(forms.Form):
    VIEW_TYPES_CHOICES = (
        (u'Temperature', u'temperature'),
        (u'Light', u'light'),
        (u'Battery', u'battery'),
    )
    listIds = forms.CharField(label='List of IDs',
                              required=True,
                              help_text='Motes separated by spaces.',
                              max_length=50)
    view_types = forms.TypedChoiceField(label='Views',
                                        choices=VIEW_TYPES_CHOICES,
                                        help_text=u'Select one view',
                                        initial='temperature')
    startDate = forms.DateTimeField(
        label='Initial period',
        initial=datetime.datetime.now() - datetime.timedelta(weeks=1),
        widget=BootstrapDateInput(
        ))  # widget= forms.DateTimeInput(format='%H:%M %d/%m/%Y')
    finalDate = forms.DateTimeField(label='Final period',
                                    initial=datetime.datetime.now(),
                                    widget=BootstrapDateInput())
Пример #11
0
class LogInterval(forms.Form):
    LOGS_TYPES_CHOICES = (
        (u'Warning', u'warning'),
        (u'Info', u'info'),
        (u'Critical', u'critical'),
    )
    startDate = forms.DateTimeField(
        label='Initial period',
        required=True,
        help_text='Insert initial time and date for log consult',
        widget=BootstrapDateInput(
        ))  #widget= forms.DateTimeInput(format='%H:%M %d/%m/%Y'),
    finalDate = forms.DateTimeField(
        label='Final period',
        initial=datetime.datetime.now(),
        required=True,
        help_text='Insert final time and date for log consult',
        widget=BootstrapDateInput())
    log_type = forms.ChoiceField(label='Log type',
                                 choices=LOGS_TYPES_CHOICES,
                                 help_text="Select log type to view",
                                 initial='Warning')
Пример #12
0
class RevisionForm(forms.ModelForm):
    class Meta:
        model = Revision

    f_actualizacion = forms.DateField(widget=BootstrapDateInput(attrs={}, ), )
    cambios = forms.CharField(label='Registro de Cambios',
                              widget=forms.Textarea(
                                  attrs={
                                      'rows': 5,
                                      'cols': 78,
                                      'style': 'width: 80%; height: 120px',
                                      'class': 'wmd-input'
                                  }))
    revision = forms.CharField(widget=BootstrapTextInput(attrs={
        'class': 'input-mini',
    }, ), )
Пример #13
0
    def __init__(self, *args, **kwargs):
        if not 'user' in kwargs:
            raise Exception('missing user')
        self.user = kwargs.pop('user')

        if not 'customer' in kwargs:
            raise Exception('missing customer')
        self.customer = kwargs.pop('customer')

        if 'include_list' in kwargs:
            include_list = kwargs.pop('include_list')
        else:
            include_list = []

        if not 'is_stuff' in kwargs or not kwargs.pop('is_stuff'):
            used_fields = []
            for ele in include_list:
                if not ele in settings.TICKET_NON_PUBLIC_FIELDS:
                    used_fields.append(ele)
            super(SearchForm, self).__init__(*args, **kwargs)

            if self.fields.get('customer'):
                self.fields['customer'].queryset = self.fields['customer'].queryset.filter(pk=self.customer)
        else:
            used_fields = include_list
            super(SearchForm, self).__init__(*args, **kwargs)
        available_fields = []
        for field in self.fields:
            available_fields.append(str(field))

        for field in available_fields:
            if str(field) not in used_fields:
                del self.fields[str(field)]

        for field in self.fields:
            if type(self.fields[field]) is forms.fields.DateField:
                self.fields[field].widget = BootstrapDateInput()

            if type(self.fields[field]) is forms.fields.BooleanField:
                self.fields[field] = forms.NullBooleanField()

            self.fields[field].required = False

        # unset initial
        for field in self.fields:
            self.fields[field].initial = None
Пример #14
0
 class Meta:
     model = SIteContent
     fields = ('site', 'last_update', 'shipment', 'type', 'links')
     attrs = {
         'site': {
             'widget': HiddenInput(attrs={'disabled': True}),
         },
         'last_update': {
             'label': 'Last updated',
             'widget': BootstrapDateInput(attrs={'disabled': True}),
         },
         'shipment': {
             'label':
             'Shipment method',
             'help_text':
             '',
             'widget':
             Uneditable(value_calback=lambda qs, selected: ', '.join(
                 shp.name for shp in qs if shp.id in selected)),
         },
         'type': {
             'label':
             'Shop type',
             'widget':
             Uneditable(value_calback=lambda qs, selected: ', '.join(
                 type.name for type in qs if type.id in selected)),
         },
         'links': {
             'label':
             'Links to other sites',
             'help_text':
             '',
             'widget':
             Uneditable(value_calback=lambda qs, selected: [
                 format_html(u'<a href="{0}">{1}</a>', lnk.url, lnk.name)
                 for lnk in qs if lnk.id in selected
             ],
                        ),
         },
     }
Пример #15
0
class SimpleTickets(forms.Form):
    caption = forms.CharField(required=True, label=_('caption'))
    description = forms.CharField(widget=forms.Textarea(), required=False, label=_('description'))
    assigned = forms.ModelChoiceField(queryset=User.objects.all(), required=False, label=_('assigned'))
    priority = forms.ModelChoiceField(queryset=ticket_priority.objects.all(), required=True, initial=get_simple_priority, label=_('priority'))
    deadline = forms.DateTimeField(widget=BootstrapDateInput(), required=False, label=_('deadline'))
Пример #16
0
 class Meta:
     model = Documento
     exclude = ('slug', )
     f_actualizacion = forms.DateField(widget=BootstrapDateInput(
         attrs={}, ), )
Пример #17
0
class TestForm(forms.Form):
    date = forms.DateField(
        widget=BootstrapDateInput(),
    )
    title = forms.CharField(
        max_length=100,
        help_text=u'This is the standard text input',
    )
    body = forms.CharField(
        max_length=100,
        help_text=u'This is a text area',
        widget=forms.Textarea(
            attrs={
                'title': 'I am "nice"',
            }
        ),
    )
    disabled = forms.CharField(
        max_length=100,
        required=False,
        help_text=u'I am disabled',
        widget=forms.TextInput(attrs={
            'disabled': 'disabled',
            'placeholder': 'I am disabled',
        })
    )
    content = forms.ChoiceField(
        choices=(
            ("text", "Plain text"),
            ("html", "HTML"),
        ),
        help_text=u'Pick your choice',
    )
    email = forms.EmailField()
    like = forms.BooleanField(required=False)
    fruits = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple,
        choices=(
            ("apple", "Apple"),
            ("pear", "Pear"),
        ),
        help_text=u'As you can see, multiple checkboxes work too',
    )
    number = forms.MultipleChoiceField(
        widget=forms.CheckboxSelectMultiple(attrs={
            'inline': True,
        }),
        choices=(
            ("3", "Three"),
            ("33", "Thirty three"),
            ("333", "Three hundred thirty three"),
        ),
        help_text=u'And can be inline',
    )
    color = forms.ChoiceField(
        widget=forms.RadioSelect(attrs={'data-demo-attr': 'bazinga'}),
        choices=(
            ("#f00", "red"),
            ("#0f0", "green"),
            ("#00f", "blue"),
        ),
        help_text=u'And we have <i>radiosets</i>',
    )
    prepended = forms.CharField(
        max_length=100,
        help_text=u'I am prepended by a P',
        widget=BootstrapTextInput(prepend='P'),
    )

    def clean(self):
        cleaned_data = super(TestForm, self).clean()
        raise forms.ValidationError("This error was added to show the non field errors styling.")
        return cleaned_data
Пример #18
0
    def addField(self, fieldtype, varname, label, options, **kwargs):
        field = None
        if fieldtype == 'FloatField':  # float
            field = forms.FloatField(label=label, required=False)

        if fieldtype == 'AutoField':  # int
            field = forms.IntegerField(label=label, required=False)

        if fieldtype == 'BooleanField':  # boolean
            field = forms.NullBooleanField(label=label, required=False)

        if fieldtype == 'NullBooleanField':
            field = forms.NullBooleanField(label=label, required=False)

        if fieldtype == 'CharField' and not options:  # str
            field = forms.CharField(label=label, required=False)

        if fieldtype == 'TextField':  # str
            field = forms.TextField(label=label, required=False)

        if fieldtype == 'DateField':  # date
            field = forms.DateField(widget=BootstrapDateInput(),
                                    label=label,
                                    required=False)

        if fieldtype == 'TimeField':  # time
            field = forms.TimeField(widget=TimeWidget(),
                                    label=label,
                                    required=False)

        if fieldtype == 'DateTimeField':  # datetime
            field = forms.DateTimeField(widget=DateTimeWidget(),
                                        label=label,
                                        required=False)

        if fieldtype == 8:  # enum
            pass

        if fieldtype == 9:  # hidden
            field = forms.CharField(widget=forms.HiddenInput(),
                                    label=label,
                                    required=False)

        if fieldtype == 'select':  # select
            field = forms.ChoiceField(widget=forms.Select(
                attrs={
                    'style': 'font-family: \'FontAwesome\', \'sans-serif\';'
                }),
                                      choices=options,
                                      label=label,
                                      required=False)
            self.select_vars.append(varname)

        if fieldtype == 11:  # dateshort
            initial = self.getDefaultDate(initial)
            field = forms.DateField(label=label, required=False)

        if field:
            setattr(self, varname, field)
            self.fields[varname] = field
        else:
            raise Exception('missing field type %s' % fieldtype)