Skip to content

Commit

Permalink
Fix error-handling of missing template files (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
kizniche committed Jan 23, 2022
1 parent 941c296 commit d919499
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ If you are upgrading from a version prior to 8.12.10, following the upgrade, you
- Fix issue with TTNv3 Input if there's no payload
- Fix Desktop Widgets resizing when viewing on mobile browsers
- Fix rotation and flip for fswebcam camera library
- Fix error-handling of missing template files ([#1145](https://github.com/kizniche/mycodo/issues/1145))

### Features

Expand Down
9 changes: 9 additions & 0 deletions mycodo/functions/average_last_multiple.py
Expand Up @@ -151,13 +151,22 @@ def loop(self):
channel, unit, measurement = return_measurement_info(
device_measurement, conversion)

self.logger.debug("Dev: {}, unit: {}, channel: {}, measurement: {}, max age:; {}".format(
device_device_id,
unit,
channel,
measurement,
self.max_measure_age))

last_measurement = read_last_influxdb(
device_device_id,
unit,
channel,
measure=measurement,
duration_sec=self.max_measure_age)

self.logger.debug("last_measurement: {}".format(last_measurement))

if not last_measurement:
self.logger.error(
"One more more measurements were not within the set Max Age. Not calculating average.")
Expand Down
8 changes: 8 additions & 0 deletions mycodo/mycodo_flask/routes_static.py
Expand Up @@ -46,6 +46,13 @@ def before_request_admin_exist():
blueprint.before_request(before_request_admin_exist)


def template_exists(path):
path_start = "{}/mycodo/mycodo_flask/templates".format(INSTALL_DIRECTORY)
path_full = "{}/{}".format(path_start, path)
if os.path.exists(path_full) and os.path.abspath(path_full).startswith(path_start):
return True


@blueprint.context_processor
def inject_variables():
"""Variables to send with every page request"""
Expand Down Expand Up @@ -81,6 +88,7 @@ def inject_variables():
mycodo_version=MYCODO_VERSION,
permission_view_settings=user_has_permission('view_settings', silent=True),
dict_translation=TRANSLATIONS,
template_exists=template_exists,
themes=THEMES,
upgrade_available=misc.mycodo_upgrade_available)

Expand Down
Expand Up @@ -12,7 +12,12 @@
<div class="col-auto">
<input onclick="return confirm('{{_('Are you sure you want to delete this?')}}') && $(this).processRequest(this, 'delete_action');" name="delete_action" value="{{_('Delete')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
</div>
{% include 'pages/function_options/action_options/'+each_action.action_type+'.html' %}
{% set template_file = 'pages/function_options/action_options/'+each_action.action_type+'.html' %}
{% if template_exists(template_file) %}
{% include template_file %}
{% else %}
Error: Template {{template_file}} doesn't exist.
{% endif %}
</div>
</form>
</div>

0 comments on commit d919499

Please sign in to comment.