from django.shortcuts import render, get_object_or_404, redirect
from django.core.exceptions import PermissionDenied
from django.http import HttpRequest, HttpResponse
from .models import *

def check_ownership(request: HttpRequest, *args, **kwargs) -> HttpRequest:
    contact = Contact.objects.get(user=request.user)
    # print ()

    # try:
    # product = Product.objects.get( pk=pk )
    product = get_object_or_404( Product,  pk = kwargs['pk'] )
    if (contact.id == product.contact.id ):
        return True
    return False

    # get_object_or_404(Product, (Q(pk=pk) & Q(contact=contact)))
    #
    # if request.user = :
    #     return request
    # # Return a HTTP 403 back to the user
    # raise PermissionDenied
