Пример #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)
Пример #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)
Пример #3
0
    def test_delete_role(self):
        role_name = 'super_admin'
        new_role = models.Role(name=role_name)
        db_session.add(new_role)
        db_session.commit()

        role = models.Role.query.filter_by(name=role_name).first()

        url = self.live_server_url + '/admin/users/roles'

        self.browser.get(url)

        table = self.browser.find_element_by_id('roles-list')
        td = table.find_elements_by_tag_name('td')
        self.assertIn(role_name, [t.text for t in td])

        delete_url = '/admin/users/roles/delete/' + str(role.id)
        delete_button_xpath = "//a[@href='{}']".format(delete_url)
        button = table.find_element_by_xpath(delete_button_xpath)

        button.click()

        table = self.browser.find_element_by_id('roles-list')
        td = table.find_elements_by_tag_name('td')

        self.assertNotIn(role_name, [t.text for t in td])
Пример #4
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)
Пример #5
0
    def test_delete_role(self):
        new_role = Role(name='super_admin')
        db_session.add(new_role)
        db_session.commit()

        role = Role.query.filter_by(name='super_admin').first()
        role_id = str(role.id)

        count_before_delete = Role.query.count()
        response = self.client.get('/admin/users/roles/delete/' + role_id)
        count_after_delete = Role.query.count()

        self.assertStatus(response, 302)
        self.assertIsNone(Role.query.filter_by(id=role.id).first())
        self.assertEqual(count_before_delete, count_after_delete + 1)
Пример #6
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)
Пример #7
0
    def test_delete_role(self):
        new_role = Role(name='super_admin')
        db_session.add(new_role)
        db_session.commit()

        role = Role.query.filter_by(name='super_admin').first()
        role_id = str(role.id)

        count_before_delete = Role.query.count()
        response = self.client.get('/admin/users/roles/delete/' + role_id)
        count_after_delete = Role.query.count()

        self.assertStatus(response, 302)
        self.assertIsNone(Role.query.filter_by(id=role.id).first())
        self.assertEqual(count_before_delete, count_after_delete + 1)
Пример #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)
Пример #9
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)
Пример #10
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)
Пример #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)
Пример #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)
Пример #13
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)
Пример #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)
Пример #15
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)
Пример #16
0
    def setUp(self):
        db_session.remove()
        db_session.configure(bind=self.test_engine)
        Base.metadata.create_all(self.test_engine)

        role1 = models.Role('admin')
        role2 = models.Role('client')

        db_session.add(role1)
        db_session.add(role2)
        db_session.commit()

        user = models.User('danzaw', '*****@*****.**',
                           "it's a secret", role_id=role1.id)
        user2 = models.User('himon', '*****@*****.**',
                            "it's a secret", role_id=role2.id)

        db_session.add(user)
        db_session.add(user2)
        db_session.commit()

        account = models.Account('danzaw', '*****@*****.**',
                                 "it's a secret", 'webapi_key')

        db_session.add(account)
        db_session.commit()

        shipping_type1 = models.ShippingType('Kurier', False)
        shipping_type2 = models.ShippingType('Odbiór osobisty', True)

        db_session.add(shipping_type1)
        db_session.add(shipping_type2)

        auction_type1 = models.AuctionType('sklepowa')
        auction_type2 = models.AuctionType('zwykła')

        db_session.add(auction_type1)
        db_session.add(auction_type2)

        db_session.commit()
Пример #17
0
def create_db():
    Base.metadata.reflect()
    Base.metadata.drop_all()
    Base.metadata.create_all()

    role1 = models.Role('admin')
    role2 = models.Role('client')

    db_session.add(role1)
    db_session.add(role2)
    db_session.commit()


    user = models.User('danzaw', '*****@*****.**', "it's a secret", 1)
    user2 = models.User('himon', '*****@*****.**', "it's a secret", 2)

    db_session.add(user)
    db_session.add(user2)
    db_session.commit()

    account = models.Account('danzaw', '*****@*****.**',
                             "it's a secret", 'webapi_key')

    db_session.add(account)
    db_session.commit()

    shipping_type1 = models.ShippingType('Kurier', False)
    shipping_type2 = models.ShippingType('Odbiór osobisty', True)

    db_session.add(shipping_type1)
    db_session.add(shipping_type2)

    auction_type1 = models.AuctionType('sklepowa')
    auction_type2 = models.AuctionType('zwykła')

    db_session.add(auction_type1)
    db_session.add(auction_type2)

    db_session.commit()