Skip to content

Commit

Permalink
Allow to register buttons below report from other apps
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Feb 5, 2024
1 parent cf2904b commit 7fd2d82
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions radis/collections/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db.models.signals import post_migrate

from radis.core.site import register_main_menu_item
from radis.reports.site import register_report_panel_button


class CollectionsConfig(AppConfig):
Expand All @@ -20,6 +21,8 @@ def register_app():
label="Collections",
)

register_report_panel_button(1, "collections/_collection_select_button.html")


def init_db(**kwargs):
create_app_settings()
Expand Down
3 changes: 3 additions & 0 deletions radis/notes/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db.models.signals import post_migrate

from radis.core.site import register_main_menu_item
from radis.reports.site import register_report_panel_button


class NotesConfig(AppConfig):
Expand All @@ -20,6 +21,8 @@ def register_app():
label="Notes",
)

register_report_panel_button(2, "notes/_note_edit_button.html")


def init_db(**kwargs):
create_app_settings()
Expand Down
23 changes: 23 additions & 0 deletions radis/reports/site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Any, NamedTuple

from django.http import HttpRequest


class ReportPanelButton(NamedTuple):
order: int
template_name: str


report_panel_buttons: list[ReportPanelButton] = []


def register_report_panel_button(order: int, template_name: str) -> None:
global report_panel_buttons
report_panel_buttons.append(ReportPanelButton(order, template_name))
report_panel_buttons = sorted(report_panel_buttons, key=lambda x: x.order)


def base_context_processor(request: HttpRequest) -> dict[str, Any]:
return {
"report_panel_buttons": report_panel_buttons,
}
6 changes: 4 additions & 2 deletions radis/reports/templates/reports/_report_buttons_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
{% bootstrap_icon "eye" %}
Preview
</button>
{% include "collections/_collection_select_button.html" %}
{% include "notes/_note_edit_button.html" %}
{# Additional buttons that can be registered by other apps #}
{% for button in report_panel_buttons %}
{% include button.template_name %}
{% endfor %}
</div>
{% include "reports/_references.html" %}
</div>
1 change: 1 addition & 0 deletions radis/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"radis.core.site.base_context_processor",
"radis.reports.site.base_context_processor",
],
},
},
Expand Down

0 comments on commit 7fd2d82

Please sign in to comment.