Пример #1
0
def items(request):
    if request.method == "POST":
        form = Profileform(request.POST, request.FILES)
        if form.is_valid():
            item = Items(
                author=request.POST['author'],
                profile_pic=request.FILES['profile_pic'],
                item_name=request.POST['item_name'],
                servings=request.POST['servings'],
                preparation_time=request.POST['preparation_time'],
                cooking_time=request.POST['cooking_time'],
                food_image=request.FILES['food_image'],
                ingredients=request.POST['ingredients'],
                direction=request.POST['direction'],
                item_type=request.POST['item_type'],
            )
            current_user = request.user.id
            item.save()
            name = item.id
            add_author(request, current_user, name)
        else:
            pass
        return redirect('/items/')
    else:
        form = Profileform()
        current_user = request.user.id
        items = Items_List.objects.all().select_related('item_list').filter(
            user_name_id=current_user).order_by('item_list__item_name')
        lists = Items_List.objects.select_related('item_list')
        return render(request, 'author_items.html', {
            'items': items,
            'form': form
        })
Пример #2
0
def add_item_to_shopping_list(id):
    # get the access token from header
    access_token = request.headers.get('Authorization')
    if access_token:
        # attempt to decode the token and get the User ID
        user_id = Users.decode_token(access_token)
        if not isinstance(user_id, str):
            # check if shopping list exists in the database
            shopping_list = ShoppingLists.query.filter_by(user_id=user_id,
                                                          id=id).first()
            if not shopping_list:
                return make_response(
                    jsonify({
                        "message":
                        "Shopping list can not be found to add items"
                    })), 404
            data = request.get_json()
            item = Items(name=data['name'],
                         quantity=data['quantity'],
                         shopping_list_id=id,
                         bought_from=data['bought_from'],
                         status=data['status'])
            item.save()
            return make_response(
                jsonify({"message": "Item added to shopping list"})), 201
        else:
            # user is not legit, so the payload is an error message
            message = user_id
            response = {'message': message}
            return make_response(jsonify(response)), 401
    return make_response(jsonify({'message':
                                  'Please register or login.'})), 401
Пример #3
0
def processAdd(request):
    if request.method == 'POST':
        if request.user.is_authenticated and request.user.is_superuser:
            adder = Items(titulo=request.POST['titulo'],
                          short=request.POST['short'],
                          descricao=request.POST['descricao'],
                          preco=request.POST['preco'],
                          picture=request.FILES['picture'],
                          quantidade=request.POST['quantidade'])
            adder.save()
            return redirect('adminpanel')
        else:
            return redirect('home')
    else:
        return redirect('home')
Пример #4
0
def addprofile(request):
    if request.method == 'POST':
        item = Items(
            author=request.POST['author'],
            profile_pic=request.FILES['profile_pic'],
            item_name=request.POST['item_name'],
            servings=request.POST['servings'],
            preparation_time=request.POST['preparation_time'],
            cooking_time=request.POST['cooking_time'],
            food_image=request.FILES['food_image'],
            ingredients=request.POST['ingredients'],
            direction=request.POST['direction'],
            item_type=request.POST['item_type'],
        )
        current_user = request.user.id
        item.save()
        return redirect('/items/')
    else:
        return redirect('/items/')