Beispiel #1
0
def delete_subjects():
    """
    Render a delete subject form.
    """

    course_type = request.args.get('course_type')
    form = SubjectsForm(course_type=course_type)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    json = pfactory.grades_of_subjects_dao().find({'courseType': course_type})
    json = list(json)
    json = dumps(json)
    if form.validate_on_submit():
        index = str(form.index.data)
        condition = {
            'title': form.requirement.data,
            'courseType': form.course_type.data
        }
        dao.find_one_and_update(
            condition, {'$set': {
                'subjects.' + index + '.deleted': ""
            }})

        return redirect(
            url_for('crud_subjects.delete_subjects',
                    success_msg='Disciplina deletada com sucesso',
                    course_type=form.course_type.data))
    return render_template(
        'admin/delete_subjects.html',
        form=form,
        subjects=json,
        success_msg=request.args.get('success_msg'),
    )
def delete_subjects():
    """
    Render a delete subject form.
    """

    course_type = request.args.get('course_type')
    form = SubjectsForm(course_type=course_type)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    json = pfactory.grades_of_subjects_dao().find({'courseType' : course_type})
    json = list(json)
    json = dumps(json)
    if form.validate_on_submit():
        index = str(form.index.data)
        condition = {'title': form.requirement.data, 'courseType' : form.course_type.data}
        dao.find_one_and_update(condition, {
            '$set': {'subjects.' + index + '.deleted' : ""}
        })

        return redirect(
            url_for(
                'crud_subjects.delete_subjects',
                success_msg='Disciplina deletada com sucesso',
                course_type=form.course_type.data
            )
        )
    return render_template(
        'admin/delete_subjects.html',
        form=form,
        subjects=json,
        success_msg=request.args.get('success_msg'),
    )
Beispiel #3
0
def edit_subjects():
    """
    Render an edit subject form.
    """
    course_type = request.args.get('course_type')
    if (course_type is None):
        course_type = 'Mestrado'

    form = SubjectsForm(course_type=course_type)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    json = pfactory.grades_of_subjects_dao().find({'courseType': course_type})
    json = list(json)
    json = dumps(json)
    if form.validate_on_submit():
        index = str(form.index.data)
        new_subject = {
            'name': form.name.data,
            'description': form.description.data,
            'workloadInHours': form.workload_in_hours.data,
            'credits': form.credits.data
        }

        condition = {
            'title': form.requirement.data,
            'courseType': form.course_type.data
        }

        dao.find_one_and_update(condition,
                                {'$set': {
                                    'subjects.' + index: new_subject
                                }})
        return redirect(
            url_for('crud_subjects.edit_subjects',
                    course_type=form.course_type.data))
    return render_template(
        'admin/edit_subjects.html',
        form=form,
        subjects=json,
    )
def edit_subjects():
    """
    Render an edit subject form.
    """
    course_type = request.args.get('course_type')
    if (course_type is None):
        course_type = 'Mestrado'

    form = SubjectsForm(course_type=course_type)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    json = pfactory.grades_of_subjects_dao().find({'courseType': course_type })
    json = list(json)
    json = dumps(json)
    if form.validate_on_submit():
        index = str(form.index.data)
        new_subject = {
            'name': form.name.data,
            'description': form.description.data,
            'workloadInHours': form.workload_in_hours.data,
            'credits': form.credits.data
        }

        condition = {'title': form.requirement.data, 'courseType' : form.course_type.data}

        dao.find_one_and_update(condition, {
            '$set': {'subjects.' + index : new_subject}
        })
        return redirect(
            url_for(
                'crud_subjects.edit_subjects',
                course_type=form.course_type.data
            )
        )
    return render_template(
        'admin/edit_subjects.html',
        form=form,
        subjects=json,
    )
def view_subjects(initials):
    """Render a view for subjects."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    grades_of_subjects = pfactory.grades_of_subjects_dao().find({ '$or': [ { 'title': 'Eletivas' }, { 'title':'Obrigatórias' } ] })

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/subjects.html',
        std=get_std_for_template(post_graduation),
        grades_of_subjects=grades_of_subjects
    )
Beispiel #6
0
def view_subjects(initials):
    """Render a view for subjects."""

    pfactory = PosGraduationFactory(initials)
    post_graduation = pfactory.post_graduation

    grades_of_subjects = pfactory.grades_of_subjects_dao().find()

    # renders an own page or redirect to another (external/404)?
    return render_template(
        'public/subjects.html',
        std=get_std_for_template(post_graduation),
        grades_of_subjects=grades_of_subjects
    )
Beispiel #7
0
def subjects():
    """
    Render a subject form.
    """

    course_type = request.args.get('course_type')
    form = SubjectsForm(course_type=course_type)
    print(course_type, file=sys.stderr)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    if form.validate_on_submit():
        new_subject = {
            'name': form.name.data,
            'description': form.description.data,
            'workloadInHours': form.workload_in_hours.data,
            'credits': form.credits.data
        }

        condition = {
            'title': form.requirement.data,
            'courseType': form.course_type.data
        }

        dao.find_one_and_update(condition,
                                {'$push': {
                                    'subjects': new_subject
                                }})

        return redirect(
            url_for(
                'crud_subjects.subjects',
                success_msg='Disciplina adicionada com sucesso.',
                course_type=form.course_type.data,
            ))

    return render_template(
        'admin/subjects.html',
        form=form,
    )
def subjects():
    """
    Render a subject form.
    """

    course_type = request.args.get('course_type')
    form = SubjectsForm(course_type=course_type)
    print(course_type, file=sys.stderr)

    pfactory = PosGraduationFactory(current_user.pg_initials)
    dao = pfactory.grades_of_subjects_dao()
    if form.validate_on_submit():
        new_subject = {
            'name': form.name.data,
            'description': form.description.data,
            'workloadInHours': form.workload_in_hours.data,
            'credits': form.credits.data
        }

        condition = {'title': form.requirement.data, 'courseType' : form.course_type.data }

        dao.find_one_and_update(condition, {
            '$push': {'subjects': new_subject}
        })

        return redirect(
            url_for(
                'crud_subjects.subjects',
                success_msg='Disciplina adicionada com sucesso.',
                course_type=form.course_type.data,
            )
        )

    return render_template(
        'admin/subjects.html',
        form=form,
    )