From e5acb7892be25195ec74c4015801dbce9b139913 Mon Sep 17 00:00:00 2001 From: Julien Moura Date: Thu, 18 Apr 2024 17:07:49 +0200 Subject: [PATCH] feature(rules): add date to rules context --- .../jobs/job_profiles_synchronizer.py | 7 +++++-- .../utils/computer_environment.py | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/qgis_deployment_toolbelt/jobs/job_profiles_synchronizer.py b/qgis_deployment_toolbelt/jobs/job_profiles_synchronizer.py index 6f340369..43ab26dc 100644 --- a/qgis_deployment_toolbelt/jobs/job_profiles_synchronizer.py +++ b/qgis_deployment_toolbelt/jobs/job_profiles_synchronizer.py @@ -24,7 +24,10 @@ # package from qgis_deployment_toolbelt.jobs.generic_job import GenericJob from qgis_deployment_toolbelt.profiles.qdt_profile import QdtProfile -from qgis_deployment_toolbelt.utils.computer_environment import environment_dict +from qgis_deployment_toolbelt.utils.computer_environment import ( + datetime_dict, + environment_dict, +) # ############################################################################# # ########## Globals ############### @@ -129,7 +132,7 @@ def filter_profiles_on_rules( li_profiles_matched = [] li_profiles_unmatched = [] - context_object = {"environment": environment_dict()} + context_object = {"date": datetime_dict, "environment": environment_dict()} for profile in li_downloaded_profiles: if profile.rules is None: logger.debug(f"No rules to apply to {profile.name}") diff --git a/qgis_deployment_toolbelt/utils/computer_environment.py b/qgis_deployment_toolbelt/utils/computer_environment.py index 6f6e755b..e33d2eaa 100644 --- a/qgis_deployment_toolbelt/utils/computer_environment.py +++ b/qgis_deployment_toolbelt/utils/computer_environment.py @@ -11,9 +11,11 @@ # ########## Libraries ############# # ################################## -# Standard library import logging import platform + +# Standard library +from datetime import date from sys import platform as opersys # ############################################################################# @@ -29,6 +31,22 @@ # ################################## +def datetime_dict() -> dict: + """Returns a context dictionary with date informations that can be used in QDT + various places: rules... + + Returns: + dict: dict with current date informations + """ + today = date.today() + return { + "current_day": today.day, + "current_weekday": today.weekday(), # monday = 0, sunday = 6 + "current_month": today.month, + "current_year": today.year, + } + + def environment_dict() -> dict: """Returns a dictionary containing some environment information (computer, network, platform) that can be used in QDT various places: rules...