Esempio n. 1
0
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first()

    if user is None:
        return render_template('admin/errors/404.html'), 404

    form = EditUserForm(request.form)
    form.role.choices = [(role.id, role.name)
                         for role in Role.query.order_by('name')]
    form.role.default = user.role_id
    form.process(request.form)

    if request.method == 'POST' and form.validate():
        user.login = form.login.data
        user.mail = form.mail.data

        try:
            db_session.add(user)
            db_session.commit()
            return redirect(url_for('admin.manage_users'))
        except IntegrityError:
            db_session.rollback()
            form.login.errors.append('Login lub mail jest już używany')

    return render_template('admin/users/form.html', form=form, user=user)
Esempio n. 2
0
def edit_user(user_id):
    user = User.query.filter_by(id=user_id).first()

    if user is None:
        return render_template('admin/errors/404.html'), 404

    form = EditUserForm(request.form)
    form.role.choices = [(role.id, role.name)
                         for role in Role.query.order_by('name')]
    form.role.default = user.role_id
    form.process(request.form)

    if request.method == 'POST' and form.validate():
        user.login = form.login.data
        user.mail = form.mail.data

        try:
            db_session.add(user)
            db_session.commit()
            return redirect(url_for('admin.manage_users'))
        except IntegrityError:
            db_session.rollback()
            form.login.errors.append('Login lub mail jest już używany')

    return render_template('admin/users/form.html', form=form, user=user)
Esempio n. 3
0
def add_role():
    form = RolesForm(request.form)

    if request.method == 'POST' and form.validate():
        role = Role(name=form.name.data)
        db_session.add(role)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_roles'))
        except IntegrityError:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

    return render_template('admin/roles/form.html', form=form)
Esempio n. 4
0
def delete_role(role_id):
    role = Role.query.filter_by(id=role_id).first()

    if role is None:
        return render_template('admin/errors/404.html'), 404

    db_session.delete(role)

    try:
        db_session.commit()
    except IntegrityError:
        db_session.rollback()
        flash('Nie można usunąć roli, gdy istnieją przypisanie do niej użytkownicy')

    return redirect(url_for('admin.manage_roles'))
Esempio n. 5
0
def add_role():
    form = RolesForm(request.form)

    if request.method == 'POST' and form.validate():
        role = Role(name=form.name.data)
        db_session.add(role)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_roles'))
        except IntegrityError:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

    return render_template('admin/roles/form.html', form=form)
Esempio n. 6
0
def add_shipping_type():
    form = ShippingTypesForm(request.form)

    if request.method == 'POST' and form.validate():
        shipping_type = ShippingType(name=form.name.data,
                                     is_boolean=form.is_boolean.data)

        db_session.add(shipping_type)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_shipping_types'))
        except IntegrityError:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

    return render_template('admin/shipping_types/form.html', form=form)
Esempio n. 7
0
def delete_role(role_id):
    role = Role.query.filter_by(id=role_id).first()

    if role is None:
        return render_template('admin/errors/404.html'), 404

    db_session.delete(role)

    try:
        db_session.commit()
    except IntegrityError:
        db_session.rollback()
        flash(
            'Nie można usunąć roli, gdy istnieją przypisanie do niej użytkownicy'
        )

    return redirect(url_for('admin.manage_roles'))
Esempio n. 8
0
def add_shipping_type():
    form = ShippingTypesForm(request.form)

    if request.method == 'POST' and form.validate():
        shipping_type = ShippingType(name=form.name.data,
                                     is_boolean=form.is_boolean.data)

        db_session.add(shipping_type)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_shipping_types'))
        except IntegrityError:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

    return render_template('admin/shipping_types/form.html', form=form)
Esempio n. 9
0
def add_user():
    form = UserForm(request.form)
    form.role.choices = [(role.id, role.name)
                         for role in Role.query.order_by('name')]

    if request.method == 'POST' and form.validate():
        user = User(login=form.login.data,
                    mail=form.mail.data,
                    password=form.password.data,
                    role_id=form.role.data)

        try:
            db_session.add(user)
            db_session.commit()
            return redirect(url_for('admin.manage_users'))
        except IntegrityError:
            db_session.rollback()
            form.login.errors.append('Login lub mail jest już używany')

    return render_template('admin/users/add.html', form=form)
Esempio n. 10
0
def edit_role(role_id):
    role = Role.query.filter_by(id=role_id).first()

    if role is None:
        return render_template('admin/errors/404.html'), 404

    form = RolesForm(request.form)

    if request.method == 'POST' and form.validate():
        role.name = form.name.data
        db_session.add(role)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_roles'))
        except IntegrityError:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

    return render_template('admin/roles/form.html', form=form, role=role)
Esempio n. 11
0
def add_user():
    form = UserForm(request.form)
    form.role.choices = [(role.id, role.name)
                         for role in Role.query.order_by('name')]

    if request.method == 'POST' and form.validate():
        user = User(login=form.login.data,
                    mail=form.mail.data,
                    password=form.password.data,
                    role_id=form.role.data)

        try:
            db_session.add(user)
            db_session.commit()
            return redirect(url_for('admin.manage_users'))
        except IntegrityError:
            db_session.rollback()
            form.login.errors.append('Login lub mail jest już używany')

    return render_template('admin/users/add.html', form=form)
Esempio n. 12
0
def edit_role(role_id):
    role = Role.query.filter_by(id=role_id).first()

    if role is None:
        return render_template('admin/errors/404.html'), 404

    form = RolesForm(request.form)

    if request.method == 'POST' and form.validate():
        role.name = form.name.data
        db_session.add(role)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_roles'))
        except IntegrityError:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

    return render_template('admin/roles/form.html', form=form, role=role)
Esempio n. 13
0
def edit_shipping_type(shipping_type_id):
    shipping_type = ShippingType.query.filter_by(id=shipping_type_id).first()

    if shipping_type is None:
        return render_template('admin/errors/404.html'), 404

    form = ShippingTypesForm(request.form)

    if request.method == 'POST' and form.validate():
        shipping_type.name = form.name.data
        shipping_type.is_boolean = form.is_boolean.data

        db_session.add(shipping_type)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_shipping_types'))
        except IntegrityError as ex:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

    return render_template('admin/shipping_types/form.html', form=form, shipping_type=shipping_type)
Esempio n. 14
0
def edit_shipping_type(shipping_type_id):
    shipping_type = ShippingType.query.filter_by(id=shipping_type_id).first()

    if shipping_type is None:
        return render_template('admin/errors/404.html'), 404

    form = ShippingTypesForm(request.form)

    if request.method == 'POST' and form.validate():
        shipping_type.name = form.name.data
        shipping_type.is_boolean = form.is_boolean.data

        db_session.add(shipping_type)

        try:
            db_session.commit()
            return redirect(url_for('admin.manage_shipping_types'))
        except IntegrityError as ex:
            db_session.rollback()
            form.name.errors.append('Nazwa jest już zajęta')

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