def prep_snippets(snip, param): """Split snippets `snip` into separate languages and substitute parameters `param` with their values.""" snip = split(snip) snip['nl'] = {k: prime(v, param['nl']) for k, v in snip['nl'].items()} snip['en'] = {k: prime(v, param['en']) for k, v in snip['en'].items()} return snip
def manage(): layouts = fetch_data('layouts', ['value']) parameters = split(fetch_data('parameters', ['value_nl', 'value_en'])) snippets = split(fetch_data('snippets', ['value_nl', 'value_en'])) snippets = { 'nl': {k: prime(v, parameters['nl']) for k, v in snippets['nl'].items()}, 'en': {k: prime(v, parameters['en']) for k, v in snippets['en'].items()}, } settings = fetch_data('settings', ['muteerbaar']) table = 'messages' fields = [ 'subject_nl', 'subject_en', 'body_nl', 'body_en', 'layout', 'settings', ] data = fetch_data(table, fields) if request.method == 'POST': new_data = request.get_json() put_data(table, new_data, fields) return redirect(url_for('messages.manage')) return render_template( 'manager/messages.html', module='messages', layouts=layouts, parameters=parameters, snippets=snippets, settings=settings, data=data, fields=fields, )
def manage(): table = 'snippets' fields = ['value_nl', 'value_en'] parameters = split(fetch_data('parameters', fields)) data = fetch_data(table, fields) if request.method == 'POST': new_data = request.get_json() put_data(table, new_data, fields) return redirect(url_for('snippets.manage')) return render_template( 'manager/snippets.html', module='snippets', parameters=parameters, data=data, fields=fields, )
def manage(): parameters = split(fetch_data('parameters', ['value_nl', 'value_en'])) snippets = fetch_data('snippets', ['value_nl', 'value_en']) snippets = prep_snippets(snippets, parameters) variables = {k: {**parameters[k], **snippets[k]} for k in parameters} sql = """ SELECT m.label as mededeling, subject_nl as koptekst, subject_en as koptekst_en, body_nl as inhoud, body_en as inhoud_en, value as layout, faculteit, communicatiekanaal, type_mededeling, muteerbaar, actueel, formaat, e_mail_adres_1, antwoordadres, ander_antwoordadres, verstuur_in_context, verstuur_vanaf_tijdstip, zichtbaar_in_student, documentset, keuze_zichtbaar_in_document, toon_antwoordadres_no_reply, toon_antwoordadres_mijzelf, toon_antwoordadres_opgeven FROM messages m INNER JOIN settings s ON m.settings = s.label INNER JOIN layouts l ON m.layout = l.label; """ db = get_db() messages = [dict(row) for row in db.execute(sql).fetchall()] for msg in messages: layout_nl = prime(msg['layout'], variables['nl']) layout_en = prime(msg['layout'], variables['en']) msg['mededeling'] = msg['mededeling'].upper() msg['koptekst'] = fix(prime(msg['koptekst'], variables['nl'])) msg['koptekst_en'] = fix(prime(msg['koptekst_en'], variables['en'])) msg['koptekst_nls'] = msg['koptekst'] msg['inhoud'] = markdown(prime(msg['inhoud'], variables['nl'])) msg['inhoud_en'] = markdown(prime(msg['inhoud_en'], variables['en'])) msg['inhoud'] = fix(prime(layout_nl, dict(content=msg['inhoud']))) msg['inhoud_en'] = fix(prime(layout_en, dict(content=msg['inhoud_en']))) msg['inhoud_nls'] = msg['inhoud'] msg['omschrijving'] = msg['koptekst'] msg['omschrijving_en'] = msg['koptekst_en'] msg['omschrijving_nls'] = msg['koptekst'] del msg['layout'] if request.method == 'POST': r = request.get_json() selection = r['selection'] xml = build_xml(selection, messages) return make_response(jsonify(xml)) return render_template('manager/export.html', module='xml', extension='xml', mime='text/plain', data=[msg['mededeling'] for msg in messages])