Beispiel #1
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []
        final_attrs = self.build_attrs(attrs, name=name)
        id_ = final_attrs.get('id', None)
        output = [u'<ul>']
        # Normalize to strings
        str_values = set([force_text(v) for v in value])
        for i, (option_value,
                option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if id_:
                final_attrs = dict(final_attrs, id='%s_%s' % (id_, i))
                label_for = format_html(u' for="{0}_{1}"', id_, i)
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs,
                               check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = format_html(option_label)
            output.append(
                format_html(u'<li><label{0}>{1} {2}</label></li>', label_for,
                            rendered_cb, option_label))
        output.append(u'</ul>')
        return mark_safe('\n'.join(output))
Beispiel #2
0
    class Meta:
        model = FilterPolicy
        # The order of the fields in html table is defined here
        fields = ('filter_name', 'enabled', 'nb_thread', 'log_level',
                  'cache_size', 'threshold', 'mmdarwin_enabled',
                  'mmdarwin_parameters')

        widgets = {
            'enabled':
            CheckboxInput(attrs={"class": "js-switch"}),
            'nb_thread':
            NumberInput(attrs={'class': 'form-control'}),
            'threshold':
            NumberInput(attrs={'class': 'form-control'}),
            'log_level':
            Select(choices=DARWIN_LOGLEVEL_CHOICES,
                   attrs={'class': 'form-control select2'}),
            'cache_size':
            NumberInput(attrs={'class': 'form-control'}),
            'mmdarwin_enabled':
            CheckboxInput(attrs={"class": "js-switch mmdarwin-enabled-btn"}),
            'mmdarwin_parameters':
            TextInput(
                attrs={"class": "form-control tags-input mmdarwin-parameters"})
        }

        labels = {
            'mmdarwin_enabled': 'Enable custom Rsyslog calls',
            'mmdarwin_parameters': 'Rsyslog parameters:'
        }
Beispiel #3
0
 class Meta:
     model = DefaultTrip
     fields = ('morning_departure_time', 'morning_arriving_time',
               'evening_departure_time', 'has_for_start', 'deactivate',
               'user_is_driver')
     widgets = {
         'morning_departure_time':
         TimeInput(attrs={
             'type': 'time',
             'class': 'form-control require-input'
         }),
         'morning_arriving_time':
         TimeInput(attrs={
             'type': 'time',
             'class': 'form-control require-input'
         }),
         'evening_departure_time':
         TimeInput(attrs={
             'type': 'time',
             'class': 'form-control require-input'
         }),
         'deactivate':
         CheckboxInput(
             attrs={
                 'class': 'toggle_button_deactivate_day',
                 '@click': 'deactivate_fields($event.target)'
             }),
         'user_is_driver':
         CheckboxInput(attrs={'class': 'toggle_button_driver'}),
     }
Beispiel #4
0
 def render(self, name, value, attrs=None, choices=(), renderer=None):
     if value is None:
         value = []
     final_attrs = self.build_attrs(attrs)
     output = [u'<ul>']
     global_readonly = 'readonly' in final_attrs
     str_values = set([v for v in value])
     for i, (option_value,
             option_label) in enumerate(chain(self.choices, choices)):
         if not global_readonly and 'readonly' in final_attrs:
             # If the entire group is readonly keep all options readonly
             del final_attrs['readonly']
         if isinstance(option_label, dict):
             if dict.get(option_label, 'readonly'):
                 final_attrs = dict(final_attrs, readonly='readonly')
             option_label = option_label['label']
         final_attrs = dict(final_attrs, id='{}_{}'.format(attrs['id'], i))
         label_for = u' for="{}"'.format(final_attrs['id'])
         cb = CheckboxInput(final_attrs,
                            check_test=lambda value: value in str_values)
         rendered_cb = cb.render(name, option_value)
         output.append(u'<li><label%s>%s %s</label></li>' %
                       (label_for, rendered_cb, option_label))
     output.append(u'</ul>')
     return mark_safe(u'\n'.join(output))
 def render_body(self, name, value, attrs):
     output = []
     has_id = attrs and "id" in attrs
     final_attrs = self.build_attrs(attrs, name=name)
     str_values = set([force_text(v) for v in value])
     for i, (pk, item) in enumerate(self.choices):
         # If an ID attribute was given, add a numeric index as a suffix,
         # so that the checkboxes don't all have the same ID attribute.
         if has_id:
             final_attrs = dict(final_attrs, id="{}_{}".format(attrs["id"], i))
         item = self.choices.queryset.get(pk=pk)
         cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
         option_value = force_text(pk)
         rendered_cb = cb.render(name, option_value)
         output.append("<tr><td>{}</td>".format(rendered_cb))
         for attr in self.item_attrs:
             if callable(attr):
                 content = attr(item)
             elif callable(getattr(item, attr)):
                 content = getattr(item, attr)()
             else:
                 content = getattr(item, attr)
             output.append("<td>{}</td>".format(escape(content)))
         output.append("</tr>")
     output.append("</tbody>")
     return "".join(output)
 def render_body(self, name, value, attrs):
     output = ['<tbody>']
     has_id = attrs and 'id' in attrs
     final_attrs = self.build_attrs(attrs)
     final_attrs['class'] = "tableselectmultiple selectable-checkbox"
     if self.bootstrap_style:
         final_attrs['class'] += " form-check-input"
     str_values = set([force_text(v) for v in value])
     choice_pks = [pk for (pk, item) in self.choices]
     choices = self.choices.queryset.filter(pk__in=choice_pks)
     for i, item in enumerate(choices):
         # If an ID attribute was given, add a numeric index as a suffix,
         # so that the checkboxes don't all have the same ID attribute.
         if has_id:
             final_attrs = dict(
                 final_attrs, id='{}_{}'.format(attrs['id'], i),
             )
         cb = CheckboxInput(final_attrs,
                            check_test=lambda value: value in str_values)
         option_value = force_text(item.pk)
         rendered_cb = cb.render(name, option_value)
         output.append('<tr><td>{}</td>'.format(rendered_cb))
         for item_attr in self.item_attrs:
             attr = item_attr \
                 if isinstance(item_attr, str) \
                 else item_attr[0]
             content = get_underscore_attrs(attr, item)
             output.append('<td>{}</td>'.format(escape(content)))
         output.append('</tr>')
     output.append('</tbody>')
     return ''.join(output)
Beispiel #7
0
    class Meta:
        model = Member

        exclude = ('waiver', )
        fields = [
            'email', 'email_consent', 'first_name', 'last_name',
            'preferred_name', 'date_of_birth', 'guardian_name', 'phone',
            'street', 'city', 'province', 'country', 'post_code', 'waiver',
            'banned', 'suspended', 'notes', 'involvement'
        ]
        widgets = {
            'email':
            EmailInput(attrs={'class': 'mdl-textfield__input'}),
            'email_consent':
            CheckboxInput(attrs={'class': 'mdl-checkbox__input'}),
            'first_name':
            TextInput(attrs={'class': 'mdl-textfield__input'}),
            'last_name':
            TextInput(attrs={'class': 'mdl-textfield__input'}),
            'involvement':
            CheckboxSelectMultiple(choices=Member.involvement_choices,
                                   attrs={'class': 'mdl-checkbox__input'}),
            'preferred_name':
            TextInput(attrs={'class': 'mdl-textfield__input'}),
            'guardian_name':
            DateInput(attrs={
                'class': 'mdl-textfield__input',
                'readonly': 'readonly'
            }),
            'phone':
            TextInput(attrs={
                'class': 'mdl-textfield__input',
                'pattern': '[0-9]*'
            }),
            'street':
            TextInput(attrs={'class': 'mdl-textfield__input'}),
            'city':
            TextInput(attrs={'class': 'mdl-textfield__input'}),
            'province':
            TextInput(attrs={'class': 'mdl-textfield__input'}),
            'country':
            TextInput(attrs={'class': 'mdl-textfield__input'}),
            'post_code':
            TextInput(
                attrs={
                    'class': 'mdl-textfield__input',
                    'pattern': '[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]'
                }),
            'notes':
            Textarea(attrs={'class': 'mdl-textfield__input'}),
            'suspended':
            CheckboxInput(attrs={'class': 'mdl-checkbox__input'}),
            'banned':
            CheckboxInput(attrs={'class': 'mdl-checkbox__input'}),
        }

        labels = {
            'email_consent':
            'I consent to receiving digital communication from the BCBC.'
        }
Beispiel #8
0
 class Meta:
     model = Message
     fields = [
         "header",
         "content",
         "category",
         "tags",
         "start_date",
         "end_date",
         "deadline_date",
         "show_deadline",
         "visible",
     ]
     labels = {
         "header": _("Header"),
         "content": _("Content"),
         "category": _("Category"),
         "tags": _("Tags"),
         "start_date": _("Start date"),
         "end_date": _("End date"),
         "deadline_date": _("Deadline"),
         "show_deadline": _("Show deadline"),
         "visible": _("Visible"),
     }
     widgets = {
         "header": TextInput(),
         "content": CKEditorWidget(),
         "start_date": AdminDateWidget(),
         "end_date": AdminDateWidget(),
         "deadline_date": AdminDateWidget(),
         "category": Select(),
         "tags": SelectMultiple(),
         "show_deadline": CheckboxInput(),
         "visible": CheckboxInput(),
     }
Beispiel #9
0
class PageForm(FlatpageForm):

    template_name = CharField(widget=TextInput(attrs={
        'disabled': 'true',
    }),
                              required=False)

    enable_comments = BooleanField(widget=CheckboxInput(attrs={
        'disabled': 'true',
    }),
                                   required=False)

    registration_required = BooleanField(
        widget=CheckboxInput(attrs={
            'disabled': 'true',
        }), required=False)

    class Meta:
        model = FlatPage
        widgets = {
            'content': CKEditorWidget(),
            'sites': SelectMultiple(attrs={
                'readonly': 'readonly',
            }),
        }
Beispiel #10
0
	class Meta:
		model = Salud
		fields = (
			'persona',
			'conapdis',
			'cuidador',
 		 	'discapacidad',
			'mtlp',
 		 	'alcoholismo',
 		 	'tabaquismo',
 		 	'drogas',
 		 	'patologia',
 		 	'tipoapoyo',
		)
		widgets = {
			'persona': HiddenInput(),
            'conapdis': TextInput(attrs={'class':'form-control input-sm'}),
            'cuidador': autocomplete.ModelSelect2(url='demografia:personaAutoComplete', forward=['sexo'], attrs={'data-placeholder': '----------', 'data-minimum-input-length': 3, 'class':'form-control input-sm'}),
 		 	'discapacidad': CheckboxSelectMultiple(),
            'mtlp': CheckboxInput(attrs={'class':'form-control input-sm'}),
 		 	'alcoholismo': CheckboxInput(attrs={'class':'form-control input-sm'}),
 		 	'tabaquismo': CheckboxInput(attrs={'class':'form-control input-sm'}),
 		 	'drogas': CheckboxInput(attrs={'class':'form-control input-sm'}),
 		 	'patologia': CheckboxSelectMultiple(),
 		 	'tipoapoyo': CheckboxSelectMultiple()
        }
Beispiel #11
0
    class Meta:
        model = Envelopes
        fields = [
            'name', 'monthly_replenishment', 'closed', 'onetime_envelope',
            'max_amount'
        ]
        widgets = {
            'name':
            TextInput(attrs={
                'class': 'form-control',
                'placeholder': u'Название'
            }),
            'monthly_replenishment':
            TextInput(attrs={
                'class': 'form-control',
                'placeholder': u'Месячное пополнение'
            }),
            'max_amount':
            TextInput(
                attrs={
                    'class': 'form-control',
                    'placeholder': u'Максимальная сумма конверта'
                }),
            'onetime_envelope':
            CheckboxInput(attrs={'class': 'checkbox'}),
            'closed':
            CheckboxInput(attrs={'class': 'checkbox'})
        }

        labels = {'closed': u'Закрыт', 'onetime_envelope': u'Разовый'}
Beispiel #12
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []
        final_attrs = self.build_attrs(attrs, name=name)
        id_ = final_attrs.get('id', None)
        output = [u'<ul>']
        # Normalize to strings
        str_values = set([force_text(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if id_:
                final_attrs = dict(final_attrs, id='%s_%s' % (id_, i))
                label_for = format_html(u' for="{0}_{1}"', id_, i)
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = format_html(option_label)
            output.append(format_html(u'<li><label{0}>{1} {2}</label></li>',
                                      label_for, rendered_cb, option_label))
        output.append(u'</ul>')
        return mark_safe('\n'.join(output))
Beispiel #13
0
 class Meta:
     model = AppEnv
     fields = [
         'juntagrico_admin_email', 'juntagrico_email_user',
         'juntagrico_email_password', 'juntagrico_email_host',
         'juntagrico_email_port', 'juntagrico_email_tls',
         'juntagrico_email_ssl', 'juntagrico_secret_key', 'various'
     ]
     widgets = {
         'juntagrico_admin_email':
         TextInput(attrs={'class': 'form-control'}),
         'juntagrico_email_user':
         TextInput(attrs={'class': 'form-control'}),
         'juntagrico_email_password':
         TextInput(attrs={'class': 'form-control'}),
         'juntagrico_email_host':
         TextInput(attrs={'class': 'form-control'}),
         'juntagrico_email_port':
         TextInput(attrs={'class': 'form-control'}),
         'juntagrico_email_tls':
         CheckboxInput(attrs={'class': 'form-control'}),
         'juntagrico_email_ssl':
         CheckboxInput(attrs={'class': 'form-control'}),
         'various': Textarea(attrs={'class': 'form-control'})
     }
Beispiel #14
0
 class Meta:
     model = OpenIDRepository
     fields = ('name', 'provider', 'provider_url', 'client_id',
               'client_secret', 'scopes', 'use_proxy', 'verify_certificate',
               'user_scope')
     widgets = {
         'name':
         TextInput(attrs={'class': 'form-control'}),
         'provider':
         Select(choices=PROVIDERS_TYPE,
                attrs={'class': 'form-control select2'}),
         'provider_url':
         TextInput(attrs={'class': 'form-control'}),
         'client_id':
         TextInput(attrs={'class': 'form-control'}),
         'client_secret':
         TextInput(attrs={'class': 'form-control'}),
         'scopes':
         TextInput(attrs={
             'class': 'form-control',
             'data-role': "tagsinput"
         }),
         'use_proxy':
         CheckboxInput(attrs={"class": " js-switch"}),
         'verify_certificate':
         CheckboxInput(attrs={"class": " js-switch"}),
         'user_scope':
         Select(attrs={'class': 'form-control select2'})
     }
Beispiel #15
0
 class Meta:
     model = get_user_model()
     fields = ('username', 'first_name', 'last_name', 'email', 'churches',
               'groups', 'is_superuser', 'is_staff', 'is_active',
               'date_joined', 'last_login')
     widgets = {
         'username':
         TextInput(attrs={'class': 'input input-bordered w-full max-w-sm'}),
         'first_name':
         TextInput(attrs={'class': 'input input-bordered w-full max-w-sm'}),
         'last_name':
         TextInput(attrs={'class': 'input input-bordered w-full max-w-sm'}),
         'email':
         TextInput(attrs={'class': 'input input-bordered w-full max-w-sm'}),
         'churches':
         SelectMultiple(attrs={
             'class':
             'select select-bordered select-multiple w-full max-w-sm'
         }),
         'groups':
         SelectMultiple(attrs={
             'class':
             'select select-bordered select-multiple w-full max-w-sm'
         }),
         'is_superuser':
         CheckboxInput(attrs={'class': 'toggle toggle-primary'}),
         'is_staff':
         CheckboxInput(attrs={'class': 'toggle toggle-primary'}),
         'is_active':
         CheckboxInput(attrs={'class': 'toggle toggle-primary'}),
         'date_joined':
         TextInput(attrs={'class': 'input input-bordered w-full max-w-sm'}),
         'last_login':
         TextInput(attrs={'class': 'input input-bordered w-full max-w-sm'}),
     }
Beispiel #16
0
    class Meta:
        model = Ticket
        fields = ['status',
                  'priority',
                  'tecnico_pre_diagnostico',
                  'tecnico_de_campo',
                  'is_customer',
                  'customer_code',
                  'order',
                  'losses',
                  'need_paper',
                  'resolution_report', ]

        widgets = {
            'status': Select(attrs={'class': 'form-control', 'placeholder': 'Status'}),
            'priority': Select(attrs={'class': 'form-control', 'placeholder': 'Prioridade'}),
            'tecnico_pre_diagnostico': Select(attrs={'class': 'form-control', 'placeholder': 'Pré diagnostico'}),
            'tecnico_de_campo': Select(attrs={'class': 'form-control', 'placeholder': 'Tecnico de campo'}),
            'is_customer': CheckboxInput(attrs={'class': 'form-control'}),
            'customer_code': TextInput(attrs={'class': 'form-control'}),
            'order': TextInput(attrs={'class': 'form-control'}),
            'losses': NumberInput(attrs={'class': 'form-control'}),
            'need_paper': CheckboxInput(attrs={'class': 'form-control'}),
            'resolution_report': Textarea(attrs={'class': 'form-control'})
        }
Beispiel #17
0
    class Meta:
        model = Backend
        fields = ('enabled', 'name', 'mode', 'timeout_connect', 'timeout_server', 'custom_haproxy_conf',
                  'accept_invalid_http_response', 'http_forwardfor_header', 'http_forwardfor_except',
                  'enable_http_health_check', 'http_health_check_method', 'http_health_check_uri',
                  'http_health_check_version', 'enable_http_keep_alive', 'http_keep_alive_timeout',
                  'balancing_mode', 'balancing_param', 'http_health_check_expect_match',
                  'http_health_check_expect_pattern', 'tags', 'http_backend_dir')

        widgets = {
            'enabled': CheckboxInput(attrs={"class": " js-switch"}),
            'name': TextInput(attrs={'class': 'form-control'}),
            'mode': Select(choices=MODE_CHOICES, attrs={'class': 'form-control select2'}),
            'timeout_connect': NumberInput(attrs={'class': 'form-control'}),
            'timeout_server': NumberInput(attrs={'class': 'form-control'}),
            'custom_haproxy_conf': Textarea(attrs={'class': 'form-control'}),

            'http_backend_dir': TextInput(attrs={'class': "form-control"}),
            'accept_invalid_http_response': CheckboxInput(attrs={'class': "form-control js-switch"}),
            'http_forwardfor_header': TextInput(attrs={'class': 'form-control', 'placeholder': 'header name'}),
            'http_forwardfor_except': TextInput(attrs={'class': 'form-control', 'placeholder': 'this IP address'}),
            'enable_http_health_check': CheckboxInput(attrs={'class': "form-control js-switch"}),
            'http_health_check_method': Select(choices=HEALTH_CHECK_METHOD_CHOICES, attrs={'class': 'form-control select2'}),
            'http_health_check_uri': TextInput(attrs={'class': 'form-control'}),
            'http_health_check_version': Select(choices=HEALTH_CHECK_VERSION_CHOICES, attrs={'class': 'form-control select2'}),
            'http_health_check_expect_match': Select(choices=HEALTH_CHECK_EXPECT_CHOICES, attrs={'class': 'form-control select2'}),
            'http_health_check_expect_pattern': TextInput(attrs={'class': 'form-control'}),
            'enable_http_keep_alive': CheckboxInput(attrs={'class': "form-control js-switch"}),
            'http_keep_alive_timeout': NumberInput(attrs={'class': 'form-control'}),
            'balancing_mode': Select(choices=BALANCING_CHOICES, attrs={'class': 'form-control select2'}),
            'balancing_param': TextInput(attrs={'class': 'form-control'}),
            'tags': TextInput(attrs={'class': 'form-control'})
        }
 def render(self, name, value, attrs=None, choices=()):
     if value is None: value = []
     has_id = attrs and 'id' in attrs
     final_attrs = self.build_attrs(attrs, name=name)
     output = [u'<table class="existing_objects_list">']
     str_values = set([force_unicode(v) for v in value])  # Normalize to strings.
     output.append(u'<tr><th>%s</th>' % conditional_escape(self.checkbox_label))
     for label, attr in self.item_attrs:
         output.append(u'<th>%s</th>' % conditional_escape(label))
     output.append(u'</tr>')
     for i, (option_value, item) in enumerate(self.choices):
         # If an ID attribute was given, add a numeric index as a suffix,
         # so that the checkboxes don't all have the same ID attribute.
         if has_id:
             final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
         cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
         option_value = force_unicode(option_value)
         rendered_cb = cb.render(name, option_value)
         output.append(u'<tr><td>%s</td>' % rendered_cb)
         for label, attr in self.item_attrs:
             if callable(attr):
                 content = attr(item)
             elif callable(getattr(item, attr)):
                 content = getattr(item, attr)()
             else:
                 content = getattr(item, attr)
             output.append(u'<td>%s</td>' % conditional_escape(content))
         output.append(u'</tr>')
     output.append(u'</table>')
     return mark_safe(u'\n'.join(output))
Beispiel #19
0
 class Meta:
     model = RareDiseaseReport
     fields = (
         'contribution_to_phenotype',
         'change_med',
         'clinical_trial',
         'requires_validation',
         'discussion',
         'action',
         'inform_reproductive_choice',
         'surgical_option',
         'add_surveillance_for_relatives',
         'classification',
         'id',
     )
     widgets = {
         'id': HiddenInput(),
         'surgical_option': CheckboxInput(),
         'requires_validation': Select(),
         'change_med': CheckboxInput(),
         'add_surveillance_for_relatives': CheckboxInput(),
         'clinical_trial': CheckboxInput(),
         'inform_reproductive_choice': CheckboxInput(),
         'discussion': Textarea(attrs={'rows': '4'}),
         'action': Textarea(attrs={'rows': '4'})
     }
Beispiel #20
0
 class Meta:
     model = BillModel
     fields = [
         'xref',
         'amount_due',
         'amount_paid',
         'paid',
         'paid_date',
         'progress',
         'progressible'
     ]
     widgets = {
         'xref': TextInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
                                  'placeholder': 'External Reference...'}),
         'date': DateInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
         'amount_due': TextInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES, 'placeholder': '$$$'}),
         'terms': Select(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
         'paid_date': DateInput(
             attrs={
                 'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
                 'placeholder': _('Date (YYYY-MM-DD)...')}
         ),
         'amount_paid': TextInput(
             attrs={
                 'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
             }),
         'progress': TextInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
         'progressible': CheckboxInput(attrs={'type': 'checkbox'}),
         'paid': CheckboxInput(attrs={'type': 'checkbox'}),
     }
Beispiel #21
0
    def get_selected_and_unselected(self, name, value, attrs):
        if value is None:
            value = []

        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, extra_attrs={'name': name})

        # Normalize to strings
        str_values = [force_text(v) for v in value]

        selected = []
        unselected = []

        for i, (option_value, option_label) in enumerate(chain(self.choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = ' for="%s"' % conditional_escape(final_attrs['id'])
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs,
                               check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_text(option_label))

            try:
                edit_link = reverse(
                    f'admin:{self.model_cls._meta.app_label}_{self.model_cls._meta.model_name}_change',
                    args=[option_value])
            except NoReverseMatch:
                edit_link = None

            item = {
                'label_for': label_for,
                'rendered_cb': rendered_cb,
                'option_label': option_label,
                'option_value': option_value,
                'edit_link': edit_link
            }

            if option_value in str_values:
                selected.append(item)
            else:
                unselected.append(item)

        # Reorder `selected` array according str_values which is a set of `option_value`s in the
        # order they should be shown on screen
        ordered = []

        for s in str_values:
            for select in selected:
                if s == select['option_value']:
                    ordered.append(select)

        selected = ordered

        return selected, unselected
Beispiel #22
0
 class Meta:
     model = ModuleSupport
     exclude = ('module', 'archive_flag', 'staging_flag', 'current_flag',
                'version_number', 'copy_number')
     widgets = {
         'lab_support_required':
         CheckboxInput(attrs={
             'data-toggle': 'collapse',
             'data-target': '#lab_support_collapse'
         }),
         'lab_support_skills':
         TextInput(attrs={'class': 'form-control form-control-sm'}),
         'lab_support_notes':
         Textarea(attrs={
             'rows': '3',
             'class': 'form-control form-control-sm'
         }),
         'tutorial_support_required':
         CheckboxInput(
             attrs={
                 'data-toggle': 'collapse',
                 'data-target': '#tutorial_support_collapse'
             }),
         'tutorial_support_skills':
         TextInput(attrs={'class': 'form-control form-control-sm'}),
         'tutorial_support_notes':
         Textarea(attrs={
             'rows': '3',
             'class': 'form-control form-control-sm'
         }),
     }
Beispiel #23
0
 class Meta:
     document = Application
     widgets = {
         'name': TextInput(attrs={'class': 'form-control'}),
         'tags': TextInput(attrs={'class': 'form-control'}),
         'public_name': TextInput(attrs={'class': 'form-control'}),
         'public_alias': TextInput(attrs={'class': 'form-control'}),
         'public_dir': TextInput(attrs={'class': 'form-control'}),
         'private_uri': TextInput(attrs={'class': 'form-control'}),
         'auth_timeout': TextInput(attrs={'class': 'form-control'}),
         'auth_portal': TextInput(attrs={'class': 'form-control'}),
         'sso_url': TextInput(attrs={'class': 'form-control'}),
         'app_krb_service': TextInput(attrs={'class': 'form-control'}),
         'app_disconnect_url': TextInput(attrs={'class': 'form-control'}),
         'sso_forward_basic_url':
         TextInput(attrs={'class': 'form-control'}),
         'sso_profile': HiddenInput(attrs={'class': 'form-control'}),
         'sso_after_post_request':
         TextInput(attrs={'class': 'form-control'}),
         'rules_set': SelectMultiple(attrs={'class': 'form-control'}),
         'whitelist_ips': TextInput(attrs={'class': 'form-control'}),
         'ssl_cipher': TextInput(attrs={'class': 'form-control'}),
         'datasets': SelectMultiple(attrs={'class': 'form-control'}),
         'timeout': TextInput(attrs={'class': 'form-control'}),
         'ttl': TextInput(attrs={'class': 'form-control'}),
         'sso_direct_post': CheckboxInput(attrs={'class': 'js-switch'}),
         'sso_forward_get_method':
         CheckboxInput(attrs={'class': 'js-switch'}),
         'pw_min_len': TextInput(attrs={'class': 'form-control'}),
         'pw_min_upper': TextInput(attrs={'class': 'form-control'}),
         'pw_min_lower': TextInput(attrs={'class': 'form-control'}),
         'pw_min_number': TextInput(attrs={'class': 'form-control'}),
         'pw_min_symbol': TextInput(attrs={'class': 'form-control'}),
         'group_registration': Select()
     }
Beispiel #24
0
    class Meta:
        model = InvoiceModel
        fields = [
            'amount_due',
            'amount_paid',
            'paid',
            'paid_date',
            'progress',
            'progressible'
        ]
        labels = {
            'progress': _('Progress Amount 0.00 -> 1.00 (percent)'),
            'amount_paid': _('Amount Received')
        }
        widgets = {
            'date': DateInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
            'amount_due': TextInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES, 'placeholder': '$$$'}),
            'terms': Select(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
            'paid_date': DateInput(
                attrs={
                    'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
                    'placeholder': _('Paid Date (YYYY-MM-DD)...')}
            ),
            'amount_paid': TextInput(
                attrs={
                    'class': DJANGO_LEDGER_FORM_INPUT_CLASSES
                }),
            'progress': TextInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
            'progressible': CheckboxInput(attrs={'type': 'checkbox'}),
            'paid': CheckboxInput(attrs={'type': 'checkbox'}),

        }
Beispiel #25
0
    class Meta:
        model = Ticket
        fields = ['queue',
                  'problems',
                  'submitter_name',
                  'submitter_company',
                  'submitter_phone',
                  'submitter_email',
                  'status',
                  'priority',
                  'tecnico_pre_diagnostico',
                  'tecnico_de_campo',
                  'is_customer',
                  'customer_code',
                  'order',
                  'need_paper',
                  'resolution_report', ]

        widgets = {
            'queue': Select(attrs={'class': 'form-control', 'placeholder': 'Queue'}),
            'problems': CheckboxSelectMultiple(attrs={'class': 'form-control'}),
            'submitter_name': TextInput(attrs={'class': 'form-control'}),
            'submitter_company': TextInput(attrs={'class': 'form-control'}),
            'submitter_phone': TextInput(attrs={'class': 'form-control'}),
            'submitter_email': EmailInput(attrs={'class': 'form-control'}),
            'status': Select(attrs={'class': 'form-control', 'placeholder': 'Status'}),
            'priority': Select(attrs={'class': 'form-control', 'placeholder': 'Prioridade'}),
            'tecnico_pre_diagnostico': Select(attrs={'class': 'form-control', 'placeholder': 'Pré diagnostico'}),
            'tecnico_de_campo': Select(attrs={'class': 'form-control', 'placeholder': 'Tecnico de campo'}),
            'is_customer': CheckboxInput(attrs={'class': 'form-control'}),
            'customer_code': TextInput(attrs={'class': 'form-control'}),
            'order': TextInput(attrs={'class': 'form-control'}),
            'need_paper': CheckboxInput(attrs={'class': 'form-control'}),
            'resolution_report': Textarea(attrs={'class': 'form-control'})
        }
Beispiel #26
0
 def render(self, name, value, attrs=None, choices=()):
     if value is None:
         value = []
     has_id = attrs and 'id' in attrs
     final_attrs = self.build_attrs(attrs, name=name)
     output = []
     # Normalize to strings.
     str_values = set([force_unicode(v) for v in value])
     for i, (option_value, item) in enumerate(self.choices):
         # If an ID attribute was given, add a numeric index as a suffix,
         # so that the checkboxes don't all have the same ID attribute.
         if has_id:
             final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
         cb = CheckboxInput(final_attrs,
                            check_test=lambda value: value in str_values)
         option_value = force_unicode(option_value)
         rendered_cb = cb.render(name, option_value)
         output.append(u'<tr><td class="row-select">%s</td>' % rendered_cb)
         for attr in self.item_attrs:
             if callable(attr):
                 content = attr(item)
             elif hasattr(item, attr):
                 if callable(getattr(item, attr)):
                     content = getattr(item, attr)()
                 else:
                     content = getattr(item, attr)
             else:
                 content = item[attr]
             if not isinstance(content, SafeText):
                 content = escape(content)
             output.append(u'<td>%s</td>' % content)
         output.append(u'</tr>')
     return mark_safe(u'\n'.join(output))
Beispiel #27
0
    def test_render_check_exception(self):
        """
        Calling check_test() shouldn't swallow exceptions (#17888).
        """
        widget = CheckboxInput(
            check_test=lambda value: value.startswith('hello'), )

        with self.assertRaises(AttributeError):
            widget.render('greeting', True)
Beispiel #28
0
 class Meta:
     model = BillModel
     fields = [
         'xref', 'amount_due', 'amount_paid', 'paid', 'paid_date',
         'progress', 'accrue', 'bill_status', 'terms', 'markdown_notes'
     ]
     widgets = {
         'xref':
         TextInput(
             attrs={
                 'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
                 'placeholder': 'External Reference...'
             }),
         'date':
         DateInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
         'amount_due':
         TextInput(attrs={
             'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
             'placeholder': '$$$'
         }),
         'terms':
         Select(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
         'bill_status':
         Select(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
         'paid_date':
         DateInput(
             attrs={
                 'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
                 'placeholder': _('Date (YYYY-MM-DD)...')
             }),
         'amount_paid':
         TextInput(attrs={
             'class': DJANGO_LEDGER_FORM_INPUT_CLASSES,
         }),
         'progress':
         TextInput(attrs={'class': DJANGO_LEDGER_FORM_INPUT_CLASSES}),
         'accrue':
         CheckboxInput(attrs={'type': 'checkbox'}),
         'paid':
         CheckboxInput(attrs={'type': 'checkbox'}),
         'cash_account':
         Select(attrs={
             'class': DJANGO_LEDGER_FORM_INPUT_CLASSES + ' is-danger'
         }),
         'prepaid_account':
         Select(attrs={
             'class': DJANGO_LEDGER_FORM_INPUT_CLASSES + ' is-danger'
         }),
         'unearned_account':
         Select(attrs={
             'class': DJANGO_LEDGER_FORM_INPUT_CLASSES + ' is-danger'
         }),
         'markdown_notes':
         Textarea(attrs={'class': 'textarea'})
     }
     labels = {'progress': 'Bill Progress Amount (%)'}
Beispiel #29
0
    class Meta:
        model = GoalkeeperGame
        exclude = ('game_type', 'phase', 'read_seq')

        widgets = {
            'config':
            Select(attrs={'class': 'form-control'}),
            'number_of_directions':
            Select(attrs={'class': 'form-control'}),
            'number_of_plays':
            NumberInput(attrs={'class': 'form-control'}),
            'min_hits':
            NumberInput(attrs={'class': 'form-control'}),
            'min_hits_in_seq':
            NumberInput(attrs={'class': 'form-control'}),
            'sequence':
            TextInput(attrs={'class': 'form-control'}),
            'plays_to_relax':
            NumberInput(attrs={'class': 'form-control'}),
            'play_pause':
            CheckboxInput(attrs={'class': 'form-control'}),
            'play_pause_key':
            TextInput(attrs={'class': 'form-control'}),
            'player_time':
            NumberInput(attrs={'class': 'form-control'}),
            'celebration_time':
            NumberInput(attrs={'class': 'form-control'}),
            'score_board':
            CheckboxInput(attrs={'class': 'form-control'}),
            'final_score_board':
            Select(attrs={'class': 'form-control'}),
            'left_key':
            TextInput(attrs={'class': 'form-control'}),
            'center_key':
            TextInput(attrs={'class': 'form-control'}),
            'right_key':
            TextInput(attrs={'class': 'form-control'}),
            'depth':
            NumberInput(attrs={
                'class': 'form-control',
                'readonly': 'readonly'
            }),
            'seq_step_det_or_prob':
            TextInput(attrs={
                'class': 'form-control',
                'readonly': 'readonly'
            }),
            'create_seq_manually':
            Select(attrs={'class': 'form-control'}),
            'show_history':
            CheckboxInput(attrs={'class': 'form-control'}),
            'send_markers_eeg':
            TextInput(attrs={'class': 'form-control'}),
            'port_eeg_serial':
            TextInput(attrs={'class': 'form-control'}),
        }
Beispiel #30
0
    def test_render_check_exception(self):
        """
        Calling check_test() shouldn't swallow exceptions (#17888).
        """
        widget = CheckboxInput(
            check_test=lambda value: value.startswith('hello'),
        )

        with self.assertRaises(AttributeError):
            widget.render('greeting', True)
Beispiel #31
0
 class Meta:
     model = Utilisateur
     fields = ["nom_utilisateur", "mdp_utilisateur", "actif_utilisateur", "est_admin"]
     widgets = {
         'nom_utilisateur': TextInput(attrs={'class': 'blue-text text-darken-4'}),
         'mdp_utilisateur': PasswordInput(attrs={'class': 'blue-text text-darken-4'}),
         'confirmMdpUtilisateur': PasswordInput(attrs={'class': 'blue-text text-darken-4'}),
         'actif_utilisateur' : CheckboxInput(),
         'est_admin': CheckboxInput()
     }
Beispiel #32
0
 class Meta:
     model = ModuleChangeSummary
     exclude = ('module', 'archive_flag', 'staging_flag', 'current_flag',
                'version_number', 'copy_number')
     widgets = {
         'changes_to_outcomes':
         CheckboxInput(
             attrs={
                 'data-toggle': 'collapse',
                 'data-target': '#changes_to_outcomes_collapse'
             }),
         'changes_to_outcomes_desc':
         Textarea(attrs={
             'rows': '2',
             'class': 'form-control form-control-sm'
         }),
         'changes_to_teaching':
         CheckboxInput(
             attrs={
                 'data-toggle': 'collapse',
                 'data-target': '#changes_to_teaching_collapse'
             }),
         'changes_to_teaching_desc':
         Textarea(attrs={
             'rows': '2',
             'class': 'form-control form-control-sm'
         }),
         'changes_to_assessments':
         CheckboxInput(
             attrs={
                 'data-toggle': 'collapse',
                 'data-target': '#changes_to_assessments_collapse'
             }),
         'changes_to_assessments_desc':
         Textarea(attrs={
             'rows': '2',
             'class': 'form-control form-control-sm'
         }),
         'changes_other':
         CheckboxInput(
             attrs={
                 'data-toggle': 'collapse',
                 'data-target': '#changes_other_collapse'
             }),
         'changes_other_desc':
         Textarea(attrs={
             'rows': '2',
             'class': 'form-control form-control-sm'
         }),
         'changes_rationale':
         Textarea(attrs={
             'rows': '2',
             'class': 'form-control form-control-sm'
         })
     }
Beispiel #33
0
 class Meta:
     model = Instructor
     fields = ['hobbies', 'profile_picture', 'first_name', 'last_name', 'city', 'city_district', 'zip_code', 'description', 'is_private_instructor', 'work_in_student_home', 'work_in_instructor_home', 'maximum_students', 'price', 'price_model']
     widgets = {
         'first_name': TextInput(attrs={'class': 'form-control', 'placeholder': 'Förnamn'}),
         'last_name': TextInput(attrs={'class': 'form-control', 'placeholder': 'Efternamn'}),
         'hobbies': RadioSelect(),
         'city': TextInput(attrs={'class': 'form-control', 'placeholder': 'Stad... ex. Stockholm, Göteborg...'}),
         'city_district': TextInput(attrs={'class': 'form-control', 'placeholder': 'Kommun: ex. Sollentuna, Täby...'}),
         'zip_code': TextInput(attrs={'class': 'form-control', 'placeholder': 'Postnummer: ex. 123 45...'}),
         'description': Textarea(attrs={'class': 'form-control', 'placeholder': 'Kort biografi om dig själv: Hej...', 'rows':20}),
         'is_private_instructor': CheckboxInput(attrs={'class': 'bootstrap-switch', 'data-on-label': 'JA', 'data-off-label': 'NEJ', 'onchange': 'hide_show_instructor_fields()'}),
         'work_in_student_home': CheckboxInput(),
         'work_in_instructor_home': CheckboxInput(),
         'maximum_students': NumberInput(attrs={'class': 'form-control', 'placeholder': 'Antal personer jag klan lära ut till per tillfälle'}),
         'price': NumberInput(attrs={'class': 'form-control', 'placeholder': 'Pris per timme'}),
         'price_model': RadioSelect(),
     }
     error_messages = {
         'first_name': {
             'required': _('Du måste fylla i ditt förnamn'),
             'max_length': _('Texten du skrev in här var för långt'),
         },
         'last_name': {
             'required': _('Du måste fylla i ditt efternamn'),
             'max_length': _('Texten du skrev in här var för långt'),
         },
         'hobbies': {
             'required': _('Du måste välja en hobby'),
         },
         'city': {
             'required': _('Du måste fylla i din stad'),
             'max_length': _('Texten du skrev in här var för långt'),
         },
         'city_district': {
             'required': _('Du måste fylla i din kommun/stadsdel'),
             'max_length': _('Texten du skrev in här var för långt'),
         },
         'zip_code': {
             'required': _('Du måste fylla i ditt postnummer'),
             'max_length': _('Texten du skrev in här var för långt'),
         },
         'description': {
             'max_length': _('Texten du skrev in här var för långt, max 2500 tecken'),
         },
         'work_in_student_home': {
         },
         'work_in_instructor_home': {
         },
         'maximum_students': {
             'required': _('Du måste fylla i hur många hobbyister du kan ta per gång'),
             'max_length': _('Texten du skrev in här var för långt'),
         },
     }
Beispiel #34
0
    def render(self, name, value, attrs=None, choices=(), new_maps=()):
        if value is None:
            value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)

        # Normalize to strings
        str_values = [force_text(v) for v in value]

        vals = []
        last_uimap = 0

        for i, (option_value, option_label) in enumerate(chain(self.choices,
                                                               choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = ' for="%s"' % conditional_escape(final_attrs['id'])
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs,
                               check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_text(option_label))
            item = {'label_for': label_for, 'rendered_cb': rendered_cb,
                    'option_label': option_label, 'option_value': option_value}
            vals.append(item)
            last_uimap += 1

        for i, newmap in enumerate(new_maps):

            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'],
                                                              i + last_uimap))
                label_for = ' for="%s"' % conditional_escape(final_attrs['id'])
            else:
                label_for = ''
            cb = CheckboxInput(final_attrs,
                               check_test=lambda l: False)
            option_value = 't' + str(newmap.id)
            rendered_cb = cb.render(name, option_value)
            option_label = newmap.__unicode__()
            option_label = conditional_escape(force_text(option_label))
            item = {'label_for': label_for, 'rendered_cb': rendered_cb,
                    'option_label': option_label, 'option_value': option_value}
            vals.append(item)

        html = render_to_string(
            'sortedm2m/sorted_checkbox_select_multiple_widget.html',
            {'vals': vals, })
        return mark_safe(html)
    def render_body(self, name, value, attrs):
        output = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        str_values = set([force_text(v) for v in value])
        for i, (pk, item) in enumerate(self.choices):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='{}_{}'.format(attrs['id'], i))
            item = self.choices.queryset.get(pk=pk)
            cb = CheckboxInput(final_attrs,
                               check_test=lambda value: value in str_values)
            option_value = force_text(pk)
            rendered_cb = cb.render(name, option_value)
            # Custom checkbox wrapper for Shopify Styling.
            pre_rendered_cb = \
                """<tr>
                <td>
                    <label class="Polaris-Choice Polaris-Choice--labelHidden" for="{0}">
                        <div class="Polaris-Choice__Control">
                            <div class="Polaris-Checkbox">
                                {1}
                                    <div class="Polaris-Checkbox__Backdrop"></div>
                                <div class="Polaris-Checkbox__Icon">
                                    <span class="Polaris-Icon">
                                        <svg class="Polaris-Icon__Svg" viewBox="0 0 20 20">
                                            <g fill-rule="evenodd">
                                                <path d="M8.315 13.859l-3.182-3.417a.506.506 0 0 1 0-.684l.643-.683a.437.437 0 0 1 .642 0l2.22 2.393 4.942-5.327a.437.437 0 0 1 .643 0l.643.684a.504.504 0 0 1 0 .683l-5.91 6.35a.437.437 0 0 1-.642 0"></path><path d="M8.315 13.859l-3.182-3.417a.506.506 0 0 1 0-.684l.643-.683a.437.437 0 0 1 .642 0l2.22 2.393 4.942-5.327a.437.437 0 0 1 .643 0l.643.684a.504.504 0 0 1 0 .683l-5.91 6.35a.437.437 0 0 1-.642 0"></path>
                                            </g>
                                        </svg>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div class="Polaris-Choice__Label"></div>
                    </label>
                </td>""".format('{}_{}'.format(attrs['id'], i), rendered_cb)

            pre_rendered_cb = pre_rendered_cb.replace('class="tableselectmultiple"','class="Polaris-Checkbox__Input"')

            output.append(pre_rendered_cb)

            for attr in self.item_attrs:
                if callable(attr):
                    content = attr(item)
                elif callable(getattr(item, attr)):
                    content = getattr(item, attr)()
                else:
                    content = getattr(item, attr)
                output.append('<td>{}</td>'.format(escape(content)))
            output.append('</tr>')
        output.append('</tbody>')
        return ''.join(output)
Beispiel #36
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<ul>']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])

        no = 0
        previous_node_depth = 0
        
        walk_list = getattr(self, "walk_list", [])
        
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            if walk_list and len(walk_list) > no:
                # special case is special
                if walk_list[no].tree_path == "":
                    node_depth = 0
                else:
                    node_depth = len(walk_list[no].tree_path.split("/"))
            else:
                node_depth = 0

            if node_depth < previous_node_depth:
                output.append((u'</ul>'*(previous_node_depth-node_depth)))

            if node_depth > previous_node_depth:
                output.append(u'<ul>')

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))
            output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))

            previous_node_depth = node_depth
            no += 1
        
        # It's tree baby! There is no root at the end
        if 0 < previous_node_depth:
            output.append((u'</ul>'*(previous_node_depth)))

        output.append(u'</ul>')
        return mark_safe(u'\n'.join(output))
Beispiel #37
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [_table_header % {"name": attrs["id"]}]
        # Normalize to strings
        str_values = set([force_text(v) for v in value])

        extra_class = "check_%s" % attrs["id"]
        if "class" in final_attrs:
            final_attrs["class"] = "%s %s" % (final_attrs["class"], extra_class)
        else:
            final_attrs["class"] = extra_class

        for i, (option_value, option_object) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = format_html(' for="{0}"', final_attrs['id'])
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            distance = "0 m"
            description = "?"
            if len(option_object.runs.all()):
                distances = list(set([run.distance for run in option_object.runs.all()]))
                distance = ", ".join(["%d m" % d for d in distances])
                description = "; ".join(run.name for run in option_object.runs.all())
            distance = force_text(distance)
            description = smart_text(description)

            tr_id = "select_line_%s" % final_attrs["id"]
            output.append(
                format_html(
                    u'<tr id="{5}" class="entry"><td>{0}</td><td>{1}</td><td><label{2}>{3}</label></td><td>{4}</td></tr>',
                    rendered_cb,
                    force_text(option_object.start_time),
                    label_for,
                    distance,
                    description,
                    tr_id))
        output.append(format_html(
            u'<tr class="lastline"><td colspan="4" class="alert alert-success">bitte erst oben ausfüllen</td></tr>'))
        output.append(_table_footer)
        output.append(_check_js % {"name": attrs["id"], "class": extra_class})
        return mark_safe('\n'.join(output))
Beispiel #38
0
    def render_checkbox(self, output, has_id, final_attrs, attrs, i, str_values, option_value, name, option_label):
        # If an ID attribute was given, add a numeric index as a suffix,
        # so that the checkboxes don't all have the same ID attribute.
        if has_id:
            final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
            label_for = u' for="%s"' % final_attrs['id']
        else:
            label_for = ''

        cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
        option_value = force_unicode(option_value)
        rendered_cb = cb.render(name, option_value)
        option_label = conditional_escape(force_unicode(option_label))
        output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
Beispiel #39
0
    def render(self, name, value, attrs=None, choices=()):
        cs = []
        for c in self.choices:
            c = list(c)
            c.append(True)
            cs.append(c)

        dps = Daypart.objects.active()
        cs = []
        t_dp_day = None
        for dp in dps:
            row_title = False
            if not t_dp_day == dp.get_day_display():
                row_title = dp.get_day_display()
                t_dp_day = dp.get_day_display()

            c = [dp.pk, '%02d - %02d' % (dp.time_start.hour, dp.time_end.hour), row_title]
            cs.append(c)

        self.choices = cs

        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<ul class="unstyled" style="float: left;">']
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value, option_label, row_title) in enumerate(chain(self.choices, choices)):
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))

            if row_title:
                output.append(u'</ul><ul class="unstyled" style="float: left;"><li class="title">%s</li>' % row_title)

            output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))

        return mark_safe(u'\n'.join(output))
Beispiel #40
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_cb = cb.render(name, option_value)
            output.append(u'<td>%s</td>' % rendered_cb)
        output.append(u'')
        return mark_safe(u'\n'.join(output))
Beispiel #41
0
 def render(self, name, value, attrs=None, choices=()):
     if value is None:
         value = []
     has_id = attrs and 'id' in attrs
     final_attrs = self.build_attrs(attrs, name=name)
     output = []
     # Normalize to strings.
     str_values = set([force_unicode(v) for v in value])
     for i, (option_value, item) in enumerate(self.choices):
         # If an ID attribute was given, add a numeric index as a suffix,
         # so that the checkboxes don't all have the same ID attribute.
         if has_id:
             final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
         cb = CheckboxInput(
             final_attrs,
             check_test=lambda value: value in str_values)
         option_value = force_unicode(option_value)
         rendered_cb = cb.render(name, option_value)
         output.append(u'<tr>')
         output.append(u'<td class="row-select">%s</td>' % rendered_cb)
         for attr in self.item_attrs:
             css_name = attr
             if callable(attr):
                 content = attr(item)
                 css_name = attr.__name__.strip("_")
             elif hasattr(item, attr):
                 if callable(getattr(item, attr)):
                     content = getattr(item, attr)()
                 else:
                     content = getattr(item, attr)
             else:
                 content = item[attr]
             if not isinstance(content, SafeText):
                 content = escape(content)
             css = (
                 ' class="field-%s"'
                 % css_name.lower().replace("_", "-").replace(" ", "-"))
             output.append(u'<td%s>%s</td>' % (css, content))
         output.append(u'</tr>')
     return mark_safe(u'\n'.join(output))
Beispiel #42
0
 def render(self, name, value, attrs=None, choices=()):
     if value is None: value = []
     has_id = attrs and 'id' in attrs
     final_attrs = self.build_attrs(attrs, name=name)
     output = []
     str_values = set([force_text(v) for v in value])  # Normalize to strings.
     for i, (option_value, item) in enumerate(self.choices):
         if has_id:
             final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
         cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
         option_value = force_text(option_value)
         rendered_cb = cb.render(name, option_value)
         output.append(u'<tr><td>%s</td>' % rendered_cb)
         for attr in self.item_attrs:
             if callable(attr):
                 content = attr(item)
             elif callable(getattr(item, attr)):
                 content = getattr(item, attr)()
             else:
                 content = getattr(item, attr)
             output.append(u'<td>%s</td>' % escape(content))
         output.append(u'</tr>')
     return mark_safe(u'\n'.join(output))
Beispiel #43
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<div class="check-holder"><div class="check-row">']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))
            output.append(u'<label%s>%s<span class="label-text">%s</span></label>' % (label_for, rendered_cb, option_label))
        output.append(u'</div></div>')
        return mark_safe(u'\n'.join(output))
Beispiel #44
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = ['<div>']
        # Normalize to strings
        str_values = set([force_text(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = format_html(' for="{0}" class="checkbox-inline"', final_attrs['id'])
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_text(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = force_text(option_label)
            output.append(format_html('<label{0}>{1} <span>{2}</span></label>',
                                      label_for, rendered_cb, str(option_label)))
        output.append('</div>')
        return mark_safe('\n'.join(output))
Beispiel #45
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []
        has_id = attrs and "id" in attrs
        final_attrs = self.build_attrs(attrs, name=name)

        # set up output attributes
        html = u""
        table_rows = u""

        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])

        # setup the id attr
        if has_id:
            id = attrs["id"]
        else:
            id = u""

        # set up the html for output
        html += """
            <table border="0" cellspacing="0" cellpadding="0" id="%(id)s">
            <tr>
                <th class="header-col-1">&nbsp;</th>
                <th class="header-col-2">View</th>
                <th class="header-col-3">Change</th>
            </tr>
            %(table_rows)s
            </table>
        """
        for i, (group_name, group) in enumerate(groupby(self.choices, lambda x: x[1])):
            view_input_value = force_unicode(group.next()[0])
            change_input_value = force_unicode(group.next()[0])

            if has_id:
                final_attrs = dict(final_attrs, id="%s_%s" % (attrs["id"], i))

            cb_view = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            cb_change = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            rendered_cb_view = cb_view.render(name, view_input_value)
            rendered_cb_change = cb_change.render(name, change_input_value)

            if (i % 2) == 0:
                tr_class = ' class="alt" '
            else:
                tr_class = ""

            table_rows += """
                <tr%(tr_class)s>
                    <td>%(group_name)s</td>
                    <td>%(view_checkbox)s</td>
                    <td>%(change_checkbox)s</td>
                </tr>
            """ % {
                "tr_class": tr_class,
                "group_name": conditional_escape(force_unicode(group_name)),
                "view_checkbox": rendered_cb_view,
                "change_checkbox": rendered_cb_change,
            }

        html = html % {"id": id, "table_rows": table_rows}
        return mark_safe(html)
Beispiel #46
0
    def render(self, name, value, attrs=None, choices=()):
        """
            renders the widget.
        """
        def update_dictionary( d, item_label, checkbox, label_for, motherlist = [] ):
                b = d
                # item_label = item_label.strip()
                for mother in motherlist:
                    mother = mother.strip()
                    if mother in b.keys():
                        b = b[mother]['children']
                    else:
                        m = { 'label': u'', 'checkbox': u'', 'label_for': u'', 'children': {} }
                        b[mother] = m
                        b = m['children']
                if item_label in b.keys():
                    b[item_label]['label'] = conditional_escape(force_unicode( item_label ))
                    b[item_label]['checkbox'] = checkbox
                    b[item_label]['label_for'] = label_for
                else:
                    i = { 'label': conditional_escape(force_unicode( item_label )) , 
                          'checkbox': checkbox, 
                          'label_for': label_for,
                          'children': {} }
                    b[item_label] = i
                return d
        def write_output_old( out, item, depth = 0 ):
            if depth:
                out.append(u'<li>%s <label%s>%s %s</label></li>' % (
                                '.' * depth * 3,
                                item['label_for'], item['checkbox'], item['label']) )
            else:
                out.append(u'<li><label%s>%s %s</label></li>' % (
                                item['label_for'], item['checkbox'], item['label']) )
            
            for i in item['children'].keys():
                write_output_old( out, item['children'][i], depth+1)
        def write_output( out, item, depth = 0 ):
            out.append(u'<tr><td style="padding: 5px 0 5px %spx;">%s %s</label></td></tr>' % (
                                str(5 + depth * 20),
                                item['checkbox'], item['label']) )
            
            for i in item['children'].keys():
                write_output( out, item['children'][i], depth+1)
                        
        
        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        # output = [u'<ul>']
        output = ['<table><tbody>']
        output_inner = {}
        # output_debug = "DEBUG: "
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            # If an ID attribute was given, add a numeric index as a suffix,
            # so that the checkboxes don't all have the same ID attribute.
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            
            option_value = force_unicode(option_value)
            rendered_cb = cb.render(name, option_value)
            
            option_label = force_unicode(option_label)
            temp = option_label.split( self.split_char )
            mothers = []
            if len(temp) > 1:
                mothers = temp[:-1]
            actual_name = temp[-1].strip()
            # now we search the node we insert this checkbox.
            # entry = { 'checkbox': cb, 'label': escaped..., children: {} }
            update_dictionary( output_inner, actual_name, rendered_cb, label_for, mothers )
            
        for i in output_inner.keys():
            write_output(output, output_inner[i], 0)
        
        output.append(u'</tbody></table>')
        return mark_safe(u'\n'.join(output))