Esempio n. 1
0
class PasswordChangeForm(_PasswordChangeForm):
    old_password = forms.CharField(label=_("Old password"),
                                    widget=forms.PasswordInput, help_text='Enter your current Password')
    new_password1 = forms.CharField(label=_("New password confirmation"),
                                    widget=forms.PasswordInput, help_text='Enter your desired new Password')
    new_password2 = forms.CharField(label=_("New password confirmation"),
                                   widget=forms.PasswordInput, help_text='Repeat your new Password')
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'password-change-form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '.'
        
        layout = Layout(
            Row(HTML('<legend>Password Change</legend>')),
            Row(Column(Field('old_password', css_class='span4'))),
            Row(Column(Field('new_password1', css_class='span4'))),
            Row(Column(Field('new_password2', css_class='span4'))),
			
			Row(
                Div(
                    Submit('Save', 'Save Changes', css_class='btn-primary'),
                css_class='form-actions')
            )
        )
        self.helper.add_layout(layout)

        return super(PasswordChangeForm, self).__init__(*args, **kwargs)
Esempio n. 2
0
class ServiceForm(ModelForm):
    class Meta:
        model = Service
        parent_model = Profile

    def __init__(self, *args, **kwargs):
        super(ServiceForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False
        layout_profile = Layout(Fieldset(
            _('Link'),
            'url',
            'title',
            'DELETE',
        ))

        base_layout = Row(
            Column(Field('username', css_class='input-large'),
                   css_class='span4'),
            Column(Field('service', css_class='input-medium'),
                   css_class='span2'),
            Column(Field('DELETE', css_class='input-mini'), css_class='span1'),
            css_class='row service-row',
        )

        self.helper.add_layout(base_layout)
Esempio n. 3
0
class UserProfileForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'applicant-settings-form'
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '.'
        
        layout = Layout(
            HTML('<legend>Personal Profile</legend>'),
            Row(Column(Field('title', css_class='span1'))),
            Row(Column(Field('first_name', css_class='span3'))),
			Row(Column(Field('middle_name', css_class='span3'))),
			Row(Column(Field('last_name', css_class='span3'))),
			Row(Column(Field('national_id', css_class='span2'))),
            
            Row(
                Div(
                    Submit('Save', 'Save Changes', css_class='btn-primary'),
                css_class='form-actions')
            )
        )
        self.helper.add_layout(layout)
        
        return super(UserProfileForm, self).__init__(*args, **kwargs)
    
    first_name = forms.CharField()
    last_name = forms.CharField()
    
    class Meta:
        model = UserProfile
        fields = [
			'title','first_name','middle_name',
			'last_name','national_id',
		]
Esempio n. 4
0
class LocationForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'applicant-settings-form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '.'
        
        layout = Layout(
            HTML('<legend>Location</legend>'),
            Row(Column(Field('village', css_class='span4'))),
            Row(Column(Field('county', css_class='span3'))),
			Row(Column(Field('province', css_class='span3'))),
			Row(Column(Field('country', css_class='span4'))),
            
            Row(
                Div(
                    Submit('Save', 'Save Changes', css_class='btn-primary'),
                css_class='form-actions')
            )
        )
        self.helper.add_layout(layout)
        
        return super(LocationForm, self).__init__(*args, **kwargs)
    
    class Meta:
        model = UserProfile
        fields = [
			'village',
            'province',
			'county',
			'country',
		]
Esempio n. 5
0
    def test_second_layout_multifield_column_buttonholder_submit_div(self):
        if settings.CRISPY_TEMPLATE_PACK != 'uni_form':
            warnings.warn('skipping uniform tests with CRISPY_TEMPLATE_PACK=%s' % settings.CRISPY_TEMPLATE_PACK)
            return
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                MultiField("Some company data",
                    'is_company',
                    'email',
                    css_id = "multifield_info",
                    title = "multifield_title",
                    multifield_test = "123"
                ),
                Column(
                    'first_name',
                    'last_name',
                    css_id = "column_name",
                    css_class = "columns",
                ),
                ButtonHolder(
                    Submit('Save the world', '{{ value_var }}', css_class='button white', data_id='test', data_name='test'),
                    Submit('store', 'Store results')
                ),
                Div(
                    'password1',
                    'password2',
                    css_id="custom-div",
                    css_class="customdivs",
                    test_markup="123"
                )
            )
        )

        template = get_template_from_string(u"""
                {% load crispy_forms_tags %}
                {% crispy form form_helper %}
            """)
        c = Context({'form': TestForm(), 'form_helper': form_helper, 'value_var': "Save"})
        html = template.render(c)

        self.assertTrue('multiField' in html)
        self.assertTrue('formColumn' in html)
        self.assertTrue('id="multifield_info"' in html)
        self.assertTrue('title="multifield_title"' in html)
        self.assertTrue('multifield-test="123"' in html)
        self.assertTrue('id="column_name"' in html)
        self.assertTrue('class="formColumn columns"' in html)
        self.assertTrue('class="buttonHolder">' in html)
        self.assertTrue('input type="submit"' in html)
        self.assertTrue('button white' in html)
        self.assertTrue('data-id="test"' in html)
        self.assertTrue('data-name="test"' in html)
        self.assertTrue('name="save-the-world"' in html)
        self.assertTrue('value="Save"' in html)
        self.assertTrue('name="store"' in html)
        self.assertTrue('value="Store results"' in html)
        self.assertTrue('id="custom-div"' in html)
        self.assertTrue('class="customdivs"' in html)
        self.assertTrue('test-markup="123"' in html)
Esempio n. 6
0
class PatientInsuranceForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'patient-insurance-form'
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '.'
        
        layout = Layout(
            Row(HTML('<legend>Patient Insurance</legend>')),
            Row(Column('name')),
            Row(Column('insurance')),
            Row(Column('subscriber_policy_id')),
            Row(Column('status')),
            Row(Column('coverage_start_date')),
            Row(Column('coverage_end_date')),
            Row(Column('notes')),
            Row(
				Div(
					Submit('Save', 'Save Changes', css_class='btn-primary'),
				css_class='form-actions')
			)
        )
        self.helper.add_layout(layout)

        return super(PatientInsuranceForm, self).__init__(*args, **kwargs)
    
    name = forms.CharField(required=False, help_text="Name of the insurance, if customised for the Patient.")
    
    class Meta:
        model = PatientInsurance
        exclude = ['patient']
Esempio n. 7
0
class LinkForm(ModelForm):
    class Meta:
        model = Link
        parent_model = Profile
        exclude = []

    def __init__(self, *args, **kwargs):
        super(LinkForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False
        layout_profile = Layout(Fieldset(
            _('Link'),
            'url',
            'title',
            'DELETE',
        ))

        base_layout = Row(
            Column(Field('url', css_class='input-medium'), css_class='span5'),
            Column(Field('title', css_class='input-medium'),
                   css_class='span5'),
            Column(Field('DELETE', css_class='input-mini'),
                   css_class='span2 delete'),
            css_class='row-fluid link-row form-autogrow',
        )

        self.helper.add_layout(base_layout)
Esempio n. 8
0
class AnonymousSessionSubmissionForm(forms.ModelForm):
    speaker_name = forms.CharField(required=True, label="Dein Name")
    speaker_email = forms.EmailField(required=True, label="Deine E-Mail-Adresse")
    captcha = ReCaptchaField(attrs={'theme': 'white'}, use_ssl=True)

    class Meta(object):
        model = models.Session
        fields = ('title', 'abstract', 'speaker_name', 'speaker_email', 'type')
        widgets = {
            'type': forms.RadioSelect
        }
        help_texts = {
            'speaker_email': u"""Wir benötigen deine E-Mail-Adresse, um etwaige Termin und Themefragen mit dir abklären zu können."""
        }

    def __init__(self, *args, **kwargs):
        super(AnonymousSessionSubmissionForm, self).__init__(*args, **kwargs)
        del self.fields['abstract'].widget.attrs['cols']
        self.fields['type'].required = True
        self.fields['type'].empty_label = None
        _extend_type_choice_labels(self.fields['type'])
        self.helper = FormHelper()
        layout = Layout(
            Field('title'), Field('abstract'),
            Field('speaker_name'), Field('speaker_email'),
            Field('captcha'),
            Field('type'),
            ButtonHolder(Submit("submit", "Abschicken"))
        )
        self.helper.add_layout(layout)
Esempio n. 9
0
class BaseReleaseReleationForm(StripWhitespaceFormMixin, ModelForm):
    class Meta:
        model = Relation
        parent_model = Release
        fields = ('url', 'service')

    def __init__(self, *args, **kwargs):
        super(BaseReleaseReleationForm, self).__init__(*args, **kwargs)
        instance = getattr(self, 'instance', None)
        self.fields['service'].widget.instance = instance
        if instance and instance.id:
            self.fields['service'].widget.attrs['readonly'] = True

        self.helper = FormHelper()
        self.helper.form_tag = False

        base_layout = Row(
            Column(Field('url', css_class='input-xlarge'),
                   css_class='span6 relation-url'),
            Column(Field('service', css_class='input-mini'),
                   css_class='span4'),
            Column(Field('DELETE', css_class='input-mini'),
                   css_class='span2 delete'),
            css_class='row-fluid relation-row form-autogrow',
        )

        self.helper.add_layout(base_layout)

    def clean_service(self):
        return self.instance.service

    service = forms.CharField(label='',
                              widget=ReadOnlyIconField(**{'url': 'whatever'}),
                              required=False)
    url = forms.URLField(label=_('Website / URL'), required=False)
Esempio n. 10
0
class PatientEncounterForm(BaseModelForm):
	def __init__(self, *args, **kwargs):
		self.helper = FormHelper()
		self.helper.form_id = '%s-form' % self._meta.model._meta.object_name
		self.helper.form_class = 'general_form'
		self.helper.form_method = 'POST'
		self.helper.form_action = '#'

		self.layout = Layout(
			Div(HTML('<legend>Enter Encounter</legend>')),
            Row(Column(Field('frequency', css_class='span2'))),
			Row(Column(Field('type', css_class='span3'))),
			Row(Column(Field('provider', css_class='span4'))),
			Row(Column(Field('location', css_class='span4'))),
			Row(Column(Field('completed'))),
			Row(Column(Field('start_time'))),
			Row(Column(Field('end_time'))),
			Row(Field('observation_notes'), css_class="textarea-column"),
			
			Row(
				Div(
					Submit('Save', 'Save Changes', css_class='btn-primary'),
				css_class='form-actions'
				)
			)
		)
		self.helper.add_layout(self.layout)
		super(PatientEncounterForm, self).__init__(*args, **kwargs)
    
	class Meta:
		model = Encounter
		exclude = ['user', 'patient_complience', 'text']
		widgets = {
			'observation_notes' : forms.Textarea,
		}
Esempio n. 11
0
    def get_crispy_helper(self, form_class, fieldsets):
        # TODO extract to mixin
        from crispy_forms.helper import FormHelper, Layout
        from crispy_forms.layout import Div, Fieldset

        helper = getattr(form_class, 'helper', None)

        if helper and isinstance(helper, FormHelper):
            return helper

        helper = FormHelper()

        helper_args = []
        for header, _fieldset in fieldsets:
            _fieldset_args = []
            for _field in _fieldset['fields']:
                if isinstance(_field, (tuple, list)):
                    row = Div(
                        *_field,
                        css_class='form-row form-group field-box col-sm-%s' %
                        (12 / len(_field)))
                else:
                    row = Div(*_field, css_class='form-row form-group')

                _fieldset_args.append(row)
            helper_args.append(
                Fieldset(header,
                         *_fieldset_args,
                         css_class=_fieldset.get('classes')))
        helper.add_layout(Layout(*helper_args))
        return helper
Esempio n. 12
0
class ProblemTestForm(BaseModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'problem-form'
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '#'
        
        self.layout = Layout(
            Div(HTML('<legend>Add Diagnosis</legend>')),
            Row(Column(Field('name'))),
            Row(Column(Field('problem'))),
            Row(Column(Field('expected_outcomes'))),
            Row(Column('details'), css_class='textarea-column'),
            Row(
				Div(
					Submit('Save', 'Save Changes', css_class='btn-primary'),
				css_class='form-actions')
			)
        )
        self.helper.add_layout(self.layout)
        super(ProblemTestForm, self).__init__(*args, **kwargs)
        
    class Meta:
        model = ProblemTest
        exclude = ['patient', 'slug', 'date_added']
        widgets = {
            'expected_outcomes': forms.Textarea,
            'details': forms.Textarea
        }
Esempio n. 13
0
class EncounterTestResultForm(BaseModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'problem-form'
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '#'
        
        self.layout = Layout(
            Div(HTML('<legend>Add Diagnosis</legend>')),
            Row(Column(Field('name'))),
            Row(Column(Field('encounter_test'))),
            Row(Column(Field('inference'))),
            Row(Column('notes'), css_class='textarea-column'),
            Row(
				Div(
					Submit('Save', 'Save Changes', css_class='btn-primary'),
				css_class='form-actions')
			)
        )
        self.helper.add_layout(self.layout)
        super(EncounterTestResultForm, self).__init__(*args, **kwargs)
        
    class Meta:
        model = EncounterTest
        exclude = ['date_added']
        widgets = {
            'notes': forms.Textarea
        }
Esempio n. 14
0
class ProblemForm(BaseModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'problem-form'
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '#'
        
        self.layout = Layout(
            Div(HTML('<legend>Create Problem</legend>')),
            Row(Column(Field('code'))),
            Row(Column(Field('type'))),
            Row(Column(Field('source'))),
            Row(Column(Field('status'))),
            Row(Column('notes'), css_class='textarea-column'),
            Row(
				Div(
					Submit('Save', 'Save Changes', css_class='btn-primary'),
				css_class='form-actions')
			)
        )
        
        self.helper.add_layout(self.layout)
        super(ProblemForm, self).__init__(*args, **kwargs)
        
    class Meta:
        model = Problem
        exclude = ['patient', 'attachments', 'name']
        widgets = {
            'side_effects' : forms.Textarea
        }
Esempio n. 15
0
class ExportCreateForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(ExportCreateForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_id = "bulk_edit%s" % 'asd'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = True
        """"""
        layout = Layout(
            Field('agree_terms'),
            Field('agree_documentation'),
            FormActions(
                Submit('submit', 'Continue', css_class='btn btn-primary')),
        )
        self.helper.add_layout(layout)

    agree_terms = forms.BooleanField(
        label=_('I agree to the Terms & Conditions'),
        initial=False,
        required=True,
    )

    agree_documentation = forms.BooleanField(
        label=_('I read the ducumentation and know how Exporting works'),
        initial=False,
        required=True,
    )
Esempio n. 16
0
class RegisterForm(forms.Form):
	email = forms.EmailField(
		label = 'Email naslov',
		required = True,
		error_messages={
			'required': 'Vnesite email naslov',
			'invalid': 'Email naslov ni pravilen'
		}
	)
	
	password = forms.CharField(
		label = 'Geslo',
		max_length = 50,
		required = True,
		widget = forms.PasswordInput,
		)	


	def __init__(self, *args, **kwargs):
		super(RegisterForm, self).__init__(*args, **kwargs)

		self.helper = FormHelper()
		self.helper.form_method = 'POST'
		self.helper.form_tag = True
		self.helper.form_class = 'form-signin'
		self.helper.add_layout(Layout(
			Fieldset(_('Registracija'),
			         'email',
			         'password',
			),
			ButtonHolder(
				Submit('submit', _('Registracija'), css_class='btn btn-lg btn-primary btn-block'),
			),
		))
Esempio n. 17
0
def test_layout_fieldset_row_html_with_unicode_fieldnames(settings):
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Fieldset(
                "Company Data",
                "is_company",
                css_id="fieldset_company_data",
                css_class="fieldsets",
                title="fieldset_title",
                test_fieldset="123",
            ),
            Fieldset(
                "User Data",
                "email",
                Row(
                    "password1",
                    "password2",
                    css_id="row_passwords",
                    css_class="rows",
                ),
                HTML('<a href="#" id="testLink">test link</a>'),
                HTML(
                    """
                    {% if flag %}{{ message }}{% endif %}
                """
                ),
                "first_name",
                "last_name",
            ),
        )
    )

    template = Template(
        """
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """
    )
    c = Context(
        {
            "form": SampleForm(),
            "form_helper": form_helper,
            "flag": True,
            "message": "Hello!",
        }
    )
    html = template.render(c)

    assert 'id="fieldset_company_data"' in html
    assert 'class="fieldsets' in html
    assert 'title="fieldset_title"' in html
    assert 'test-fieldset="123"' in html
    assert 'id="row_passwords"' in html
    assert html.count("<label") == 6

    assert 'class="row rows"' in html

    assert "Hello!" in html
    assert "testLink" in html
Esempio n. 18
0
class OrderForm(BaseModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = '%s-form' % self._meta.model._meta.object_name
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '#'
        
        self.layout = Layout(
            Div(HTML('<legend>Add Order</legend>')),
            Row(Column(Field('encounter'))),
            Row(Column(Field('discontinued'))),
            Row(Column('instructions', css_class='textarea-column')),
            Row(Column('concept_notes'), css_class='textarea-column'),
			Row(
				Div(
					Submit('Save', 'Save Changes', css_class='btn-primary'),
				css_class='form-actions')
			)
        )
        self.helper.add_layout(self.layout)
        super(OrderForm, self).__init__(*args, **kwargs)
        
    class Meta:
        model = Order
        exclude = ['discontinued_reason']
        widgets = {
            'instructions': forms.Textarea,
            'concept_notes': forms.Textarea
        }
Esempio n. 19
0
class BaseMediaartistFormSet(BaseInlineFormSet):
    def __init__(self, *args, **kwargs):

        self.instance = kwargs['instance']

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

        self.helper = FormHelper()
        self.helper.form_id = "id_artists_form_%s" % 'inline'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        base_layout = Row(
            Column(Field('join_phrase'), css_class='span3'),
            Column(Field('artist'), css_class='span5'),
            Column(Field('DELETE', css_class='input-mini'), css_class='span4'),
            css_class='mediaartist-row row-fluid form-autogrow',
        )

        self.helper.add_layout(base_layout)

    def add_fields(self, form, index):
        # allow the super class to create the fields as usual
        super(BaseMediaartistFormSet, self).add_fields(form, index)

        # created the nested formset
        try:
            instance = self.get_queryset()[index]
            pk_value = instance.pk
        except IndexError:
            instance = None
            pk_value = hash(form.prefix)
Esempio n. 20
0
class ProgramForm(BaseModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'problem-form'
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '#'
        
        self.layout = Layout(
            Div(HTML('<h2 class="form_title">Create Immunization</h2>'), css_class="form_title_div"),
            Row(Column('name')),
            Row(Column('type')),
            Row(Column('is_public')),
            Row(Column('problem')),
            Row('concept_notes'),
            Row('expected_outcome_notes'),
            Row(
                Column(
                    Submit('Save', 'Save Changes'),
                )
            )
        )
        self.helper.add_layout(self.layout)
        super(ProgramForm, self).__init__(*args, **kwargs)
        
    class Meta:
        model = Program
        exclude = ['program_owner']
        widgets = {
            'concept_notes': forms.Textarea,
            'expected_outcome_notes': forms.Textarea
        }
Esempio n. 21
0
class InvitationForm(forms.Form):

    email = forms.EmailField()
    message = forms.CharField(widget=forms.Textarea())

    def __init__(self, *args, **kwargs):
        super(InvitationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        self.helper.add_layout(
            Layout(
                Field('email', css_class='input-xlarge'),
                Field('message', css_class='input-xlarge'),
            ))

    def clean_email(self):
        data = self.cleaned_data['email']
        if get_user_model().objects.filter(email=data).exists():
            raise forms.ValidationError(
                _('A user with the e-mail address {} already exists.').format(
                    data))

        return data
Esempio n. 22
0
class EnrolledProgramForm(BaseModelForm):
    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_id = 'problem-form'
        self.helper.form_class = 'general_form'
        self.helper.form_method = 'POST'
        self.helper.form_action = '#'
        
        self.layout = Layout(
            Div(HTML('<h2 class="form_title">Create Immunization</h2>'), css_class="form_title_div"),
            Row(Column('program')),
            Row(Column('enroller')),
            Row(Column('enrollee')),
            Row(Column('date_completed')),
            Row('outcome_notes'),
            Row(
                Column(
                    Submit('Save', 'Save Changes'),
                )
            )
        )
        self.helper.add_layout(self.layout)
        super(EnrolledProgramForm, self).__init__(*args, **kwargs)
        
    class Meta:
        model = EnrolledProgram
        widgets = {
            'outcome_notes': forms.Textarea
        }
Esempio n. 23
0
class BaseAlbumartistForm(ModelForm):
    class Meta:
        model = ReleaseAlbumartists
        parent_model = Release
        fields = (
            'artist',
            'join_phrase',
            'position',
        )

    def __init__(self, *args, **kwargs):
        instance = getattr(self, 'instance', None)
        super(BaseAlbumartistForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False

        base_layout = Row(
            Column(Field('join_phrase'), css_class='span3'),
            Column(Field('artist'), css_class='span5'),
            Column(Field('DELETE'), css_class='span4 delete'),
            css_class='albumartist-row row-fluid form-autogrow',
        )

        self.helper.add_layout(base_layout)

    def clean_artist(self):
        artist = self.cleaned_data['artist']
        if artist and not artist.pk:
            log.debug('saving not existant artist: %s' % artist.name)
            artist.save()
        return artist

    artist = search_fields.AutocompleteField('alibrary.artist',
                                             allow_new=True,
                                             required=False)
Esempio n. 24
0
class EventForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
		self.helper = FormHelper()
		self.helper.form_id = '%s-form' % self._meta.model._meta.object_name
		self.helper.form_class = 'general_form'
		self.helper.form_method = 'POST'
		self.helper.form_action = '#'

		layout = Layout(
			Div(HTML('<legend>Create Reminder</legend>'), css_class="form_title_div"),
			Row(Column('patient')),
			Row(Column('message')),
			Row(Column('frequency')),
			Row(Column('start_date'), Column('end_date')),
			
			Row(
				ButtonHolder(
					Submit('Save', 'Save Changes'),
				)
			)
		)
		self.helper.add_layout(layout)
		super(EventForm, self).__init__(*args, **kwargs)
        
    class Meta:
		model = Event
		widgets = {
			'message' : forms.Textarea
		}
		
Esempio n. 25
0
class ReleaseActionForm(Form):

    publish = forms.BooleanField(label=_('Save & Publish'), required=False)

    def __init__(self, *args, **kwargs):
        self.instance = kwargs.pop('instance', False)
        super(ReleaseActionForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.add_layout(ACTION_LAYOUT)

    def clean(self, *args, **kwargs):

        cd = super(ReleaseActionForm, self).clean()
        publish = cd.get('publish', False)

        if publish:
            missing_licenses = []
            for media in self.instance.get_media():
                if not media.license:
                    missing_licenses.append(
                        _('No license set for "%s"' % media.name))

            if len(missing_licenses) > 0:
                self._errors['publish'] = self.error_class(missing_licenses)
                del cd['publish']

        return cd

    def save(self, *args, **kwargs):
        return True
Esempio n. 26
0
class ContactFormCaptcha(ContactForm):
    """ContactForm form with captcha"""

    captcha = CaptchaField(label=_('Protection Code'),
                           error_messages={'required': _('Please enter protection code'),
                                           'invalid': _('Invalid protection code')})

    def __init__(self, *args, **kwargs):
        """Form initialization method

        :param args: form args
        :param kwargs: form keyword args
        """
        self.helper = FormHelper()
        layout = Layout(
            Fieldset(
                _('Contact form'),
                #'subject',
                'sender_name',
                'sender_email',
                'message',
                'captcha',
            ),
            ButtonHolder(
                Button('cancel', _('Cancel'), css_class='secondaryAction'),
                Submit('submit', _('Submit'), css_class='primaryAction'),
            )
        )
        self.helper.add_layout(layout)
        self.helper.form_id = 'contact_form'
        self.helper.form_action = ''
        self.helper.form_method = 'POST'
        self.helper.form_style = 'inline'

        super(ContactForm, self).__init__(*args, **kwargs)
Esempio n. 27
0
def test_column_has_css_classes(settings):
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """)

    form = SampleForm()
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Fieldset(
                'Company Data',
                'is_company',
                'email',
                'password1',
                'password2',
                css_id="multifield_info",
            ), Column(
                'first_name',
                'last_name',
            )))

    c = Context({'form': form, 'form_helper': form_helper})
    html = template.render(c)
    print(html)

    if settings.CRISPY_TEMPLATE_PACK == 'uni_form':
        assert html.count('formColumn') == 1
        assert html.count('col') == 0
    elif settings.CRISPY_TEMPLATE_PACK == 'bootstrap4':
        assert html.count('formColumn') == 0
        assert html.count('col') == 1
Esempio n. 28
0
class DemographicsForm(ModelForm):
    class Meta:
        model = Evaluator
        fields = ["birth_date", "gender"]
        widgets = {
            "birth_date":
            widgets.SelectDateWidget(years=range(this_year, this_year -
                                                 100, -1))
        }

    gender = ChoiceField(choices=Evaluator._meta.get_field("gender").choices,
                         widget=widgets.RadioSelect)

    def __init__(self, *args, **kwargs):
        super(DemographicsForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.add_layout(
            MultiWidgetField(
                'birth_date',
                attrs=({
                    'style':
                    'width: 33%; display: inline-block;max-width:100px;'
                })))
Esempio n. 29
0
class FeedbackForm(forms.ModelForm):

    class Meta:
        model = Feedback
        

    
    def __init__(self, *args, **kwargs):

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

        self.helper = FormHelper()
        self.helper.form_id = "import_create%s" % ''
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = True
        """"""
        layout = Layout(
            Fieldset(
                  'Your feedback',
                  Field('name'),
                  Field('email'),
                  Field('comment'),
            ),    
            FormActions(
                Submit('submit', 'Submit', css_class='btn btn-primary')
            ),
        )
        self.helper.add_layout(layout)
Esempio n. 30
0
    def test_change_layout_dynamically_delete_field(self):
        template = get_template_from_string(
            u"""
            {% load crispy_forms_tags %}
            {% crispy form form_helper %}
        """
        )

        form = TestForm()
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                Fieldset(u"Company Data", "is_company", "email", "password1", "password2", css_id="multifield_info"),
                Column("first_name", "last_name", css_id="column_name"),
            )
        )

        # We remove email field on the go
        # Layout needs to be adapted for the new form fields
        del form.fields["email"]
        del form_helper.layout.fields[0].fields[1]

        c = Context({"form": form, "form_helper": form_helper})
        html = template.render(c)
        self.assertFalse("email" in html)
Esempio n. 31
0
class ActionForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(ActionForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = "form-horizontal"
        self.helper.form_tag = False
        self.helper.add_layout(ACTION_LAYOUT)
Esempio n. 32
0
class ReleaseActionForm(Form):

    publish = forms.BooleanField(label=_('Save & Publish'), required=False)

    def __init__(self, *args, **kwargs):
        self.instance = kwargs.pop('instance', False)
        super(ReleaseActionForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.add_layout(ACTION_LAYOUT)

    def clean(self, *args, **kwargs):

        cd = super(ReleaseActionForm, self).clean()
        publish = cd.get('publish', False)

        if publish:
            missing_licenses = []
            for media in self.instance.get_media():
                if not media.license:
                    missing_licenses.append(_('No license set for "%s"' % media.name))

            if len(missing_licenses) > 0:
                self._errors['publish'] = self.error_class(missing_licenses)
                del cd['publish']

        return cd


    def save(self, *args, **kwargs):
        return True
Esempio n. 33
0
class HorarioForm(forms.ModelForm):
    class Meta:
        model = Horario
        exclude = ("baja_date_created", "alta_date_created", "is_active")

    dia = forms.ChoiceField(choices=DIAS_SELECT,
                             widget=forms.Select(), required=False, label='Dia')
    def __init__(self, *args, **kwargs):
        super(HorarioForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.label_class = 'form-group'
        #self.fields['materia'].widget.attrs['onchange']="javascript:cambiarProfesores()"
        #self.fields['profesores'].widget.attrs['disabled'] = True
        self.helper.add_input(Submit('submit', 'Guardar'))
        self.helper.add_layout(
        Fieldset('Adicionar Horario',
                 'clave_horario',
                 'nombre',
                 #'materia',
                 'profesores',
                 'hora_inicio',
                 'minutos_inicio',
                 'hora_termino',
                 'minutos_termino',
                 'dia',
                 'aula',
                 'grupo',


                 ),
    )
Esempio n. 34
0
def test_column_has_css_classes():
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """)

    form = SampleForm()
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Fieldset(
                "Company Data",
                "is_company",
                "email",
                "password1",
                "password2",
                css_id="multifield_info",
            ),
            Column("first_name", "last_name"),
        ))

    c = Context({"form": form, "form_helper": form_helper})
    html = template.render(c)

    assert html.count("formColumn") == 0
    assert html.count("col-md") == 1
Esempio n. 35
0
class CashInvoicePaymentForm(Form):
    receipt_number = fields.IntegerField()
    amount = fields.DecimalField(max_digits=8,
                                 decimal_places=2,
                                 validators=[validators.MinValueValidator(0)])

    def __init__(self, *args, instance, **kwargs):
        super().__init__(*args, **kwargs)
        self.instance = instance
        self.helper = FormHelper()
        self.helper.include_media = False
        layout = self.helper.build_default_layout(self)
        layout.fields.append(
            ButtonHolder(
                Submit('pay', 'Record Payment'),
                HTML(
                    '<a href="{}" class="btn btn-secondary">Cancel</a>'.format(
                        reverse(
                            'front_desk.check_in',
                            kwargs={
                                'username': self.instance.recipient.username
                            },
                        )))))
        self.helper.add_layout(layout)

    def clean_amount(self):
        amount = self.cleaned_data['amount']
        expected_amount = self.instance.total
        if amount != expected_amount:
            raise ValidationError(
                'The invoice was for USD {}'.format(expected_amount))
        return amount
Esempio n. 36
0
class BaseLabelReleationFormSet(BaseGenericInlineFormSet):

        
        
    def __init__(self, *args, **kwargs):

        self.instance = kwargs['instance']
        super(BaseLabelReleationFormSet, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_id = "id_releasemediainline_form_%s" % 'asdfds'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False
        
        base_layout = Row(
                Column(
                       Field('url', css_class='input-xlarge'),
                       css_class='span5'
                       ),
                Column(
                       Field('service', css_class='input-small'),
                       css_class='span1'
                       ),
                Column(
                       Field('DELETE', css_class='input-mini'),
                       css_class='span1'
                       ),
                css_class='row relation-row',
        )
 
        self.helper.add_layout(base_layout)
Esempio n. 37
0
def test_change_layout_dynamically_delete_field():
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """)

    form = SampleForm()
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Fieldset(
                'Company Data',
                'is_company',
                'email',
                'password1',
                'password2',
                css_id="multifield_info",
            ), Column(
                'first_name',
                'last_name',
                css_id="column_name",
            )))

    # We remove email field on the go
    # Layout needs to be adapted for the new form fields
    del form.fields['email']
    del form_helper.layout.fields[0].fields[1]

    c = Context({'form': form, 'form_helper': form_helper})
    html = template.render(c)
    assert 'email' not in html
Esempio n. 38
0
def test_bs4_column_css_classes(settings):
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """)

    form = SampleForm()
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Column(
                'first_name',
                'last_name',
            ),
            Column(
                'first_name',
                'last_name',
                css_class='col-sm'
            ),
            Column(
                'first_name',
                'last_name',
                css_class='mb-4'
            ),
        )
    )

    c = Context({'form': form, 'form_helper': form_helper})
    html = template.render(c)

    assert html.count('col-md') == 2
    assert html.count('col-sm') == 1
Esempio n. 39
0
class ActionForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(ActionForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_tag = False
        self.helper.add_layout(ACTION_LAYOUT)
def form_helper(button=None,
                form=None,
                formset=None,
                form_tag=False,
                label_size=4,
                label_offset=0,
                field_size=8):

    helper = FormHelper()
    helper.form_tag = form_tag

    if label_size:
        helper.label_class = "col-md-{}".format(label_size)
        helper.field_class = "col-md-{}".format(field_size)

    if label_offset:
        helper.label_size = ' col-md-offset-{}'.format(label_offset)

    if form:
        helper.add_layout(helper.build_default_layout(form))

    if formset:
        helper.template = "bootstrap/table_inline_formset.html"

    if form and button:
        helper.layout.fields.append(
            Div(Div(StrictButton(button,
                                 css_class="btn btn-default",
                                 type="submit"),
                    css_class="col-md-{} col-md-offset-{}".format(
                        field_size, (label_size + label_offset))),
                css_class="form-group"))
    return helper
Esempio n. 41
0
File: forms.py Progetto: 2e2a/l-rex
 def custom_helper(self):
     helper = FormHelper()
     helper.add_layout(
         Layout(
             Fieldset(
                 'Basic settings',
                 'title',
                 'item_type',
                 HTML('<hr>'),
             ),
             Fieldset(
                 'Restrictions on participation',
                 'password',
                 'participant_id',
                 'end_date',
                 'trial_limit',
                 HTML('<hr>'),
             ),
             Fieldset(
                 'Additional design features',
                 'use_blocks',
                 'pseudo_randomize_question_order',
                 'enable_item_rating_feedback',
                 HTML('<hr>'),
             ),
         ))
     return helper
Esempio n. 42
0
File: forms.py Progetto: 2e2a/l-rex
 def __new__(cls, form_count=None, custom_formset=None, study=None):
     helper = FormHelper()
     helper.form_tag = cls.form_tag
     layout = cls.get_layout(study)
     if layout:
         helper.add_layout(layout)
     if cls.form_tag:
         inputs = cls.get_inputs(study=study)
         if inputs is None:
             helper.add_input(PrimarySubmit('submit', 'Submit'))
             helper.add_input(SecondarySubmit('save', 'Save'))
             if form_count:
                 helper.add_input(SecondarySubmit('reset', 'Reset'))
         else:
             for input in inputs:
                 helper.add_input(input)
     factory_kwargs = {
         'form': cls.form,
     }
     if form_count:
         factory_kwargs.update({
             'extra': 0,
             'min_num': form_count,
         })
     else:
         form_disabled = study.is_active or study.is_finished
         factory_kwargs.update({
             'extra': 1 if not form_disabled else 0,
             'can_delete': True
         })
     if custom_formset:
         factory_kwargs['formset'] = custom_formset
     formset_class = forms.modelformset_factory(cls.model, **factory_kwargs)
     formset_class.helper = helper
     return formset_class
    def test_change_layout_dynamically_delete_field(self):
        template = loader.get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy form form_helper %}
        """)

        form = TestForm()
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                Fieldset(
                    u'Company Data',
                    'is_company',
                    'email',
                    'password1',
                    'password2',
                    css_id = "multifield_info",
                ),
                Column(
                    'first_name',
                    'last_name',
                    css_id = "column_name",
                )
            )
        )

        # We remove email field on the go
        # Layout needs to be adapted for the new form fields
        del form.fields['email']
        del form_helper.layout.fields[0].fields[1]

        c = Context({'form': form, 'form_helper': form_helper})
        html = template.render(c)
        self.assertFalse('email' in html)
Esempio n. 44
0
class ContactUsForm(ContactForm):
    """
    Form to handle contacting us when we don't offer the service required
    """

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_id = 'contact-us-form'
        self.helper.form_method = 'post'
        self.helper.form_action = reverse('public:contact_us')

        self.helper.add_layout(Layout(
            Div(
                Field('name'),
                Field('message'),
                Field('email'),
                css_class='modal-body'
            ),
            Div(
                Submit('send', 'Send', css_id='send-contact-us-modal'),
                css_class='modal-footer',
            ),
        ))

        super(ContactUsForm, self).__init__(*args, **kwargs)
Esempio n. 45
0
class AnonymousSessionSubmissionForm(forms.ModelForm):
    speaker_name = forms.CharField(required=True, label="Dein Name")
    speaker_email = forms.EmailField(required=True,
                                     label="Deine E-Mail-Adresse")
    captcha = ReCaptchaField(attrs={'theme': 'white'}, use_ssl=True)

    class Meta(object):
        model = models.Session
        fields = ('title', 'abstract', 'speaker_name', 'speaker_email', 'type')
        widgets = {'type': forms.RadioSelect}
        help_texts = {
            'speaker_email':
            u"""Wir benötigen deine E-Mail-Adresse, um etwaige Termin und Themefragen mit dir abklären zu können."""
        }

    def __init__(self, *args, **kwargs):
        super(AnonymousSessionSubmissionForm, self).__init__(*args, **kwargs)
        del self.fields['abstract'].widget.attrs['cols']
        self.fields['type'].required = True
        self.fields['type'].empty_label = None
        _extend_type_choice_labels(self.fields['type'])
        self.helper = FormHelper()
        layout = Layout(Field('title'), Field('abstract'),
                        Field('speaker_name'), Field('speaker_email'),
                        Field('captcha'), Field('type'),
                        ButtonHolder(Submit("submit", "Abschicken")))
        self.helper.add_layout(layout)
Esempio n. 46
0
File: forms.py Progetto: 2e2a/l-rex
class StudyFilterSortForm(contrib_forms.CrispyForm):
    SORT_BY_DATE = 'date'
    SORT_BY_NAME = 'name'
    SORT_BY_CHOICES = (
        (SORT_BY_DATE, 'date'),
        (SORT_BY_NAME, 'name'),
    )
    sort_by = forms.ChoiceField(choices=SORT_BY_CHOICES, label='')
    archived = forms.BooleanField(required=False)
    shared = forms.BooleanField(required=False)

    def __init__(self, *args, **kwargs):
        sort_by = kwargs.pop('sort_by')
        archived = kwargs.pop('archived')
        shared = kwargs.pop('shared')
        super().__init__(*args, **kwargs)
        self.fields['sort_by'].initial = sort_by
        self.fields['archived'].initial = archived
        self.fields['shared'].initial = shared

    def init_helper(self):
        self.helper = FormHelper()
        self.helper.add_layout(
            Layout(
                HTML('<div class="me-2 text-secondary">Sort by:</div>'),
                Div('sort_by', css_class='mr-2'),
                HTML('<div class="mx-2 text-secondary">Show:</div>'),
                Div('archived', css_class='me-2'),
                Div('shared', css_class='me-2'),
            ))
        submit = Submit('submit', 'Update')
        submit.field_classes = 'btn btn-sm btn-outline-secondary'
        self.helper.add_input(submit)
        self.helper.form_class = 'd-flex align-items-baseline px-2 pt-2'
        self.helper.form_method = 'GET'
Esempio n. 47
0
class BaseMediaReleationFormSet(BaseGenericInlineFormSet):
    def __init__(self, *args, **kwargs):
        self.instance = kwargs['instance']
        super(BaseMediaReleationFormSet, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_id = "id_releasemediainline_form_%s" % 'asdfds'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        base_layout = Row(
            Column(
                Field('url', css_class='input-xlarge'),
                css_class='span6 relation-url'
            ),
            Column(
                Field('service', css_class='input-mini'),
                css_class='span4'
            ),
            Column(
                Field('DELETE', css_class='input-mini'),
                css_class='span2'
            ),
            css_class='row-fluid relation-row form-autogrow',
        )

        self.helper.add_layout(base_layout)
Esempio n. 48
0
class ImportCreateForm(forms.Form):
    
    def __init__(self, *args, **kwargs):
        super(ImportCreateForm, self).__init__(*args, **kwargs)        
        
        self.helper = FormHelper()
        self.helper.form_id = "bulk_edit%s" % 'asd'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = True
        """"""
        layout = Layout(

              Field('agree_terms'),
              Field('agree_documentation'),
  
            FormActions(
                Submit('submit', 'Continue', css_class='btn btn-primary')
            ),
        )
        self.helper.add_layout(layout)
    
    agree_terms = forms.BooleanField(
        label = _('I agree to the Terms & Conditions'),
        initial = False,
        required = True,
    )

    agree_documentation = forms.BooleanField(
        label = _('I read the ducumentation and know how Importing works'),
        initial = False,
        required = True,
    )
Esempio n. 49
0
def test_change_layout_dynamically_delete_field():
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """)

    form = SampleForm()
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Fieldset(
                "Company Data",
                "is_company",
                "email",
                "password1",
                "password2",
                css_id="multifield_info",
            ),
            Column(
                "first_name",
                "last_name",
                css_id="column_name",
            ),
        ))

    # We remove email field on the go
    # Layout needs to be adapted for the new form fields
    del form.fields["email"]
    del form_helper.layout.fields[0].fields[1]

    c = Context({"form": form, "form_helper": form_helper})
    html = template.render(c)
    assert "email" not in html
Esempio n. 50
0
    def get_form_helper(self):
        helper = FormHelper()
        helper.form_tag = False
        helper.include_media = False
        helper.add_layout(self.get_form_layout())

        return helper
Esempio n. 51
0
    def test_second_layout_multifield_column_buttonholder_submit_div(self):
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                MultiField("Some company data",
                           'is_company',
                           'email',
                           css_id="multifield_info",
                           title="multifield_title",
                           multifield_test="123"),
                Column(
                    'first_name',
                    'last_name',
                    css_id="column_name",
                    css_class="columns",
                ),
                ButtonHolder(
                    Submit('Save the world',
                           '{{ value_var }}',
                           css_class='button white',
                           data_id='test',
                           data_name='test'), Submit('store',
                                                     'Store results')),
                Div('password1',
                    'password2',
                    css_id="custom-div",
                    css_class="customdivs",
                    test_markup="123")))

        template = loader.get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy form form_helper %}
        """)
        c = Context({
            'form': TestForm(),
            'form_helper': form_helper,
            'value_var': "Save"
        })
        html = template.render(c)

        self.assertTrue('multiField' in html)
        self.assertTrue('formColumn' in html)
        self.assertTrue('id="multifield_info"' in html)
        self.assertTrue('title="multifield_title"' in html)
        self.assertTrue('multifield-test="123"' in html)
        self.assertTrue('id="column_name"' in html)
        self.assertTrue('class="formColumn columns"' in html)
        self.assertTrue('class="buttonHolder">' in html)
        self.assertTrue('input type="submit"' in html)
        self.assertTrue('button white' in html)
        self.assertTrue('data-id="test"' in html)
        self.assertTrue('data-name="test"' in html)
        self.assertTrue('name="save-the-world"' in html)
        self.assertTrue('value="Save"' in html)
        self.assertTrue('name="store"' in html)
        self.assertTrue('value="Store results"' in html)
        self.assertTrue('id="custom-div"' in html)
        self.assertTrue('class="customdivs"' in html)
        self.assertTrue('test-markup="123"' in html)
Esempio n. 52
0
class ReleaseBulkeditForm(Form):

    def __init__(self, *args, **kwargs):

        self.instance = kwargs.pop('instance', False)
        self.disable_license = False
        if self.instance and self.instance.publish_date:
            self.disable_license = True

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


        self.helper = FormHelper()
        self.helper.form_id = "bulk_edit%s" % 'asd'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False


        form_class = 'input-xlarge'
        if self.disable_license:
            form_class = 'hidden'


        base_layout = Div(
                Div(HTML('<h4>%s</h4><p>%s</p>' % (_('Bulk Edit'), _('Choose Artist name and/or license to apply on each track.'))), css_class='form-help'),
                Row(
                    Column(
                           Field('bulk_artist_name', css_class='input-xlarge'),
                           css_class='span6'
                           ),
                    Column(
                           HTML('<button type="button" id="bulk_apply_artist_name" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>' % _('Apply Artist to all tracks')),
                           css_class='span2'
                           ),
                    css_class='releasemedia-row row',
                ),
                Row(
                    Column(
                           Field('bulk_license', css_class=form_class),
                           css_class='span6'
                           ),
                    Column(
                           HTML('<button type="button" id="bulk_apply_license" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>' % _('Apply License to all tracks')),
                           css_class='span2'
                           ),
                    css_class='releasemedia-row row',
                ),
                css_class='bulk_edit',
        )


        self.helper.add_layout(base_layout)

    # Fields
    bulk_artist_name = selectable.AutoCompleteSelectField(ArtistLookup, allow_new=True, required=False, label=_('Artist'))
    #bulk_license = selectable.AutoComboboxSelectField(LicenseLookup, allow_new=False, required=False, label=_('License'))
    bulk_license = forms.ModelChoiceField(queryset=License.objects.all(), required=False, label=_('License'))
Esempio n. 53
0
class ExportCreateModelForm(forms.ModelForm):
    class Meta:
        model = Export
        exclude = (
            'user',
            'type',
            'status',
        )

        widgets = {
            #'image': AdvancedFileInput(image_width=76),
            'notes': forms.Textarea(attrs={
                'rows': 2,
                'cols': 30
            }),
        }

    def __init__(self, *args, **kwargs):
        super(ExportCreateModelForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_id = "bulk_edit%s" % 'asd'
        self.helper.form_class = 'form-horizontal form-compact'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = True
        """"""
        layout = Layout(
            Fieldset(
                _('Information'),
                Field('notes', css_class='input-xxlarge'),
            ),
            Fieldset(
                _('Terms & Legal'),
                Field('agree_terms'),
                Field('agree_documentation'),
            ),
            FormActions(
                HTML(
                    '<button type="submit" value="Submit" class="btn btn-primary pull-right"><i class="icon-ok icon-white"></i> Agree & Continue</button>'
                ),
                HTML(
                    '<button type="reset" name="reset" value="reset" class="reset btn btn-secondary pull-right"><i class="icon-trash"></i> Cancel</button>'
                ),
            ),
        )
        self.helper.add_layout(layout)

    agree_terms = forms.BooleanField(
        label=_('I agree to the Terms & Conditions'),
        initial=False,
        required=True,
    )

    agree_documentation = forms.BooleanField(
        label=_('I read the ducumentation and know how Exporting works'),
        initial=False,
        required=True,
    )
Esempio n. 54
0
class ReleaseBulkeditForm(Form):

    def __init__(self, *args, **kwargs):

        self.instance = kwargs.pop('instance', False)
        self.disable_license = False

        """
        # publishing removed
        if self.instance and self.instance.publish_date:
            self.disable_license = True
        """
        super(ReleaseBulkeditForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        form_class = 'input-xlarge'
        if self.disable_license:
            form_class = 'hidden'

        base_layout = Div(
                Div(HTML('<p>"%s": %s</p>' % (_('Bulk Edit'), _('Choose Artist name and/or license to apply on each track.')))),
                Row(
                    Column(
                           Field('bulk_artist_name', css_class='input-xlarge'),
                           css_class='main'
                           ),
                    Column(
                           HTML('<button type="button" id="bulk_apply_artist_name" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>' % _('Apply Artist to all tracks')),
                           css_class='side'
                           ),
                    css_class='bulkedit-row row-fluid',
                ),
                Row(
                    Column(
                           Field('bulk_license', css_class=form_class),
                           css_class='main'
                           ),
                    Column(
                           HTML('<button type="button" id="bulk_apply_license" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>' % _('Apply License to all tracks')),
                           css_class='side'
                           ),
                    css_class='bulkedit-row row-fluid',
                ),
                css_class='bulk_edit',
        )

        self.helper.add_layout(base_layout)

    bulk_artist_name = search_fields.AutocompleteField('alibrary.artist', allow_new=True, required=False, label=_('Artist'))
    bulk_license = forms.ModelChoiceField(queryset=License.objects.filter(selectable=True), required=False, label=_('License'))

    def save(self, *args, **kwargs):
        return True
Esempio n. 55
0
def test_second_layout_multifield_column_buttonholder_submit_div():
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            MultiField(
                "Some company data",
                'is_company',
                'email',
                css_id="multifield_info",
                title="multifield_title",
                multifield_test="123"
            ),
            Column(
                'first_name',
                'last_name',
                css_id="column_name",
                css_class="columns",
            ),
            ButtonHolder(
                Submit('Save the world', '{{ value_var }}', css_class='button white', data_id='test', data_name='test'),
                Submit('store', 'Store results')
            ),
            Div(
                'password1',
                'password2',
                css_id="custom-div",
                css_class="customdivs",
                test_markup="123"
            )
        )
    )

    template = Template("""
            {% load crispy_forms_tags %}
            {% crispy form form_helper %}
        """)
    c = Context({'form': SampleForm(), 'form_helper': form_helper, 'value_var': "Save"})
    html = template.render(c)

    assert 'multiField' in html
    assert 'formColumn' in html
    assert 'id="multifield_info"' in html
    assert 'title="multifield_title"' in html
    assert 'multifield-test="123"' in html
    assert 'id="column_name"' in html
    assert 'class="formColumn columns"' in html
    assert 'class="buttonHolder">' in html
    assert 'input type="submit"' in html
    assert 'button white' in html
    assert 'data-id="test"' in html
    assert 'data-name="test"' in html
    assert 'name="save-the-world"' in html
    assert 'value="Save"' in html
    assert 'name="store"' in html
    assert 'value="Store results"' in html
    assert 'id="custom-div"' in html
    assert 'class="customdivs"' in html
    assert 'test-markup="123"' in html
Esempio n. 56
0
def test_layout_fieldset_row_html_with_unicode_fieldnames(settings):
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Fieldset(
                'Company Data',
                'is_company',
                css_id="fieldset_company_data",
                css_class="fieldsets",
                title="fieldset_title",
                test_fieldset="123"
            ),
            Fieldset(
                'User Data',
                'email',
                Row(
                    'password1',
                    'password2',
                    css_id="row_passwords",
                    css_class="rows",
                ),
                HTML('<a href="#" id="testLink">test link</a>'),
                HTML("""
                    {% if flag %}{{ message }}{% endif %}
                """),
                'first_name',
                'last_name',
            )
        )
    )

    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """)
    c = Context({
        'form': SampleForm(),
        'form_helper': form_helper,
        'flag': True,
        'message': "Hello!",
    })
    html = template.render(c)

    assert 'id="fieldset_company_data"' in html
    assert 'class="fieldsets' in html
    assert 'title="fieldset_title"' in html
    assert 'test-fieldset="123"' in html
    assert 'id="row_passwords"' in html
    assert html.count('<label') == 6

    if settings.CRISPY_TEMPLATE_PACK == 'uni_form':
        assert 'class="formRow rows"' in html
    elif settings.CRISPY_TEMPLATE_PACK == 'bootstrap4':
        assert 'class="form-row rows"' in html
    else:
        assert 'class="row rows"' in html
    assert 'Hello!' in html
    assert 'testLink' in html
Esempio n. 57
0
def test_second_layout_multifield_column_buttonholder_submit_div():
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            MultiField(
                "Some company data",
                "is_company",
                "email",
                css_id="multifield_info",
                title="multifield_title",
                multifield_test="123",
            ),
            Column(
                "first_name",
                "last_name",
                css_id="column_name",
                css_class="columns",
            ),
            ButtonHolder(
                Submit(
                    "Save the world", "{{ value_var }}", css_class="button white", data_id="test", data_name="test"
                ),
                Submit("store", "Store results"),
            ),
            Div("password1", "password2", css_id="custom-div", css_class="customdivs", test_markup="123"),
        )
    )

    template = Template(
        """
            {% load crispy_forms_tags %}
            {% crispy form form_helper %}
        """
    )
    c = Context({"form": SampleForm(), "form_helper": form_helper, "value_var": "Save"})
    html = template.render(c)

    assert "multiField" in html
    assert "formColumn" in html
    assert 'id="multifield_info"' in html
    assert 'title="multifield_title"' in html
    assert 'multifield-test="123"' in html
    assert 'id="column_name"' in html
    assert 'class="formColumn columns"' in html
    assert 'class="buttonHolder">' in html
    assert 'input type="submit"' in html
    assert "button white" in html
    assert 'data-id="test"' in html
    assert 'data-name="test"' in html
    assert 'name="save-the-world"' in html
    assert 'value="Save"' in html
    assert 'name="store"' in html
    assert 'value="Store results"' in html
    assert 'id="custom-div"' in html
    assert 'class="customdivs"' in html
    assert 'test-markup="123"' in html
Esempio n. 58
0
class ReleaseBulkeditForm(Form):
    def __init__(self, *args, **kwargs):

        self.instance = kwargs.pop('instance', False)
        self.disable_license = False
        if self.instance and self.instance.publish_date:
            self.disable_license = True

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

        self.helper = FormHelper()
        self.helper.form_id = "bulk_edit%s" % 'asd'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        form_class = 'input-xlarge'
        if self.disable_license:
            form_class = 'hidden'

        base_layout = Div(
            Div(HTML(
                '<h4>%s</h4><p>%s</p>' %
                (_('Bulk Edit'),
                 _('Choose Artist name and/or license to apply on every track.'
                   ))),
                css_class='form-help'),
            Row(
                Column(Field('bulk_artist_name', css_class='input-xlarge'),
                       css_class='span6'),
                Column(HTML(
                    '<button type="button" id="bulk_apply_artist_name" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>'
                    % _('Apply Artist to all tracks')),
                       css_class='span2'),
                css_class='releasemedia-row row',
            ),
            Row(
                Column(Field('bulk_license', css_class=form_class),
                       css_class='span6'),
                Column(HTML(
                    '<button type="button" id="bulk_apply_license" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>'
                    % _('Apply License to all tracks')),
                       css_class='span2'),
                css_class='releasemedia-row row',
            ),
            css_class='bulk_edit',
        )

        self.helper.add_layout(base_layout)

    # Fields
    bulk_artist_name = selectable.AutoCompleteSelectField(ArtistLookup,
                                                          allow_new=True,
                                                          required=False,
                                                          label=_('Artist'))
Esempio n. 59
0
def test_layout_fieldset_row_html_with_unicode_fieldnames(settings):
    form_helper = FormHelper()
    form_helper.add_layout(
        Layout(
            Fieldset(
                'Company Data',
                'is_company',
                css_id="fieldset_company_data",
                css_class="fieldsets",
                title="fieldset_title",
                test_fieldset="123"
            ),
            Fieldset(
                'User Data',
                'email',
                Row(
                    'password1',
                    'password2',
                    css_id="row_passwords",
                    css_class="rows",
                ),
                HTML('<a href="#" id="testLink">test link</a>'),
                HTML("""
                    {% if flag %}{{ message }}{% endif %}
                """),
                'first_name',
                'last_name',
            )
        )
    )

    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form form_helper %}
    """)
    c = Context({
        'form': SampleForm(),
        'form_helper': form_helper,
        'flag': True,
        'message': "Hello!",
    })
    html = template.render(c)

    assert 'id="fieldset_company_data"' in html
    assert 'class="fieldsets' in html
    assert 'title="fieldset_title"' in html
    assert 'test-fieldset="123"' in html
    assert 'id="row_passwords"' in html
    assert html.count('<label') == 6

    if settings.CRISPY_TEMPLATE_PACK == 'uni_form':
        assert 'class="formRow rows"' in html
    else:
        assert 'class="row rows"' in html
    assert 'Hello!' in html
    assert 'testLink' in html
    def test_layout_fieldset_row_html_with_unicode_fieldnames(self):
        form_helper = FormHelper()
        form_helper.add_layout(
            Layout(
                Fieldset(
                    u'Company Data',
                    u'is_company',
                    css_id = "fieldset_company_data",
                    css_class = "fieldsets",
                    title = "fieldset_title",
                    test_fieldset = "123"
                ),
                Fieldset(
                    u'User Data',
                    u'email',
                    Row(
                        u'password1',
                        u'password2',
                        css_id = "row_passwords",
                        css_class = "rows",
                    ),
                    HTML('<a href="#" id="testLink">test link</a>'),
                    HTML(u"""
                        {% if flag %}{{ message }}{% endif %}
                    """),
                    u'first_name',
                    u'last_name',
                )
            )
        )

        template = loader.get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy form form_helper %}
        """)
        c = Context({
            'form': TestForm(),
            'form_helper': form_helper,
            'flag': True,
            'message': "Hello!",
        })
        html = template.render(c)

        self.assertTrue('id="fieldset_company_data"' in html)
        self.assertTrue('class="fieldsets' in html)
        self.assertTrue('title="fieldset_title"' in html)
        self.assertTrue('test-fieldset="123"' in html)
        self.assertTrue('id="row_passwords"' in html)
        self.assertEqual(html.count('<label'), 6)

        if self.current_template_pack == 'uni_form':
            self.assertTrue('class="formRow rows"' in html)
        else:
            self.assertTrue('class="row rows"' in html)
        self.assertTrue('Hello!' in html)
        self.assertTrue('testLink' in html)