Skip to content
Snippets Groups Projects
Commit 1c0297a2 authored by Vermaat's avatar Vermaat
Browse files

Show an announcement on every webpage with an optional link

parent 32de1ef9
No related branches found
No related tags found
No related merge requests found
"""
Simplistic interface to setting a user announcement.
We store up to one announcement at a time, containing a text body and an
optional 'read more' URL. Since getting the announcement should be really
fast, it can be done on every website pageview without problems.
"""
from mutalyzer.redisclient import client
def set_announcement(body, url=None):
"""
Set announcement.
"""
announcement = {'body': body}
if url:
announcement['url'] = url
client.hmset('announcement', announcement)
def unset_announcement():
"""
Unset announcement.
"""
client.delete('announcement')
def get_announcement():
"""
Get announcement.
"""
announcement = client.hgetall('announcement')
if not announcement:
return
return {'body': announcement['body'],
'url': announcement.get('url')}
...@@ -9,6 +9,7 @@ import json ...@@ -9,6 +9,7 @@ import json
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
from .. import announce
from ..db import session from ..db import session
from ..db.models import Assembly, Chromosome from ..db.models import Assembly, Chromosome
from .. import mapping from .. import mapping
...@@ -113,6 +114,20 @@ def sync_cache(wsdl_url, url_template, history=7): ...@@ -113,6 +114,20 @@ def sync_cache(wsdl_url, url_template, history=7):
cache_sync.sync_with_remote(wsdl_url, url_template, history) cache_sync.sync_with_remote(wsdl_url, url_template, history)
def set_announcement(body, url=None):
"""
Set announcement to show to the user.
"""
announce.set_announcement(body, url=url)
def unset_announcement():
"""
Unset announcement to show to the user.
"""
announce.unset_announcement()
def main(): def main():
""" """
Command-line interface to Mutalyzer administrative tools. Command-line interface to Mutalyzer administrative tools.
...@@ -194,6 +209,23 @@ def main(): ...@@ -194,6 +209,23 @@ def main():
default=7, help='number of days to go back in the remote cache ' default=7, help='number of days to go back in the remote cache '
'(default: 7)') '(default: 7)')
p = subparsers.add_parser(
'set-announcement', help='set user announcement',
description=set_announcement.__doc__.split('\n\n')[0],
epilog='The announcement is shown on every page of the website.')
p.set_defaults(func=set_announcement)
p.add_argument(
'body', metavar='ANNOUNCEMENT',
help='announcement text to show to the user')
p.add_argument(
'--url', metavar='URL', dest='url',
help='URL to more information on the announcement')
p = subparsers.add_parser(
'unset-announcement', help='unset user announcement',
description=unset_announcement.__doc__.split('\n\n')[0])
p.set_defaults(func=unset_announcement)
args = parser.parse_args() args = parser.parse_args()
try: try:
......
...@@ -277,6 +277,9 @@ ...@@ -277,6 +277,9 @@
<td width="0"></td> <td width="0"></td>
<td width="0"> <td width="0">
{% if announcement %}
<p><b>Announcement:</b> {{ announcement.body }}{% if announcement.url %} <a href="{{ announcement.url }}">read more</a>{% endif %}</p>
{% endif %}
<center> <center>
<h2>Mutalyzer {{ mutalyzer_version }}<br> <h2>Mutalyzer {{ mutalyzer_version }}<br>
......
...@@ -19,8 +19,8 @@ from spyne.server.http import HttpBase ...@@ -19,8 +19,8 @@ from spyne.server.http import HttpBase
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
import mutalyzer import mutalyzer
from mutalyzer import (describe, File, Retriever, Scheduler, stats, util, from mutalyzer import (announce, describe, File, Retriever, Scheduler, stats,
variantchecker) util, variantchecker)
from mutalyzer.config import settings from mutalyzer.config import settings
from mutalyzer.db import session from mutalyzer.db import session
from mutalyzer.db.models import BATCH_JOB_TYPES from mutalyzer.db.models import BATCH_JOB_TYPES
...@@ -46,7 +46,8 @@ def add_globals(): ...@@ -46,7 +46,8 @@ def add_globals():
'json_root_url' : settings.JSON_ROOT_URL, 'json_root_url' : settings.JSON_ROOT_URL,
'piwik' : settings.PIWIK, 'piwik' : settings.PIWIK,
'piwik_base_url' : settings.PIWIK_BASE_URL, 'piwik_base_url' : settings.PIWIK_BASE_URL,
'piwik_site_id' : settings.PIWIK_SITE_ID} 'piwik_site_id' : settings.PIWIK_SITE_ID,
'announcement' : announce.get_announcement()}
@website.route('/') @website.route('/')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment