Skip to content

Commit

Permalink
feature(rules): add date to rules context
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Apr 18, 2024
1 parent f8620f3 commit e5acb78
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions qgis_deployment_toolbelt/jobs/job_profiles_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###############
Expand Down Expand Up @@ -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}")
Expand Down
20 changes: 19 additions & 1 deletion qgis_deployment_toolbelt/utils/computer_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
# ########## Libraries #############
# ##################################

# Standard library
import logging
import platform

# Standard library
from datetime import date
from sys import platform as opersys

# #############################################################################
Expand All @@ -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...
Expand Down

0 comments on commit e5acb78

Please sign in to comment.