def get_or_create_user(username): user = User.query.filter_by(username=username).first() if user is None: user = User(username) db.add(user) db.commit() return user
def update_event_tracking_status(event_id): attribs_required_for_complete_event = 2 event = get_event(event_id) if event.event_type is not None: attribs_required_for_complete_event -= 1 # if event.event_severity is not None: # attribs_required_for_complete_event -= 1 if event.event_duration is not None: attribs_required_for_complete_event -= 1 if attribs_required_for_complete_event == 0: event.event_tracking_status_name = 'COMPLETE' elif attribs_required_for_complete_event < 2: event.event_tracking_status_name = 'PARTIALLY_COMPLETE' else: event.event_tracking_status_name = 'CREATED' db.commit()
def update_event_severity(event_id, severity): event = get_event(event_id) event.event_severity = severity db.commit()
def update_event_duration(event_id, duration): event = get_event(event_id) event.event_duration = duration db.commit()
def update_event_type(event_id, event_type): event = get_event(event_id) event.event_type = event_type db.commit()
def update_event(event): db.commit()
def delete_event(event_id): Event.query.filter_by(id=event_id).delete() db.commit()
def create_event(user_id, event_time, event_type=None, severity=None, duration=None): event = Event(user_id, event_time, event_type, severity, duration) db.add(event) db.commit() return event