Exemplo n.º 1
0
 def headers(self):
     headers = DataTablesHeader(DataTablesColumn(_("View Form")),
                                DataTablesColumn(_("Username")),
                                DataTablesColumn(_("Submit Time")),
                                DataTablesColumn(_("Form Type")),
                                DataTablesColumn(_("Error Type")),
                                DataTablesColumn(_("Error Message")))
     headers.no_sort = True
     return headers
Exemplo n.º 2
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn(_('Date')),
         DataTablesColumn(_('Content')),
         DataTablesColumn(_('Phone Number')),
         DataTablesColumn(_('Direction')),
         DataTablesColumn(_('Gateway')),
         DataTablesColumn(_('Status')),
     )
Exemplo n.º 3
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn(_('Code')),
         DataTablesColumn(_('Facility Name')),
         DataTablesColumn(_('Delivery Status')),
         DataTablesColumn(_('Delivery Date')),
         DataTablesColumn(_('This Cycle Lead Time')),
         DataTablesColumn(_('Average Lead Time In Days'))
     )
Exemplo n.º 4
0
def data_table(request, domain):
    # TODO this should be async (large tables time out)
    table_ids = request.GET.getlist("table_id")
    try:
        sheets = prepare_fixture_html(table_ids, domain)
    except FixtureDownloadError as e:
        messages.info(request, six.text_type(e))
        raise Http404()
    sheets.pop("types")
    if not sheets:
        return {
            "headers":
            DataTablesHeader(DataTablesColumn("No lookup Tables Uploaded")),
            "rows": []
        }
    selected_sheet = list(sheets.values())[0]
    selected_sheet_tag = list(sheets.keys())[0]
    data_table = {
        "headers": None,
        "rows": None,
        "table_id": selected_sheet_tag
    }
    headers = [
        DataTablesColumn(header) for header in selected_sheet["headers"]
    ]
    data_table["headers"] = DataTablesHeader(*headers)
    if selected_sheet["headers"] and selected_sheet["rows"]:
        data_table["rows"] = [[
            format_datatables_data(x or "--", "a") for x in row
        ] for row in selected_sheet["rows"]]
    else:
        messages.info(
            request,
            _("No items are added in this table type. Upload using excel to add some rows to this table"
              ))
        data_table["rows"] = [["--" for x in range(0, len(headers))]]
    return data_table
Exemplo n.º 5
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn("Date Created"),
         DataTablesColumn("Account"),
         DataTablesColumn("Project"),
         DataTablesColumn("Billing Admin"),
         DataTablesColumn("Stripe Transaction ID"),
         DataTablesColumn("Amount (USD)"),
     )
Exemplo n.º 6
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn("Show Form", sortable=False, span=1),
         DataTablesColumn("Received", prop_name="received_on", span=1),
         DataTablesColumn("Created Date", prop_name="form.meta.timeStart", span=1),
         DataTablesColumn("Encounter Date", sortable=False, span=1),
         DataTablesColumn("Form", prop_name="form.#type", span=1),
         DataTablesColumn("CHW", prop_name="form.meta.username", span=1)
     )
Exemplo n.º 7
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn("Gateway Type"),
         DataTablesColumn("Specific Gateway"),
         DataTablesColumn("Direction"),
         DataTablesColumn("Country Code"),
         DataTablesColumn("Prefix"),
         DataTablesColumn("Fee (Amount, Currency)")
     )
Exemplo n.º 8
0
 def headers(self):
     return DataTablesHeader(*[
         DataTablesColumn('Vaccine'),
         DataTablesColumn('Number'),
         DataTablesColumn('Total Eligible'),
         DataTablesColumn('Percentage'),
         DataTablesColumn('Dropout Number'),
         DataTablesColumn('Dropout Percentage')
     ])
Exemplo n.º 9
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn('#'),
         DataTablesColumn('Equipment & Materials'),
         DataTablesColumn('Available'),
         DataTablesColumn('Usable'),
         DataTablesColumn('Not Available'),
         DataTablesColumn('No. of AWCs requiring replacement')
     )
Exemplo n.º 10
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn(_("Username")),
         DataTablesColumn(_("Project Spaces")),
         DataTablesColumn(_("Date Joined")),
         DataTablesColumn(_("Last Login")),
         DataTablesColumn(_("Type")),
         DataTablesColumn(_("SuperUser?")),
     )
Exemplo n.º 11
0
    def __init__(self, header, agg_column, format_fn=None, slug=None, *args, **kwargs):
        """
        Args:
            :param header:
                The column header.
            :param name:
                The name of the column. This must match up to a column name in the report database.
            :param args:
                Additional positional arguments will be passed on when creating the DataTablesColumn
            :param agg_column:
                Instance of sqlagg column class. See sqlagg.columns.BaseColumn
        Kwargs:
            :param header_group=None:
                An instance of corehq.apps.reports.datatables.DataTablesColumnGroup to which this column header will
                be added.
            :param sortable:
                Indicates if the column should be sortable. If true and no format_fn is provided then
                the default datatables format function is used. Defaults to True.
            :param sort_type:
                See corehq.apps.reports.datatables.DTSortType
            :param format_fn=None:
                Function to apply to value before display. Useful for formatting and sorting.
                See corehq.apps.reports.util.format_datatables_data
            :param slug=None:
                Unique ID for the column. If not supplied assumed to be 'agg_column.name'.
                This is used by the Report API.
            :param kwargs:
                Additional keyword arguments will be passed on when creating the DataTablesColumn

        """
        self.slug = slug or agg_column.name

        if 'sortable' not in kwargs:
            kwargs['sortable'] = True

        if kwargs['sortable'] and 'sort_type' not in kwargs and not isinstance(agg_column, SimpleColumn):
            kwargs['sort_type'] = DTSortType.NUMERIC
            format_fn = format_fn or format_data

        self.view = agg_column

        self.header_group = kwargs.pop('header_group', None)
        self.header = header

        self.data_tables_column = DataTablesColumn(header, *args, **kwargs)
        if self.header_group:
            self.header_group.add_column(self.data_tables_column)

        super(DatabaseColumn, self).__init__(format_fn=format_fn)
Exemplo n.º 12
0
 def headers(self):
     return DataTablesHeader(
         DataTablesColumn("Date", span=1, sort_type=DATE, prop_name='date',
                          sort_direction=[DTSortDirection.DSC,
                                          DTSortDirection.ASC]),
         DataTablesColumn("Log Type", span=1, prop_name='type'),
         DataTablesColumn("Logged in Username", span=2,
                          prop_name='username'),
         DataTablesColumn("Device Users", span=2),
         DataTablesColumn("Device ID", span=2, prop_name='device_id'),
         DataTablesColumn("Message", span=5, prop_name='msg'),
         DataTablesColumn("App Version", span=1, prop_name='app_version'),
     )
Exemplo n.º 13
0
    def headers(self):
        columns = [
            DataTablesColumn(
                mark_safe(
                    f"""
                    {_('Select')}<button id="all" class="select-visible btn btn-xs btn-default">{_('all')}</button>
                    <button id="none" class="select-none btn btn-xs btn-default">{_('none')}</button>
                    """
                ),
                sortable=False, span=3
            ),
            DataTablesColumn(_('Status')),
            DataTablesColumn(_('URL')),
            DataTablesColumn(_('Last sent date')),
            DataTablesColumn(_('Retry Date')),
            DataTablesColumn(_('Delivery Attempts')),
            DataTablesColumn(_('View payload')),
            DataTablesColumn(_('Resend')),
            DataTablesColumn(_('Cancel or Requeue payload'))
        ]
        if toggles.SUPPORT.enabled_for_request(self.request):
            columns.insert(2, DataTablesColumn(_('Payload ID')))

        return DataTablesHeader(*columns)
Exemplo n.º 14
0
    def columns(self):
        view_case_column = DataTablesColumn(
            _("View Case"),
            prop_name='_link',
            sortable=False,
        )

        if self._is_exporting:
            persistent_cols = [
                DataTablesColumn(
                    "@case_id",
                    prop_name='@case_id',
                    sortable=True,
                )
            ]
        elif self.is_rendered_as_email:
            persistent_cols = [view_case_column]
        else:
            persistent_cols = [
                DataTablesColumn(
                    "case_name",
                    prop_name='case_name',
                    sortable=True,
                    visible=False,
                ),
                view_case_column,
            ]

        return persistent_cols + [
            DataTablesColumn(
                column,
                prop_name=column,
                sortable=column not in CASE_COMPUTED_METADATA,
            ) for column in CaseListExplorerColumns.get_value(
                self.request, self.domain)
        ]
Exemplo n.º 15
0
    def headers(self):
        headers = DataTablesHeader(
            DataTablesColumn('Facility'),
            DataTablesColumn('Date of transaction submission'),
            DataTablesColumn('Transaction Type'))

        if not self.split_by_product:
            headers.add_column(DataTablesColumn("Product"))
            headers.add_column(DataTablesColumn("Stock On Hand"))
            headers.add_column(DataTablesColumn("Consumption"))
        else:
            for product in self.products:
                headers.add_column(
                    DataTablesColumn("{0} Stock on Hand".format(product.name)))
                headers.add_column(
                    DataTablesColumn("{0} Consumption".format(product.name)))
        return headers
Exemplo n.º 16
0
 def headers(self):
     columns = [
         DataTablesColumn(ugettext_lazy('Status')),
         DataTablesColumn(ugettext_lazy('Incremenal Export Name')),
         DataTablesColumn(ugettext_lazy('Date')),
         DataTablesColumn(ugettext_lazy('Cases in export')),
         DataTablesColumn(ugettext_lazy('Download File')),
         DataTablesColumn(ugettext_lazy('Request Details')),
     ]
     return DataTablesHeader(*columns)
Exemplo n.º 17
0
 def headers(self):
     headers = DataTablesHeader(
         DataTablesColumn(_("Username"), prop_name="username.exact"),
         DataTablesColumn(_("Project Spaces")),
         DataTablesColumn(_("Date Joined"), prop_name="date_joined"),
         DataTablesColumn(_("Last Login"), prop_name="last_login"),
         DataTablesColumn(_("Type"), prop_name="doc_type"),
         DataTablesColumn(_("SuperUser?"), prop_name="is_superuser"),
     )
     return headers
Exemplo n.º 18
0
 def headers(self):
     headers = DataTablesHeader(
         DataTablesColumn(_("Mother Name"), prop_name="mother_name.#value"),
         DataTablesColumn(_("Baby Name"), sortable=False),
         DataTablesColumn(_("CHW Name"), prop_name="owner_display", sortable=False),
         DataTablesColumn(_("Date of Delivery"),  prop_name="date_birth.#value"),
         DataTablesColumn(_("PNC Visit Completion"), sortable=False),
         DataTablesColumn(_("Delivery"), prop_name="place_birth.#value"),
     )
     return headers
Exemplo n.º 19
0
 def headers(self):
     # These match the values returned by rows()
     return DataTablesHeader(
         DataTablesColumn('Subject Key'),
         DataTablesColumn('Study Subject ID'),
         DataTablesColumn('Enrollment Date'),
         DataTablesColumn('Sex'),
         DataTablesColumn('Date of Birth'),
         DataTablesColumn('Events'),
     )
Exemplo n.º 20
0
 def report_context(self):
     context = {'name': self.name, 'export_only': self.export_only}
     if not self.needs_filters:
         context['data_providers'] = [{
             'title':
             data_provider.title,
             'slug':
             data_provider.slug,
             'headers':
             DataTablesHeader(
                 *(DataTablesColumn(header)
                   for header in data_provider.headers), ),
             'rows':
             data_provider.rows,
         } for data_provider in self.data_providers]
     return context
Exemplo n.º 21
0
    def __init__(self,
                 header,
                 aggregate_fn,
                 columns,
                 format_fn=None,
                 slug=None,
                 **kwargs):
        """
        Args:
            :param header:
                The column header.
            :param aggregate_fn:
                The function used to aggregate the individual values into a single value.
            :param columns:
                List of columns (instances of sqlagg.BaseColumn).
        Kwargs:
            :param format_fn=None:
                Function to apply to value before display. Useful for formatting and sorting.
                See corehq.apps.reports.util.format_datatables_data
            :param slug=None:
                Unique ID for the column. If not supplied assumed to be slugify(header).
                This is used by the Report API.
            :param sortable:
                Indicates if the column should be sortable. If true and no format_fn is provided then
                the default datatables format function is used. Defaults to True.
            :param sort_type:
                See corehq.apps.reports.datatables.DTSortType
        """
        self.aggregate_fn = aggregate_fn
        self.slug = slug or slugify(header)

        if 'sortable' not in kwargs:
            kwargs['sortable'] = True

        if kwargs['sortable'] and 'sort_type' not in kwargs:
            kwargs['sort_type'] = DTSortType.NUMERIC
            format_fn = format_fn or format_data

        self.header = header
        self.header_group = kwargs.pop('header_group', None)
        self.data_tables_column = DataTablesColumn(header, **kwargs)
        if self.header_group:
            self.header_group.add_column(self.data_tables_column)

        self.view = sqlagg.AggregateColumn(aggregate_fn, *columns)

        super(AggregateColumn, self).__init__(format_fn=format_fn)
Exemplo n.º 22
0
 def headers(self):
     headers = DataTablesHeader(
         DataTablesColumn("Name", span=3),
         DataTablesColumn("Organization", span=2),
         DataTablesColumn("Category", span=2),
         DataTablesColumn("Copies", span=2),
         DataTablesColumn("License", span=2),
         DataTablesColumn("Last Modified", span=3, sort_type=DTSortType.NUMERIC)
     )
     headers.custom_sort = [[1, 'asc']]
     return headers
Exemplo n.º 23
0
 def headers(self):
     header = DataTablesHeader(
         DataTablesColumn(_("Timestamp")),
         DataTablesColumn(_("User Name")),
         DataTablesColumn(_("Phone Number")),
         DataTablesColumn(_("Direction")),
         DataTablesColumn(_("Message")),
         DataTablesColumn(_("Type"), sortable=False),
     )
     header.custom_sort = [[0, 'desc']]
     return header
Exemplo n.º 24
0
 def headers(self):
     header = DataTablesHeader(
         DataTablesColumn(_('Date')),
         DataTablesColumn(_('Content'), sortable=False),
         DataTablesColumn(_('Type'), sortable=False),
         DataTablesColumn(_('Recipient'), sortable=False),
         DataTablesColumn(_('Status'), sortable=False),
         DataTablesColumn(_('Detail'), sortable=False),
     )
     header.custom_sort = [[0, 'desc']]
     return header
Exemplo n.º 25
0
 def _columns(self):
     selected_app_info = "selected app version {app_id}".format(
         app_id=self.selected_app_id
     ) if self.selected_app_id else "for last built app"
     return [
         DataTablesColumn(_("Username"),
                          prop_name='username.exact',
                          sql_col='user_dim__username'),
         DataTablesColumn(
             _("Last Submission"),
             prop_name='reporting_metadata.last_submissions.submission_date',
             alt_prop_name=
             'reporting_metadata.last_submission_for_user.submission_date',
             sql_col='last_form_submission_date'),
         DataTablesColumn(
             _("Last Sync"),
             prop_name='reporting_metadata.last_syncs.sync_date',
             alt_prop_name='reporting_metadata.last_sync_for_user.sync_date',
             sql_col='last_sync_log_date'),
         DataTablesColumn(
             _("Application"),
             help_text=_(
                 "The name of the application from the user's last request."
             ),
             sortable=False),
         DataTablesColumn(
             _("Application Version"),
             help_text=_(
                 "The application version from the user's last request."),
             prop_name='reporting_metadata.last_builds.build_version',
             alt_prop_name=
             'reporting_metadata.last_build_for_user.build_version',
             sql_col='last_form_app_build_version'),
         DataTablesColumn(
             _("CommCare Version"),
             help_text=_(
                 """The CommCare version from the user's last request"""),
             prop_name=
             'reporting_metadata.last_submissions.commcare_version',
             alt_prop_name=
             'reporting_metadata.last_submission_for_user.commcare_version',
             sql_col='last_form_app_commcare_version'),
         DataTablesColumn(
             _("Number of unsent forms in user's phone"),
             help_text=_(
                 "The number of unsent forms in users' phones for {app_info}"
                 .format(app_info=selected_app_info)),
             sortable=False),
     ]
Exemplo n.º 26
0
    def headers(self):
        header = DataTablesHeader()
        columns = self.model.columns
        if self.model.have_groups:
            header.add_column(DataTablesColumnGroup('', columns[0].data_tables_column))
        else:
            header.add_column(columns[0].data_tables_column)

        self.groups = SQLProduct.objects.filter(domain=self.domain, is_archived=False)
        for group in self.groups:
            if self.model.have_groups:
                header.add_column(DataTablesColumnGroup(group.name,
                    *[columns[j].data_tables_column for j in xrange(1, len(columns))]))
            else:
                header.add_column(DataTablesColumn(group.name))

        return header
Exemplo n.º 27
0
    def headers(self):
        r_type = self.slug.split('_')[0]
        if r_type == 'district':
            col_name = 'hf'
        else:
            col_name = 'user_name'

        def format(data):
            if col_name == 'user_name':
                return raw_username(data)
            else:
                return data
        headers = DataTablesHeader()
        headers.add_column(self.columns[0].data_tables_column)
        for head in self.records.keys():
            headers.add_column(DataTablesColumn(format(head)))
        return headers
Exemplo n.º 28
0
 def columns(self):
     return [
         DataTablesColumn('date', help_text=_('timestamp for receipt of incoming emg request, automatic')),
         DataTablesColumn('location code', help_text=_('the location that corresponds to the health facility')),
         DataTablesColumn('status', help_text=_('current status of the transaction (rejected, cancelled, '
                                                'cancelled by user, received, approved, dispatched, delivered, '
                                                'confirmed)')),
         DataTablesColumn('total delivery time', help_text=_('time between emg status and rec status, '
                                                             'total time to resupply  in minutes')),
         DataTablesColumn('confirmation timestamp', help_text=_('timestamp for receipt of rec confirmation')),
         DataTablesColumn('emergency order request', help_text=_('structured string with product long codes'
                                                                 ' (for example, 10010203MD) and quantities'
                                                                 ' for products requested in emg request ')),
         DataTablesColumn('delivered products cost', help_text=_('value of products dropped to the'
                                                                 ' health facility, tanzanian shillings')),
         DataTablesColumn('products requested and not confirmed',
                          help_text=_('structured string with products '
                                      'that were not confirmed based on the request'))
     ]
Exemplo n.º 29
0
    def __init__(self, header, aggregate_fn, *columns, **kwargs):
        """
        Args:
            :param header:
                The column header.
            :param aggregate_fn:
                The function used to aggregate the individual values into a single value.
            :param columns:
                List of columns (instances of sqlagg.BaseColumn).
        """
        self.aggregate_fn = aggregate_fn

        self.header_group = kwargs.pop('header_group', None)
        self.data_tables_column = DataTablesColumn(header, **kwargs)
        if self.header_group:
            self.header_group.add_column(self.data_tables_column)

        self.view = sqlagg.AggregateColumn(aggregate_fn, *columns)
Exemplo n.º 30
0
 def headers(self):
     headers = DataTablesHeader(
         DataTablesColumn(_("Case Type"), prop_name="type.exact"),
         DataTablesColumn(_("Name"), prop_name="name.exact"),
         DataTablesColumn(_("Owner"),
                          prop_name="owner_display",
                          sortable=False),
         DataTablesColumn(_("Created Date"), prop_name="opened_on"),
         DataTablesColumn(_("Created By"),
                          prop_name="opened_by_display",
                          sortable=False),
         DataTablesColumn(_("Modified Date"), prop_name="modified_on"),
         DataTablesColumn(_("Status"),
                          prop_name="get_status_display",
                          sortable=False))
     headers.custom_sort = [[5, 'desc']]
     return headers