From 93fd357d2afd6b6b85abc0719b99dfd64b22bf79 Mon Sep 17 00:00:00 2001 From: Ramez Ashraf Date: Thu, 12 Oct 2023 13:39:24 +0300 Subject: [PATCH] - Implement Slick reporting media override feature + docs - Add `Integrating reports into your Admin site` section to the docs --- CHANGELOG.md | 4 ++ docs/source/ref/settings.rst | 20 +++++++ .../topics/integrating_slick_reporting.rst | 58 +++++++++++++++++++ docs/source/topics/structure.rst | 11 ++++ slick_reporting/app_settings.py | 10 ++++ slick_reporting/views.py | 2 +- 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 docs/source/topics/structure.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 998c451..03a9e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [] +- Implement Slick reporting media override feature + docs +- Add `Integrating reports into your Admin site` section to the docs + ## [1.2.0] - 2023-10-10 - Add ``get_slick_reporting_media`` and ``get_charts_media`` templatetags - Add `get_group_by_custom_querysets` hook to ReportView diff --git a/docs/source/ref/settings.rst b/docs/source/ref/settings.rst index 186a731..6e82ae5 100644 --- a/docs/source/ref/settings.rst +++ b/docs/source/ref/settings.rst @@ -20,6 +20,26 @@ Below are the default settings for django-slick-reporting. You can override them datetime.now().year, 1, 1, 0, 0, 0, tzinfo=timezone.utc ), # Default: 1st Jan of current year "DEFAULT_END_DATE_TIME": datetime.datetime.today(), # Default to today + "DEFAULT_CHARTS_ENGINE": SLICK_REPORTING_DEFAULT_CHARTS_ENGINE, + "MEDIA": { + "override": False, # set it to True to override the media files, + # False will append the media files to the existing ones. + "js": ( + "https://cdn.jsdelivr.net/momentjs/latest/moment.min.js", + "https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js", + "https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js", + "https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js", + "slick_reporting/slick_reporting.js", + "slick_reporting/slick_reporting.report_loader.js", + "slick_reporting/slick_reporting.datatable.js", + ), + "css": { + "all": ( + "https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css", + "https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css", + ) + }, + }, "FONT_AWESOME": { "CSS_URL": "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css", "ICONS": { diff --git a/docs/source/topics/integrating_slick_reporting.rst b/docs/source/topics/integrating_slick_reporting.rst index a14b370..b5b9e85 100644 --- a/docs/source/topics/integrating_slick_reporting.rst +++ b/docs/source/topics/integrating_slick_reporting.rst @@ -80,3 +80,61 @@ Here is how it looks like: {% endblock %} + + +Integrating reports into your Admin site +========================================= + +1. Most probably you would want to override the default admin to add the extra report urls +https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#overriding-the-default-admin-site + +2. Add the report url to your admin site main get_urls + +.. code-block:: python + + class CustomAdminAdminSite(admin.AdminSite): + def get_urls(self): + from my_apps.reports import MyAwesomeReport + + urls = super().get_urls() + urls = [ + path( + "reports/my-awesome-report/", + MyAwesomeReport.as_view(), + name="my-awesome-report", + ), + ] + urls + return urls + +Note that you need to add the reports urls to the top, or else the wildcard catch will raise a 404 + +3. Override slick_reporting/base.html to extend the admin site + +.. code-block:: html+django + + {% extends 'admin/base_site.html' %} + {% load i18n static slick_reporting_tags %} + + {% block title %}{{ report_title }}{% endblock %} + + {% block extrahead %} + {% include "slick_reporting/js_resources.html" %} + {% get_charts_media "all" %} + {% endblock %} + + {% block breadcrumbs %} + + {% endblock %} + + +4. You might want to override the report.html as well to set your styles, You can also use a different template for the crispy form + + + + + diff --git a/docs/source/topics/structure.rst b/docs/source/topics/structure.rst new file mode 100644 index 0000000..6491795 --- /dev/null +++ b/docs/source/topics/structure.rst @@ -0,0 +1,11 @@ +.. _structure: + +================ +Rows and columns +================ + +It's natural to think of a report as a form of tabular data, with rows and columns. + +We willexplore the ways one can create the rows and column of a report. + +a simple example diff --git a/slick_reporting/app_settings.py b/slick_reporting/app_settings.py index 1a5a656..7bab3b2 100644 --- a/slick_reporting/app_settings.py +++ b/slick_reporting/app_settings.py @@ -94,6 +94,16 @@ def get_slick_reporting_settings(): user_settings = getattr(settings, "SLICK_REPORTING_SETTINGS", {}) user_chart_settings = user_settings.get("CHARTS", {}) + user_media_settings = user_settings.get("MEDIA", {}) + override_media = user_media_settings.get("override", False) + if override_media: + slick_settings["MEDIA"] = user_media_settings + else: + slick_settings["MEDIA"]["js"] = slick_settings["MEDIA"]["js"] + user_media_settings.get("js", ()) + slick_settings["MEDIA"]["css"]["all"] = slick_settings["MEDIA"]["css"]["all"] + user_media_settings.get( + "css", {} + ).get("all", ()) + slick_chart_settings.update(user_chart_settings) slick_settings.update(user_settings) slick_settings["CHARTS"] = slick_chart_settings diff --git a/slick_reporting/views.py b/slick_reporting/views.py index a1042bd..85b7737 100644 --- a/slick_reporting/views.py +++ b/slick_reporting/views.py @@ -442,7 +442,7 @@ def get_form_crispy_helper(self): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context[self.report_title_context_key] = self.report_title + context[self.report_title_context_key] = self.get_report_title() context["crispy_helper"] = self.get_form_crispy_helper() context["auto_load"] = self.auto_load context["report"] = self