Example #1
0
def add(action_done=False):
    try:
        if action_done:
            absent_teacher_ids = request.form.getlist('my-select[]')
            replaced_by_teacher_id = request.form['replaced_by']
            school = db_utils.school()
            academic_year = db_utils.academic_year()
            if absent_teacher_ids:
                for t_id in absent_teacher_ids:
                    r = ReplacementTeacher(
                        replacing_id=t_id,
                        replaced_by_id=replaced_by_teacher_id,
                        school=school,
                        academic_year=academic_year)
                    db.session.add(r)
                r.first_replacement_teacher = True
                db.session.commit()
        else:
            form = forms.AddForm()
            teachers = [(i, t, '')
                        for i, t in db_teacher.db_teacher_list(select=True,
                                                               full_name=True)]
            return render_template('settings/replacements/replacement.html',
                                   form=form,
                                   all_teachers=teachers,
                                   title='Voeg een vervanger toe',
                                   action='add',
                                   role='add',
                                   subject='settings.replacements')
    except Exception as e:
        log.error(u'Could not add replacement {}'.format(e))
        utils.flash_plus(u'Kan vervanger niet toevoegen', e)
        db.session.rollback()
    return redirect(url_for('settings.replacements.show'))
def default_grade_filter():
    try:
        teacher_found = db_teacher.db_teacher(code=current_user.username.upper())
        teacher_in_schedule = not not db_schedule.db_schedule_list(teacher=teacher_found) if teacher_found else False
        if teacher_in_schedule:
            teacher_id = db_teacher.db_teacher(code=current_user.username.upper()).id
        else:
            teacher_id = db_teacher.db_teacher_list()[0].id
        session_set_grade_filter(teacher_id=teacher_id, day_hour='None', grade_id=-1, lesson_id=-1, changed_item='teacher')
    except Exception as e:
        log.error('default_grade_filter error : {}'.format(e))
Example #3
0
def edit(action_done=False, id=-1):
    try:
        if action_done:
            absent_teacher_ids = request.form.getlist('my-select[]')
            replaced_by_teacher_id = request.form['replaced_by']
            school = db_utils.school()
            academic_year = db_utils.academic_year()
            for r in db_replacement.replacement_list(
                    id=replaced_by_teacher_id):
                db.session.delete(r)
            if absent_teacher_ids:
                for t_id in absent_teacher_ids:
                    r = ReplacementTeacher(
                        replacing_id=t_id,
                        replaced_by_id=replaced_by_teacher_id,
                        school=school,
                        academic_year=academic_year)
                    db.session.add(r)
                r.first_replacement_teacher = True
            db.session.commit()
        else:
            chbx_id_list = request.form.getlist('chbx')
            if chbx_id_list:
                id = int(chbx_id_list[0])  # only the first one can be edited
                absent_teacher_ids = db_replacement.replacement_list(
                    id=id, ids_only=True)
                # absent_teachers = db_teacher.db_teacher_list(select=True, full=True, id_list=replacements)
                all_teachers = db_teacher.db_teacher_list(select=True,
                                                          full_name=True)
                filtered_teachers = []
                for i, t in all_teachers:
                    if i in absent_teacher_ids:
                        filtered_teachers.append((i, t, 'selected'))
                    else:
                        filtered_teachers.append((i, t, ''))

                form = forms.EditForm()
                form.replaced_by.choices = [
                    (id, db_teacher.db_teacher(id=id, full_name=True))
                ]
                return render_template(
                    'settings/replacements/replacement.html',
                    form=form,
                    all_teachers=filtered_teachers,
                    title='Wijzig een vervanger toe',
                    action='edit',
                    role='edit',
                    subject='settings.replacements')

    except Exception as e:
        log.error(u'Could not edit replacement {}'.format(e))
        utils.flash_plus(u'Kan vervanger niet wijzigen', e)
        db.session.rollback()
    return redirect(url_for('settings.replacements.show'))
def load_user(user_id):
    user = User.query.get(int(user_id))
    if user:
        user.teacher = db_teacher.db_teacher(code=user.username.upper())
        user.in_schedule = not not db_schedule.db_schedule_list(teacher=user.teacher) if user.teacher else False
        user.in_replacement = not not db_replacement.replacement_list(id=user.teacher.id) if user.teacher else False
        teacher_ids = []
        if not user.in_schedule and not user.in_replacement:
            user.in_replacement = True
            try:
                teacher_ids = [db_teacher.db_teacher(code='XXXX').id]
            except:
                None
        else:
            if user.in_schedule:
                teacher_ids.append(user.teacher.id)
            if user.in_replacement:
                teacher_ids += db_replacement.replacement_list(user.teacher.id, ids_only=True)
        if teacher_ids:
            user.teacher_list = db_teacher.db_teacher_list(select=True, full_name=True, id_list=teacher_ids)

    return user
Example #5
0
 def __init__(self, *args, **kwargs):
     super(EditForm, self).__init__(*args, **kwargs)
     self.replaced_by.choices = db_teacher.db_teacher_list(select=True,
                                                           schedule=False,
                                                           full_name=True)
Example #6
0
 def __init__(self, *args, **kwargs):
     super(TeacherFilter, self).__init__(*args, **kwargs)
     self.teacher.choices = [('', '')] + db_teacher.db_teacher_list(
         full_name=True, schedule=False, select=True)
Example #7
0
def upload_schedule(rfile):
    try:
        # format csv file :
        log.info(u'Import timetable from : {}'.format(rfile))
        academic_year = request.form['selected_academic_year']
        valid_from = datetime.datetime.strptime(
            request.form['select-date-from'], '%d-%m-%Y')

        # first, delete current timetable
        delete_classmoments(academic_year, valid_from)

        fieldnames = [
            'VOLGNUMMER', 'KLAS', 'LEERKRACHT', 'VAK', 'LOKAAL', 'DAG', 'UUR'
        ]
        timetable_file = csv.DictReader(rfile,
                                        fieldnames=fieldnames,
                                        delimiter=',',
                                        encoding='utf-8-sig')
        nbr_classmoments = 0
        nbr_lessons = 0
        error_message = ''
        nbr_grades = 0
        nbr_classgroups = 0
        grades = {g.code: g for g in db_grade.db_grade_list(in_schedule=False)}
        classgroups = {c.code: c for c in db_classgroup.db_classgroup_list()}
        lessons = {l.code: l for l in db_lesson.db_lesson_list(schedule=False)}
        teachers = {
            t.code: t
            for t in db_teacher.db_teacher_list(schedule=False)
        }

        for t in timetable_file:
            # skip empy records
            if t['KLAS'] != '' and t['LEERKRACHT'] != '' and t[
                    'VAK'] != '' and t['DAG'] != '' and t['UUR'] != '':
                if t['LEERKRACHT'] in teachers:
                    find_teacher = teachers[t['LEERKRACHT']]
                    classgroup_code = t['KLAS']
                    if len(classgroup_code.split(' ')) == 1:
                        grade_code = classgroup_code
                    else:
                        grade_code = classgroup_code.split(' ')[0]
                    lesson_code = t['VAK']
                    # check for grade.  If it not exists, add it first
                    if grade_code in grades:
                        find_grade = grades[grade_code]
                    else:
                        find_grade = Grade(code=grade_code,
                                           school=db_utils.school())
                        db.session.add(find_grade)
                        grades[grade_code] = find_grade
                        nbr_grades += 1
                    # check for classgroup, if not present, add
                    if classgroup_code in classgroups:
                        find_classgroup = classgroups[classgroup_code]
                    else:
                        find_classgroup = Classgroup(code=classgroup_code,
                                                     grade=find_grade)
                        db.session.add(find_classgroup)
                        classgroups[classgroup_code] = find_classgroup
                        nbr_classgroups += 1
                    # add lesson, if not already present
                    if lesson_code in lessons:
                        find_lesson = lessons[lesson_code]
                    else:
                        find_lesson = Lesson(code=lesson_code,
                                             school=db_utils.school())
                        db.session.add(find_lesson)
                        lessons[lesson_code] = find_lesson
                        nbr_lessons += 1
                    classmoment = Schedule(day=int(t['DAG']),
                                           hour=int(t['UUR']),
                                           classgroup=find_classgroup,
                                           teacher=find_teacher,
                                           lesson=find_lesson,
                                           school=db_utils.school(),
                                           academic_year=int(academic_year),
                                           valid_from=valid_from)
                    db.session.add(classmoment)
                    nbr_classmoments += 1
                else:
                    log.info(u'import timetable: teacher not found: {}'.format(
                        t['LEERKRACHT']))
                    error_message += u'{} : niet gevonden<br>'.format(
                        t['LEERKRACHT'])

        # load schedule for teacher XXXX
        period = day = 1
        teacher = db_teacher.db_teacher(code='XXXX')
        lesson = db_lesson.db_lesson_list()[0]
        for g in db_grade.db_grade_list():
            classgroups = db_classgroup.db_classgroup_list(grade=g)
            for cg in classgroups:
                classmoment = Schedule(day=day,
                                       hour=period,
                                       classgroup=cg,
                                       teacher=teacher,
                                       lesson=lesson,
                                       school=db_utils.school(),
                                       academic_year=int(academic_year),
                                       valid_from=valid_from)
                db.session.add(classmoment)
            period += 1
            if period > 9:
                period = 1
                day += 1
        db.session.commit()
        log.info(
            u'import: added {} classmoments, {} grades, {} classgroups and {} lessons'
            .format(nbr_classmoments, nbr_grades, nbr_classgroups,
                    nbr_lessons))
        if error_message == '':
            utils.flash_plus(
                u'Lesrooster is geïmporteerd, {} lestijden, {} klassen, {} klasgroepen en {} lessen toegevoegd'
                .format(nbr_classmoments, nbr_grades, nbr_classgroups,
                        nbr_lessons))
        else:
            utils.flash_plus(u'Lesrooster kan niet worden geïmporteerd',
                             format(error_message))

    except Exception as e:
        utils.flash_plus(u'Kan bestand niet importeren', e)
    return
Example #8
0
class EditReplacementForm(FlaskForm):
    replaced_by = SelectField('Vervangende leerkracht',
                              choices=db_teacher.db_teacher_list(
                                  select=True, schedule=False))
    id = IntegerField(widget=HiddenInput())
Example #9
0
def filter_grade():
    try:
        if not current_user.in_schedule and not current_user.in_replacement and current_user.is_strict_user:
            log.error(u'Level 1 user not in schedule')
            utils.flash_plus(u'Sorry, u kan op deze pagina niets zien')
            return FilterForm(), []

        if 'change_id' in request.form:  # filters on grade-page are used
            teacher_id = int(request.form['teacher'])
            day_hour = request.form['dayhour']
            changed_item = request.form['change_id']
            try:
                lesson_id = int(request.form['lesson'])
            except:
                lesson_id = -1
            try:
                grade_id = int(request.form['grade'])
            except:
                grade_id = -1
            db_user.session_set_grade_filter(teacher_id, day_hour, grade_id, lesson_id, changed_item)
        teacher_id, day_hour, grade_id, lesson_id, changed_item = db_user.session_get_grade_filter()
        schedules = db_grade.db_filter_grade(teacher_id, day_hour, grade_id, lesson_id, changed_item)
    except Exception as e:
        log.error(u'No schedule found {}'.format(e))
        utils.flash_plus(u'Er is nog geen lesrooster geladen')
        return FilterForm(), []
    try:
        #put all students in one list and sort on last name
        students = []
        for s in schedules:
            students += db_student.db_student_list(classgroup=s.classgroup)
        students = sorted(students, key=lambda i: i.last_name)
        teacher_grades = db_grade.db_grade_list(schedules[0].teacher, html_select=True)
        is_single_grade, classgroup_codes = db_grade.db_single_grade(schedules)
        teacher_lessons = db_lesson.db_lesson_list(schedules[0].teacher, html_select=True)
        teacher_schedules = db_schedule.db_schedule_list(schedules[0].teacher, html_select=True)

        # create filter
        form_filter = FilterForm()
        form_filter.teacher.data = str(schedules[0].teacher.id)
        if current_user.is_at_least_supervisor:
            choices = db_teacher.db_teacher_list(select=True, full_name=True)
        elif current_user.teacher_list:
            choices = current_user.teacher_list
        else:
            choices = None
        form_filter.teacher.choices = choices

        form_filter.dayhour.data = schedules[0].get_data_day_hour()
        form_filter.dayhour.choices = utils.filter_duplicates_out(teacher_schedules, Schedule.get_choices_day_hour())

        if is_single_grade:
            form_filter.grade.data = str(schedules[0].classgroup.grade.id)
        else:
            teacher_grades.append(('disabled-unused', classgroup_codes))
            form_filter.grade.data = 'disabled-unused'
        form_filter.grade.choices = utils.filter_duplicates_out(teacher_grades, db_grade.db_grade_list(html_select=True))

        form_filter.lesson.data = str(schedules[0].lesson.id)
        form_filter.lesson.choices = utils.filter_duplicates_out(teacher_lessons, db_lesson.db_lesson_list(html_select=True))

        db_user.session_set_grade_filter(day_hour=schedules[0].get_data_day_hour(), grade_id=schedules[0].classgroup.grade.id,
                                         lesson_id=schedules[0].lesson.id)

    except Exception as e:
        log.error(u'Cannot filter the grade {}'.format(e))
        utils.flash_plus(u'Er is een probleem met de filter', e)
        return FilterForm(), []
    return form_filter, students