Example #1
0
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)
    def __call__(self, **kwargs):
        try:
            self.county = kwargs.get("county")
            self.sub_county = kwargs.get("sub_county")
            self.village = kwargs.get("village")
            self.other_details = kwargs.get("other_details")
            self.is_default = kwargs.get("is_default", self.is_default)
            self.customer_id = kwargs.get("customer_id")

            if self.is_default:
                self.query.filter_by(customer_id=self.customer_id).update(
                    {"is_default": False})

            if not self.query.filter_by(customer_id=self.customer_id).first():
                self.is_default = True

            session.add(self)
            session.commit()

            return True

        except Exception as e:
            print("Error whilst saving customer address: ", e)
            session.rollback()
            return None
Example #3
0
    def __call__(self, **kwargs):
        try:
            self.name = kwargs.get("name")
            self.product_picture = kwargs.get("product_picture")
            self.description = kwargs.get("description")
            self.price = kwargs.get("price")
            self.resturant_id = kwargs.get("resturant_id")
            brand_name = kwargs.get("brand")
            self.sub_category_id = kwargs.get("sub_category_id")
            brand_exists = brnd.Brand.read_brand_filter(
                brnd.Brand.name.like("%{}%".format(brand_name)))
            if brand_exists:
                self.brand = brand_exists
            else:
                brand = brnd.Brand(name=brand_name)
                self.brand = brand

            self.buying_price = kwargs.get("buying_price", 0)
            self.selling_price = kwargs.get("selling_price", 0)
            self.served_with = kwargs.get("served_with", 'none')
            self.commission_fee = kwargs.get("commission_fee", 0.0)
            self.headsup = kwargs.get("headsup", "clickEat")

            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error while adding product: ", e)
            session.rollback()
            return False
Example #4
0
def set_new_password(token):
    form = NewPasswordForm()
    if form.validate_on_submit():
        token_gen = TokenGenerator()
        token_gen.verify_password_token(token)
        user = token_gen.user
        if user != None:
            user.password = form.new_password.data
            session.commit()
            mail_ = general_email
            mail_.context = dict(
                user_name=user.name,
                text="Your password has been reset successfully.")
            mail_.title = "Password Reset"
            mail_.recipients = [user.email]
            mail_.send()
            flash(
                "Your new password has been reset. Please try to log in with the new password.",
                "success")
        else:
            flash(
                "Please request a new password reset. Either this link is invalid or expired.",
                "danger")
    context = dict(form=form, token=token)
    return render_template("new_password.html", **context)
Example #5
0
    def __call__(self, **kwargs):
        try:
            self.product_id = kwargs.get("product_id")
            self.customer_id = kwargs.get("customer_id")
            self.product_name = kwargs.get("product_name")
            self.product_image = kwargs.get("product_image")
            self.unit_price = kwargs.get("unit_price")
            self.quantity = kwargs.get("quantity")
            self.served_with = kwargs.get("served_with", "none")
            self.free_delivery = kwargs.get("free_delivery", False)
            self.restaurant = kwargs.get("restaurant", "clickEat")
            item_exists = self.query.filter_by(
                customer_id = self.customer_id,
                product_id = self.product_id,
                is_ordered = False
            ).first()
            if item_exists:
                item_exists.quantity += int(self.quantity)
                session.commit()
                # if item_exists.quantity > product.quantity:
                #     session.rollback()
                #     print("Product already exists on cart and quantity you are specifying is more than what is available.")
                #     return False
                # else:
                #     session.commit()
            else:
                session.add(self)
                session.commit()

            return True

        except Exception as e:
            print("Error While adding to Cart: ", e)
            session.rollback()
            return False
Example #6
0
    def __call__(self, **kwargs):
        try:
            self.product_id = kwargs.get("product_id")
            self.price = kwargs.get("price")
            self.from_date = kwargs.get("from_date")
            self.to_date = kwargs.get("to_date")
            self.is_scheduled = kwargs.get("is_scheduled")

            if self.is_scheduled:
                product_discount = self.read_product_discount(self.product_id)

                if product_discount:
                    kwargs["products_discount"] = product_discount
                    return self.update_promotional_price(**kwargs)
                else:
                    product = pdts.Products.read_product(self.product_id)
                    if product and product.price > self.price:
                        product.promotional_price_set = True
                        session.add(self)
                        session.commit()
                    else:
                        return False

                    return True
        except Exception as e:
            print("Adding product discount error: ", e)
            session.rollback()
            return False
Example #7
0
    def __call__(self, **kwargs):
        try:
            self.courier_name = kwargs.get("courier_name")
            self.driver_license_number = kwargs.get("driver_license_number")
            self.contact = kwargs.get("contact")
            self.second_contact = kwargs.get("second_contact")
            self.email = kwargs.get("email")
            self.address = kwargs.get("address")
            self.district = kwargs.get("district")
            self.vehicle_type = kwargs.get("vehicle_type")
            self.vehicle_license_plate_number = kwargs.get(
                "vehicle_license_plate_number")
            self.courier_pic = kwargs.get("courier_pic")
            self.local_council_1_letter = kwargs.get("local_council_1_letter")
            self.agreement_letter = kwargs.get("agreement_letter")
            self.national_id_number = kwargs.get("national_id_number")

            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error whilst adding courier: ", e)
            session.rollback()
            return False
Example #8
0
def signup():
    next_ = request.args.get("next")
    signup_form = SignupForm(next_=next_)
    if signup_form.validate_on_submit():
        data = signup_form.data
        name = data["name"]
        email = data["email"]
        telephone_code = data["telephone_code"]
        telephone = data["telephone"]
        password = data["password"]
        customer = Customer(name=name,
                            email=email,
                            contact=join_telephone(telephone_code, telephone),
                            password=password)
        session.add(customer)
        session.commit()
        if customer:
            login_user(customer, duration=timedelta(1))
            flash("Your account has been created.", "success")
        else:
            flash("There was an error creating your account.", "danger")
        if data['next_']:
            return redirect(data['next_'])
        return redirect(url_for('index_bp.index'))
    login_form = LoginForm(next_=next_)
    return render_template("signin_signup/signin-signup.html",
                           show_signup=True,
                           signup_form=signup_form,
                           login_form=login_form)
Example #9
0
    def customer_care_terminate_order(self, reason):
        try:
            self.is_terminated = True
            self.termination_reason = reason
            cash_on_delivery = pym.CashOnDelivery.read_cash_on_delivery(
                payment_id=self.payment[0].payment_id)

            if cash_on_delivery:
                cash_on_delivery.status = "cancelled"

            if self.customer.email:
                mail_ = order_cancelled_email
                mail_.recipients = [self.customer.email]
                mail_.text = "We have cancelled the following order:{order}, because of the following reason: \n{reason}".format(
                    order=self.order_ref_simple_version, reason=reason)
                mail_.send()
                session.commit()
                return True

            else:
                session.commit()
                return True
        except Exception as e:
            session.rollback()
            print("Terminating order error: ", e)
            return False
Example #10
0
 def delete_pdt_from_top_selling(cls, product_id):
     try:
         cls.query.filter_by(product_id=product_id).delete()
         session.commit()
         return True
     except Exception as e:
         print("Error while deleting product from top selling product", e)
         session.rollback()
         return False
 def delete_customer_address(cls, id):
     try:
         session.query(cls).filter_by(id=id).delete()
         session.commit()
         return True
     except Exception as e:
         print("Error: >>>>>>>>>>>>>", e)
         session.rollback()
         return False
Example #12
0
 def change_password(self, old_password, new_password):
     if(self.verify_password(old_password)):
         new_password = pwd_context.hash(new_password)
         self._password = new_password
         session.commit()
         return True
     else:
         session.rollback()
         return False
Example #13
0
 def update_employee_details(self, **kwargs):
     try:
         self.email = kwargs.get("email", self.email)
         self.name = kwargs.get("name", self.name)
         self.contact = kwargs.get("contact", self.contact)
         self.address = kwargs.get("address", self.address)
         session.commit()
     except Exception as e:
         session.rollback()
         raise Exception(f"Updating user error: {e}")
Example #14
0
    def __call__(self, name):
        try:
            self.name = name
            session.add(self)
            session.commit()

        except Exception as e:
            print("Adding brand error: ", e)
            session.rollback()
            raise
 def delete_image(cls, id):
     try:
         image = cls.query.filter_by(image_id=id).first()
         if image:
             session.query(cls).filter_by(image_id=id).delete()
             session.commit()
             return True
         else:
             return False
     except:
         session.rollback()
Example #16
0
    def __call__(self, name):
        try:
            self.name = name
            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Adding Category error: ", e)
            session.rollback()
            return False
Example #17
0
    def delete_cart_item(cls, id):
        try:
            product = cls.query.filter_by(product_id=id).first()
            cls.query.filter_by(product_id=id).delete()
            session.commit()
            return cls.read_customer_cart_items(product.customer_id)

        except Exception as e:
            print("Error whilst deleting cart item!!.", e)
            session.rollback()
            return False
Example #18
0
    def __call__(self, **kwargs):
        try:
            self.type_name = kwargs.get("type_name")

            session.add(self)
            session.commit()
            return self

        except Exception as e:
            print("Error whilst adding account_type: ", e)
            session.rollback()
            return False
Example #19
0
    def __call__(self, **kwargs):
        try:
            self.order_ref = kwargs.get("order_ref")
            self.customer_id = kwargs.get("customer_id")
            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error whilst adding order record: ", e)
            session.rollback()
            return False
Example #20
0
    def __call__(self, **kwargs):
        try:
            self.quantity = kwargs.get("quantity")
            self.product_id = kwargs.get("product_id")
            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error whilst adding tracking product detail: ", e)
            session.rollback()
            return False
Example #21
0
    def __call__(self, **kwargs):
        try:
            self.payment_method_id = kwargs.get("payment_method_id")
            self.order_id = kwargs.get("order_id")

            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error whilst adding payment record: ", e)
            session.rollback()
            return False
Example #22
0
    def update_customer(self, **kwargs):
        try:
            self.name = kwargs.get("name", self.name)
            self.email = kwargs.get("email", self.email)
            self.contact = kwargs.get("contact", self.contact)
            self.second_contact = kwargs.get("second_contact", self.second_contact)
            session.commit()
            return True

        except Exception as e:
            print("Update customer Error:", e)
            session.rollback()
            return False 
Example #23
0
    def __call__(self, **kwargs):
        try:
            self.comment = kwargs.get("comment")
            self.customer_id = kwargs.get("customer_id")
            self.product_id = kwargs.get("product_id")
            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error whilst adding comment: ", e)
            session.rollback()
            return False
Example #24
0
    def __call__(self, **kwargs):
        try:
            self.method = kwargs.get("method")
            self.availability_period = kwargs.get("availability_period")

            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error whilst adding delivery method: ", e)
            session.rollback()
            return False
 def update_customer_address(cls, **kwargs):
     try:
         address = cls.query.filter_by(id=kwargs.get("address_id")).first()
         address.county = kwargs.get("county")
         address.sub_county = kwargs.get("sub_county")
         address.village = kwargs.get("village")
         address.other_details = kwargs.get("other_details")
         session.commit()
         return True
     except Exception as e:
         print("Error: >>>>>>>>>>>>>>>>", e)
         session.rollback()
         return False
Example #26
0
    def __call__(self, **kwargs):
        try:
            self.payment_id = kwargs.get("payment_id")
            self.transaction_ref = kwargs.get("transaction_ref")
            self.status = "pending"

            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Error whilst recording transaction: ", e)
            session.rollback()
            return False
Example #27
0
    def remove_promotion_price(cls, product_id):
        try:
            product = pdts.Products.read_product(product_id)
            if product and cls.query.filter_by(product_id=product_id).delete():
                product.promotional_price_set = False
                session.commit()
                return True
            else:
                return False

        except Exception as e:
            print("Removing product promotion price error: ", e)
            session.rollback()
            return False
Example #28
0
    def update_cart_item(cls, **kwargs):
        item = cls.query.filter_by(
                customer_id = kwargs.get("customer_id"),
                product_id = kwargs.get("product_id"),
                is_ordered = False
            ).first()

        if item:
            item.quantity = kwargs.get("quantity")
            session.commit()

            return cls.read_customer_cart_items(kwargs.get("customer_id"))

        else:
            return False
Example #29
0
 def __call__(self, **kwargs):
     try:
         product = self.query.filter_by(
             product_id=kwargs.get("product_id")).first()
         if product:
             return False
         else:
             self.product_id = kwargs.get("product_id")
             session.add(self)
             session.commit()
             return True
     except Exception as e:
         print("Error while adding product to top most selling product: ",
               e)
         session.rollback()
         return False
Example #30
0
    def __call__(self, **kwargs):
        try:
            self.district_name = kwargs.get("county_name")
            self.parish_name = kwargs.get("parish_name", "Arua city")
            self.sub_county_name = kwargs.get("sub_county_name")
            self.village = kwargs.get("village")
            self.fee = kwargs.get("fee")

            session.add(self)
            session.commit()
            return True

        except Exception as e:
            print("Adding Place fee error: ", e)
            session.rollback()
            return False