def update_bulk_person(person, full_name=None, ad_user_name=None, rfid_code=None, ss_user_name=None, ss_internal_nbr=None, enabled=None, active=None, updated=True, data=None): try: if full_name: person.name = full_name if ad_user_name: person.ad_user_name = ad_user_name if rfid_code: person.rfid_code = rfid_code if ss_user_name: person.ss_user_name = ss_user_name if ss_internal_nbr: person.ss_internal_nbr = ss_internal_nbr if data: person.data = data if enabled is not None: person.set_flag(Person.ENABLED_FLAG, enabled) if active is not None: person.set_flag(Person.ACTIVE_FLAG, active) if updated is not None: person.set_flag(Person.UPDATED_FLAG, updated) return person except Exception as e: mutils.raise_error('could not edit bulk person', e) return None
def update_person(person, full_name=None, ad_user_name=None, rfid_code=None, ss_user_name=None, ss_internal_nbr=None, enabled=None, active=None, updated=True, data=None): try: person = update_bulk_person(person, full_name=full_name, ad_user_name=ad_user_name, rfid_code=rfid_code, ss_user_name=ss_user_name, ss_internal_nbr=ss_internal_nbr, enabled=enabled, active=active, updated=updated, data=data) db.session.commit() return person except Exception as e: mutils.raise_error('could not edit person', e) return None
def get_timeslot_ids(): try: timeslot_ids = [t.id for t in db.session.query(Timeslot.id)] return timeslot_ids except Exception as e: mutils.raise_error('could not get timeslot ids', e) return []
def get_registrations(id=None, student_id=None, ack_sent=None, enabled=None, first=False): try: registrations = Registration.query if id: registrations = registrations.filter(Registration.id == id) if student_id: registrations = registrations.filter( Registration.student_id == student_id) if ack_sent is not None: registrations = registrations.filter( Registration.ack_sent == ack_sent) if enabled is not None: registrations = registrations.filter( Registration.enabled == enabled) if first: registration = registrations.first() return registration registrations = registrations.all() return registrations except Exception as e: mutils.raise_error('could not get registrations', e) return None
def update_bulk_teacher(teacher, name=None, user_name=None, badge=None, smartschool_id=None, smartschool_flags=None, data=None, enabled=None): try: if name: teacher.name = name if user_name: teacher.user_name = user_name if badge: teacher.badge_code = badge if smartschool_id: teacher.smartschool_id = smartschool_id if smartschool_flags: teacher.smartschool_flags = smartschool_flags if data: teacher.data = data if enabled is not None: teacher.enabled = enabled return teacher except Exception as e: mutils.raise_error('could not edit bulk teacher', e) return None
def update_bulk_student(student, name=None, ss_user_name=None, ad_user_name=None, badge=None, data=None, wisa_nbr=None, enabled=None): try: if name: student.name = name if ss_user_name: student.ss_user_name = ss_user_name if ad_user_name: student.ad_user_name = ad_user_name if badge: student.badge_code = badge if wisa_nbr: student.wisa_nbr = wisa_nbr if data: student.data = data if enabled is not None: student.enabled = enabled return student except Exception as e: mutils.raise_error('could not edit bulk student', e) return None
def get_table_config(table): try: table_config = configuration[table] table_config['table_action'] = f'{table}.table_action' table_config['table_ajax'] = f'{table}.table_ajax' return table_config except Exception as e: raise_error('Kan de configuratietabel niet ophalen', e)
def get_free_timeslots(): try: timeslots = Timeslot.query.join(Registration, isouter=True).filter(Registration.id==None) timeslots = timeslots.all() return timeslots except Exception as e: mutils.raise_error('could not get free timeslots', e) return None
def prepare_item_config_for_view(table, action): try: item_config = table['item'][action] item_config['item_action'] = f'{table["view"]}.item_action' item_config['action'] = action except Exception as e: raise_error('Kan de itemconfiguratietabel niet ophalen', e) return item_config
def delete_persons(person=None, persons=None): try: if person: persons = [person] for person in persons: db.session.delete(person) db.session.commit() except Exception as e: mutils.raise_error('could not delete persons', e)
def update_registration(registration, timeslot=None, ack_send_retry=None): try: if timeslot: registration.timeslot = timeslot if ack_send_retry is not None: registration.ack_send_retry = ack_send_retry db.session.commit() except Exception as e: mutils.raise_error('could not update registration', e)
def add_timeslot(date=None, meeting_url=None, enabled=None): try: if date and meeting_url and enabled: timeslot = Timeslot(date=date, length=30, meeting_url=meeting_url, enabled=enabled) db.session.add(timeslot) db.session.commit() log.info(f'added timeslot: {date}') return timeslot except Exception as e: mutils.raise_error('could add timeslot', e) return None
def get_default_values(): try: timeslot_template = json.loads( msettings.get_configuration_setting( 'registration-timeslot-template')) timeslots_data = get_timeslots() ret = {'template': timeslot_template, 'timeslots': timeslots_data} return ret except Exception as e: mutils.raise_error(f'could not get default timeslot values', e) return None
def delete_timeslots(id=None, id_list=None): try: if id: id_list = [id] for i in id_list: timeslot = get_first_timeslot(i) db.session.delete(timeslot) db.session.commit() except Exception as e: mutils.raise_error('could not remove timeslots', e) return []
def delete_registrations(id=None, id_list=None): try: if id: id_list = [id] for i in id_list: registration = get_first_registration(id=int(i)) db.session.delete(registration) db.session.commit() except Exception as e: mutils.raise_error('could not remove registrations', e) return []
def get_timeslots(): try: timeslots = mtimeslot.get_timeslots() timeslots_data = [] for timeslot in timeslots: formio = timeslot.ret_formio() formio['timeslot-date'] = mutils.datetime_to_formiodate( formio['timeslot-date']) timeslots_data.append(formio) return timeslots_data except Exception as e: mutils.raise_error(f'could not get timeslots', e) return None
def get_students(enabled=None, first=False): try: students = Student.query if enabled is not None: students = students.filter(Student.enabled == enabled) if first: student = students.first() return student students = students.all() return students except Exception as e: mutils.raise_error('could not get students', e) return None
def get_timeslots(id=None, first=False): try: timeslots = Timeslot.query if id: timeslots = timeslots.filter(Timeslot.id == id) if first: timeslot = timeslots.first() return timeslot timeslots = timeslots.order_by(Timeslot.date).all() return timeslots except Exception as e: mutils.raise_error('could not get timeslots', e) return None
def update_timeslot(timeslot, date=None, meeting_url=None, enabled=None): try: if date is not None: timeslot.date = date if meeting_url is not None: timeslot.meeting_url = meeting_url if enabled is not None: timeslot.enabled = enabled db.session.commit() return timeslot except Exception as e: mutils.raise_error('could update timeslot', e) return None
def get_teachers(enabled=None, first=False): try: teachers = Person.query if enabled is not None: teachers = teachers.filter(Person.enabled == enabled) if first: teacher = teachers.first() return teacher teachers = teachers.all() return teachers except Exception as e: mutils.raise_error('could not get teachers', e) return None
def get_persons(enabled=None, active=None, new=None, updated=None, role=None, first=False, count=False): try: persons = Person.query if enabled is not None: if enabled: persons = persons.filter( Person.flags.op('&')(Person.ENABLED_FLAG)) else: persons = persons.filter(~Person.flags.op('&') (Person.ENABLED_FLAG)) if active is not None: if active: persons = persons.filter( Person.flags.op('&')(Person.ACTIVE_FLAG)) else: persons = persons.filter(~Person.flags.op('&') (Person.ACTIVE_FLAG)) if updated is not None: if updated: persons = persons.filter( Person.flags.op('&')(Person.UPDATED_FLAG)) else: persons = persons.filter(~Person.flags.op('&') (Person.UPDATED_FLAG)) if new is not None: if new: persons = persons.filter(Person.flags.op('&')(Person.NEW_FLAG)) else: persons = persons.filter(~Person.flags.op('&') (Person.NEW_FLAG)) if role: persons = persons.filter(Person.flags.op('&')(role)) if first: person = persons.first() return person elif count: nbr = persons.count() return nbr persons = persons.all() return persons except Exception as e: mutils.raise_error('could not get persons', e) return None
def add_registration(student_id, student_name, parent_name, nbr_coaccount, timeslot): try: data = json.dumps({ 'student_name': student_name, 'parent_name': parent_name, 'nbr_coaccount': nbr_coaccount }) registration = Registration(student_id=student_id, data=data, timeslot=timeslot) db.session.add(registration) db.session.commit() return registration except Exception as e: mutils.raise_error('could not add registration', e) return None
def add_person(full_name=None, ad_user_name=None, rfid_code=None, ss_user_name=None, ss_internal_nbr=None, role=None, data=None): try: person = add_bulk_person(full_name=full_name, ad_user_name=ad_user_name, rfid_code=rfid_code, ss_user_name=ss_user_name, ss_internal_nbr=ss_internal_nbr, role=role, data=data) db.session.commit() return person except Exception as e: mutils.raise_error('could not add person', e) return None
def add_teacher(name=None, user_name=None, badge=None, smartschool_id=None, smartschool_flags=None, data=None, enabled=True): try: teacher = add_bulk_teacher(name=name, user_name=user_name, badge=badge, smartschool_id=smartschool_id, smartschool_flags=smartschool_flags, data=data, enabled=enabled) db.session.commit() return teacher except Exception as e: mutils.raise_error('could not add teacher', e) return None
def add_student(name=None, ss_user_name=None, ad_user_name=None, badge=None, data=None, wisa_nbr=None, enabled=True): try: student = add_bulk_student(name=name, ss_user_name=ss_user_name, ad_user_name=ad_user_name, badge=badge, wisa_nbr=wisa_nbr, enabled=enabled, data=data) db.session.commit() return student except Exception as e: mutils.raise_error('could not add student', e) return None
def add_bulk_teacher(name=None, user_name=None, badge=None, smartschool_id=None, smartschool_flags=None, data=None, enabled=True): try: teacher = Person(full_name=name, user_name=user_name, badge_code=badge, smartschool_id=smartschool_id, smartschool_flags=smartschool_flags, enabled=enabled, data=data) db.session.add(teacher) return teacher except Exception as e: mutils.raise_error('could not add bulk teacher', e) return None
def prepare_config_table_for_view(table): try: out = mutils.deepcopy(table) for i in out['template']: if 'order_by' in i: del i['order_by'] if not 'orderable' in i: i['orderable'] = False if 'format_data' in out: del out['format_data'] if 'pre_filter' in out: del out['pre_filter'] if 'post_processing' in out: del out['post_processing'] if 'search_data' in out: del out['search_data'] out['table_action'] = f'{out["view"]}.table_action' out['table_ajax'] = f'{out["view"]}.table_ajax' except Exception as e: raise_error('Kan de configuratietabel niet ophalen', e) return out
def add_bulk_person(full_name=None, ad_user_name=None, rfid_code=None, ss_user_name=None, ss_internal_nbr=None, role=None, data=None): try: flags = role | Person.ACTIVE_FLAG | Person.ENABLED_FLAG | Person.NEW_FLAG person = Person(full_name=full_name, ad_user_name=ad_user_name, rfid_code=rfid_code, ss_user_name=ss_user_name, ss_internal_nbr=ss_internal_nbr, flags=flags, data=data) db.session.add(person) return person except Exception as e: mutils.raise_error('could not add bulk person', e) return None
def end_add_bulk_teacher(): try: db.session.commit() except Exception as e: mutils.raise_error('could not end add bulk teacher', e) return None
def end_add_bulk_student(): try: db.session.commit() except Exception as e: mutils.raise_error('could not end add bulk student', e) return None