Skip to content

Commit

Permalink
- Implement Slick reporting media override feature + docs
Browse files Browse the repository at this point in the history
- Add `Integrating reports into your Admin site` section to the docs
  • Loading branch information
RamezIssac committed Oct 12, 2023
1 parent e11f1ff commit 93fd357
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions docs/source/ref/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/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/[email protected]/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": {
Expand Down
58 changes: 58 additions & 0 deletions docs/source/topics/integrating_slick_reporting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,61 @@ Here is how it looks like:
</div>
</div>
{% 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 %}
<ul class="breadcrumb heading-text">
<a href="{% url 'admin:index' %}" class="breadcrumb-item">
<i class="icon-home2 mx-2"></i> {% trans 'Home' %} </a>
<a class="breadcrumb-item"> {% trans 'Reports' %}</a>
<a class="breadcrumb-item"> {{ report_title }}</a>
</ul>
{% 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





11 changes: 11 additions & 0 deletions docs/source/topics/structure.rst
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions slick_reporting/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion slick_reporting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93fd357

Please sign in to comment.