...
 
Commits (3)
/srv/archive
\ No newline at end of file
......@@ -25,7 +25,7 @@ celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
#celery = Celery(__name__, broker=Config.CELERY_BROKER_URL)
@celery.task
def send_to_topic(topic, subject, message, location, message_id):
def send_to_topic(topic, subject, message, location, message_id, raw):
"""Background task to send to firebase ip"""
with app.app_context():
result = {}
......@@ -40,6 +40,7 @@ def send_to_topic(topic, subject, message, location, message_id):
'message_id' : message_id,
'message_subject' : subject,
'topic_name' : topic,
'description' : raw['info'][0]['description'],
}
result = push_service.notify_topic_subscribers(
......
......@@ -58,6 +58,7 @@ class LoginForm(Form):
class MessageForm(Form):
active = BooleanField(_('Active'))
description = TextField(_('Description'))
message = TextAreaField(_('Message'), [DataRequired()])
subject = TextField(_('Subject'))
location = TextField(_('Location'))
......@@ -80,6 +81,7 @@ class MessageForm(Form):
class MessageEditForm(Form):
active = BooleanField(_('Active'))
description = TextField(_('Description'))
message = TextAreaField(_('Message'), [DataRequired()])
subject = TextField(_('Subject'))
location = TextField(_('Location'))
......
......@@ -72,8 +72,10 @@ def dashboard():
sent.append(topic)
message = form.message.data.encode('utf-8').strip()
location = form.location.data.encode('utf-8').strip()
raw = {}
raw['identifier'] = datetime.datetime.utcfromtimestamp(time.time()).strftime('HF-%Y%m%d-%H%M%S-Z')
raw['info'] = [{ 'description' : form.description.data } ]
msg = Message()
msg.subject = form.subject.data
......@@ -266,6 +268,12 @@ def message_edit(mid=0):
# Override the auto form to handle utf-8 and b64encode
message.message = base64.b64encode(message.message.encode('utf-8'))
message.location = locationfinder(message.location.encode('utf-8'))
# Helluva ugly hack, but deadlines!
raw = {}
raw['identifier'] = message.raw['identifier']
raw['info'] = [{ 'description' : form.description.data } ]
message.raw = raw
db.session.add(message)
db.session.commit()
flash(gettext("Message") + str(message.id) + gettext(" edited.") )
......@@ -407,7 +415,7 @@ def sendalarm():
except:
m.location = locationfinder(m.location)
try:
send = send_to_topic(m.topic.id, m.subject, m.message, m.location, m.id)
send = send_to_topic(m.topic.id, m.subject, m.message, m.location, m.id, m.raw)
except requests.exceptions.RequestException as e:
pass
else:
......
......@@ -45,6 +45,15 @@
{% endfor %}
{% endif %}
</div>
<div class="form-group" style="width: 50%">
{{ form.description.label }}
{{ form.description(class_="form-control", value="Kort beskrivning utan HTML") }}
{% if form.description.errors %}
{% for e in form.description.errors %}
<p class="help-block">{{ e }}</p>
{% endfor %}
{% endif %}
</div>
<div class="form-group" style="width: 50%">
{{ form.message.label }}
{{ form.message(class_="form-control", cols="25", rows="10") }}
......
......@@ -56,6 +56,21 @@
{% endif %}
</div>{# end col #}
</div>{# end row #}
<div class="row">
<div class="col-sm-12">
Description:<br/>
{% if 'info' in data.raw %}
<input id="description" name="description" size="80" type="text" value="{{ data.raw['info'][0]['description'] }}">
{% else %}
{{ form.description(size=80) }}
{% endif %}
{% if form.description.errors %}
{% for e in form.description.errors %}
<p class="help-block">{{ e }}</p>
{% endfor %}
{% endif %}
</div>{# end col #}
</div>{# end row #}
<div class="row">
<div class="col-sm-12">
Message:<br/>
......