Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow request parameter overrides for template, orientation and paperformat #86

Merged
merged 4 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/senaite/impress/publishview.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def get_uids(self):
"""
return filter(None, self.request.get("items", "").split(","))

def get_request_parameter(self, parameter, default=None):
"""Returns the request parameter
"""
return self.request.get(parameter, default)

def get_collection(self, uids=None, group_by=None):
"""Wraps the given UIDs into a collection of SuperModels
"""
Expand Down Expand Up @@ -266,6 +271,9 @@ def get_report_templates(self, extensions=[".pt", ".html"]):
def get_default_template(self, default="senaite.lims:Default.pt"):
"""Returns the configured default template from the registry
"""
template = self.get_request_parameter("template")
if self.template_exists(template):
return template
template = api.get_registry_record(
"senaite.impress.default_template")
if template is None:
Expand All @@ -275,6 +283,9 @@ def get_default_template(self, default="senaite.lims:Default.pt"):
def get_default_paperformat(self, default="A4"):
"""Returns the configured default paperformat from the registry
"""
paperformat = self.get_request_parameter("paperformat")
if paperformat in self.get_paperformats():
return paperformat
paperformat = api.get_registry_record(
"senaite.impress.default_paperformat")
if paperformat is None:
Expand All @@ -284,6 +295,9 @@ def get_default_paperformat(self, default="A4"):
def get_default_orientation(self, default="portrait"):
"""Returns the configured default orientation from the registry
"""
orientation = self.get_request_parameter("orientation")
if orientation in ["portrait", "landscape"]:
return orientation
orientation = api.get_registry_record(
"senaite.impress.default_orientation")
if orientation is None:
Expand All @@ -304,6 +318,17 @@ def get_developer_mode(self):
"senaite.impress.developer_mode", False)
return mode

def template_exists(self, template):
"""Checks if the template exists
"""
if not template:
return False
finder = getUtility(ITemplateFinder)
template_path = finder.find_template(template)
if template_path is None:
return False
return True

def get_report_template(self, template=None):
"""Returns the path of report template
"""
Expand Down
14 changes: 7 additions & 7 deletions src/senaite/impress/static/js/scripts/senaite.impress.publish.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/senaite/impress/static/js/src/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class PublishAPI
segments = location.pathname.split "/"
current_view = segments[segments.length-1]
url = @get_base_url().split(current_view)[0]
return "#{url}#{api_endpoint}/#{endpoint}"
# we also pass back eventual query parameters to the API
params = location.search
return "#{url}#{api_endpoint}/#{endpoint}#{params}"


get_url_parameter: (name) ->
Expand Down
Loading