Skip to content

Commit

Permalink
Handle empty news version
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Sep 17, 2024
1 parent bad6e24 commit d5ba90a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/plugins/newspopup/controllers/news_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def index(self):
news_plugin_conf = next((e for e in data["plugins"]["mobile"] if e["name"] == "NewsPopup"), None)
if news_plugin_conf:
news_version = news_plugin_conf["cfg"]["newsRev"]
if news_version is None:
news_version = ""
except Exception as e:
self.logger.warn("Unable to read news version: %s" % (str(e)))

Expand Down Expand Up @@ -79,16 +81,17 @@ def update_news(self):
try:
with open(viewer_config_file, 'r+') as fh:
data = json.load(fh)
news_version = request.values.get('news_version', '')

news_plugin_conf = next((e for e in data["plugins"]["common"] if e["name"] == "NewsPopup"), None)
if news_plugin_conf:
news_plugin_conf["cfg"]["newsRev"] = request.values.get('news_version')
news_plugin_conf["cfg"]["newsRev"] = news_version
news_plugin_conf = next((e for e in data["plugins"]["desktop"] if e["name"] == "NewsPopup"), None)
if news_plugin_conf:
news_plugin_conf["cfg"]["newsRev"] = request.values.get('news_version')
news_plugin_conf["cfg"]["newsRev"] = news_version
news_plugin_conf = next((e for e in data["plugins"]["mobile"] if e["name"] == "NewsPopup"), None)
if news_plugin_conf:
news_plugin_conf["cfg"]["newsRev"] = request.values.get('news_version')
news_plugin_conf["cfg"]["newsRev"] = news_version

fh.seek(0)
json.dump(data, fh, indent=2)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/newspopup/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ <h1>{{ title }}</h1>
<form class="form form-horizontal" action="{{ action }}" method="post" style="display: none">
<input id="csrf_token" name="csrf_token" type="hidden" value="{{ csrf_token() }}">
<input id="news_contents" name="news_contents" type="hidden" value="">
<div style="display: flex; align-items: center">
<label class="col-form-label" for="news_version">News&nbsp;version:&nbsp;</label>
<div style="display: flex; align-items: center" class="py-2">
<label class="col-form-label" for="news_version" style="white-space: nowrap">News version (leave empty to disable news):&nbsp;</label>
<input class="form-control" id="news_version" name="news_version" type="text" value="{{ news_version }}">
</div>

Expand Down

0 comments on commit d5ba90a

Please sign in to comment.