Exemplo n.º 1
0
def edit_group():
    form = GroupForm()

    if request.method == 'GET':

        group_id = request.args.get('group_id')
        db = PostgresDb()
        group = db.sqlalchemy_session.query(Group).filter(Group.group_id == group_id).one()

        # fill form and send to student
        form.group_id.data = group.group_id
        form.group_name.data = group.group_name
        form.group_faculty.data = group.group_faculty

        return render_template('group_form.html', form=form, form_name="Edit group", action="edit_group")

    else:

        if not form.validate():
            return render_template('group_form.html', form=form, form_name="Edit group", action="edit_group")
        else:
            db = PostgresDb()
            # find student
            group = db.sqlalchemy_session.query(Group).filter(Group.group_id == form.group_id.data).one()

            # update fields from form data
            group.group_id = form.group_id.data
            group.group_faculty = form.group_faculty.data
            group.group_name = form.group_name.data

            db.sqlalchemy_session.commit()

            return redirect(url_for('index_group'))
Exemplo n.º 2
0
def new_group():
    form = GroupForm()

    if request.method == 'POST':
        if not form.validate():
            return render_template('group_form.html',
                                   form=form,
                                   form_name="New group",
                                   action="new_group")
        else:
            new_group = ormGroup(group_name=form.group_name.data,
                                 group_description=form.group_name.data)

            person = db.session.query(ormPersons).filter(
                ormPersons.id == current_user.id).one()

            person.group.append(new_group)

            # Dima.group.append(Books)
            db.session.add(person)
            db.session.commit()

            return redirect(url_for('group'))

    return render_template('group_form.html',
                           form=form,
                           form_name="New group",
                           action="new_group")
Exemplo n.º 3
0
def new_group():
    form = GroupForm()

    if request.method == 'POST':
        if not form.validate():
            return render_template('group_form.html', form=form, form_name="New group", action="new_group")
        else:
            group_obj = Group(
                group_faculty=form.group_faculty.data,
                group_name=form.group_name.data)

            db = PostgresDb()
            db.sqlalchemy_session.add(group_obj)
            db.sqlalchemy_session.commit()

            return redirect(url_for('index_group'))

    return render_template('group_form.html', form=form, form_name="New group", action="new_group")
Exemplo n.º 4
0
def edit_group():

    form = GroupForm()

    if request.method == 'GET':

        group_id = request.args.get('group_id')
        group = db.session.query(Group).filter(
            Group.group_id == group_id).one()

        # fill form and send to user
        form.group_id.data = group.group_id
        form.group_name.data = group.group_name
        form.group_topic.data = group.group_topic

        return render_template('group_form.html',
                               form=form,
                               form_name="Edit group",
                               action="edit_group")

    else:

        if form.validate() != False:
            return render_template('group_form.html',
                                   form=form,
                                   form_name="Edit group",
                                   action="edit_group")
        else:
            # find user
            group = db.session.query(Group).filter(
                Group.group_id == form.group_id.data).one()

            # update fields from form data
            group.group_id = form.group_id.data
            group.group_name = form.group_name.data
            group.group_topic = form.group_topic.data

            db.session.commit()

            return redirect(url_for('group'))
Exemplo n.º 5
0
def new_group():

    form = GroupForm()

    if request.method == 'POST':
        if form.validate() != False:
            return render_template('group_form.html',
                                   form=form,
                                   form_name="New group",
                                   action="new_group")
        else:
            new_group = Group(group_id=form.group_id.data,
                              group_name=form.group_name.data,
                              group_topic=form.group_topic.data)

            db.session.add(new_group)
            db.session.commit()

            return redirect(url_for('group'))

    return render_template('group_form.html',
                           form=form,
                           form_name="New group",
                           action="new_group")