utils.py 1.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from flask import abort, render_template
from datetime import datetime

from models.database import Speaker

from shared import db

def render_layout(template, **kwargs):
    current_time = datetime.now()
    return render_template(template, current_time=current_time, **kwargs)
       
def speaker_by_name_or_number(name_or_number, event_id):
    if name_or_number.isnumeric():
        number = int(name_or_number)
15
        speaker = Speaker.query.filter_by(number=number, event_id=event_id).first()
16 17 18 19 20 21 22 23 24
        if speaker is not None:
            return speaker
        else:
            speaker = Speaker("", number, event_id)
            db.session.add(speaker)
            db.session.commit()
            return speaker
    else:
        name = name_or_number
25
        speaker = Speaker.query.filter_by(name=name, event_id=event_id).first()
26 27 28 29 30 31 32 33
        if speaker is not None:
            return speaker
        else:
            speaker = Speaker(name, 0, event_id)
            db.session.add(speaker)
            db.session.commit()
            return speaker