mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-05 06:00:53 -04:00
Update default templates and add update command (#166)
This commit adds config_files for default data and, using that, creates a new way to update our default templates without needing to hardcode a migration. --------- Co-authored-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
This commit is contained in:
@@ -65,6 +65,8 @@ from app.models import (
|
||||
Notification,
|
||||
Organisation,
|
||||
Service,
|
||||
Template,
|
||||
TemplateHistory,
|
||||
User,
|
||||
)
|
||||
from app.utils import get_local_midnight_in_utc
|
||||
@@ -765,3 +767,28 @@ def create_user_jwt(token):
|
||||
service_id = token[-73:-37]
|
||||
api_key = token[-36:]
|
||||
print(create_jwt_token(api_key, service_id))
|
||||
|
||||
|
||||
def _update_template(id, name, template_type, content, subject):
|
||||
|
||||
template = Template.query.filter_by(id=id).first()
|
||||
template.name = name
|
||||
template.template_type = template_type
|
||||
template.content = '\n'.join(content)
|
||||
template.subject = subject
|
||||
|
||||
history = TemplateHistory.query.filter_by(id=id).first()
|
||||
history.name = name
|
||||
history.template_type = template_type
|
||||
history.content = '\n'.join(content)
|
||||
history.subject = subject
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@notify_command(name='update-templates')
|
||||
def update_templates():
|
||||
with open(current_app.config['CONFIG_FILES'] + '/templates.json') as f:
|
||||
data = json.load(f)
|
||||
for d in data:
|
||||
_update_template(d['id'], d['name'], d['type'], d['content'], d['subject'])
|
||||
|
||||
Reference in New Issue
Block a user