예제 #1
0
def upload_shopify():
    user = User.find_by_email(session.get('email'))
    if request.method == 'POST':
        file = request.files['file']
        stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
        csv_input = csv.DictReader(stream)
        for row in csv_input:
            shop_order = Shopifyorder(
                row['Name'], row['Email'], row['Financial Status'],
                row['Paid at'], row['Fulfillment Status'], row['Fulfilled at'],
                row['Accepts Marketing'], row['Currency'], row['Subtotal'],
                row['Shipping'], row['Taxes'], row['Total'],
                row['Discount Code'], row['Discount Amount'],
                row['Shipping Method'], row['Created at'],
                row['Lineitem quantity'], row['Lineitem name'],
                row['Lineitem price'], row['Lineitem compare at price'],
                row['Lineitem sku'], row['Lineitem requires shipping'],
                row['Lineitem taxable'], row['Lineitem fulfillment status'],
                row['Shipping Company'], row['Notes'], row['Note Attributes'],
                row['Cancelled at'], row['Payment Method'],
                row['Payment Reference'], row['Refunded Amount'],
                row['Vendor'], row['Id'], row['Tags'],
                row['Lineitem discount'])
            shop_order.save_to_mongo()
    Shopifyorder.fill_missing_info()

    return render_template('files/files_index.html', user=user)
예제 #2
0
def expense():
    error_msg = None
    if not Expense.check_user_access(session.get('email'), 'admin'):
        # this is for the access level testing. move it to decorator
        return render_template('users/login.html')

    if request.method == 'POST':
        date = datetime.strptime(request.form['date'], '%Y-%m-%d')
        category = request.form['category']
        item = request.form['item']
        remarks = request.form['remarks']
        cost = request.form['amount']
        exp_obj = Expense(date, category, item, remarks, cost)
        exp_obj.save_to_mongo()

    expenses = Expense.get_all_expense()  #
    sum_dict = Expense.get_sum_dict()

    user = User.find_by_email(session.get('email'))

    return render_template('expense/expense.html',
                           expenses=expenses,
                           error_msg=error_msg,
                           user=user,
                           sum_dict=sum_dict)
예제 #3
0
def upload_fedex():
    user = User.find_by_email(session.get('email'))
    if request.method == 'POST':
        file = request.files['file']
        stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
        csv_input = csv.DictReader(stream)
        # for i in csv_input:
        #     print(i)

        for row in csv_input:
            # print(row['Shipper Reference 1'])
            shopify = Shopifyorder.get_by_name('{}{}'.format(
                '#', row['Shipper Reference 1']))
            # print(shopify.name)
            if shopify:
                # for i in row.keys():
                #     print(i)
                # print('\n\n\n\n\n')
                shopify.shipping_company = 'fedex'
                shopify.shipping_cost = float(row['Air Waybill Total Amount'])
                print(row['Air Waybill Charge Label'])
                # shopify.payment_method = row['product_type']
                # print(shopify.payment_method)
                shopify.save_to_mongo()

    return render_template('files/files_index.html', user=user)
예제 #4
0
def order():
    if not Order.check_user_access(session.get('email'), 'admin'):
        # this is for the access level testing. move it to decorator
        return render_template('users/login.html')
    error_msg = None

    if request.method == 'POST':
        ord_date = request.form['ord_date']
        name = request.form['name']
        descr = request.form['descr']
        # size = request.form['size']
        vendor = request.form['vendor']
        # qty = request.form['qty']
        # u_price = request.form['u_price']
        gst = request.form['gst']
        ship = request.form['ship']
        total = request.form['total']
        rcv_date = request.form['rcv_date']
        ord_obj = Order(ord_date=ord_date,
                        name=name,
                        descr=descr,
                        vendor=vendor,
                        gst=gst,
                        ship=ship,
                        total=total,
                        rcv_date=rcv_date)
        ord_obj.save_to_mongo()

    orders = Order.get_all_order()
    user = User.find_by_email(session.get('email'))

    return render_template('order/order.html',
                           orders=orders,
                           error_msg=None,
                           user=user)
예제 #5
0
def order_edit(_id):
    user = User.find_by_email(session.get('email'))
    if request.method == 'GET':
        order = Order.get_ord_by_id(_id)
        return render_template('order/edit.html',
                               order=order,
                               user=user,
                               items=order.items)
    else:
        ord_obj = Order.get_ord_by_id(_id)
        ord_date = request.form['ord_date']
        name = request.form['name']
        descr = request.form['descr']
        vendor = request.form['vendor']
        gst = request.form['gst']
        ship = request.form['ship']
        total = request.form['total']
        rcv_date = request.form['rcv_date']
        ord_obj.ord_date = ord_date
        ord_obj.name = name
        ord_obj.descr = descr
        ord_obj.vendor = vendor
        ord_obj.gst = gst
        ord_obj.ship = ship
        ord_obj.total = total
        ord_obj.rcv_date = rcv_date
        ord_obj.save_to_mongo()
    return redirect(url_for('order.order'))
예제 #6
0
파일: views.py 프로젝트: zanalkamar/alloons
def investor():
    error_msg = None
    if not Investor.check_user_access(session.get('email'), 'admin'):
        # this is for the access level testing. move it to decorator
        return render_template('users/login.html')

    if request.method == 'POST':
        name = request.form['name']
        mobile = request.form['mobile']
        email = request.form['email']
        join_date = request.form['date']
        # name, join_date = None, contacts = None, sku_dict = None, _id = None
        inv_obj = Investor(name=name,
                           join_date=join_date,
                           contacts={
                               'mobile': mobile,
                               'email': email
                           })
        inv_obj.save_to_mongo()

    investors = Investor.get_all()
    user = User.find_by_email(session.get('email'))
    return render_template('investor/investor.html',
                           investors=investors,
                           error_msg=error_msg,
                           user=user)
예제 #7
0
def login_users():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        try:
            if User.login_user(email, password):
                session['email'] = email
                # return redirect(url_for("device.device"))
                user = User.find_by_email(email)
                return render_template('home.html', user=user)
            else:
                return render_template('users/login.html')
        except Exception as e:
            # change this to proper Error management
            print(e)
            return render_template('users/login.html')
    return render_template('users/login.html')
예제 #8
0
def edit_user(_id):
    # if not User.check_access_email(session.get('email'), 'super_user'):
    #     return render_template('users/login.html')
    user = User.find_by_email(session.get('email'))
    if request.method == 'GET':
        user_obj = User.find_by_id(_id)
        return render_template('users/edit.html', user_obj=user_obj, user=user)
    else:
        name = request.form['name']
        email = request.form['email']
        password = request.form['password']
        access = request.form['access']
        user_obj = User.find_by_id(_id)
        user_obj.name = name
        user_obj.email = email
        user_obj.password = password if password else user_obj.password
        user_obj.access = access
        user_obj.save_to_mongo()
        return redirect(url_for('users.users'))
예제 #9
0
def add_user():
    # if not User.check_access_email(session.get('email'), 'super_user'):
    #     return render_template('users/login.html')
    error_msg = None
    if request.method == 'POST':
        email = request.form['email']
        name = request.form['name']
        password = request.form['password']
        access = request.form['access']
        try:
            User.register_user(email, password, name, access)
        except Exception as e:
            # print(e)
            error_msg = e

    all_users = User.get_all_users()
    return render_template('users/users.html',
                           users=all_users,
                           error_msg=error_msg)
예제 #10
0
def users():
    # if not User.check_access_email(session.get('email'), 'super_user'):
    #     return render_template('users/login.html')
    # user = User.find_by_email(session.get('email'))
    user = None
    all_user_obj = User.get_all_users()
    # print('User is {}'.format(user.name))
    return render_template('users/users.html',
                           user_objs=all_user_obj,
                           error_msg=None,
                           user=user)
예제 #11
0
def login():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        try:
            if User.is_login_valid(email, password):
                session['email'] = email
                return redirect(url_for("users.home"))
        except UserErrors.UserError as e:
            return render_template("login.html", error=e.message)
    return render_template(
        "login.html")  # Send the user an error if their login was invalid
예제 #12
0
def register_user():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        try:
            if User.register_user(email, password):
                session['email'] = email
                return redirect(url_for(".user_alerts"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("users/register.html"
                           )  # Send the user an error if the login was invalid
예제 #13
0
def register():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        first_name = request.form['first_name']
        last_name = request.form['last_name']

        try:
            if User.register_user(email, password, first_name, last_name,
                                  user_name):
                session['email'] = email
                return redirect(url_for("users.home"))
        except UserErrors.UserError as e:
            return e.message

    return render_template("register.html")
예제 #14
0
def upload_ecom():
    user = User.find_by_email(session.get('email'))
    if request.method == 'POST':
        file = request.files['file']
        stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
        csv_input = csv.DictReader(stream)
        for row in csv_input:
            shopify = Shopifyorder.get_by_name('{}{}'.format(
                '#', row['order_number']))
            if shopify:
                shopify.shipping_company = 'ecom'
                shopify.shipping_cost = float(row['Total'])
                # shopify.payment_method = row['product_type']
                shopify.save_to_mongo()

    return render_template('files/files_index.html', user=user)
예제 #15
0
def edit_profile():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        user_name = request.form['user_name']

        try:
            if User.register_user(email, password, title, first_name,
                                  last_name, department):
                session['email'] = email
                return redirect(url_for("users.home"))
        except UserErrors.UserError as e:
            return e.message

    return render_template(
        "register.html")  # Send the user an error if their login was invalid
예제 #16
0
파일: views.py 프로젝트: zanalkamar/alloons
def investor_edit(_id):
    user = User.find_by_email(session.get('email'))
    if request.method == 'GET':
        investor = Investor.get_investor_by_id(_id)
        return render_template('investor/edit.html',
                               investor=investor,
                               user=user)
    else:
        sku_amount = request.form['sku_amount']
        sku = request.form['sku']
        sku_descr = request.form['sku_descr']
        # sku description should be auto populated for him
        sku_amount = request.form['sku_amount']
        sku_num = request.form['sku_num']
        # this num should be changed to quantity
        sku_date = request.form['inv_date']
        inv = Investor.get_investor_by_id(_id)
        # inv.sku_dict[sku] = dict(amount=int(sku_amount), number=int(sku_num))

        inv.save_to_mongo()
    return redirect(url_for('investor.investor'))
예제 #17
0
def expense_edit(_id):
    user = User.find_by_email(session.get('email'))
    if request.method == 'GET':
        expense = Expense.get_exp_by_id(_id)
        return render_template('expense/edit.html', expense=expense, user=user)
    else:
        # date = request.form['date']
        date = datetime.strptime(request.form['date'], '%Y-%m-%d')
        # category = request.form['category']
        item = request.form['item']
        remarks = request.form['remarks']
        # cost = request.form['amount']
        amount = request.form['amount']
        exp = Expense.get_exp_by_id(_id)
        exp.date = date
        # exp.category = category
        exp.item = item
        exp.remarks = remarks
        exp.amount = amount
        exp.save_to_mongo()
    return redirect(url_for('expense.expense'))
예제 #18
0
파일: views.py 프로젝트: zanalkamar/alloons
def shopify():
    error_msg = None
    if not Shopifyorder.check_user_access(session.get('email'), 'admin'):
        # this is for the access level testing. move it to decorator
        return render_template('users/login.html')

    # if request.method == 'POST':
    #     date = request.form['date']
    #     category = request.form['category']
    #     item = request.form['item']
    #     remarks = request.form['remarks']
    #     cost = request.form['amount']
    #     exp_obj = Shopifyorder(date, category, item, remarks, cost)
    #     exp_obj.save_to_mongo()

    shopify_orders = Shopifyorder.get_all_shopify()  #
    user = User.find_by_email(session.get('email'))

    return render_template('shopify/shopify.html',
                           shopify=shopify_orders,
                           error_msg=error_msg,
                           user=user)
예제 #19
0
def user():
    return dict(user=User.get_by_email(session['email']))
예제 #20
0
def del_user(_id):
    # if not User.check_access_email(session.get('email'), 'super_user'):
    #     return render_template('users/login.html')
    User.del_user_by_id(_id)
    return redirect(url_for('users.users'))
예제 #21
0
def upload_file():
    user = User.find_by_email(session.get('email'))
    if request.method == 'POST':
        file = request.files['file']
        Files.create_and_save_gridfs(file)
    return render_template('files/files_index.html', user=user)
예제 #22
0
def files_index():
    user = User.find_by_email(session.get('email'))
    files = Files.get_all_files()
    return render_template('files/files_index.html', files=files, user=user)
예제 #23
0
 def check_user_access(email, access_level):
     if email:
         return User.check_access_email(email, access_level)
예제 #24
0
def user_home():
    email = session.get('email')
    if email:
        return render_template('home.html', user=User.find_by_email(email))
    else:
        return render_template('home.html', user=None)
예제 #25
0
def view_profile():
    return render_template('', user=User.get_by_email(
        session['email']))  #front end code for the profile page
예제 #26
0
def view(user_id):
    return render_template('users/profile.html', user=User.get_by_id(user_id))
예제 #27
0
def user_alerts():
    user = User.find_by_email(session['email'])
    alerts = user.get_alerts()
    return render_template('users/alerts.html', alerts=alerts)
예제 #28
0
def home():
    if session.get('email'):
        return render_template('home.html',
                               user=User.get_by_email(session['email']))
    return render_template('home.html')