コード例 #1
0
ファイル: admin.py プロジェクト: Yoronex/KVLSTikker
def admin_drinks():
    check_if_local_machine()
    form = DrinkForm()
    filters = ProductFilterForm()

    query = Product.query
    query = apply_filters(query)
    products = query.order_by(Product.order.asc()).all()

    if request.method == "POST":
        check_if_not_view_only()
        if form.validate_on_submit():
            alert = (dbhandler.adddrink(
                form.name.data, float(form.price.data), form.category.data,
                int(form.pos.data) + 1, form.image.data, form.hoverimage.data,
                form.recipe.data, form.inventory_warning.data,
                float(form.alcohol.data), form.volume.data, form.unit.data))
            flash(alert[0], alert[1])

            socket.update_stats()

            return redirect(url_for('admin_drinks'))
        else:
            flash(form.errors, "danger")
    flash_form_errors(form.errors)
    return render_template('admin/mandrinks.html',
                           title="Productbeheer",
                           h1="Productbeheer",
                           Product=Product,
                           products=products,
                           form=form,
                           filters=filters), 200
コード例 #2
0
ファイル: admin.py プロジェクト: Yoronex/KVLSTikker
def admin_users():
    check_if_local_machine()

    form = UserRegistrationForm()
    filters = UsersFilterForm()

    query = User.query
    query = apply_filters(query)
    users = query.all()

    if form.validate_on_submit():
        check_if_not_view_only()
        alert = (dbhandler.adduser(form.name.data, form.email.data,
                                   form.group.data, form.profitgroup.data,
                                   form.birthday.data))
        flash(alert[0], alert[1])

        socket.update_stats()

        return redirect(url_for('admin_users'))
    flash_form_errors(form.errors)
    return render_template("admin/manusers.html",
                           title="Gebruikersbeheer",
                           h1="Gebruikersbeheer",
                           users=users,
                           Usergroup=Usergroup,
                           form=form,
                           filters=filters), 200
コード例 #3
0
def purchase(cart, product_id):
    # Parse the raw cart string into something readable
    parsed_cart = parse_cart_string(cart, product_id)
    # Get the product object
    product = Product.query.get(product_id)
    # If this total order is a round...
    if parsed_cart['round']:
        # Create the purchases for everyone to make them count for the stats (with a price of 0)
        create_purchases(parsed_cart['orders'], product, False, 0)
        # Create an order for the paying user
        order = {
            'user_id': parsed_cart['round_giver'],
            'amount': parsed_cart['total_bought']
        }
        # Let the paying user pay for everything
        success_messages = create_purchases([order], product, True,
                                            product.price)
    else:
        # Create purchases for every order
        success_messages = create_purchases(parsed_cart['orders'], product,
                                            False, product.price)

    # Create the final alert for both Tikker and Tikker BigScreen
    create_and_send_final_flash(success_messages)
    # Update the stats on BigScreen
    socket.update_stats()

    # If there are shared orders left...
    if parsed_cart['shared']:
        # Return this order
        return {'shared': True, 'shared_amount': parsed_cart['shared_amount']}
    else:
        return {'shared': False}
コード例 #4
0
def purchase_from_orders(orders, product_id, r=False):
    # Get the product object
    product = Product.query.get(product_id)
    # Because we only have orders and not a parsed cart, we have to calculate the total bought
    total_bought = sum(i['amount'] for i in orders)
    # If borrel mode is enabled for this product...
    if dbhandler.borrel_mode_enabled and product_id in dbhandler.borrel_mode_drinks:
        # Create the purchases for everyone to make them count for the stats (with a price of 0)
        create_purchases(orders, product, r, 0)
        # Create an order for the paying user
        order = {
            'user_id': dbhandler.settings['borrel_mode_user'],
            'amount': total_bought
        }
        # Let the paying user pay for everything
        success_messages = create_purchases([order], product, True,
                                            product.price)
    else:
        # Create purchases for every order
        success_messages = create_purchases(orders, product, r, product.price)

    # Create the final alert for both Tikker and Tikker BigScreen
    create_and_send_final_flash(success_messages)
    # Update the stats on BigScreen
    socket.update_stats()
コード例 #5
0
ファイル: admin.py プロジェクト: Yoronex/KVLSTikker
def admin_users_delete_undo(userid):
    check_if_local_machine()
    check_if_not_view_only()

    user = User.query.get(userid)
    if not user.deleted:
        flash("Deze gebruiker is niet verwijderd!", "danger")
    else:
        alert = (dbhandler.soft_del_user(userid))
        flash(alert[0], alert[1])

    socket.update_stats()

    return redirect(url_for('admin_users'))
コード例 #6
0
ファイル: admin.py プロジェクト: Yoronex/KVLSTikker
def admin_drinks_edit(drinkid):
    check_if_local_machine()
    check_if_not_view_only()

    form = ChangeDrinkForm()
    form2 = ChangeDrinkImageForm()
    recipe = ""
    product = Product.query.get(drinkid)
    if product.recipe_input is not None:
        for key, value in product.recipe_input.items():
            recipe = recipe + str(value) + "x" + str(key) + ", "

    if form.submit1.data and form.validate_on_submit():
        alert = (dbhandler.editdrink_attr(drinkid, form.name.data,
                                          float(form.price.data),
                                          form.category.data,
                                          int(form.pos.data) + 1,
                                          form.purchaseable.data,
                                          form.recipe.data,
                                          form.inventory_warning.data,
                                          float(form.alcohol.data),
                                          int(form.volume.data),
                                          form.unit.data))
        flash(alert[0], alert[1])

        socket.update_stats()

        return redirect(url_for('admin_drinks'))
    if form2.submit2.data and form2.validate_on_submit():
        alert = (dbhandler.editdrink_image(drinkid, form2.image.data,
                                           form2.hoverimage.data))
        flash(alert[0], alert[1])
        return redirect(url_for('admin_drinks'))
    flash_form_errors(form.errors)
    flash_form_errors(form2.errors)
    return render_template('admin/editdrink.html',
                           title="{} bewerken".format(product.name),
                           h1="Pas {} (ID: {}) aan".format(
                               product.name, product.id),
                           product=product,
                           form=form,
                           form2=form2,
                           recipe=recipe[:-2]), 200
コード例 #7
0
ファイル: admin.py プロジェクト: Yoronex/KVLSTikker
def admin_users_delete_exec(userid):
    check_if_local_machine()
    check_if_not_view_only()

    user = User.query.get(userid)

    if user.balance != 0.0:
        flash("Deze gebruiker heeft nog geen saldo van € 0!", "danger")
        return redirect(url_for('admin_users'))

    if not user.deleted:
        alert = (dbhandler.soft_del_user(userid))
        flash(alert[0], alert[1])
    else:
        # alert = (dbhandler.hard_del_user(userid))
        # flash(alert[0], alert[1])
        flash(
            "Wegens enkele ontdekte fouten in Tikker is het verwijderen van gebruikers tijdelijk uitgeschakeld",
            "danger")

    socket.update_stats()

    return redirect(url_for('admin_users'))
コード例 #8
0
def purchase_dinner(cart, total_costs, comments):
    # Parse the raw cart string into something readable
    parsed_cart = parse_cart_string(cart, -1)
    # Get the dinner ID
    dinner_id = dbhandler.settings['dinner_product_id']
    # If the dinner ID is None, return an error, as we should not have entered this method
    if dinner_id is None:
        raise ValueError("Dinner ID is None")
    # Get the product object
    product = Product.query.get(dinner_id)
    # Determine the price for one dinner
    price_pp = round_up(float(total_costs) / parsed_cart['total_bought'])
    # Add this to the inventory, so it can remain zero after purchasing
    dbhandler.add_inventory(dinner_id, parsed_cart['total_bought'], price_pp,
                            comments)
    # Create the purchases for every order
    success_messages = create_purchases(parsed_cart['orders'], product, False,
                                        price_pp)

    # Create the final alert for both Tikker and Tikker BigScreen
    create_and_send_final_flash(success_messages)
    # Update the stats on BigScreen
    socket.update_stats()
コード例 #9
0
ファイル: admin.py プロジェクト: Yoronex/KVLSTikker
def upgrade():
    check_if_local_machine()
    check_if_not_view_only()

    # Create the two forms that will be included
    upgr_form = UpgradeBalanceForm()
    decl_form = DeclarationForm()

    # If one of the forms has been submitted
    if (upgr_form.upgr_submit.data and upgr_form.validate_on_submit()) or \
            (decl_form.decl_submit.data and decl_form.validate_on_submit()):
        # Change the decimal amount to a float
        amount = float(upgr_form.amount.data)

        # The amount cannot be negative!
        if amount < 0.0:
            flash("Opwaardering kan niet negatief zijn!", "danger")
            return render_template('admin/upgrade.html',
                                   title='Opwaarderen',
                                   h1="Opwaarderen",
                                   upgr_form=upgr_form,
                                   decl_form=decl_form)

        # If the upgrade form has been filled in...
        if upgr_form.upgr_submit.data and upgr_form.validate_on_submit():
            # Add the upgrade to the database
            upgrade = (dbhandler.addbalance(int(upgr_form.user.data),
                                            "Opwaardering", amount))
            # Get the user for the messages that now follow
            user = User.query.get(upgrade.user_id)

            socket.send_transaction("{} heeft opgewaardeerd met € {}".format(
                user.name,
                str("%.2f" % upgrade.amount).replace(".", ",")))
            flash(
                "Gebruiker {} heeft succesvol opgewaardeerd met € {}".format(
                    user.name,
                    str("%.2f" % upgrade.amount).replace(".", ",")), "success")

        # If the declaration form has been filled in
        else:
            # Add the upgrade to the database
            upgrade = (dbhandler.add_declaration(int(decl_form.user.data),
                                                 decl_form.description.data,
                                                 amount,
                                                 int(decl_form.payer.data)))
            # Get the user for the messages that now follow
            user = User.query.get(upgrade.user_id)

            socket.send_transaction("{} heeft € {} teruggekregen ({})".format(
                user.name,
                str("%.2f" % upgrade.amount).replace(".", ","),
                upgrade.description))
            flash(
                "Gebruiker {} heeft succesvol € {} teruggekregen voor: {}".
                format(user.name,
                       str("%.2f" % upgrade.amount).replace(".", ","),
                       upgrade.description), "success")

        # Update the daily stats
        socket.update_stats()

        return redirect(url_for('admin'))

    # Show errors if there are any
    flash_form_errors(upgr_form.errors)
    flash_form_errors(decl_form.errors)
    return render_template('admin/upgrade.html',
                           title='Opwaarderen',
                           h1="Opwaarderen",
                           upgr_form=upgr_form,
                           decl_form=decl_form)