예제 #1
0
    def update(username, id):
        product = Product.query.get(id)
        view_data = ProductController.__get_view_data()
        categories_products = CategoryProduct()

        product_form = view_data["product_form"]
        categories = view_data["categories"]

        if not product_form.validate():
            flash("Tuotteen muokkaus epäonnistui", "error")
            return render("users/product_edit.html",
                          categories = categories,
                          product_form = product_form,
                          product = product)

        if not product.update(product_form):
            flash("Tuotteen muokkaus epäonnistui", "error")
            return render("users/product_edit.html",
                          categories = categories,
                          product_form = product_form,
                          product = product)

        if not categories_products.add_product_categories(product.id, product_form.categories.data):
            flash("Tuote muokkaus onnistui. Kategorioiden lisäyksessä tapahtui virhe", "error")
            return render("users/product_form.html",
                          categories = categories,
                          product_form = product_form)

        flash("Tuote päivitetty", "success")
        return redirect(url_for("user_product_list", username = username))
예제 #2
0
    def change_password(username):
        change_password_form = ChangePasswordForm(request.form)

        if not change_password_form.validate():
            return render("users/main.html",
                          user=User.query.filter_by(username=username).first(),
                          user_form=UserForm(),
                          change_password_form=change_password_form,
                          password_form_open=True)

        user = User.find_by_username_password(
            username, change_password_form.old_password.data)

        if not user:
            flash("Väärä vanha salasana", "error")
            return render("users/main.html",
                          user=User.query.filter_by(username=username).first(),
                          user_form=UserForm(),
                          change_password_form=change_password_form,
                          password_form_open=True)

        if not user.update_password(change_password_form.new_password.data):
            flash("Salasanan vaihto epäonnistui", "error")
            return render("users/main.html",
                          user=user,
                          user_form=UserForm(),
                          change_password_form=change_password_form)

        flash("Salasanan vaihto onnistui", "success")
        return render("users/main.html",
                      user=user,
                      user_form=UserForm(),
                      change_password_form=ChangePasswordForm())
예제 #3
0
    def create():
        product_form = ProductForm(request.form)
        categories_products = CategoryProduct()

        view_data = ProductController.__get_view_data()
        product_form = view_data["product_form"]
        categories_list = view_data["categories"]

        if not product_form.validate():
            flash("Tuotteen julkaisu epäonnistui", "error")
            return render("users/product_form.html",
                          product_form = product_form,
                          categories = categories_list)

        product = Product(
            product_form.name.data,
            product_form.price.data,
            product_form.quantity.data,
            current_user.id
        )

        if not product.save("product create:"):
            flash("Tuotteen julkaisu epäonnistui", "error")
            return render("users/product_form.html",
                          product_form = product_form,
                          categories = categories_list)

        if not categories_products.add_product_categories(product.id, product_form.categories.data):
            flash("Tuote julkaistu. Kategorioiden lisäyksessä tapahtui virhe", "error")
            return render("users/product_form.html",
                          product_form = product_form,
                          categories = categories_list)

        flash("Tuote julkaistu", "success")
        return redirect(url_for("product_list"))
예제 #4
0
    def purchase(id):
        product = Product.query.get(id)
        user = User.query.filter_by(username = current_user.username).first()

        if not user.purchase(product):
            flash("Tuotteen osto epäonnistui, onko sinulla varmasti tarpeeksi rahaa?", "error")
            return render("products/details.html", comment_form = CommentForm(), product = product)

        flash("Tuotteen osto onnistui", "success")
        return render("products/details.html", comment_form = CommentForm(), product = product)
예제 #5
0
    def edit(product_id):
        view_data = ProductController.__get_view_data()
        product = Product.query.get(product_id)
        selected_categories = list(map(lambda cat: str(cat.id), product.categories))

        return render("users/product_edit.html",
                       product_form = view_data["product_form"],
                       product = product,
                       selected_categories = selected_categories,
                       categories = view_data["categories"])
예제 #6
0
    def delete(id):
        user = User.query.filter_by(id=id).first()
        if user == None or not user.delete("user delete"):
            flash("Käyttäjätilin poistamaminen epäonnistui", "error")
            return render("users/main.html",
                          user=user,
                          user_form=UserForm(),
                          change_password_form=ChangePasswordForm())

        flash("Käyttäjätili poistettu", "success")
        return redirect(url_for("index"))
예제 #7
0
    def add_balance(username):
        balance_form = BalanceForm(request.form)

        if not balance_form.validate():
            return render("users/balance_form.html",
                          balance_form=BalanceForm())

        user = User.query.filter_by(username=username).first()

        if not user.set_balance(balance_form.balance.data):
            flash("Saldon päivittäminen epäonnistui", "error")
            return render("users/balance_form.html",
                          balance_form=BalanceForm())

        flash(
            "Saldon pävittäminen onnistui, saldon määrä on " +
            str(user.balance), "success")
        return render("users/main.html",
                      user=user,
                      user_form=UserForm(),
                      change_password_form=ChangePasswordForm())
예제 #8
0
    def update(username):
        user_form = UserForm(request.form)
        user = User.query.filter_by(username=username).first()

        if not user_form.validate():
            return render("users/main.html",
                          user=user,
                          user_form=user_form,
                          change_password_form=ChangePasswordForm())

        if not user.update(user_form):
            flash("Käyttäjätilin päivittäminen epäonnistu", "error")
            return render("users/main.html",
                          user=user,
                          user_form=user_form,
                          change_password_form=ChangePasswordForm())

        flash("Tilin tiedot päivitetty", "success")
        return render("users/main.html",
                      user=user,
                      user_form=UserForm(),
                      change_password_form=ChangePasswordForm())
예제 #9
0
    def create(product_id):
        comment_form = CommentForm(request.form)

        if not comment_form.validate():
            return render("products/details.html",
                          comment_open=True,
                          comment_form=comment_form,
                          product=Product.query.get(product_id))

        comment = Comment(comment_form.comment.data, product_id,
                          current_user.id)

        if not comment.save("comment save"):
            flash("Kommentin lähettäminen epäonnistui", "error")
            return render("products/details.html",
                          comment_open=True,
                          comment_form=comment_form,
                          product=Product.query.get(product_id))

        # return back with empty form
        flash("Kommentti lisätty", "success")
        return render("products/details.html",
                      comment_form=CommentForm(),
                      product=Product.query.get(product_id))
예제 #10
0
    def get():
        search_form = SearchForm(request.args)
        categories = Category.query.all()
        search_form.categories.choices = list(
            map(lambda cat: (cat.id, cat.name), categories))
        search_form.categories.choices.append((-1, "Kategoriton"))

        return render(
            "search/main.html",
            search_form=search_form,
            products=Product.find_by_criteria(
                search_form.name.data,
                list(map(lambda id: int(id),
                         search_form.categories.data)), search_form.price.data,
                search_form.minimum.data, search_form.date_start.data,
                search_form.date_end.data, search_form.seller.data))
예제 #11
0
 def balance_form():
     return render("users/balance_form.html", balance_form=BalanceForm())
예제 #12
0
 def current_user_list():
     return render("users/product_list.html", products = Product.query.filter_by(user_id = current_user.id).all())
예제 #13
0
 def form():
     view_data = ProductController.__get_view_data()
     return render("users/product_form.html", product_form = view_data["product_form"], categories = view_data["categories"])
예제 #14
0
 def get(id):
     return render("products/details.html", comment_form = CommentForm(), product = Product.query.get(id))
예제 #15
0
 def index(username):
     return render("users/main.html",
                   user=User.query.filter_by(username=username).first(),
                   user_form=UserForm(),
                   change_password_form=ChangePasswordForm())
예제 #16
0
def index():
    return render("index.html")
예제 #17
0
 def index():
     return render("products/main.html", products = Product.query.order_by(desc(Product.created_at)).filter(Product.quantity > 0).all())