Skip to content

Commit

Permalink
Enhance settings
Browse files Browse the repository at this point in the history
  • Loading branch information
RamezIssac committed Sep 24, 2023
1 parent 83e5eeb commit 18fd509
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 40 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file.
## [1.1.1] -
- Change settings to be a dict , adding support JQUERY_URL and FONT AWESOME customization
- Fix issue with chartjs not being loaded
- Enhance Font Awesome mapping by adding it to the settings
- Enhance Font Awesome mapping by adding it to the settings
- Remove `SLICK_REPORTING_FORM_MEDIA`

## [1.1.0] -
- Breaking: changed ``report_title_context_key`` default value to `report_title`
Expand Down
37 changes: 17 additions & 20 deletions slick_reporting/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,19 @@ def get_end_date():
SLICK_REPORTING_DEFAULT_START_DATE = lazy(get_start_date, datetime.datetime)()
SLICK_REPORTING_DEFAULT_END_DATE = lazy(get_end_date, datetime.datetime)()

SLICK_REPORTING_FORM_MEDIA_DEFAULT = {
# "css": {
# "all": (
# "https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.css",
# "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css",
# )
# },
# "js": (
# "https://code.jquery.com/jquery-3.3.1.slim.min.js",
# "https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.js",
# "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js",
# "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js",
# "https://code.highcharts.com/highcharts.js",
# ),
}

SLICK_REPORTING_FORM_MEDIA = getattr(settings, "SLICK_REPORTING_FORM_MEDIA", SLICK_REPORTING_FORM_MEDIA_DEFAULT)
SLICK_REPORTING_DEFAULT_CHARTS_ENGINE = getattr(settings, "SLICK_REPORTING_DEFAULT_CHARTS_ENGINE", "highcharts")


SLICK_REPORTING_JQUERY_URL = getattr(
settings, "SLICK_REPORTING_JQUERY_URL", "https://code.jquery.com/jquery-3.7.0.min.js"
)

SLICK_REPORTING_SETTINGS = getattr(settings, "SLICK_REPORTING_SETTINGS", {})

SLICK_REPORTING_SETTINGS_DEFAULT = {
"JQUERY_URL": SLICK_REPORTING_JQUERY_URL,
"DEFAULT_START_DATE_TIME": SLICK_REPORTING_DEFAULT_START_DATE,
"DEFAULT_END_DATE_TIME": SLICK_REPORTING_DEFAULT_END_DATE,
"DEFAULT_START_DATE_TIME": get_start_date(),
"DEFAULT_END_DATE_TIME": get_end_date(),
"FONT_AWESOME": {
"CSS_URL": "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css",
"ICONS": {
Expand All @@ -77,4 +60,18 @@ def get_end_date():
},
}

SLICK_REPORTING_SETTINGS = {**SLICK_REPORTING_SETTINGS_DEFAULT, **SLICK_REPORTING_SETTINGS}

def get_slick_reporting_settings():
slick_settings = {**SLICK_REPORTING_SETTINGS_DEFAULT, **getattr(settings, "SLICK_REPORTING_SETTINGS", {})}
start_date = getattr(settings, "SLICK_REPORTING_DEFAULT_START_DATE", False)
end_date = getattr(settings, "SLICK_REPORTING_DEFAULT_END_DATE", False)
# backward compatibility, todo remove in next major release
if start_date:
slick_settings["DEFAULT_START_DATE_TIME"] = start_date
if end_date:
slick_settings["DEFAULT_END_DATE_TIME"] = end_date

return slick_settings


SLICK_REPORTING_SETTINGS = lazy(get_slick_reporting_settings, dict)()
9 changes: 0 additions & 9 deletions slick_reporting/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,6 @@ class SlickReportForm(BaseReportForm):
Holds basic function
"""

@property
def media(self):
from .app_settings import SLICK_REPORTING_FORM_MEDIA

return forms.Media(
css=SLICK_REPORTING_FORM_MEDIA.get("css", {}),
js=SLICK_REPORTING_FORM_MEDIA.get("js", []),
)

def get_start_date(self):
return self.cleaned_data.get("start_date")

Expand Down
15 changes: 5 additions & 10 deletions slick_reporting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
from django.utils.functional import Promise
from django.views.generic import FormView

from .app_settings import (
SLICK_REPORTING_DEFAULT_END_DATE,
SLICK_REPORTING_DEFAULT_START_DATE,
)
from .app_settings import SLICK_REPORTING_SETTINGS
from .forms import (
report_form_factory,
get_crispy_helper,
Expand Down Expand Up @@ -221,7 +218,7 @@ def get_form_class(self):
display_compute_remainder=self.crosstab_compute_remainder,
excluded_fields=self.excluded_fields,
fkeys_filter_func=self.form_filter_func,
initial=self.get_form_initial(),
initial=self.get_initial(),
show_time_series_selector=self.time_series_selector,
time_series_selector_choices=self.time_series_selector_choices,
time_series_selector_default=self.time_series_selector_default,
Expand Down Expand Up @@ -383,12 +380,10 @@ def filter_results(self, data, for_print=False):
def get_report_slug(cls):
return cls.report_slug or cls.__name__.lower()

@staticmethod
def get_form_initial():
# todo revise why not actually displaying datetime on screen
def get_initial(self):
return {
"start_date": SLICK_REPORTING_DEFAULT_START_DATE,
"end_date": SLICK_REPORTING_DEFAULT_END_DATE,
"start_date": SLICK_REPORTING_SETTINGS["DEFAULT_START_DATE_TIME"],
"end_date": SLICK_REPORTING_SETTINGS["DEFAULT_END_DATE_TIME"],
}

def get_form_crispy_helper(self):
Expand Down

0 comments on commit 18fd509

Please sign in to comment.