コード例 #1
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def account_settings():
    account_settings_form = AccountSettingsForm()
    password_change_form = ChangePasswordForm()
    user = StaffAccounts.read_user(id=current_user.id)
    current_tab = request.args.get("tab", "personal")
    if request.method == "GET":
        account_settings_form = AccountSettingsForm(obj=current_user)

    if account_settings_form.validate_on_submit():
        user.update_employee_details(
            email=account_settings_form.email.data.strip(),
            name=account_settings_form.name.data.strip(),
            contact=account_settings_form.contact.data.strip(),
            address=account_settings_form.address.data.strip())
        flash("Updated your details successfully", "success")
        return redirect(url_for(".account_settings"))

    elif password_change_form.validate_on_submit():
        if user.verify_password(password_change_form.current_password.data):
            user.hash_password(password_change_form.new_password.data)
            session.commit()
            flash(
                "Password changed successfully, please try to log in with new password",
                "success")
            return redirect(
                url_for(".account_settings", current_tab="password"))
        else:
            flash("Current password is incorrect", "danger")
            return redirect(
                url_for(".account_settings", current_tab="password"))

    context = dict(account_settings_form=account_settings_form,
                   password_change_form=password_change_form,
                   current_tab=current_tab)
    return render_template("customer_care_account_settings.html", **context)
コード例 #2
0
    def post(self):
        args = forgot_password_args.parse_args()
        user = Customer.read_customer(email=args["email"])
        if user != None:
            token_gen = TokenGenerator(user=user)
            token = token_gen.generate_password_reset_token()
            mail_ = reset_email
            mail_.context = dict(user_name=user.name, token=token)
            mail_.recipients = [user.email]
            mail_.text = "To reset your password visit the following link " + url_for(
                'set_new_password', token=token, _external=True
            ) + "\n if you did not request for this email then ignore."
            mail_.send()

            return jsonify(
                status="success",
                message="Check your email inbox for password reset link.",
                data=0)

        else:
            email = args["email"]
            return jsonify(
                status="error",
                message="This email: {} is not registered with clickeat".
                format(email),
                data=0)
コード例 #3
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def customer_care_orders():
    page = int(request.args.get("page", 1))
    orders = Order.read_all_orders()
    pagination = Paginate(orders, page, 8)
    next_url = url_for(
        ".customer_care_orders",
        page=pagination.next_page) if pagination.has_next else None
    prev_url = url_for(
        ".customer_care_orders",
        page=pagination.previous_page) if pagination.has_previous else None
    return render_template('orders/orders.html',
                           orders=orders,
                           next_url=next_url,
                           prev_url=prev_url,
                           pagination=pagination,
                           current_page=page)
コード例 #4
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def approve_product(product_id):
    suspend_form = SuspendProductForm()
    if suspend_form.validate_on_submit():
        try:
            product = Products.read_product(product_id)
            product.approved = True
            session.commit()
            flash("Product approved successfully", "success")
            return redirect(
                url_for("customer_care.rest_product_detail",
                        product_id=product_id))
        except Exception as e:
            session.rollback()
            print("Error while retriving data: ", e)
            flash("Internal server error failed to update product.", "danger")

    return redirect(
        url_for("customer_care.rest_product_detail", product_id=product_id))
コード例 #5
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def customer_care_login():
    form = LoginForm()

    if form.validate_on_submit():
        user = StaffAccounts.read_user(username=form.username.data)

        if not user:
            user = StaffAccounts.read_user(email=form.username.data)

        if user and user.verify_password(form.password.data):
            login_user(user)
            _session["account_type"] = "Employee"
            return redirect(url_for(".dashboard"))
        else:
            flash("User name or Password is incorrect", "danger")
            return redirect(url_for(".customer_care_login"))

    return render_template("customer_care_login.html", form=form)
コード例 #6
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def deleteFromTopSelling(product_id):
    suspend_form = SuspendProductForm()
    if suspend_form.validate_on_submit():
        try:
            if (TopSellingProducts.delete_pdt_from_top_selling(product_id)):
                flash("Product was removed successfully!!", "success")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
            else:
                flash("Error while trying to delete product from top selling",
                      "danger")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
        except Exception as e:
            session.rollback()
            print("Error while retriving data: ", e)
            flash("Internal server error failed to update product.", "danger")
コード例 #7
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def addToTopSelling(product_id):
    suspend_form = SuspendProductForm()
    if suspend_form.validate_on_submit():
        try:
            if TopSellingProducts()(product_id=product_id):
                flash(
                    "Product added to top most selling products successfully!!",
                    "success")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
            else:
                flash("Product already added to Top most selling", "danger")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
        except Exception as e:
            session.rollback()
            print("Error while retriving data: ", e)
            flash("Internal server error failed to update product.", "danger")
コード例 #8
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def set_promotional_price(product_id):
    promotional_price_form = SetPromotionForm()
    if promotional_price_form.validate_on_submit():
        try:
            product = Products.read_product(product_id)
            product.promotional_price_set = True
            ProductDiscounts()(product_id=product_id,
                               price=promotional_price_form.price.data,
                               from_date=promotional_price_form.from_date.data,
                               to_date=promotional_price_form.to_date.data,
                               is_scheduled=True)
            flash("Product promotional price set successfully", "success")
            return redirect(
                url_for("customer_care.rest_product_detail",
                        product_id=product_id))
        except Exception as e:
            session.rollback()
            print("Error while retriving data: ", e)
            flash("Internal server error failed to update product.", "danger")

    return redirect(
        url_for("customer_care.rest_product_detail", product_id=product_id))
コード例 #9
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def remove_promotion_price(product_id):
    suspend_form = SuspendProductForm()
    if suspend_form.validate_on_submit():
        try:
            if ProductDiscounts.remove_promotion_price(product_id):
                flash("Product promotional price removed successfully",
                      "success")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
            else:
                flash("Product promotional price was not removed successfully",
                      "danger")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
        except Exception as e:
            session.rollback()
            print("Error while retriving data: ", e)
            flash("Internal server error failed to update product.", "danger")

    return redirect(
        url_for("customer_care.rest_product_detail", product_id=product_id))
コード例 #10
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def terminate_order(order_id):
    form = ReasonForm()
    order = Order.read_order(id=order_id)
    if order.is_terminated and order.termination_reason:
        flash("Order already terminated", "danger")
        return redirect(
            url_for(".customer_care_order_detail", order_id=order_id))

    if order.is_paid:
        flash(
            "Cannot terminate already paid order, items have to be returned and customer compensated",
            "danger")
        return redirect(
            url_for(".customer_care_order_detail", order_id=order_id))

    if form.validate_on_submit() and order:
        if order.customer_care_terminate_order(form.reason.data):
            flash("Order terminated successfully", "success")
        else:
            flash("Failed to terminate order", "danger")
    else:
        flash("Failed to terminate order", "danger")

    return redirect(url_for(".customer_care_order_detail", order_id=order_id))
コード例 #11
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def add_product():
    form = AddProductForm()
    brands = Brand.read_all_bandss_filter_by("brand_id", "name")
    if request.method == "GET":
        form.restaurant.choices = Resturant.read_all_restaurants_filter_by(
            "id", "business_name")
        form.brand.choices = brands
        form.sub_cat.choices = SubCategory.read_all_subcategories_filter_by(
            "sub_category_id", "name")
        form.price.data = 0
        form.buying_price.data = 0
        form.selling_price.data = 0
        form.served_with.data = "none"
        form.commission_fee.data = 0.0
        form.headsup.data = "clickEat"

    if form.validate_on_submit():
        try:
            product_picture = save_picture(form.product_picture.data, None,
                                           "static/product_images", 500, 500)
            price = form.price.data
            rest_id = form.restaurant.data
            brand_name = [
                brand for brand in brands if brand[0] == form.brand.data
            ][0][1]
            if (Products()(name=form.name.data,
                           product_picture=product_picture,
                           description=form.description.data,
                           price=form.price.data,
                           resturant_id=form.restaurant.data,
                           brand=brand_name,
                           sub_category_id=form.sub_cat.data,
                           buying_price=form.buying_price.data,
                           selling_price=form.selling_price.data,
                           served_with=form.served_with.data,
                           commission_fee=form.commission_fee.data,
                           headsup=form.headsup.data)):
                flash("Product added successfully", "success")
                return redirect(url_for("customer_care.add_product"))

        except Exception as e:
            print("Error while trying to save product: ", e)
            session.rollback()
            flash("Error while trying to save product", "danger")

    return render_template('restaurants/restaurant/product/add_product.html',
                           form=form)
コード例 #12
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def logout():
    logout_user()
    _session.pop("account_type")

    return redirect(url_for(".customer_care_login"))
コード例 #13
0
ファイル: routes.py プロジェクト: Byenkya/ClickEat-Code
def rest_product_detail(product_id):
    product = Products.read_product(product_id)
    top_selling_status = TopSellingProducts.read_top_most_selling_product(
        product_id)
    comments = Comments.product_comments(product_id)
    product_rating = Rate.read_product_rate(product_id)
    restuarant = Resturant.read_restaurant(id=product.resturant_id)
    form = ProductsVerificationForm()
    promotional_price_form = SetPromotionForm()
    suspend_form = SuspendProductForm()
    suspend_form.product_id.data = product_id

    if request.method == "GET":
        form = ProductsVerificationForm(obj=product)
        form.sub_category.choices = SubCategory.read_all_subcategories_filter_by(
            "sub_category_id",
            "name",
            category_id=product.sub_category.category_id)

    # form.category.choices = Category.read_all_categories_by_attr("category_id","name")

    if form.validate_on_submit():
        if form.product_picture.data:
            try:
                product_pic = save_picture(form.product_picture.data,
                                           product.product_picture,
                                           "static/product_images", 500, 500)
                # product.sub_category_id = form.sub_category.data
                product.name = form.name.data
                product.product_picture = product_pic
                product.price = form.price.data
                product.description = form.description.data
                product.product = form.price.data
                product.buying_price = form.buying_price.data
                product.selling_price = form.selling_price.data
                product.served_with = form.served_with.data
                product.commission_fee = form.commission_fee.data
                product.headsup = form.headsup.data
                product.free_delivery = form.free_delivery.data
                session.commit()
                flash("Product updated successfully", "success")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
            except Exception as e:
                print("Customer care updating product error:", e)
                session.rollback()
                flash("Internal server error failed to update product.",
                      "danger")
        else:
            try:
                # product.sub_category_id = form.sub_category.data
                product.name = form.name.data
                product.price = form.price.data
                product.description = form.description.data
                product.product = form.price.data
                product.buying_price = form.buying_price.data
                product.selling_price = form.selling_price.data
                product.served_with = form.served_with.data
                product.commission_fee = form.commission_fee.data
                product.headsup = form.headsup.data
                product.free_delivery = form.free_delivery.data
                session.commit()
                flash("Product updated successfully", "success")
            except Exception as e:
                print("Customer care updating product error:", e)
                session.rollback()
                flash("Internal server error failed to update product.",
                      "danger")
        return redirect(
            url_for("customer_care.rest_product_detail",
                    product_id=product_id))

    return render_template(
        'restaurants/restaurant/product/product_details.html',
        shop=restuarant,
        product=product,
        product_rating=product_rating,
        comments=comments,
        form=form,
        promo_form=promotional_price_form,
        suspend_form=suspend_form,
        top_selling_status=top_selling_status)