コード例 #1
0
ファイル: forms.py プロジェクト: axant/tgapp-stroller2
class BuyProductForm(Form):
    child = CustomListLayout
    css_class = "form-horizontal"

    product = HiddenField(validator=Validator(required=True))

    quantity = SingleSelectField(label=l_("Quantity"), options=[],
                                 validator=IntValidator(min=1, required=True),
                                 container_attrs={'class': 'form-group'},
                                 label_attrs={'class': 'col-sm-12'},
                                 wrapper_attrs={'class': 'col-sm-4'},
                                 css_class="form-control -quantity")
    submit = None

    submit1 = SubmitButton(value=l_('Add to cart'), key='add_to_cart', name='action',
                          css_class='btn btn-block btn-success stroller2-buy-product-submit-button')
    submit2 = SubmitButton(value=l_('Buy now'), key='buy_now', name='action',
                           css_class='btn btn-block btn-success stroller2-buy-product-submit-button')

    def prepare(self):
        super(BuyProductForm, self).prepare()

        product_field = self.child.children.product
        quantity_field = self.child.children.quantity
        product = app_globals.shop.product.get(_id=product_field.value)
        opts = [({'value': c}, c) for c in range(1, product.configurations[0].qty + 1)]
        quantity_field.grouped_options = [(None, opts)]
コード例 #2
0
ファイル: forms.py プロジェクト: axant/tgapp-stroller2
class NewCategoryForm(ListForm):
    name = TextField(label=l_('Name'), validator=Validator(required=True), css_class='form-control',
                     container_attrs={'class': 'form-group'})
    parent_id = SingleSelectField(label=l_('Parent'),
                                  css_class="form-control", container_attrs={'class': 'form-group'},
                                  options=Deferred(lambda: [(c._id, c.name[tg.config.lang])
                                                            for c in app_globals.shop.category.get_all()]))
    submit = SubmitButton(value=l_('Create'), css_class='btn btn-default')
コード例 #3
0
ファイル: forms.py プロジェクト: axant/tgapp-calendarevents
 class fields(WidgetsList):
     name = TextField(
         label_text=l_("Calendar Name"),
         validator=validators.UnicodeString(not_empty=True))
     events_type = SingleSelectField(
         label_text=l_('Events Type'),
         options=lambda:
         [e.name for e in config['_calendarevents']['event_types']],
         validator=validators.UnicodeString(not_empty=False))
コード例 #4
0
ファイル: forms.py プロジェクト: axant/tgapp-calendarevents
 class NewCalendarForm(TableForm):
     name = TextField(label=l_("Calendar Name"), validator=Required)
     events_type = SingleSelectField(
         label=l_('Events Type'),
         prompt_text=None,
         validator=Required,
         options=Deferred(
             lambda:
             [e.name for e in config['_calendarevents']['event_types']]))
コード例 #5
0
ファイル: forms.py プロジェクト: axant/tgapp-calendarevents
 class fields(WidgetsList):
     event = HiddenField()
     cal = HiddenField(validator=SQLAEntityConverter(model.Calendar))
     name = TextField(
         label_text=l_('Event Name'),
         validator=validators.UnicodeString(not_empty=True))
     summary = TextArea(
         label_text=l_('Event short summary'),
         validator=validators.UnicodeString(not_empty=False))
     datetime = CalendarDateTimePicker(label_text=l_('Event date'))
     location = TextField(
         label_text=l_('Event Location (es: turin,it)'),
         validator=validators.UnicodeString(not_empty=True))
     linked_entity = SingleSelectField(label_text=l_('Linked Entity'))
コード例 #6
0
ファイル: forms.py プロジェクト: axant/tgapp-calendarevents
    class NewEventForm(TableForm):
        event = HiddenField()
        cal = HiddenField(validator=SQLAEntityConverter(model.Calendar))
        name = TextField(label=l_('Event Name'), validator=Required)
        summary = TextArea(label=l_('Event short summary'))
        datetime = CalendarDateTimePicker(label=l_('Event date'))
        location = TextField(label=l_('Event Location (es: turin,it)'),
                             validator=Required)
        linked_entity = SingleSelectField(label=l_('Linked Entity'))

        def prepare(self):
            #simulate ToscaWidget1 child_args
            for c in self.child.children:
                if c.key == 'linked_entity':
                    c.options = self.child_args.get('linked_entity',
                                                    {}).get('options', [])
                    break

            super(NewEventForm, self).prepare()
コード例 #7
0
class PhoneNumberForm(TableForm):
    country_code = SingleSelectField(validator=Required)
    phone_number = TextField(validator=UniquePhoneNumberValidator(
        not_empty=True))
コード例 #8
0
def group(df, aggregation, **kwargs):
    """Groups the data by one or more columns and applies an aggregation function"""
    g = df.groupby(as_index=bool(kwargs.pop('as_index', False)), **kwargs)
    return g.agg(aggregation)


group.form_fields = [
    TextField('by',
              label=l_('Group By'),
              validator=CommaSeparatedListValidator(required=True),
              value='{{.options.by}}',
              placeholder='comma separated fields (name, surname, age)'),
    SingleSelectField('aggregation',
                      label=l_('Aggregation Function'),
                      validator=Validator(required=True),
                      attrs=dict(value='{{.options.aggregation}}'),
                      prompt_text=None,
                      options=[('sum', 'Sum'), ('count', 'Count'),
                               ('avg', 'Average')])
]


def setvalue(df, field, value):
    """Set all the values in a column with the provided one.

    If the column does not exists a new one is created.
    The value can be a numerical expression that calculates the
    value from existing columns.

    Special values: