예제 #1
0
파일: forms.py 프로젝트: gavchan/cmsman
 def __init__(self, *args, **kwargs):
     self.drug_obj = kwargs.pop('drug_obj', None)
     self.vendor_obj = kwargs.pop('vendor_obj', None)
     self.next_url = kwargs.pop('next_url')
     super(NewItemForm, self).__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.form_tag = True
     self.helper.render_unmentioned_fields = False
     self.helper.form_id = 'id-NewItemForm'
     self.helper.form_class = 'cmmForms'
     self.helper.form_method = 'post'
     if self.next_url:
         action_url = "%s?next=%s" % (
             reverse('inventory:NewItem'),
             self.next_url
         )
     else:
         action_url = reverse('inventory:NewItem')
     self.helper.form_action = action_url
     self.initial['active'] = True
     self.initial['item_type'] = ItemType.objects.get(name='Consumable').id
     self.initial['category'] = Category.objects.get(name='Consumable').id
     try:
         self.initial['vendor'] = self.vendor_obj.id
     except:
         pass
     self.helper.layout = Layout(
         Hidden('version', '1'),
         Row(
             Column('name', css_class='form-group col-md-8'),
             Column(UneditableField('cmsid'), css_class='form-group col-md-4'),
             css_class='form-row',
         ),
         Row(
             Column('note', css_class='form-group col-md-8 mb-0'),
             Column(UneditableField('reg_no'), css_class='form-group col-md-4'),
             css_class='form-row',
         ),
         Row(
             Column('vendor', css_class='form-group col-md-4 mb-0'),
             Column('category', css_class='form-group col-md-4 mb-0'),
             Column(UneditableField('item_type'), css_class='form-group col-md-4 mb-0'),
             css_class="form-row",
         ),
         Row(Column('is_active'), css_class='form-row'),
         Hidden('item_type',  ItemType.objects.get(name='Consumable').id),
         FormActions(
             Submit('submit', 'Submit'),
             Button(
                 'back', 'Cancel',
                 css_class='btn-light',
                 onclick="javascript:history.go(-1);"
             ),
         ),
     )
예제 #2
0
    def __init__(self, *args, submit_title="TITLE", **kwargs):
        super(MotForm, self).__init__(*args, **kwargs)

        correct_arraylist(self)

        # Crérer le helper (pour le rendering)
        self.helper = FormHelper(self)

        self.helper.form_tag = False
        self.helper.render_required_fields = True

        self.helper.form_class = 'form-vertical'
        self.helper.form_id = 'id-mot-form'
        self.helper.layout = Layout(
            Div(Div(HTML("<h3>Masculins</h3>"), css_class=("card-header")),
                Div(Row(
                    Div('masculin_singulier', css_class="col-sm-3"),
                    Div('masculin_pluriel', css_class="col-sm-3"),
                    Div('validation', css_class="col-sm-2"),
                    Div('terminaison', css_class="col-sm-2"),
                    UneditableField('source', readonly=True),
                ),
                    Row(
                        InlineCheckboxes('problème_signalé',
                                         css_class="col-sm-4"),
                        Field('visible', css_class="col-sm-4"),
                    ),
                    Row(Div('masculin_sinuglier_autres', css_class="col-sm-6"),
                        Div('masculin_pluriel_autres', css_class="col-sm-6"),
                        css_class='row'),
                    fréquenceLayout,
                    dictionnairesLayout,
                    notesLayout,
                    css_class="card-body"),
                css_class="card"),
            # Div(
            #     Div(HTML("<h3>Caracteristiques</h3>"), css_class=("card-header")),
            #     Div(
            #         Div(
            #             # HTML('source: {{ form.instance.source }}'),
            #             css_class='row'
            #         ),
            #         Div(
            #             Div('commentaire_externe', css_class="col-sm-6"),
            #             Div('liens', css_class="col-sm-6"),
            #             css_class='row'
            #         ),
            #         Div(
            #             Div(Field('commentaires_internes_text', readonly=True), css_class="col-sm-6"),
            #             Div('new_commentaire_interne', css_class="col-sm-6"),
            #             css_class='row'
            #         ),
            #         css_class="card-body"
            #     ),
            #     css_class="card"
            # ),
        )
예제 #3
0
    def __init__(self, *args, **kwargs):

        super(IncidentForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-3'
        self.helper.field_class = 'col-lg-5'
        self.helper.form_action = '.'
        self.helper.layout = Layout(
            'start_date', 'end_date',
            UneditableField('test', css_class="input-xlarge"), 'street',
            'street_nr', 'incident_type', Submit('submit', 'Submit'))
예제 #4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     # for field in self.fields.values():
     #     field.widget.attrs["class"] = "sm-form-control col-12 mb-4"
     self.helper = FormHelper()
     self.helper.layout = Layout(
         HTML("""
             <ul id="progressbar" class="center">
                 <li class="active">Personal Details</li>
                 <li>Bank Information</li>
                 <li>Verification Fee</li>
             </ul>
         """),
         Fieldset(
             "Personal Information",
             "first_name",
             "mid_name",
             "last_name",
             "state",
             "lga",
             HTML(
                 """<input type="button" name="next" class="next action-button btn-block button button-border button-circle font-weight-medium ml-0 topmargin-sm" value="Next"/>"""
             ),
         ),
         Fieldset(
             "Bank Information",
             HTML(
                 """<small class="text-info bottommargin-lg">Please attach all relevant supporting document</small>"""
             ),
             "bank_name",
             "bvn",
             "acc_no",
             "st_o_acc",
             HTML(
                 """<input type="button" name="next" class="next action-button btn-block button button-border button-circle font-weight-medium ml-0 topmargin-sm" value="Next"/>"""
             ),
             HTML(
                 """<a href="{% url 'home' %}" class="center action-button-previous btn-block button button-border button-circle font-weight-medium ml-0 topmargin-sm">RESET FORM</a>"""
             ),
         ),
         Fieldset(
             "Verify",
             "email",
             "phone",
             UneditableField("amount", css_class='sm-form-control'),
             HTML(
                 """<input onclick="payWithPaystackOrg()" id="pay" type="submit" name="verify" class="submit action-button btn-block button button-border button-circle font-weight-medium ml-0 topmargin-sm" value="Verify"/>"""
             ),
             HTML(
                 """<a href="{% url 'home' %}" class="center action-button-previous btn-block button button-border button-circle font-weight-medium ml-0 topmargin-sm">RESET FORM</a>"""
             ),
         ),
     )
예제 #5
0
 def __init__(self, *args, **kwargs):
     super(ChildForm, self).__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.form_class = 'form-horizontal'
     self.helper.label_class = 'col-lg-2'
     self.helper.field_class = 'col-lg-8'
     self.helper.layout = Layout(
         Fieldset(
             'ID',
             PrependedText('child_id', 'ID'),
             PrependedText('babylab_id', 'B'),
             PrependedText('kid_neurolab_id', 'K'),
         ),
         Fieldset(
             'Demographics',
             'name_first_text',
             'name_last_text',
             'gender_type',
             'dob_date',
             UneditableField('age'),
             'ethnicity',
             'race',
             Field('family', type='hidden'),
         ),
         Fieldset(
             'Medical',
             'handedness',
             'fmri',
             'fmri_date',
             'dob_early',
             'disability',
             'disability_notes',
         ),
         Fieldset(
             'Misc',
             'breastfed',
             'breastfeeding_duration',
             'bottle_fed',
             'notes',
         ),
         SubmitCommonLayout()
     )
     self.helper.form_tag = True
예제 #6
0
    def __init__(self, *args, **kwargs):
        super(FéminineFormSetHelper, self).__init__(*args, **kwargs)
        self.form_method = 'post'
        self.render_required_fields = True
        self.form_tag = False

        self.layout = Layout(
            Div(Div(HTML("<h3>Féminins : {{ subform.singulier.value  }}</h3>"),
                    css_class=("card-header")),
                Div(Row(
                    Field('singulier', wrapper_class="col-sm-3"),
                    Field('pluriel', wrapper_class="col-sm-3"),
                    Field('validation', wrapper_class="col-sm-2"),
                    Field('stratégie', wrapper_class="col-sm-2"),
                    Field('libelles', wrapper_class="col-sm-2"),
                    UneditableField('source', readonly=True),
                ),
                    fréquenceLayout,
                    dictionnairesLayout,
                    notesLayout,
                    css_class="card-body"),
                Field('DELETE'),
                css_class="card flexion_entry"), )
예제 #7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.form_class = 'form-horizontal'
     # self.helper.label_class = "col-sm-1"
     self.field_class = "col-sm-5"
     self.layout = Layout(
         Fieldset(
             '{{ object }}', UneditableField('id', css_class="col-sm-2"),
             'product_type', InlineRadios('threads'),
             InlineRadios('contents'), 'name', 'image',
             HTML("""{% if object.image %}
                             <img src='{{ object.image.url }}' width='100'
                             title='{{ object.name }}'/>
                             </br></br>
                        {% endif %}
                      """)),
         Row(
             Field('price', css_class="col-sm-8", wrapper_class="col-sm-4"),
             Field('price_pre',
                   css_class="col-sm-8",
                   wrapper_class="col-sm-4")),
         Row(
             Field('density',
                   css_class="col-sm-8",
                   wrapper_class="col-sm-4"),
             Field('density_shop',
                   css_class="col-sm-8",
                   wrapper_class="col-sm-4")),
         Row(
             Field('width', css_class="col-sm-8", wrapper_class="col-sm-4"),
             Field('width_shop',
                   css_class="col-sm-8",
                   wrapper_class="col-sm-4")),
         Row(
             Field('dollar_price',
                   css_class="col-sm-9",
                   wrapper_class="col-sm-4"),
             Field('dollar_rate',
                   css_class="col-sm-9",
                   wrapper_class="col-sm-4")),
         Row(
             Field('price_rub_m',
                   css_class="col-sm-9",
                   wrapper_class="col-sm-4"),
             Column(HTML(''), id='prices_with_coeffs',
                    css_class='col-sm-5')),
         Row(
             Field('weight_for_count',
                   css_class="col-sm-9",
                   wrapper_class="col-sm-4"),
             Field('length_for_count',
                   css_class="col-sm-9",
                   wrapper_class="col-sm-4"),
             Field('density_for_count',
                   css_class="col-sm-9",
                   wrapper_class="col-sm-4")),
         Row(
             Field('weight', css_class="col-sm-9",
                   wrapper_class="col-sm-4"),
             Field('meters_in_roll',
                   css_class="col-sm-9",
                   wrapper_class="col-sm-4"),
         ), Submit('submit',
                   _('save').title()))
예제 #8
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for name, field in self.fields.items():
            if field.widget.__class__ == forms.DateTimeInput:
                if 'class' in field.widget.attrs:
                    field.widget.attrs['class'] += 'datetimepicker'
                else:
                    field.widget.attrs.update({'class': 'datetimepicker'})

        image_id = 'image'
        self.current_image = self.instance.image_tag(css_class='border border-dark rounded', tag_id=image_id)

        self.helper = FormHelper(self)
        self.helper.form_method = 'post'
        self.helper.layout = Layout(
            Row(
                Column('title'),
                Column('location'),  # Check bug fix below
                Column('link'),
            ),
            Row(
                Column(css_class='col-lg-4'),
                Column('is_link', css_class='col-lg-8 col-md'),
            ),
            Row(
                Column('event_start_datetime', css_class='col-lg-3 col-md-6'),
                Column('event_end_datetime', css_class='col-lg-3 col-md-6'),
                Column('registration_start_datetime', css_class='col-lg-3 col-md-6'),
                Column('registration_end_datetime', css_class='col-lg-3 col-md-6'),
            ),
            Row(
                Column(css_class='col-lg-6'),
                Column('no_registration', css_class='col-lg-6 col-md'),
            ),
            Row(
                Column(
                    'max_occupancy',
                    'max_occupancy_is_current_occupancy',
                    css_class='col-md',
                ),
                Column(
                    UneditableField('current_occupancy'),
                    css_class='col-md',
                ),
            ),
            'important_message',
            'description',
            Field('image', id=image_id),
            'custom_image_dimensions', # 1
            Div(
                Row(
                    Column(UneditableField('image_height')), # 1
                    Column(UneditableField('image_width')), # 1
                ),
                HTML('<button class="btn btn-link py-0" id="image_dim_reset" formnovalidate name="image_dim_reset" style="display: none;">Reset</button>'),
                id='image_contains_info_dimensions',
                css_class='border rounded p-2 mb-3 bg-light',
            ),
            HTML(
                'Current Image<div class="my-2">' + self.current_image + '</div>'
            ),
            Row(
                Column(
                    Submit('submit', 'Save Event', css_class='mr-2'),
                    # Reset('reset', 'Reset Form', css_class='btn btn-secondary mr-2'),
                    Submit('cancel', 'Cancel', formnovalidate='', css_class='btn btn-warning mr-2'),
                ),
                css_class='my-4',
            ),
        )
        # 1. if this name is changed, change is needed in 'image_preview.js'

        # This is a temporary bug fix. "Location" field is "not required" in models.py but crispy forms seems to ignore it somehow.
        self.fields['location'].required = False
예제 #9
0
    def __init__(self, *args, **kwargs):
        self.delivery_obj = kwargs.pop('delivery_obj', None)
        super(DeliveryPaymentModalForm, self).__init__(*args, **kwargs)
        if self.delivery_obj:
            print(f"Payment for delivery # {self.delivery_obj.id}")
        else:
            print(f"Error: no delivery_obj")
        self.helper = FormHelper()
        self.helper.render_unmentioned_fields = False
        self.helper.form_id = 'id-DeliveryPaymentForm'
        self.helper.form_class = 'cmmForms'
        self.helper.form_method = 'post'
        self.helper.form_action = reverse('ledger:DeliveryPaymentModal',
                                          args=(self.delivery_obj.id, ))
        #self.initial['entry_date'] = timezone.now().strftime('%Y-%m-%d')
        today_date = timezone.now().strftime('%Y-%m-%d')
        self.exp_category_drug = ExpenseCategory.objects.get(code='1').id
        self.initial['entry_date'] = today_date
        self.initial['payment_method'] = PaymentMethod.objects.get(
            name='Cheque').pk
        self.initial['vendor'] = self.delivery_obj.vendor.id
        self.initial['payee'] = self.delivery_obj.vendor.name
        self.initial['invoice_no'] = self.delivery_obj.invoice_no
        self.initial['invoice_date'] = self.delivery_obj.invoice_date
        self.initial['other_ref'] = self.delivery_obj.other_ref
        self.initial['amount'] = self.delivery_obj.amount
        self.initial['category'] = self.exp_category_drug
        self.initial['description'] = 'Drug/Supplement'

        self.helper.layout = Layout(
            Row(
                Column(UneditableField('vendor'),
                       css_class='form-group col-md-8 mb-0'),
                Column('payee', css_class='form-group col-md-4 mb-0'),
                css_class='form-row',
            ),
            Row(
                Column(UneditableField('category'),
                       css_class='form-group col-md-4 mb-0'),
                Column(UneditableField('invoice_no'),
                       css_class='form-group col-md-4 mb-0'),
                Column(UneditableField('invoice_date'),
                       css_class='form-group col-md-4 mb-0'),
                css_class='form-row',
            ),
            Row(
                Column('payment_method', css_class='form-group col-md-4 mb-0'),
                Column('amount', css_class='form-group col-md-4 mb-0'),
                Column('description', css_class='form-group col-md-4 mb-0'),
                css_class='form-row',
            ),
            Row(
                Column('payment_ref', css_class='form-group col-md-4 mb-0'),
                Div(HTML("""
                    <label for="expected_date">Payment date</label>*
                    <div class="input-group date" id="datepicker_expected_date" data-target-input="nearest">
                        <input type="text" 
                            class="form-control datetimepicker-input"
                            data-target="#datepicker_expected_date"
                            placeholder="YYYY-MM-DD"
                            name="expected_date"
                        >
                        <div class="input-group-append" data-target="#datepicker_expected_date" data-toggle="datetimepicker">
                            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                        </div>
                    </div>
                    """),
                    css_class='form-group col-md-4'),
                Column('other_ref', css_class='form-group col-md-4 mb-0'),
                css_class="form-row",
            ),
            Row(
                Column(
                    Field('remarks',
                          css_class='form-group col-md-8 mb-0',
                          rows="1")),
                css_class="form-row",
            ),
            Hidden('entry_date', today_date),
            Hidden('version', '1'),
            Hidden('vendor', self.delivery_obj.vendor.id),
            Hidden('invoice_no', self.delivery_obj.invoice_no),
            Hidden('invoice_date', self.delivery_obj.invoice_date),
            Hidden('category', self.exp_category_drug),
            FormActions(
                Submit('submit', 'Submit'),
                HTML("""
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                """),
            ),
        )
예제 #10
0
    def __init__(self, *args, **kwargs):
        # self.request = kwargs.pop('request', None)
        super(ExpenseUpdateModalForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.render_unmentioned_fields = False
        self.helper.form_id = 'id-ExpenseForm'
        self.helper.form_class = 'cmmForms'
        self.helper.form_method = 'post'
        self.helper.form_action = reverse('ledger:ExpenseUpdateModal',
                                          args=(self.instance.pk, ))

        self.helper.layout = Layout(
            Row(
                Div(HTML("""
                    <label for="entry_date">Entry date</label>
                    <div class="input-group date" id="datepicker_entry_date" data-target-input="nearest">
                        <input type="text" 
                            class="form-control datetimepicker-input"
                            data-target="#datepicker_entry_date"
                            placeholder="YYYY-MM-DD"
                            name="entry_date"
                            value="{{ expense_obj.entry_date|date:'Y-m-d' }}"
                        >
                        <div class="input-group-append" data-target="#datepicker_entry_date" data-toggle="datetimepicker">
                            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                        </div>
                    </div>
                    """),
                    css_class='form-group col-md-4'),
                Column(Field('version', disabled=True),
                       css_class='form-group col-md-4 mb-0'),
            ),
            Row(
                Column(UneditableField('vendor'),
                       css_class='form-group col-md-8 mb-0'),
                Column('payee', css_class='form-group col-md-4 mb-0'),
                css_class='form-row',
            ),
            Row(
                Column('category', css_class='form-group col-md-4 mb-0'),
                Column('invoice_no', css_class='form-group col-md-4 mb-0'),
                Div(HTML("""
                    <label for="invoice_date">Invoice date</label>*
                    <div class="input-group date" id="datepicker_invoice_date" data-target-input="nearest">
                        <input type="text" 
                            class="form-control datetimepicker-input"
                            data-target="#datepicker_invoice_date"
                            placeholder="YYYY-MM-DD"
                            name="invoice_date"
                            value="{{ expense_obj.invoice_date|date:'Y-m-d' }}"
                        >
                        <div class="input-group-append" data-target="#datepicker_invoice_date" data-toggle="datetimepicker">
                            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                        </div>
                    </div>
                    """),
                    css_class='form-group col-md-4'),
                css_class='form-row',
            ),
            Row(
                Column('payment_method', css_class='form-group col-md-4 mb-0'),
                Column(PrependedText('amount', '$'),
                       css_class='form-group col-md-4 mb-0'),
                Column('description', css_class='form-group col-md-4 mb-0'),
                css_class='form-row',
            ),
            Row(
                Column('payment_ref', css_class='form-group col-md-4 mb-0'),
                Div(HTML("""
                    <label for="expected_date">Payment date</label>*
                    <div class="input-group date" id="datepicker_expected_date" data-target-input="nearest">
                        <input type="text" 
                            class="form-control datetimepicker-input"
                            data-target="#datepicker_expected_date"
                            placeholder="YYYY-MM-DD"
                            name="expected_date"
                            value="{{ expense_obj.expected_date|date:'Y-m-d' }}"
                        >
                        <div class="input-group-append" data-target="#datepicker_expected_date" data-toggle="datetimepicker">
                            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                        </div>
                    </div>
                    """),
                    css_class='form-group col-md-4'),
                Column('other_ref', css_class='form-group col-md-4 mb-0'),
                css_class="form-row",
            ),
            Row(
                Column(
                    Field('remarks',
                          css_class='form-group col-md-8 mb-0',
                          rows="1")),
                css_class="form-row",
            ),
            Hidden('vendor', self.instance.vendor.pk),
            Hidden('version', self.instance.version + 1),
            FormActions(
                Submit('submit', 'Submit'),
                HTML("""
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                """),
            ),
        )
예제 #11
0
class MessageForm(forms.Form):
    text_input = forms.CharField()

    textarea = forms.CharField(
        widget=forms.Textarea(),
    )

    uneditable_field = forms.ChoiceField(
        choices=(
            ('one', 'Option One'),
            ('two', 'Option two'),
        ),
        initial='two'
    )

    radio_buttons = forms.ChoiceField(
        choices=(
            ('option_one',
             "Option one is this and that be sure to include why it's great"),
            ('option_two',
             "Option two can is something else and selecting it will deselect option one")
        ),
        widget=forms.RadioSelect,
        initial='option_two',
    )

    checkboxes = forms.MultipleChoiceField(
        choices=(
            ('option_one',
             "Option one is this and that be sure to include why it's great"),
            ('option_two',
             'Option two can also be checked and included in form results'),
            ('option_three',
             'Option three can yes, you guessed it also be checked and included in form results')
        ),
        initial='option_one',
        widget=forms.CheckboxSelectMultiple,
        help_text="<strong>Note:</strong> Labels surround all the options for much larger click areas and a more usable form.",
    )

    appended_text = forms.CharField(
        help_text="Here's more help text"
    )

    appended_text2 = forms.CharField(
        help_text="And a bigger appended text field"
    )

    prepended_text = forms.CharField()

    prepended_text_two = forms.CharField()

    multicolon_select = forms.MultipleChoiceField(
        choices=(('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')),
        help_text=(
            'This strange option climbing out of the box is in the examples too '
            'Only without Flexbox '
            'https://v4-alpha.getbootstrap.com/components/forms/#form-controls'),
    )

    boolean_field = forms.BooleanField()

    file_field = forms.FileField()

    # Bootstrap4
    helper = FormHelper()
    helper.layout = Layout(
        Field('text_input', css_class='form-control-lg'),
        Field('textarea', rows="3", css_class='form-control-lg'),
        'radio_buttons',
        UneditableField('uneditable_field'),
        Field('checkboxes', style="background: #FAFAFA"),
        AppendedText('appended_text', '.00'),
        AppendedText('appended_text2', '.00', css_class='form-control-lg'),
        PrependedText('prepended_text',
                      '<input type="checkbox" checked="checked" value="" id="" name="">',
                      active=True),
        PrependedText('prepended_text_two', '@'),
        'multicolon_select',
        'boolean_field',
        'file_field',
        FormActions(
            Submit('save_changes', 'Save changes', css_class="btn-primary"),
            Submit('cancel', 'Cancel'),
        )
    )