def from_new(cls, location, organiser_id, event_name, start_time, end_time, repeat): session = Session() code = random.randint(0, 1000000) while session.query(Event.code).filter_by(code=code).first() != None: code = random.randint(0, 1000000) event = Event() eid = next_id("event") event.eid = eid event.code = code event.location = location event.organiser_id = organiser_id event.event_name = event_name event.participants = {} event.start_time = start_time event.end_time = end_time event.repeat = repeat session.add(event) session.commit() session.close() return cls( eid, location, organiser_id, event_name, code, start_time, end_time, repeat, {}, )
def create_event(location, organiser_id, event_name): # returns the code session = Session() event = Event() if session.query(func.max(Event.eid)).first()[0] != None: event.eid = session.query(func.max(Event.eid)).first()[0] + 1 else: event_id = 1 code = random.randint(0, 1000000) while session.query(Event.code).filter_by(code=code).first() != None: code = random.randint(0, 1000000) event.code = code event.location = location event.organiser_id = organiser_id event.event_name = event_name event.participants = {} session.add(event) session.commit() session.close() return code