diff --git a/osinaweb/customercore/__pycache__/custom_context.cpython-310.pyc b/osinaweb/customercore/__pycache__/custom_context.cpython-310.pyc index 83f8fde5..0a54222e 100644 Binary files a/osinaweb/customercore/__pycache__/custom_context.cpython-310.pyc and b/osinaweb/customercore/__pycache__/custom_context.cpython-310.pyc differ diff --git a/osinaweb/customercore/__pycache__/decorators.cpython-310.pyc b/osinaweb/customercore/__pycache__/decorators.cpython-310.pyc index f0dbbd78..52f5f953 100644 Binary files a/osinaweb/customercore/__pycache__/decorators.cpython-310.pyc and b/osinaweb/customercore/__pycache__/decorators.cpython-310.pyc differ diff --git a/osinaweb/customercore/__pycache__/views.cpython-310.pyc b/osinaweb/customercore/__pycache__/views.cpython-310.pyc index 409015a1..cedb592b 100644 Binary files a/osinaweb/customercore/__pycache__/views.cpython-310.pyc and b/osinaweb/customercore/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/customercore/custom_context.py b/osinaweb/customercore/custom_context.py index ed6b7514..f6721e9d 100644 --- a/osinaweb/customercore/custom_context.py +++ b/osinaweb/customercore/custom_context.py @@ -6,12 +6,25 @@ from django.db.models import Count, Q def utilities(request): active_subscriptions = None customer_open_tickets = None + customer_open_tickets_count = None + customer_open_projects = None + customer_open_projects_count = None + customer_open_invoices = None + customer_open_invoices_count = None if request.user.is_authenticated and CustomerProfile.objects.filter(user=request.user): customer = request.user.customerprofile active_subscriptions = OrderItem.objects.filter(active=True, order__customer=customer) + + customer_open_projects = Project.objects.filter(Q(status='Open') | Q(status='Pending'), customer=customer) + customer_open_projects_count = customer_open_projects.count() + + customer_open_invoices = Invoice.objects.filter(order__status='Open') + customer_open_invoices_count = customer_open_invoices.count() + customer_open_tickets = Ticket.objects.filter( Q(status__in=['Open', 'Working On']) & Q(customer=request.user.customerprofile) ).order_by('-id') + customer_open_tickets_count = customer_open_tickets.count() for ticket in customer_open_tickets: unread_updates_count = 0 @@ -29,4 +42,6 @@ def utilities(request): ticket.last_update_date_added = None - return {'active_subscriptions': active_subscriptions, 'customer_open_tickets': customer_open_tickets} + customer_open_invoices_count = customer_open_invoices.count() + customer_open_invoices_count = customer_open_invoices.count() + return {'active_subscriptions': active_subscriptions, 'customer_open_tickets': customer_open_tickets, 'customer_open_tickets_count':customer_open_tickets_count, 'customer_open_projects_count': customer_open_projects_count, 'customer_open_invoices_count': customer_open_invoices_count} diff --git a/osinaweb/customercore/decorators.py b/osinaweb/customercore/decorators.py index e59d7b5b..d8c7c1fd 100644 --- a/osinaweb/customercore/decorators.py +++ b/osinaweb/customercore/decorators.py @@ -1,12 +1,19 @@ from functools import wraps from django.shortcuts import redirect from osinacore.models import * +from django.http import QueryDict def customer_login_required(view_func): @wraps(view_func) def _wrapped_view(request, *args, **kwargs): # Check if the user is logged in and is a staff member if not request.user.is_authenticated or not CustomerProfile.objects.filter(user=request.user): - return redirect('signout') # Redirect to login URL if not staff + # 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) diff --git a/osinaweb/customercore/views.py b/osinaweb/customercore/views.py index 5d7ba863..a476edb3 100644 --- a/osinaweb/customercore/views.py +++ b/osinaweb/customercore/views.py @@ -11,7 +11,7 @@ import string from billing.add.views import * from .models import * from django.db.models import Q -from datetime import date +from django.http import Http404 # Create your views here. @@ -202,9 +202,17 @@ def customer_tickets(request, *args, **kwargs): # DETAILS + def customer_ticket_details(request, ticket_number): ticket = get_object_or_404(Ticket, ticket_number=ticket_number) + + # Check if the logged-in user is the customer associated with the ticket + if ticket.customer != request.user.customerprofile: + raise Http404("Page not found.") + ticket_updates = TicketUpdate.objects.filter(ticket=ticket).order_by('id') + + # Mark updates as read for the current user for update in TicketUpdate.objects.filter(ticket=ticket).exclude(added_by=request.user).order_by('id'): if not TicketRead.objects.filter(ticket_update=update, user=request.user).exists(): TicketRead.objects.create(ticket_update=update, user=request.user, read=True) @@ -221,7 +229,6 @@ def customer_ticket_details(request, ticket_number): - # PRODUCTS @customer_login_required def osimenu_plans(request, *args, **kwargs): diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 71e4452b..c18ee909 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/__pycache__/decorators.cpython-310.pyc b/osinaweb/osinacore/__pycache__/decorators.cpython-310.pyc index b14221ca..536e4f88 100644 Binary files a/osinaweb/osinacore/__pycache__/decorators.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/decorators.cpython-310.pyc differ diff --git a/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc b/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc index c3ee023e..315f1b19 100644 Binary files a/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc differ diff --git a/osinaweb/osinacore/__pycache__/views.cpython-310.pyc b/osinaweb/osinacore/__pycache__/views.cpython-310.pyc index 6410f010..18eadc21 100644 Binary files a/osinaweb/osinacore/__pycache__/views.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/osinacore/decorators.py b/osinaweb/osinacore/decorators.py index 719cda1b..0b8d1f52 100644 --- a/osinaweb/osinacore/decorators.py +++ b/osinaweb/osinacore/decorators.py @@ -1,13 +1,21 @@ from functools import wraps from django.shortcuts import redirect from .models import * +from django.http import QueryDict + def staff_login_required(view_func): @wraps(view_func) def _wrapped_view(request, *args, **kwargs): # Check if the user is logged in and is a staff member if not request.user.is_authenticated or not StaffProfile.objects.filter(user=request.user): - return redirect('signout') # Redirect to login URL if not staff + # 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 + return _wrapped_view \ No newline at end of file diff --git a/osinaweb/osinacore/templates/customer_main.html b/osinaweb/osinacore/templates/customer_main.html index 827b2fb3..c450c1bf 100644 --- a/osinaweb/osinacore/templates/customer_main.html +++ b/osinaweb/osinacore/templates/customer_main.html @@ -436,7 +436,7 @@
-

2

+

{{customer_open_invoices_count}}

@@ -473,7 +473,7 @@
-

2

+

{{customer_open_projects_count}}

@@ -503,7 +503,7 @@
-

2

+

{{customer_open_tickets_count}}

diff --git a/osinaweb/osinacore/templates/login.html b/osinaweb/osinacore/templates/login.html index fd2a88fe..37744bb7 100644 --- a/osinaweb/osinacore/templates/login.html +++ b/osinaweb/osinacore/templates/login.html @@ -80,7 +80,7 @@ -
{% csrf_token %} diff --git a/osinaweb/osinacore/urls.py b/osinaweb/osinacore/urls.py index b4e91f06..d33f431b 100644 --- a/osinaweb/osinacore/urls.py +++ b/osinaweb/osinacore/urls.py @@ -22,7 +22,7 @@ from django.conf import settings urlpatterns = [ path('api/', include('osinacore.api.urls')), path('login///', views.login_with_email, name='login_with_email'), - path('login', views.signin, name='signin'), + path('login/', views.signin, name='signin'), path('signup', views.signup, name='signup'), path('check-email-availability/', views.check_email_availability, name='check-email-availability'), path('activate///', views.activate, name='activate'), diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index f8833c3b..b01dfffd 100644 --- a/osinaweb/osinacore/views.py +++ b/osinaweb/osinacore/views.py @@ -37,10 +37,13 @@ def login_with_email(request, email, key): # Pages views def signin(request): + next_page = request.GET.get('next') + print(next_page) if request.user.is_authenticated: if StaffProfile.objects.filter(user=request.user) or CustomerProfile.objects.filter(user=request.user): return redirect('home') + if request.method == 'POST': form = CustomLoginForm(request.POST) if form.is_valid(): @@ -51,14 +54,18 @@ def signin(request): if user is not None: login(request, user) Connection.objects.create(status='Online', date=datetime.now(), user=user) - return redirect('home') + if next_page: + return redirect(next_page) + else: + return redirect('home') + else: messages.error(request, 'Invalid email or password. Please try again.') else: form = CustomLoginForm() - return render(request, 'login.html', {'form': form}) + return render(request, 'login.html', {'form': form, 'next_page': next_page})