From 1df496ab5aef091dd3d5ac20bb927bf446308f47 Mon Sep 17 00:00:00 2001 From: Nikhil Kumar Date: Wed, 4 Aug 2021 14:20:09 +0530 Subject: [PATCH 1/2] [FIX] LibrarySet modification issue --- esim-cloud-backend/libAPI/admin.py | 10 ++++++---- esim-cloud-backend/libAPI/forms.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/esim-cloud-backend/libAPI/admin.py b/esim-cloud-backend/libAPI/admin.py index 2fe449a3a..d2af7f9f8 100644 --- a/esim-cloud-backend/libAPI/admin.py +++ b/esim-cloud-backend/libAPI/admin.py @@ -52,9 +52,9 @@ def toggle_default(self, request, obj, parent_obj=None): ) library_set.save() messages.info(request, mark_safe( - f"Library {obj.library_name} moved to '\ - ''\ - '{library_set.name}.")) + f"Library {obj.library_name} moved to \ + \ + {library_set.name}.")) obj.library_set = library_set obj.save() @@ -75,7 +75,7 @@ def get_form(self, request, obj=None, **kwargs): def save_model(self, request, obj, form, change): # For new library set instance User = get_user_model() - user = User.objects.get(id=request.POST.get('user')) + user = User.objects.get(id=request.user.id) if obj.pk is None: obj = LibrarySet( user=user, @@ -86,6 +86,8 @@ def save_model(self, request, obj, form, change): # If the library set is being changed else: + user = (LibrarySet.objects.get(id = obj.pk)).user + obj.user = user obj.save() files = request.FILES.getlist('files') diff --git a/esim-cloud-backend/libAPI/forms.py b/esim-cloud-backend/libAPI/forms.py index 7fe0e29f9..00151cab9 100644 --- a/esim-cloud-backend/libAPI/forms.py +++ b/esim-cloud-backend/libAPI/forms.py @@ -13,6 +13,7 @@ def __init__(self, *args, **kwargs): instance = getattr(self, 'instance', None) if instance and instance.pk: self.fields['user'].widget.attrs['disabled'] = True + self.fields['user'].required = False self.fields['name'].widget.attrs['readonly'] = True class Meta: From 85a1591bd146705732543202495350904fd0cb72 Mon Sep 17 00:00:00 2001 From: Nikhil Kumar Date: Wed, 4 Aug 2021 14:26:39 +0530 Subject: [PATCH 2/2] [FIX] PEP8 issues --- esim-cloud-backend/libAPI/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esim-cloud-backend/libAPI/admin.py b/esim-cloud-backend/libAPI/admin.py index d2af7f9f8..d1dbdd7f6 100644 --- a/esim-cloud-backend/libAPI/admin.py +++ b/esim-cloud-backend/libAPI/admin.py @@ -86,7 +86,7 @@ def save_model(self, request, obj, form, change): # If the library set is being changed else: - user = (LibrarySet.objects.get(id = obj.pk)).user + user = (LibrarySet.objects.get(id=obj.pk)).user obj.user = user obj.save()