Example #1
0
def get_form_subtitle(month=None, year=None, function=None, _class='col-md-4'):
    months = get_months_list()
    subtitle = ''
    if year and month:
        for m in months:
            if m[0] == month:
                month_title = m[1]
        subtitle = month_title + " " + str(year)
    else:
        year = TODAY_LOCAL.year
        month = TODAY_LOCAL.month

    form = SQLFORM.factory(Field('month',
                                 requires=IS_IN_SET(months, zero=None),
                                 default=month,
                                 label=T("")),
                           Field('year', 'integer', default=year, label=T("")),
                           submit_button=T("Run report"))
    form.attributes['_name'] = 'form_select_date'
    form.attributes['_class'] = 'overview_form_select_date'

    input_month = form.element('select[name=month]')
    # input_month.attributes['_onchange'] = "this.form.submit();"

    input_year = form.element('input[name=year]')
    # input_year.attributes['_onchange'] = "this.form.submit();"
    input_year.attributes['_type'] = 'number'
    # input_year.attributes['_class']    = 'input_margins'

    form.element('input[name=year]')

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    ## Show current
    url_current_month = URL('my_classes_show_current')
    show_current_month = A(T("Current month"),
                           _href=url_current_month,
                           _class='btn btn-default')
    month_chooser = ''
    if not function == 'attendance_classes':
        month_chooser = overview_get_month_chooser(function)

    form = DIV(XML(
        '<form id="MainForm" action="#" enctype="multipart/form-data" method="post">'
    ),
               DIV(form.custom.widget.month,
                   form.custom.widget.year,
                   _class=_class),
               form.custom.end,
               _class='row')

    return dict(form=form,
                subtitle=subtitle,
                month_chooser=month_chooser,
                current_month=show_current_month,
                submit=submit)
Example #2
0
def get_month_subtitle(month, year):
    """
    :param month: int 1 - 12
    :return: subtitle
    """
    months = get_months_list()
    subtitle = ''
    if year and month:
        for m in months:
            if m[0] == month:
                month_title = m[1]
        subtitle = month_title + " " + str(year)

    return subtitle
Example #3
0
    def get_month_year_form(self, year=None, month=None, submit_button=''):
        """
            :return: month & year form
        """
        from general_helpers import get_months_list
        months = get_months_list()

        # Set default values
        T = current.T
        TODAY_LOCAL = current.TODAY_LOCAL
        if not year:
            year = TODAY_LOCAL.year
        if not month:
            month = TODAY_LOCAL.month
        if not submit_button:
            submit_button = T('Submit')


        form = SQLFORM.factory(
            Field('month',
                  requires=IS_IN_SET(months, zero=None),
                  default=month,
                  label=T("Month")),
            Field('year', 'integer',
                  default=year,
                  label=T("Year")),
            submit_button=submit_button,
            formstyle='bootstrap3_stacked'
        )

        # form.attributes['_name'] = 'form_select_date'
        # form.attributes['_class'] = 'overview_form_select_date'

        input_month = form.element('select[name=month]')
        # input_month.attributes['_onchange'] = "this.form.submit();"

        input_year = form.element('input[name=year]')
        # input_year.attributes['_onchange'] = "this.form.submit();"
        input_year.attributes['_type'] = 'number'
        # input_year.attributes['_class']    = 'input_margins'

        form.element('input[name=year]')

        result = self.set_form_id_and_get_submit_button(form, 'MainForm')


        return dict(form = result['form'],
                    submit = result['submit'])
Example #4
0
def index_get_form(date_from, date_until):
    """
    Get month chooser form for index
    """
    from general_helpers import get_months_list
    from general_helpers import set_form_id_and_get_submit_button

    months = get_months_list()

    form = SQLFORM.factory(
        Field('date_from', 'date', required=True,
            default=date_from,
            requires=IS_DATE_IN_RANGE(format=DATE_FORMAT,
                                      minimum=datetime.date(1900,1,1),
                                      maximum=datetime.date(2999,1,1)),
            represent=represent_date,
            label=T("From date"),
            widget=os_datepicker_widget),
        Field('date_until', 'date', required=True,
            default=date_until,
            requires=IS_DATE_IN_RANGE(format=DATE_FORMAT,
                                      minimum=datetime.date(1900,1,1),
                                      maximum=datetime.date(2999,1,1)),
            represent=represent_date,
            label=T("Until date"),
            widget=os_datepicker_widget),
        # Field('school_locations_id', db.school_locations,
        #       requires=IS_IN_DB(db(loc_query),
        #                         'school_locations.id',
        #                         '%(Name)s',
        #                         zero=T("All locations")),
        #       default=session.reports_tax_summary_index_school_locations_id,
        #       represent=lambda value, row: locations_dict.get(value, T("No location")),
        #       label=T("Location")),
        formstyle='bootstrap3_stacked',
        submit_button=T("Run report")
    )

    result = set_form_id_and_get_submit_button(form, 'MainForm')
    form = result['form']
    submit = result['submit']

    form_display = DIV(
        XML('<form id="MainForm" action="#" enctype="multipart/form-data" method="post">'),
        DIV(LABEL(form.custom.label.date_from),
            form.custom.widget.date_from,
            _class='col-md-6'
        ),
        DIV(LABEL(form.custom.label.date_until),
            form.custom.widget.date_until,
            _class='col-md-6'
        ),
        form.custom.end,
        _class='row'
    )

    return dict(
        form=result['form'],
        submit=result['submit'],
        form_display=form_display
    )