summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-02-15 17:43:11 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-02-16 10:55:15 +0100
commit83d859c32befc845aff3bc2ed4e65299e59190a0 (patch)
tree2456f50c0158accdb3d22ba467005c8fc4ae97a7
parent661a125523efe84cf1355d6f3793d49a3c5787e5 (diff)
downloadIshtar-83d859c32befc845aff3bc2ed4e65299e59190a0.tar.bz2
Ishtar-83d859c32befc845aff3bc2ed4e65299e59190a0.zip
✨ sheets: manage specific sheets for specific modules
-rw-r--r--ishtar_common/utils.py1
-rw-r--r--ishtar_common/views_item.py11
2 files changed, 9 insertions, 3 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 3081d488c..b93471eef 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -277,6 +277,7 @@ def check_model_access_control(request, model, available_perms=None):
class SheetItem:
SHOW_URL = ""
+ SHEET_ALTERNATIVES = [] # list tuple: (key checked in profile, sheet name)
def get_show_url(self):
show_url = self.SHOW_URL
if not show_url:
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 88f746b4e..9249318af 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -363,6 +363,11 @@ def show_item(model, name, extra_dct=None, model_for_perms=None, callback=None):
"/".join(reverse("show-" + name, args=["0", ""]).split("/")[:-2]) + "/"
)
profile = get_current_profile()
+ sheet_name = name
+ for profile_key, alt_name in model.SHEET_ALTERNATIVES:
+ if getattr(profile, profile_key):
+ sheet_name = alt_name
+ break
dct["PROFILE"] = profile
dct["CURRENCY"] = profile.currency
dct["ENCODING"] = settings.ENCODING
@@ -454,7 +459,7 @@ def show_item(model, name, extra_dct=None, model_for_perms=None, callback=None):
else:
filename = item.associated_filename
if doc_type == "odt" and settings.ODT_TEMPLATE:
- tpl = loader.get_template("ishtar/sheet_%s.html" % name)
+ tpl = loader.get_template(f"ishtar/sheet_{sheet_name}.html")
context_instance["output"] = "ODT"
content = tpl.render(context_instance, request)
tidy_options = {
@@ -503,7 +508,7 @@ def show_item(model, name, extra_dct=None, model_for_perms=None, callback=None):
elif doc_type == "pdf":
base_url = "/".join(request.build_absolute_uri().split("/")[0:3])
- tpl = loader.get_template("ishtar/sheet_%s_pdf.html" % name)
+ tpl = loader.get_template(f"ishtar/sheet_{sheet_name}_pdf.html")
context_instance["output"] = "PDF"
html = tpl.render(context_instance, request)
font_config = FontConfiguration()
@@ -530,7 +535,7 @@ def show_item(model, name, extra_dct=None, model_for_perms=None, callback=None):
response["Content-Disposition"] = "attachment; filename=%s.pdf" % filename
return response
else:
- tpl = loader.get_template("ishtar/sheet_%s_window.html" % name)
+ tpl = loader.get_template(f"ishtar/sheet_{sheet_name}_window.html")
content = tpl.render(context_instance, request)
return HttpResponse(content, content_type="application/xhtml")