class UserPermissionsForm(forms.ModelForm):
    """
    Custom user form based on the User model
    """
    # attributes
    checkbox_attr = {'class': 'form-check-input'}

    is_module_leader = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_office_admin = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_year_tutor = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_module_reviewer = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_admin = forms.BooleanField(required=False,
                                  widget=CheckboxInput(attrs=checkbox_attr))

    class Meta:
        model = User
        fields = ('is_module_leader', 'is_office_admin', 'is_year_tutor',
                  'is_module_reviewer', 'is_admin')
Пример #2
0
 class Meta:
     model = Setting
     fields = ('hidden_note', 'wallpaper', 'theme')
     widgets = {
         'wallpaper': FileInput(),
         'hidden_note': CheckboxInput(attrs={'id': 'hidden_note_id'}),
         'theme': CheckboxInput(attrs={'id': 'theme_id'}),
     }
Пример #3
0
 class Meta:
     model = ServiceProvider
     fields = [
         'uses_ldapauth', 'server_names', 'target_group', 'service_account',
         'service_account_contact', 'can_access_all_ldap_groups',
         'local_storage_users', 'local_storage_passwords',
         'local_storage_passwords_info', 'local_storage_groups',
         'admin_require_manual_configuration', 'production'
     ]
     widgets = {
         'service_account_contact':
         Textarea(attrs={'rows': 2}),
         'local_storage_passwords_info':
         Textarea(attrs={'rows': 5}),
         'service_account':
         CheckboxInput(attrs={'class': 'hideCheck1'}),
         'local_storage_passwords':
         CheckboxInput(attrs={'class': 'hideCheck2'}),
     }
     help_texts = {
         'uses_ldapauth':
         _('Does this service use the LDAPAuth proxy in order to access '
           'user and group data for authentication and access control?'),
         'server_names':
         _('Full server names (not IPs), separated by space. User for access '
           'control.'),
         'target_group':
         _('What is the target group (users) of this service?'),
         'service_account':
         _('Separate service account is used for LDAP queries (recommended way).'
           ),
         'service_account_contact':
         _('Email and phone number for delivering service account '
           'credentials. Use a [email protected] '
           'address and the same person\'s mobile phone in '
           'non-international format, that is, start it with 0. '
           'Separete the email and phone number by space.'),
         'can_access_all_ldap_groups':
         _('Service requires access to all LDAP groups.'),
         'local_storage_users':
         _('Service stores all users and released attributes locally. '
           'If you only save user data when user logs in, do not check '
           'this.'),
         'local_storage_passwords':
         _('Service stores user passwords locally.'),
         'local_storage_passwords_info':
         _('Why is this service storing user passwords '
           'locally and how? This is not generally a good '
           'idea.'),
         'local_storage_groups':
         _('Service stores requested groups and their member lists '
           'locally.'),
         'admin_require_manual_configuration':
         _('This service provider requires manual configuration. '
           'Set by registry admins if necessary.'),
         'production':
         _('Publish this service to LDAP production servers.'),
     }
Пример #4
0
 class Meta:
     model = Character
     fields = [
         'name', 'char_class', 'level', 'expansion', 'hardcore', 'ladder'
     ]
     widgets = {
         "ladder": CheckboxInput(attrs={'checked': False}),
         "expansion": CheckboxInput(attrs={'checked': True}),
         "hardcore": CheckboxInput(attrs={'checked': False})
     }
class UserCreationForm(forms.ModelForm):
    """
    Form that is used to create new users.
    """
    # Note: Originally this was a combination of the two forms.
    # It turns out there is an issue with multiple inheritance
    # with forms. To resolve it is fairly complicated, so for the time
    # I have created a form that just contains every attribute.

    checkbox_attr = {'class': 'form-check-input'}

    attrs = {'class': 'form-control'}
    username = forms.CharField(required=True, widget=TextInput(attrs=attrs))
    first_name = forms.CharField(required=True, widget=TextInput(attrs=attrs))
    last_name = forms.CharField(required=True, widget=TextInput(attrs=attrs))
    email = forms.EmailField(required=True, widget=TextInput(attrs=attrs))

    # permissions
    is_module_leader = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_office_admin = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_year_tutor = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_module_reviewer = forms.BooleanField(
        required=False, widget=CheckboxInput(attrs=checkbox_attr))

    is_admin = forms.BooleanField(required=False,
                                  widget=CheckboxInput(attrs=checkbox_attr))

    class Meta:
        model = User
        fields = ('username', 'first_name', 'last_name', 'email',
                  'is_module_leader', 'is_office_admin', 'is_year_tutor',
                  'is_module_reviewer', 'is_admin')

    def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)

        password = User.objects.make_random_password()
        user.set_password(password)

        # prepare the email
        mail = UserPasswordEmail(user, password)

        if commit:
            # save user and send the email
            user.save()
            mail.send()
        return user
Пример #6
0
    class Meta:
        model = Article

        fields = [
            'title', 'sw_title', 'cover_photo', 'content', 'sw_content',
            'category', 'belong_to', 'active',
            'display_cover_photo_on_view_article'
        ]
        widgets = {
            'title':
            TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'enter title'
            }),
            'sw_title':
            TextInput(
                attrs={
                    'class': 'form-control',
                    'placeholder': 'ingiza kichwa cha makala',
                    'required': 'true'
                }),
            'cover_photo':
            FileInput(attrs={
                'class': 'form-control',
                'placeholder': 'enter cover photo'
            }),
            'content':
            Textarea(
                attrs={
                    'class': 'form-control no-resize summernote',
                    'placeholder': 'Please type what you want...',
                    'rows': 40,
                    'style': 'display: none;'
                }),
            'sw_content':
            Textarea(
                attrs={
                    'class': 'form-control no-resize summernote',
                    'placeholder': 'Tafadhali andika unachotaka...',
                    'rows': 40,
                    'style': 'display: none;',
                    'required': 'true'
                }),
            'belong_to':
            Select(attrs={'class': 'form-control show-tick'}),
            'category':
            Select(attrs={'class': 'form-control show-tick'}),
            'active':
            CheckboxInput(attrs={'id': 'checkbox'}),
            'display_cover_photo_on_view_article':
            CheckboxInput(attrs={'id': 'checkbox1'}),
        }
 class Meta:
     model = Diarrhea_Symptom
     exclude = ['symptom']
     widgets = {
         'vomit': CheckboxInput(attrs={'class': 'form-check-input'}),
         'flux_stool': CheckboxInput(attrs={'class': 'form-check-input'}),
         'fever': CheckboxInput(attrs={'class': 'form-check-input'}),
         'diarrhea_amount': NumberInput(attrs={'class': 'form-control'}),
         'diarrhea_detail': TextInput(attrs={'class': 'form-control'}),
         'stomachache': TextInput(attrs={'class': 'form-control'}),
         'bowel_sound': TextInput(attrs={'class': 'form-control'}),
         'current_history': Textarea(attrs={'class': 'form-control','rows':"15", 'cols':"4"})      
     }
Пример #8
0
class RetailCuttingPatternOutputForm(forms.ModelForm):
    # Use of check_test in widget because that fields are integer in model
    is_for_cradle = forms.BooleanField(label="Cradle?", required=False, widget=CheckboxInput(check_test=lambda x: (x or 0) % 2 == 1))
    is_primary = forms.BooleanField(label="Primary?", required=False, widget=CheckboxInput(check_test=lambda x: (x or 0) % 2 == 1))

    class Meta:
        model = RetailCuttingPatternOutput

    class Media:
        css = {
            'all': ('django_bootstrap_dynamic_formsets/extra.css',)
        }
        # jquery-ui is required for django-bootstrap-dynamic-formset
        js = ('bower_components/jquery-ui/jquery-ui.min.js',)
 class Meta:
     model = Rash_Symptom
     exclude = ['symptom']
     widgets = {
         'rash_area': TextInput(attrs={'class': 'form-control'}),
         'rash_date': NumberInput(attrs={'class': 'form-control'}),
         'itch': CheckboxInput(attrs={'class': 'form-check-input'}),
         'pain': CheckboxInput(attrs={'class': 'form-check-input'}),
         'sting': CheckboxInput(attrs={'class': 'form-check-input'}),
         'fever': CheckboxInput(attrs={'class': 'form-check-input'}),
         'swell': CheckboxInput(attrs={'class': 'form-check-input'}),
         'rash_detail': TextInput(attrs={'class': 'form-control'}),    
         'pe': Textarea(attrs={'class': 'form-control', 'rows':'6', 'cols': '4'}),        
     }
 class Meta:
     model = Wound_Symptom
     exclude = ['symptom']
     widgets = {
         'emergency': CheckboxInput(attrs={'class': 'form-check-input'}),
         'insurance': CheckboxInput(attrs={'class': 'form-check-input'}),
         'is_safety': CheckboxInput(attrs={'class': 'form-check-input'}),
         'wound_area': TextInput(attrs={'class': 'form-control'}),
         'wound_date': DateInput(attrs={'class': 'form-control','type':'date'}),
         'wound_locale': TextInput(attrs={'class': 'form-control'}),
         'is_treat_before': CheckboxInput(attrs={'class': 'form-check-input'}),
         'treatment_before_detail': TextInput(attrs={'class': 'form-control'}),    
         'time': TimeInput(attrs={'class': 'form-control','type':'time'}),        
     }
Пример #11
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="row">']
        # 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 = u' for="%s"' % 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))
            output.append(u'<div class="span2"><label%s>%s %s</label></div>' %
                          (label_for, rendered_cb, option_label))
            ultimo_fila = (((i + 1) % 6) == 0)
            if ultimo_fila:
                output.append(u'</div>')
                output.append(u'<div class="row">')
        # Normalize to strings
        output.append(u'</div>')
        return mark_safe(u'\n'.join(output))
Пример #12
0
    def render(self, name, value, attrs=None):
        substitutions = {
            #uncomment to get 'Currently'
            'initial_text': "",  # self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = (
                '<img src="%s" alt="%s"/>' %
                (escape(value.url), escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions[
                    'clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions)
Пример #13
0
    def render(self, name, value, attrs=None,):

        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = u'%(input)s'

        substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs)

        if value and hasattr(value, "url"):

            template = self.template_with_initial
            if self.preview:
                substitutions['initial'] = (u'<a href="{0}">{1}</a><br /><br />\
                <a href="{0}" target="_blank"><img src="{0}" alt="" width="{2}" /></a><br /><br />'.format
                    (escape(value.url),'...'+escape(force_unicode(value))[-self.url_length:],
                     self.image_width))
            else:
                substitutions['initial'] = (u'<a href="{0}">{1}</a>'.format
                    (escape(value.url),'...'+escape(force_unicode(value))[-self.url_length:]))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
                substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions)
Пример #14
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 = ['<ul %s>' % flatatt(self.settings)]
        # 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}"', 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('<li><label{0}>{1} {2}</label></li>', label_for,
                            rendered_cb, option_label))
        output.append('</ul>')
        return mark_safe('\n'.join(output))
Пример #15
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = u'%(input)s'
        substitutions['input'] = super(ClearableFileInput,
                                       self).render(name, value, attrs)

        if value and hasattr(value, "url"):
            template = self.template_with_initial

            substitutions['initial'] = get_attachment_filename_from_url(
                force_unicode(value))

            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions[
                    'clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions)
Пример #16
0
    def render(self, name, value, attrs=None, **kwargs):
        chunkSize = getattr(settings, 'ADMIN_RESUMABLE_CHUNKSIZE',
                            "1*1024*1024")
        show_thumb = getattr(settings, 'ADMIN_RESUMABLE_SHOW_THUMB', False)
        context = {
            'name': name,
            'value': value,
            'id': attrs['id'],
            'chunkSize': chunkSize,
            'show_thumb': show_thumb
        }

        if not self.is_required:
            template_with_clear = '<span class="clearable-file-input">%(clear)s <label for="%(clear_checkbox_id)s">%(clear_checkbox_label)s</label></span>'
            substitutions = {}
            substitutions['clear_checkbox_id'] = attrs['id'] + "-clear-id"
            substitutions['clear_checkbox_name'] = attrs['id'] + "-clear"
            substitutions['clear_checkbox_label'] = self.clear_checkbox_label
            substitutions['clear'] = CheckboxInput().render(
                substitutions['clear_checkbox_name'],
                False,
                attrs={'id': substitutions['clear_checkbox_id']})
            clear_checkbox = mark_safe(template_with_clear % substitutions)
            context.update({'clear_checkbox': clear_checkbox})
        return loader.render_to_string(self.template_name, context)
Пример #17
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>']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])

        key = ''
        for i, (option_value,
                option_label) in enumerate(chain(self.choices, choices)):
            if option_value in self.all_fields['user']['fields']:
                key = 'user'
            elif option_value in self.all_fields['membership']['fields']:
                key = 'membership'
            elif option_value in self.all_fields['membership_type']['fields']:
                key = 'membership_type'
            elif option_value in self.all_fields['payment']['fields']:
                key = 'payment'
            elif option_value in self.all_fields['user_group']['fields']:
                key = 'user_group'
            elif option_value in self.all_fields['industry']['fields']:
                key = 'industry'
            elif option_value in self.all_fields['region']['fields']:
                key = 'region'
            elif option_value in self.all_fields['admin']['fields']:
                key = 'admin'
            if key:
                self.all_fields[key]['options'].append(
                    (i, option_value, option_label))
        for key in self.all_fields.keys():
            output.append(u'<div style="clear: both;"></div>')
            output.append(u'<h3>')
            output.append(self.all_fields[key]['title'])
            output.append(u'</h3>')
            output.append(u'<div class="fields-section">')
            for i, option_value, option_label in \
                    self.all_fields[key]['options']:
                # 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'<div class="field-box select-field"><label%s>%s %s</label></div>'
                    % (label_for, rendered_cb, option_label))
            output.append(u'</div>')
        output.append(u'</div>')
        return mark_safe(u'\n'.join(output))
Пример #18
0
def functionalities(request, project_id):
    project = Project.objects.get(pk=project_id)

    FunctionalityFormSet = inlineformset_factory(
        Project,
        Functionality,
        fields=(
            'title',
            'description',
            'status',
        ),
        widgets={
            'title':
            TextInput(attrs={'class': 'form-control'}),
            'description':
            Textarea(attrs={
                'class': 'form-control',
                'rows': '5'
            }),
            'status':
            CheckboxInput(attrs={'class': 'form-check form-check-inline'})
        },
        can_delete=True,
        extra=1)

    if request.method == 'POST':
        formset = FunctionalityFormSet(request.POST, instance=project)
        if formset.is_valid():
            formset.save()

    formset = FunctionalityFormSet(instance=project)
    return render(request, 'Projects/functionalities.html',
                  {'formset': formset})
Пример #19
0
 def render(self, name, value, attrs=None, choices=()):
     """ Rendre le widget """
     if value is None:
         value = []
     has_id = attrs and 'id' in attrs
     final_attrs = self.build_attrs(attrs, name=name)
     output = ['<ul>']
     # Normalize to strings
     str_values = set([str(v) for v in value])
     for i, (option_value, option_label) in enumerate(
             itertools.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='{}_{}'.format(attrs['id'], i))
             label_for = ' for="{}"'.format(final_attrs['id'])
         else:
             label_for = ''
         cb = CheckboxInput(final_attrs,
                            check_test=lambda value: value in str_values)
         option_value = str(option_value)
         rendered_cb = cb.render(name, option_value)
         option_label = conditional_escape(str(option_label))
         output.append('<li>{} <label{}>{}</label></li>'.format(
             rendered_cb, label_for, option_label))
     output.append('</ul>')
     return mark_safe('\n'.join(output))
Пример #20
0
    def render(self, name, value, attrs=None, **kwargs):
        upload_to = get_upload_to(
            self.attrs['content_type_id'], self.attrs['field_name'])
        storage = get_storage(upload_to)
        if value:
            file_name = os.path.basename(value.name)
            file_url = storage.url(file_name)
        else:
            file_url = ""

        chunkSize = getattr(settings, 'ADMIN_RESUMABLE_CHUNKSIZE', "1*1024*1024")
        show_thumb = getattr(settings, 'ADMIN_RESUMABLE_SHOW_THUMB', False)
        context = {'name': name,
                   'value': value,
                   'id': attrs['id'],
                   'chunkSize': chunkSize,
                   'show_thumb': show_thumb,
                   'field_name': self.attrs['field_name'],
                   'content_type_id': self.attrs['content_type_id'],
                   'file_url': file_url}

        if not self.is_required:
            template_with_clear = '<span class="clearable-file-input">%(clear)s <label for="%(clear_checkbox_id)s">%(clear_checkbox_label)s</label></span>'
            substitutions = {}
            substitutions['clear_checkbox_id'] = attrs['id'] + "-clear-id"
            substitutions['clear_checkbox_name'] = attrs['id'] + "-clear"
            substitutions['clear_checkbox_label'] = self.clear_checkbox_label
            substitutions['clear'] = CheckboxInput().render(
                substitutions['clear_checkbox_name'],
                False,
                attrs={'id': substitutions['clear_checkbox_id']}
            )
            clear_checkbox = mark_safe(template_with_clear % substitutions)
            context.update({'clear_checkbox': clear_checkbox})
        return loader.render_to_string(self.template_name, context)
Пример #21
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 = ['<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 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)
            option_label = force_text(option_label)
            attr_type, attr_shops, sale_name = self._sale_attrs(option_value)
            option_label = ': '.join([sale_name, option_label])
            # 0 is for internet sales.
            shops = ','.join(attr_shops)
            output.append(
                format_html(
                    u'<li product_type={0} shops={1}><label{2}>{3} {4}</label></li>',
                    attr_type, shops, label_for, rendered_cb, option_label))
        output.append('</ul>')
        return mark_safe('\n'.join(output))
Пример #22
0
    def render(self, name, value, attrs=None, renderer=None):
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
            'pretty_input_start': self.pretty_input_start,
            'pretty_input_end': self.pretty_input_end,
        }
        template = u'%(pretty_input_start)s%(input)s%(pretty_input_end)s'
        substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs, renderer)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = (u'<audio src="%s" controls></audio>'
                                        % (escape(value.url),))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id}, renderer=renderer)
                substitutions['clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions)
Пример #23
0
def field_to_widget(field):
    if type(field) is CharField:
        if field.choices:
            return Select(attrs={"class": "form-control"})
        return TextInput(attrs={"class": "form-control", "rows": 1})
    if type(field) is TextField:
        return Textarea(attrs={"class": "form-control", "rows": 1})
    if type(field) is AutoField:
        return HiddenInput(attrs={"class": "form-control", "rows": 1})
    if type(field) is IntegerField or type(field) is FloatField:
        return NumberInput(attrs={"class": "form-control"})
    if type(field) is EmailField:
        return EmailInput(attrs={"class": "form-control"})
    if type(field) is ForeignKey:
        return Select(attrs={"class": "form-control"})
    if type(field) is ManyToManyField:
        return CheckboxSelectMultiple(attrs={"class": ""})
    if type(field) is BooleanField:
        return CheckboxInput(attrs={"class": "form-control"})
    if type(field) is FileField:
        return FileInput(attrs={"class": "form-control"})
    if type(field) is DateField:
        return DateInput(attrs={"class": "form-control date", "type": "date"})
    if type(field) is DateTimeField:
        return DateTimeInput(attrs={"class": "form-control datetimepicker"})

    return TextInput(attrs={"class": "form-control", "rows": 1})
Пример #24
0
    def render(self, name, value, attrs=None):
        output = []

        # Base content.
        output.append(super(ImageFileInput, self).render(name, value, attrs))

        if value and hasattr(value, "url"):
            # Add clear checkbox input.
            output.append(
                CheckboxInput().render(
                    self._clear_checkbox_name(name), False, attrs={
                        'class': 'image-file-input-clear'
                    }))

            # Add image preview with delete icon.
            output.append(
                ('<ul class="thumbnails image-file-input-preview">'
                 '  <li>'
                 '    <a target="_blank" href="%s" class="thumbnail">'
                 '      <img src="%s" />'
                 '    </a>'
                 '    <a href="#" class="close image-file-input-delete">&times;</a>'
                 '  </li>'
                 '</ul>' % (value.url, value.url)))

        # Render.
        return mark_safe(
            '<div class="image-file-input">' + u''.join(output) + '</div>')
Пример #25
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': '',
            'input_text': '',
            'clear_template': '',
            'clear_checkbox_label': "Delete",
        }
        template_with_initial = (u'%(initial_text)s %(initial)s '
                                 u'%(clear_template)s<br />%(input_text)s '
                                 u'%(input)s')
        preview_template = ('<a href="%(url)s"><img class="preview" '
                            'src="%(url)s" /></a>')
        template = u'%(input)s'
        substitutions['input'] = super(FileInput,
                                       self).render(name, value, attrs)

        if value and hasattr(value, "url"):
            template = template_with_initial
            substitutions['initial'] = preview_template % {
                'url': escape(value.url),
            }
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = self.template_with_clear % \
                        substitutions

        return mark_safe(template % substitutions)
Пример #26
0
    def __init__(self, *args, **kwargs):
        """!
        Metodo que sobreescribe cuando se inicializa el formulario

        @date 01-03-2017
        @param self <b>{object}</b> Objeto que instancia la clase
        @param args <b>{list}</b> Lista de los argumentos
        @param kwargs <b>{dict}</b> Diccionario con argumentos
        @return Retorna el formulario validado
        """
        super(LoginForm, self).__init__(*args, **kwargs)
        self.fields['contrasena'].widget = PasswordInput()
        self.fields['contrasena'].widget.attrs.update({
            'class':
            'validate',
            'placeholder':
            'Contraseña'
        })
        self.fields['usuario'].widget.attrs.update({
            'class':
            'validate',
            'placeholder':
            'Nombre de Usuario'
        })
        self.fields['remember_me'].label = "Recordar"
        self.fields['remember_me'].widget = CheckboxInput()
        self.fields['remember_me'].required = False
Пример #27
0
    def make_context(self, request, errorcontext=None):
        context = super(EditVolunteerView,
                        self).make_context(request, errorcontext)
        context, initial_form_info = setup_event_management_form(
            self.item.e_conference,
            self.item,
            self.occurrence,
            context,
            open_to_public=False)

        context['association_form'] = EventAssociationForm(
            initial={
                'staff_area': self.area,
                'parent_event': self.parent_id
            })
        context['edit_title'] = self.title
        context['scheduling_form'].fields['approval'].widget = CheckboxInput()

        if validate_perms(request, ('Volunteer Coordinator', ), require=False):
            context.update(
                self.get_worker_allocation_forms(errorcontext=errorcontext))
            if self.request.GET.get('changed_id', None):
                context['changed_id'] = int(
                    self.request.GET.get('changed_id', None))
        else:
            context['start_open'] = True

        return context
Пример #28
0
    def render(self, name, value, attrs=None):
        '''Same render method as ClearableFileInput has except that it wraps
        displayed file name with os.path.basename for nicer output.'''
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = super(ClearableFileInput,
                                       self).render(name, value, attrs)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = format_html(u'<a href="{0}">{1}</a>',
                                                   value.url,
                                                   basename(force_text(value)))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions[
                    'clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions)
Пример #29
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': self.initial_text, 
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': '',
            }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)
        clear_template = '<div class="remove-image"><div class="remove-image btn btn-primary">Remove image</div></div><div class="image-removed">Image removed. Please click Submit to save your changes.</div>' + self.template_with_clear

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = ('<div class="logo-image-container"><img class="logo-image" src="%s" alt="%s"/></div>'
                                        % (escape(value.url),
                                           escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
                substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = clear_template % substitutions

        return mark_safe(template % substitutions)
Пример #30
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'preview': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = u'%(input)s'
        substitutions['input'] = super(DjangoClearableFileInput,
                                       self).render(name, value, attrs)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = (
                u'<a target="_blank" href="%s">%s</a>' % (value.url, value))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = checkbox_name
                substitutions['clear_checkbox_id'] = checkbox_id
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions[
                    'clear_template'] = self.template_with_clear % substitutions

        if value and hasattr(value, "url"):
            preview_template = render_to_string(
                'filebrowser/widgets/clearablefileinput.html', {
                    'value': FileObject(value.name),
                    'ADMIN_THUMBNAIL': ADMIN_THUMBNAIL,
                })
            substitutions["preview"] = preview_template

        return mark_safe(template % substitutions)