Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
    def dynamic_column(self):
        """DynamicColumn uses a function to create a Widget on the fly for each cell and uses the specified heading."""
        def make_span(view, data_item):
            return Span(view, text='Answer: %s' % (data_item.some_attribute))

        self.column = DynamicColumn(self.heading, make_span, sort_key=self.sort_key)
        self.expected_cell_html = '<span>Answer: True</span>' # raw attribute used
        self.expected_heading_html = '<span>A heading</span>'
Beispiel #6
0
    def dynamic_column_static_heading(self):
        """A DynamicColumn can also use a function to create its heading on the fly."""
        def make_span(view, data_item):
            return Span(view, text='Answer: %s' % (data_item.some_attribute))

        def make_heading(view):
            return P(view, text=self.heading)

        self.column = DynamicColumn(make_heading, make_span, sort_key=self.sort_key)
        self.expected_cell_html = '<span>Answer: True</span>' # raw attribute used
        self.expected_heading_html = '<p>A heading</p>'
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
0
 def dynamic_column(self):
     self.total_column = DynamicColumn('Heading',
                                       lambda view, item: Widget(view),
                                       make_footer_widget=lambda view, item:
                                       TextNode(view, str(item.total)))
     self.expected_total = '123'