class OrganisationUnitGrid(Dhis2Grid): title = StaticText("Organisation units") lead = LeadingColumn( label="Name", text="name", secondary_text=None, icon="get_icon", translate=False, ) dhis2_id = TextColumn(text="dhis2_id", label="ID", translate=False) code = TextColumn(text="code", translate=False) tags = TagColumn(value="index.tags.all") last_synced = DateColumn(date="instance.last_synced_at") view = LinkColumn(text="View") download = Action(label="Download all", url="get_download_url", icon="table") @property def download_url(self): return "connector_dhis2:organisation_unit_download" @property def export_suffix(self): return "organisation_units" def get_icon(self, _: OrganisationUnit): return "ui/icons/location_marker.html"
class DatasourceGrid(Datagrid): lead = LeadingColumn( label="Name", text="display_name", secondary_text="content_type_name", image_src="symbol", detail_url="get_datasource_url", ) owner = TextColumn( text="owner.display_name", secondary_text="owner.get_organization_type_display", translate=False, ) content = TextColumn(text="content") tags = TagColumn(value="tags.all") location = CountryColumn(value="countries") view = LinkColumn(text="View", url="get_datasource_url") def get_datasource_url(self, index: Index): if not hasattr(index.object, "get_absolute_url") or not callable( index.object.get_absolute_url): raise NotImplementedError( "Datasource models should implement get_absolute_url()") return index.object.get_absolute_url()
class DatasetGrid(Dhis2Grid): title = StaticText("Datasets") lead = LeadingColumn( label="Name", text="name", icon="get_icon", translate=False, ) dhis2_id = TextColumn(text="dhis2_id", label="ID", translate=False) code = TextColumn(text="code", translate=False) tags = TextColumn(text="todo_tags", translate=False) last_synced = DateColumn(date="instance.last_synced_at", label=_("Last synced")) view = LinkColumn(text="View") download = Action(label="Download all", url="get_download_url", icon="table") @property def download_url(self): return "connector_dhis2:dataset_download" @property def export_suffix(self): return "datasets" def get_icon(self, _): return "ui/icons/collection.html"
class DataElementGrid(Dhis2Grid): title = StaticText("Data elements") lead = LeadingColumn( label="Name", text="name", secondary_text="get_value_type_display", icon="get_icon", translate=False, ) dhis2_id = TextColumn(text="dhis2_id", label="ID", translate=False) code = TextColumn(text="code", translate=False) tags = TagColumn(value="index.tags.all") last_synced = DateColumn(date="instance.last_synced_at") view = LinkColumn(text="View") download = Action(label="Download all", url="get_download_url", icon="table") @property def download_url(self): return "connector_dhis2:data_element_download" @property def export_suffix(self): return "data_elements" def get_icon(self, data_element: DataElement): if data_element.domain_type == DomainType.AGGREGATE: return "ui/icons/chart_bar.html" elif data_element.domain_type == DomainType.TRACKER: return "ui/icons/user_circle.html" return "ui/icons/exclamation.html"
class DAGRunGrid(Datagrid): lead = LeadingColumn( label="Run", text="get_label", icon="get_icon", ) execution_date = DateColumn( date="execution_date", label="Execution date", date_format="%Y-%m-%d %H:%M" ) state = StatusColumn(value="status") duration = DurationColumn(duration="duration", short_form=True) user = TextColumn(text="user.display_name") view = LinkColumn(text="View") @staticmethod def get_label(run: DAGRun) -> str: if hasattr(run, "favorite") and getattr(run, "favorite") is not None: return getattr(run, "favorite") elif run.run_id.startswith("manual"): return "Manual" elif run.run_id.startswith("scheduled"): return "Scheduled" @staticmethod def is_favorite(run: DAGRun) -> str: return hasattr(run, "favorite") and getattr(run, "favorite") is not None def get_icon(self, run: DAGRun): if hasattr(run, "favorite") and getattr(run, "favorite") is not None: return "ui/icons/star.html" elif run.run_id.startswith("manual"): return "ui/icons/play.html" elif run.run_id.startswith("scheduled"): return "ui/icons/calendar.html"
class IndicatorGrid(Dhis2Grid): title = StaticText("Indicators") lead = LeadingColumn( label="Name", text="name", secondary_text="indicator_type.name", icon="get_icon", translate=False, ) dhis2_id = TextColumn(text="dhis2_id", label="ID", translate=False) code = TextColumn(text="code", translate=False) tags = TagColumn(value="index.tags.all") last_synced = DateColumn(date="instance.last_synced_at") view = LinkColumn(text="View") download = Action(label="Download all", url="get_download_url", icon="table") @property def download_url(self): return "connector_dhis2:indicator_download" @property def export_suffix(self): return "indicators" def get_icon(self, _): return "ui/icons/trending_up.html"
class BikeDatagrid(Datagrid): leading = LeadingColumn(image_src="get_datasource_image", text="model", secondary_text="brand") category = TextColumn(text="category") characteristics = TextColumn(text="suspension", secondary_text="group_set") created_at = DateColumn(date="created_at", date_format="%Y-%m-%d %H:%M:%S %Z") launch_in = DateColumn(date="launch_in", date_format="timesince") view = LinkColumn(url="get_url", text=_("View"))
class ActivityGrid(Datagrid): lead = LeadingColumn( label="Name", text="description", image_src="symbol", detail_url="get_datasource_url", bold=False, mark_safe=True, ) status = StatusColumn(value="status") date = DateColumn(date="occurred_at") view = LinkColumn(text="View", url="url")
class PipelineIndexGrid(Datagrid): lead = LeadingColumn( label="Name", text="display_name", secondary_text="content_type_name", image_src="symbol", ) location = CountryColumn(value="countries") tags = TagColumn(value="tags.all") last_run = DateColumn(date="object.last_run.execution_date", label=_("Last run")) last_state = StatusColumn(value="object.last_run.status", label=_("Last state")) view = LinkColumn(text="View")
class EnvironmentGrid(Datagrid): lead = LeadingColumn( label="Name", text="display_name", secondary_text="content_type_name", image_src="symbol", detail_url="get_url", ) content = TextColumn(text="content") tags = TagColumn(value="tags.all") view = LinkColumn(text="View", url="get_url") def get_url(self, index: Index): return index.object.get_absolute_url()
class TableGrid(Datagrid): lead = LeadingColumn( label="Name", text="name", icon="get_table_icon", translate=False, ) tags = TagColumn(value="index.tags.all") content = TextColumn(text="get_content") def get_table_icon(self, _): return "ui/icons/table.html" def get_content(self, table: Table): return _("%(rows)d rows" % {"rows": table.rows})
class DAGGrid(Datagrid): lead = LeadingColumn( label="Name", text="dag_id", secondary_text="dag.template", icon="get_icon", translate=False, ) location = CountryColumn(value="index.countries") tags = TagColumn(value="index.tags.all") last_run = DateColumn(date="last_run.execution_date", label=_("Last run")) last_state = StatusColumn(value="last_run.status", label=_("Last state")) view = LinkColumn(text="View") def get_icon(self, _) -> str: return "ui/icons/terminal.html"
class ObjectGrid(Datagrid): title = StaticText("Objects") lead = LeadingColumn( label="Name", text="filename", icon="get_table_icon", translate=False, ) directory = TextColumn(text="parent_key", translate=False) tags = TagColumn(value="index.tags.all") size = TextColumn(text="file_size_display", translate=False) type = TextColumn(text="type_display") last_modified = DateColumn(date="last_modified", date_format="%Y-%m-%d %H:%M:%S %Z") link = LinkColumn(text="View") upload = UploadAction() def __init__(self, queryset, *, prefix: str, **kwargs): self.prefix = prefix super().__init__(queryset, **kwargs) def get_table_icon(self, obj: Object): if obj.type == "directory": return "ui/icons/folder_open.html" else: return "ui/icons/document_text.html" @property def template(self): return "connector_s3/components/object_grid.html" def context(self): return { **super().context(), "refresh_url": reverse( "connector_s3:bucket_refresh", args=[self.parent_model.id] ), "upload_url": reverse( "connector_s3:object_upload", args=[self.parent_model.id] ), "prefix": self.prefix, }
class DashboardGrid(Datagrid): lead = LeadingColumn( label="Name", text="display_name", secondary_text="content", image_src="screenshot", detail_url="get_dashboard_url", ) tags = TagColumn(value="tags.all") location = CountryColumn(value="countries") info = LinkColumn(text="Info", url="info_dashboard_url") def screenshot(self, index: Index): return reverse("visualizations:dashboard_image", kwargs={"dashboard_id": index.object.id}) def get_dashboard_url(self, index: Index): return (reverse("metrics:save_redirect") + "?to=" + urllib.parse.quote(index.object.url, safe="")) def info_dashboard_url(self, index: Index): return reverse("visualizations:dashboard_detail", kwargs={"dashboard_id": index.object.id})