from functools import wraps
from django.shortcuts import redirect
from osinacore.models import *
from django.http import QueryDict
def ticket_member_required(view_func):
    @wraps(view_func)
    def _wrapped_view(request, *args, **kwargs):
        # Check if the user is logged in and is either a customer or a staff member
        if not request.user.is_authenticated or (
                not CustomerProfile.objects.filter(user=request.user) and 
                not StaffProfile.objects.filter(user=request.user)):
            # Capture the 'next' page
            next_page = request.build_absolute_uri()
            query_params = QueryDict(mutable=True)
            query_params['next'] = next_page
            query_string = query_params.urlencode()
            login_url = f"/login/?{query_string}"  # Change the login URL as per your project setup
            return redirect(login_url)

        return view_func(request, *args, **kwargs)

    return _wrapped_view
