diff options
-rw-r--r-- | ishtar_common/utils.py | 1 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 11 |
2 files changed, 9 insertions, 3 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 0a6926d9d..4043e48cf 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -278,6 +278,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 735ccf2e1..ed2fb07ea 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") |