Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibrarySet modification issue #349

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions esim-cloud-backend/libAPI/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '\
'<a href='/api/admin/libAPI/libraryset/{library_set.id}'>'\
'{library_set.name}</a>."))
f"Library {obj.library_name} moved to \
<a href='/api/admin/libAPI/libraryset/{library_set.id}'>\
{library_set.name}</a>."))
obj.library_set = library_set
obj.save()

Expand All @@ -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,
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions esim-cloud-backend/libAPI/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down