Beispiel #1
0
def admin_delete_user(user_id):
    if current_user.role != "ADMIN":
        return render_template("index.html", msg=msg_admin_feature)
    Item.delete_items_by_userid(user_id)
    List.delete_lists_by_userid(user_id)
    User.delete_user_by_userid(user_id)
    return redirect(url_for("list_users_with_item_amounts"))
Beispiel #2
0
def recipes_ingredients(recipeId):
    if not recipeAuthorization(recipeId):
        return redirect(url_for("recipes_show"))

    if request.method == "GET":
        return render_template("/recipes/ingredients.html",
                                form=IngredientForm(),
                                ingredients=Recipe.list_recipes_ingredients(recipeId),
                                recipeId=recipeId)

    form = IngredientForm(request.form)
    if not form.validate():
        return render_template("/recipes/ingredients.html",
                                form=form,
                                ingredients=Recipe.list_recipes_ingredients(recipeId),
                                recipeId=recipeId)
    
    try:
        itemId = Item.get_matching_item(form.name.data).get("id")
        ingredient = Ingredient(form.amount.data, form.name.data, recipeId, itemId)
    except:
        item = Item(Item.name_to_lexeme(form.name.data))
        db.session().add(item)
        db.session().flush()
        ingredient = Ingredient(form.amount.data, form.name.data, recipeId, item.id)

    db.session().add(ingredient)
    db.session().commit()

    return redirect(url_for("recipes_ingredients", recipeId=recipeId))
Beispiel #3
0
def items_create():
    form = ItemForm(request.form)
    form2 = CategoryForm(request.form)

    if not form.validate():
        return render_template("items/new.html", form=form)

    name = form.name.data
    it = Item.query.filter_by(name=name).first()
    if it:
        return render_template("items/new.html",
                               form=form,
                               error="Item is already listed!")
    i = Item(name)

    cid = form.category_id.data
    c = Category.query.get(cid)
    if not c:
        return render_template("categories_index")
    c.size = c.size + 1
    i.category_id = cid

    i.bought = form.bought.data
    i.account_id = current_user.id

    db.session().add(i)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #4
0
def item_rm(item_id):
    item = Item.query.get(item_id)
    db.session.delete(item)
    db.session.commit()

    userItems = Item.user_items(current_user.id)
    otherItems = Item.non_user_items(current_user.id)

    return render_template("items/list.html", items = otherItems, userItems = userItems)
Beispiel #5
0
def items_index():
    userItems = None
    otherItems = Item.non_user_items(-1) #Item.query.all()

    if current_user.is_authenticated:
        userItems = Item.user_items(current_user.id)
        otherItems = Item.non_user_items(current_user.id)
        
    return render_template("items/list.html", items = otherItems, userItems = userItems)
Beispiel #6
0
def items_create():
    form = ItemForm(request.form)

    if not form.validate():
        return render_template("items/new.html", form=form)

    i = Item(form.name.data)
    i.vegan = form.vegan.data
    i.account_id = current_user.id

    db.session().add(i)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #7
0
def create_item():
    categories = db.session.query(Category).all()
    form = CreateNewItemForm(request.form)
    category_selection = [(i.id, i.name) for i in categories]
    form.category.choices = category_selection

    if not form.validate_on_submit():
        return render_template("/items/new.html", form=form)

    new_item = Item(form.name.data)
    new_item.unit_type = form.unit_type.data
    new_item.category_id = form.category.data

    db.session().add(new_item)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #8
0
def items_create():
    form = ItemForm(request.form)
    if not form.validate():
        return render_template("items/new.html", form=form)
    item = Item(form.name.data, form.price.data, form.threshold.data)
    db.session.add(item)
    db.session.commit()
    return redirect(url_for("items_index"))
Beispiel #9
0
def index():

    did_you_know = Item.most_active_city()

    dykCity = did_you_know[0]['Place']
    dykAmount = did_you_know[0]['Amount']

    return render_template("index.html", dykCity=dykCity, dykAmount=dykAmount)
Beispiel #10
0
def index():
    top_sellers = AccountInformation.top_sellers()
    top_bidders = AccountInformation.top_bidders()
    hot_items = Item.hot_items()
    print("\n\n")
    print(hot_items)
    trending_items = []
    for xx in hot_items:
        print(xx)
        xx["bidding_time_left"] = Item.bidding_time_left(xx["id"])
        xx["end_date"] = Item.utc_quick(item_id=xx["id"])
        trending_items.append(xx)
    print("\n\n")
    print(trending_items)
    return render_template("index.html",
                           top_sellers=top_sellers,
                           top_bidders=top_bidders,
                           hot_items=trending_items)
Beispiel #11
0
def items_create():
    form = ItemForm(request.form)

    if not form.validate():
        return render_template('items/new.html', form = form)

    new_item = Item(form.name.data, 
                    form.description.data,
                    form.price.data)
    
    new_item.account_id = current_user.id
    gameName = form.gameName.data

    db.session().add(new_item)
    add_gameName_to_item(new_item, gameName)

    db.session().commit()
  
    return redirect(url_for('item_add_games', item_id = new_item.id))
Beispiel #12
0
def items_create():

    form = ItemForm(request.form)
    form.item_category.choices = [
        (c.id, c.name) for c in Category.query.order_by('name').filter_by(
            account_id=current_user.id)
    ]

    if not form.validate():
        return render_template("items/new.html", form=form)

    i = Item(form.name.data, form.expired.data)
    category = Category.query.get(form.item_category.data)
    i.account_id = current_user.id
    i.category_id = category.id

    db.session().add(i)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #13
0
def user(username):
    user = User.query.filter_by(username=username).first_or_404()
    if current_user.id != user.id:
        return render_template("index.html", msg=msg_other_user)
    form = ChangePasswordForm()
    amount = Item.amount_of_items_by_userid(current_user.id)
    return render_template("auth/userprofile.html",
                           user=user,
                           amount=amount,
                           form=form,
                           username=username)
Beispiel #14
0
def delete_game_in_item(item_id, game_id):
    
    item = Item.query.get(item_id)

    if (len(item.games) == 1):
        errorMessage = 'Myyntikohteessa on oltava vähintään yksi peli'
        form = ItemForm()
        edit_defaults(item, form)
        
        return edit_template(item, form, errorMessage = errorMessage)

    Item.delete_game(item_id, game_id)

    db.session.commit()

    form = ItemForm()
    edit_defaults(item, form)
    

        
    return edit_template(item, form) 
Beispiel #15
0
def items_create():
    form = ItemForm(request.form)
    if not form.validate():
        return render_template("items/list.html", 
        items = UserItem.list_users_items(),
        form = form)

    ui = UserItem(form.name.data, form.best_before.data)
    ui.account_id = current_user.id
    try:
        ui.item_id = Item.get_matching_item(form.name.data).get("id")
    except:
        i = Item(Item.name_to_lexeme(form.name.data))
        db.session().add(i)
        db.session().commit()
        ui.item_id = Item.get_matching_item(form.name.data).get("id")
    
    db.session().add(ui)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #16
0
def item_copy(item_id):
    item = Item.query.get(item_id)
    newItem = Item(item.name)
    newItem.brand = item.brand
    newItem.category = item.category
    newItem.weight = item.weight
    newItem.volume = item.volume
    newItem.description = item.description
    newItem.user_id = current_user.id

    db.session().add(newItem)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #17
0
def item_form():

    form = ItemForm(request.form)

    if request.method == "GET":
        return render_template("items/new.html", form=form)

    if not form.validate():
        return render_template("items/new.html", form=form)

    cc = Colorcode.query.filter(
        Colorcode.code == form.colorcode.data.code).first()
    ptype = Ptype.query.filter(Ptype.name == form.ptype.data.name).first()

    validProduct = Cc_ptype.query.filter(
        Cc_ptype.colorcode_id == cc.id, Cc_ptype.ptype_id == ptype.id).first()
    if not validProduct:
        return render_template("items/new.html",
                               form=form,
                               error="Product does not exist.")

    duplicate = Item.query.filter(Item.colorcode_id == cc.id,
                                  Item.ptype_id == ptype.id,
                                  Item.account_id == current_user.id).first()

    if duplicate:
        return render_template("items/new.html",
                               form=form,
                               error="Product already in collection.")

    item = Item()
    item.colorcode_id = cc.id
    item.ptype_id = ptype.id
    item.account_id = current_user.id

    db.session.add(item)
    db.session().commit()

    return redirect(url_for("index"))
Beispiel #18
0
def item_codesearch():

    form = CodeSearchForm(request.form)

    if not form.validate():
        return render_template("items/listpersonal.html",
                               form=form,
                               error="Invalid code")

    return render_template("items/listpersonal.html",
                           items=Item.codesearch(str(current_user.id),
                                                 form.incl.data,
                                                 form.search.data),
                           form=CodeSearchForm())
Beispiel #19
0
def items_create():
    form = ItemForm(request.form)

    if not form.validate():
        return render_template("items/new.html", form=form, warehouse_error="")

    item = Item.query.filter_by(name=form.name.data).first()

    if not item:
        item = Item(form.name.data, form.volume.data)
        db.session().add(item)
        db.session().commit()

    warehouse = Warehouse.query.filter_by(name=form.warehouse.data).first()

    if not warehouse:
        return render_template("items/new.html", form=form, warehouse_error="No such warehouse.")

    comp = Warehouse_item.query.filter_by(item_id=item.id, warehouse_id=warehouse.id).first()

    # check if item exists in warehouse

    if comp:

        new_amount = form.amount.data + comp.amount
        new_volume = new_amount * item.volume

        if not warehouse.fits(warehouse.id, new_volume):
            return render_template("items/new.html", form=form, warehouse_error="No room in warehouse.")
        elif (comp.amount + form.amount.data) < 0:
            return render_template("items/new.html", form=form, warehouse_error="Total amount can't be negative")
        
        comp.amount = new_amount

    else:

        new_amount = form.amount.data
        new_volume = new_amount * item.volume

        if not warehouse.fits(warehouse.id, new_volume):
            return render_template("items/new.html", form=form, warehouse_error="No room in warehouse.")
        
        relation = Warehouse_item(warehouse, item, new_amount)
        db.session().add(relation)
    
    db.session().commit()
    return redirect(url_for("warehouse_single", warehouse_id=warehouse.id))
Beispiel #20
0
def changePassword():
    username = current_user.username
    form = ChangePasswordForm(request.form)

    if not form.validate():
        amount = Item.amount_of_items_by_userid(current_user.id)
        return render_template("auth/userprofile.html",
                               user=user,
                               amount=amount,
                               form=form,
                               username=username)

    u = User.query.get(current_user.id)
    u.password = form.password.data
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #21
0
def item_submit_game(item_id):
    form = GameToItemForm(request.form)
    item = Item.query.get(item_id)

    if not form.validate():
        return render_template('items/addgames.html', form = form, item = item, error = '')
    
    gameName = form.name.data

    if Item.check_game_in_item(item, gameName):
        errorMessage = game_already_in_item_error_message()
        return render_template('items/addgames.html', form = form, item = item, error = errorMessage)
    
    
    add_gameName_to_item(item, gameName)

    return redirect(url_for('item_add_games', item_id = item.id))
Beispiel #22
0
def item_submit_game_edit(item_id):
    gameForm = GameToItemForm(request.form)
    item = Item.query.get(item_id)

    itemForm = ItemForm()
    edit_defaults(item, itemForm)

    if not gameForm.validate():
        return edit_template(item, itemForm, gameForm = gameForm)
    
    gameName = gameForm.name.data

    if Item.check_game_in_item(item, gameName):
        errorMessage = game_already_in_item_error_message()
        return edit_template(item, itemForm, gameForm = gameForm, errorMessage = errorMessage)
    
    add_gameName_to_item(item, gameName)

    return edit_template(item, itemForm , gameForm = gameForm)
Beispiel #23
0
def item_create():
    # New item form
    if request.method=="GET":
        return render_template("items/new.html", form = ItemForm())

    # Form validation
    form = ItemForm(request.form)
    if not form.validate():
        return render_template("items/new.html", form = form)

    # Adding new item to db
    item = Item(form.name.data)
    item.brand = form.brand.data
    item.category = form.category.data
    item.weight = form.weight.data
    item.volume = form.volume.data
    item.description = form.description.data
    item.user_id = current_user.id

    db.session().add(item)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #24
0
def items_create():
    form = ItemForm(request.form)
    list = Category.query.all()

    if not form.validate():
        return render_template("items/new.html", form = form, categories = list)

    i = Item(form.name.data, form.amount.data)
    i.bought = form.bought.data
    i.account_id = current_user.id
    i.category_id = form.category.data
    i.list_id = List.find_users_defaultlist_id(current_user.id)

    db.session().add(i)
    db.session().commit()

    return redirect(url_for("items_index"))
Beispiel #25
0
def items_date_added():
    return render_template("items/listpersonal.html",
                           items=Item.date_added(Item, str(current_user.id)),
                           form=CodeSearchForm())
Beispiel #26
0
def items_favorite():
    return render_template("items/listpersonal.html",
                           items=Item.find_favorite(Item,
                                                    str(current_user.id)),
                           form=CodeSearchForm())
Beispiel #27
0
def items_myindex():
    return render_template("items/listpersonal.html",
                           items=Item.personal_index(Item,
                                                     str(current_user.id)),
                           form=CodeSearchForm())
Beispiel #28
0
def items_index():
    return render_template("items/list.html",
                           general_index=Item.general_index())
Beispiel #29
0
def items_index():
    return render_template('items/list.html', 
                           items = Item.query.filter_by(sold = False),
                           items_total = Item.items_unsold_total())
Beispiel #30
0
def items_create():
    form = ItemForm(request.form)

    # Fetching all qualities from the database and manually adding them to the form
    qualities = Quality.query.all()
    form.quality.choices = [(quality.id, quality.name)
                            for quality in qualities]

    categories = Category.query.all()
    form.category.choices = [(category.id, category.name)
                             for category in categories]

    if not form.validate_on_submit():
        return render_template("items/new.html", form=form)

    helsinki = pytz.timezone("Europe/Helsinki")
    bidding_end = "{} {}".format(form.bidding_end.bidding_end_date.data,
                                 form.bidding_end.bidding_end_time.data)
    bidding_end = datetime.datetime.strptime(bidding_end, "%Y-%m-%d %H:%M")
    bidding_end = helsinki.localize(bidding_end)
    # Saving datetime in UTC timezone for easier processing
    bidding_end = bidding_end.astimezone(utc)

    if 'image' not in request.files:
        form.image.errors.append("No image found")
        return render_template("items/new.html", form=form)

    image_file = request.files.get("image")

    # If not image file return form
    if image_file.filename.rsplit(
            ".", 1)[1].lower() not in ["jpg", "jpeg", "png", "bmp"]:
        form.image.errors.append("Invalid filetype")
        return render_template("items/new.html", form=form)

    img = Image.open(request.files.get("image"))

    sec_filename = secure_filename(image_file.filename)
    timecode = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    file_key = "{}-{}".format(sec_filename.rsplit(".", 1)[0], timecode)

    thumbnail_image_key = "{}-400".format(file_key)
    full_image_key = "{}-800".format(file_key)

    thumbnail_image_name = "{}.jpg".format(thumbnail_image_key)
    full_image_name = "{}.jpg".format(full_image_key)

    # Image filename format: name-timestamp-size
    thumbnail_image = create_thumbnail(img)
    full_image = create_full(img)

    thumbnail_image = thumbnail_image.convert('RGB')
    thumbnail_image_bytes_stream = BytesIO()
    thumbnail_image.save(thumbnail_image_bytes_stream, "JPEG", quality=70)

    full_image = full_image.convert('RGB')
    full_image_bytes_stream = BytesIO()
    full_image.save(full_image_bytes_stream, "JPEG", quality=75)

    # if os.environ.get("AWS") == "huutokauppa-sovellus":
    #     # Save thumbnail image to s3
    #     put_object_to_s3(image_bytes=thumbnail_image_bytes_stream.getvalue(), filename=thumbnail_image_key)
    #     thumbnail_image_url = "{}{}".format(application.config["S3_LOCATION"], thumbnail_image_key)

    #     # Save full image to s3
    #     put_object_to_s3(image_bytes=full_image_bytes_stream.getvalue(), filename=full_image_key)
    #     full_image_url = "{}{}".format(application.config["S3_LOCATION"], full_image_key)
    # If running locally save images to static/images
    with open(
            os.path.join(application.config["UPLOAD_FOLDER"],
                         thumbnail_image_name), "wb") as f:
        f.write(thumbnail_image_bytes_stream.getvalue())
        thumbnail_image_url = url_for(
            'static', filename="images/{}".format(thumbnail_image_name))

    with open(
            os.path.join(application.config["UPLOAD_FOLDER"], full_image_name),
            "wb") as f:
        f.write(full_image_bytes_stream.getvalue())
        full_image_url = url_for('static',
                                 filename="images/{}".format(full_image_name))

    item = Item(starting_price=form.starting_price.data,
                current_price=form.starting_price.data,
                name=form.name.data,
                account_information_id=current_user.id,
                quality=form.quality.data,
                category=form.category.data,
                description=form.description.data,
                bidding_end=bidding_end,
                image_thumbnail=thumbnail_image_url,
                image_full=full_image_url)

    db.session().add(item)
    db.session().flush()

    # Adding a new task for the item that sells it when the bidding time ends
    task_id = sell_item.apply_async(args=[item.id], eta=bidding_end)
    item.celery_task_id = task_id.id
    db.session().commit()

    return redirect(url_for("item_detail", item_id=item.id))