Exemplo n.º 1
0
    def __init__(self, view, address_book_ui):
        super().__init__(view)
        self.rows = QueryAsSequence(Session.query(Address).order_by(
            Address.id),
                                    map_function=lambda address: Row(address))

        self.add_child(H(view, 1, text='Addresses'))

        def make_link_widget(view, row):
            return A.from_bookmark(
                view,
                address_book_ui.get_edit_bookmark(row.address,
                                                  description='Edit'))

        columns = [
            StaticColumn(Field(label='Name'), 'name', sort_key=Address.name),
            StaticColumn(EmailField(label='Email'),
                         'email_address',
                         sort_key=Address.email_address),
            StaticColumn(IntegerField(label='Zip'),
                         'zip_code',
                         sort_key=Address.zip_code),
            DynamicColumn('', make_link_widget)
        ]

        table_layout = TableLayout(striped=True)
        data_table = DataTable(view,
                               columns,
                               self.rows,
                               caption_text='All my friends',
                               summary='Summary for screen reader',
                               table_layout=table_layout,
                               css_id='address_data')
        self.add_child(data_table)
Exemplo n.º 2
0
    def __init__(self, view, address_book_ui):
        super(AddressBookPanel, self).__init__(view)
        self.rows = self.initialise_rows()

        self.add_child(H(view, 1, text='Addresses'))

        form = self.add_child(Form(view, 'address_table_form'))
        self.define_event_handler(self.events.delete_selected)

        def make_link_widget(view, row):
            return A.from_bookmark(
                view,
                address_book_ui.get_edit_bookmark(row.address,
                                                  description='Edit'))

        def make_checkbox_widget(view, row):
            return PrimitiveCheckboxInput(form, row.fields.selected_by_user)

        def make_delete_selected_button(view):
            return Button(form, self.events.delete_selected)

        columns = [
            StaticColumn(Field(label='Name'), 'name'),
            StaticColumn(EmailField(label='Email'), 'email_address'),
            DynamicColumn('', make_link_widget),
            DynamicColumn(make_delete_selected_button, make_checkbox_widget)
        ]

        table = Table(view,
                      caption_text='All my friends',
                      summary='Summary for screen reader')
        table.use_layout(TableLayout(striped=True))
        table.with_data(columns, self.rows)

        form.add_child(table)
Exemplo n.º 3
0
 def __init__(self, view):
     super().__init__(view)
     table = Table(view, caption_text='All my friends', summary='Summary for screen reader')
     table.with_data(
                     [StaticColumn(Field(label='Row Number'), 'row'),
                      StaticColumn(Field(label='Alpha'), 'alpha')],
                      table_fixture.data
                     )
     self.add_child(table)
Exemplo n.º 4
0
    def __init__(self, view):
        super(ScoringDataPanel, self).__init__(view)

        class Row(object):
            def __init__(self, request):
                self.request = request
                self.criteria = {
                    i.label: i
                    for i in self.request.get_criteria()
                }

            def does_criterion_apply(self, criterion):
                return self.criteria[criterion.label].applies

            def value_for(self, criterion):
                return self.criteria[criterion.label].score

            @property
            def score_total(self):
                return self.request.score_total

            @property
            def name(self):
                return self.request.name

            @property
            def surname(self):
                return self.request.surname

        def make_column_value(criterion, view, row):
            return TextNode(
                view, ('yes' if row.does_criterion_apply(criterion) else 'no'))

        def make_score_column_value(criterion, view, row):
            return TextNode(view, str(row.value_for(criterion)))

        columns = []
        columns.append(StaticColumn(IntegerField(label='Name'), 'name'))
        columns.append(StaticColumn(IntegerField(label='Surname'), 'surname'))
        for i in FundingRequest().get_criteria():
            columns.append(
                DynamicColumn(i.label, functools.partial(make_column_value,
                                                         i)))
            columns.append(
                DynamicColumn('#', functools.partial(make_score_column_value,
                                                     i)))
        columns.append(StaticColumn(IntegerField(label='Total'),
                                    'score_total'))

        rows = [Row(i) for i in FundingRequest.find_requests()]
        table = self.add_child(
            Table(view, caption_text='Financial Aid Applications'))
        table.use_layout(TableLayout(responsive=True, striped=True))
        table.with_data(columns, rows)
Exemplo n.º 5
0
 def __init__(self, view):
     super(MainWidget, self).__init__(view)
     table = Table(view)
     table.with_data([
         StaticColumn(Field(label='Another Row Number'), 'row_another'),
         StaticColumn(Field(label='Row Number'), 'row'),
         scenario.total_column
     ],
                     table_fixture.data,
                     footer_items=[EmptyStub(total=123)])
     self.add_child(table)
Exemplo n.º 6
0
    def __init__(self, view):
        super(QualifyDataPanel, self).__init__(view)

        class QualifyDataRow(object):
            def __init__(self, request):
                self.request = request
                self.funding_items = {
                    i.label: i
                    for i in self.request.get_funding_items()
                }

            def qualifies_for_amount(self, funding_item):
                return self.funding_items[funding_item.label].qualified_amount

            @property
            def score_total(self):
                return self.request.score_total

            @property
            def qualify_total(self):
                return self.request.qualify_total

            @property
            def name(self):
                return self.request.name

            @property
            def surname(self):
                return self.request.surname

        def make_column_value(funding_item, view, row):
            return TextNode(view, str(row.qualifies_for_amount(funding_item)))

        columns = []
        columns.append(StaticColumn(IntegerField(label='Name'), 'name'))
        columns.append(StaticColumn(IntegerField(label='Surname'), 'surname'))
        columns.append(StaticColumn(IntegerField(label='Score'),
                                    'score_total'))
        for i in FundingRequest().get_funding_items():
            columns.append(
                DynamicColumn(i.label, functools.partial(make_column_value,
                                                         i)))

        columns.append(
            StaticColumn(IntegerField(label='Total'), 'qualify_total'))

        rows = [QualifyDataRow(i) for i in FundingRequest.find_requests()]
        table = self.add_child(Table(view, caption_text='Qualifying amounts'))
        table.use_layout(TableLayout(responsive=True, striped=True))
        table.with_data(columns, rows)
Exemplo n.º 7
0
    def add_allocation_table(self):
        def make_amount_input(view, allocation):
            return self.make_allocation_input(allocation,
                                              allocation.fields.amount)

        def make_percentage_input(view, allocation):
            return self.make_allocation_input(allocation,
                                              allocation.fields.percentage)

        def make_percentage_total(view, investment_order):
            return self.make_total_widget(
                investment_order.total_allocation_percentage)

        def make_amount_total(view, investment_order):
            return self.make_total_widget(
                investment_order.total_allocation_amount)

        columns = [
            StaticColumn(Field(label='Fund'), 'fund', footer_label='Totals')
        ]
        columns.append(
            DynamicColumn('Percentage',
                          make_percentage_input,
                          make_footer_widget=make_percentage_total))
        columns.append(
            DynamicColumn('Amount',
                          make_amount_input,
                          make_footer_widget=make_amount_total))
        table = Table(self.view).with_data(
            columns,
            self.investment_order.allocations,
            footer_items=[self.investment_order])
        self.add_child(table)
Exemplo n.º 8
0
 def static_column(self):
     """StaticColumn represents an attribute of the item in a row, using a Field to translate the value of that attribute into a string and to specify a column header."""
     self.column = StaticColumn(BooleanField(label=self.heading),
                                'some_attribute',
                                sort_key=self.sort_key)
     self.expected_cell_html = 'on'  # as translated by BooleanField
     self.expected_heading_html = '<span>A heading</span>'
Exemplo n.º 9
0
    def __init__(self, view):
        super(AllFundRequestsPanel, self).__init__(view)

        funding_requests = FundingRequest.find_requests()

        def make_edit_link(view, funding_request):
            form = Form(view, 'edit_%s' % funding_request.id)
            form.add_child(
                Button(
                    form,
                    funding_request.events.edit.with_arguments(
                        funding_request_id=funding_request.id)))
            return form

        columns = [
            StaticColumn(field.unbound_copy(), field.name)
            for field in FundingRequest().fields.values()
        ]
        columns.append(DynamicColumn('', make_edit_link))

        table = self.add_child(
            Table(view, caption_text='Financial Aid Applications'))
        table.use_layout(TableLayout(responsive=True, striped=True))
        table.with_data(columns, funding_requests)
Exemplo n.º 10
0
 def static_column(self):
     self.total_column = StaticColumn(Field(label='Alpha'),
                                      'alpha',
                                      footer_label='Total')
     self.expected_total = 'Total'