aboutsummaryrefslogtreecommitdiffstats
path: root/src/account/views.py
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-06-08 12:46:53 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-07-21 13:17:51 -0400
commita09db9f287a02873c0226759f8ea444bb304cd59 (patch)
tree59e744e4b998973a808abbae2d21fbdd6201d829 /src/account/views.py
parent8ddc7e820e120f1dde4e901d3cb6f1dd3f281e65 (diff)
LaaS 3.0 Almost MVP
Change-Id: Ided9a43cf3088bb58a233dc459711c03f43e11b8 Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/account/views.py')
-rw-r--r--src/account/views.py82
1 files changed, 28 insertions, 54 deletions
diff --git a/src/account/views.py b/src/account/views.py
index 8976ff9..2d280cd 100644
--- a/src/account/views.py
+++ b/src/account/views.py
@@ -9,6 +9,7 @@
##############################################################################
+import json
import os
from django.utils import timezone
@@ -30,9 +31,7 @@ from mozilla_django_oidc.auth import OIDCAuthenticationBackend
from account.forms import AccountSettingsForm
from account.models import UserProfile
from booking.models import Booking
-from resource_inventory.models import ResourceTemplate, Image
-
-
+from api.views import delete_template, liblaas_templates
@method_decorator(login_required, name='dispatch')
class AccountSettingsView(UpdateView):
model = UserProfile
@@ -134,17 +133,21 @@ def account_resource_view(request):
return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
template = "account/resource_list.html"
- active_bundles = [book.resource for book in Booking.objects.filter(
- owner=request.user, end__gte=timezone.now(), resource__template__temporary=False)]
- active_resources = [bundle.template.id for bundle in active_bundles]
- resource_list = list(ResourceTemplate.objects.filter(owner=request.user, temporary=False))
+ if request.method == "GET":
- context = {
- "resources": resource_list,
- "active_resources": active_resources,
- "title": "My Resources"
- }
- return render(request, template, context=context)
+ r = liblaas_templates(request)
+ usable_templates = r.json()
+ user_templates = [ t for t in usable_templates if t["owner"] == str(request.user)]
+ context = {
+ "templates": user_templates,
+ "title": "My Resources"
+ }
+ return render(request, template, context=context)
+
+ if request.method == "POST":
+ return delete_template(request)
+
+ return HttpResponse(status_code=405)
def account_booking_view(request):
@@ -165,37 +168,20 @@ def account_booking_view(request):
return render(request, template, context=context)
-def account_images_view(request):
- if not request.user.is_authenticated:
- return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
- template = "account/image_list.html"
- my_images = Image.objects.filter(owner=request.user)
- public_images = Image.objects.filter(public=True)
- used_images = {}
- for image in my_images:
- if image.in_use():
- used_images[image.id] = "true"
- context = {
- "title": "Images",
- "images": my_images,
- "public_images": public_images,
- "used_images": used_images
- }
- return render(request, template, context=context)
-
def template_delete_view(request, resource_id=None):
- if not request.user.is_authenticated:
- return HttpResponse(status=403)
- template = get_object_or_404(ResourceTemplate, pk=resource_id)
- if not request.user.id == template.owner.id:
- return HttpResponse(status=403)
- if Booking.objects.filter(resource__template=template, end__gt=timezone.now()).exists():
- return HttpResponse(status=403)
- template.public = False
- template.temporary = True
- template.save()
- return HttpResponse(status=200)
+ # if not request.user.is_authenticated:
+ # return HttpResponse(status=403)
+ # template = get_object_or_404(ResourceTemplate, pk=resource_id)
+ # if not request.user.id == template.owner.id:
+ # return HttpResponse(status=403)
+ # if Booking.objects.filter(resource__template=template, end__gt=timezone.now()).exists():
+ # return HttpResponse(status=403)
+ # template.public = False
+ # template.temporary = True
+ # template.save()
+ # return HttpResponse(status=200)
+ return HttpResponse(status=404) # todo - LL Integration
def booking_cancel_view(request, booking_id=None):
@@ -212,15 +198,3 @@ def booking_cancel_view(request, booking_id=None):
booking.save()
return HttpResponse('')
-
-def image_delete_view(request, image_id=None):
- if not request.user.is_authenticated:
- return HttpResponse('no') # 403?
- image = get_object_or_404(Image, pk=image_id)
- if image.public or image.owner.id != request.user.id:
- return HttpResponse('no') # 403?
- # check if used in booking
- if image.in_use():
- return HttpResponse('no') # 403?
- image.delete()
- return HttpResponse('')