mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-27 16:59:37 +02:00
commit
44db008f02
1 changed files with 14 additions and 14 deletions
|
@ -72,23 +72,22 @@ class AdventureViewSet(viewsets.ModelViewSet):
|
||||||
return queryset.order_by(ordering)
|
return queryset.order_by(ordering)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
# if the user is not authenticated return only public adventures for retrieve action
|
# if the user is not authenticated return only public adventures for retrieve action
|
||||||
if not self.request.user.is_authenticated:
|
if not self.request.user.is_authenticated:
|
||||||
if self.action == 'retrieve':
|
if self.action == 'retrieve':
|
||||||
return Adventure.objects.filter(is_public=True)
|
return Adventure.objects.filter(is_public=True).distinct().order_by('-updated_at')
|
||||||
return Adventure.objects.none()
|
return Adventure.objects.none()
|
||||||
|
|
||||||
|
|
||||||
if self.action == 'retrieve':
|
if self.action == 'retrieve':
|
||||||
# For individual adventure retrieval, include public adventures
|
# For individual adventure retrieval, include public adventures
|
||||||
return Adventure.objects.filter(
|
return Adventure.objects.filter(
|
||||||
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
else:
|
else:
|
||||||
# For other actions, include user's own adventures and shared adventures
|
# For other actions, include user's own adventures and shared adventures
|
||||||
return Adventure.objects.filter(
|
return Adventure.objects.filter(
|
||||||
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
|
|
||||||
def retrieve(self, request, *args, **kwargs):
|
def retrieve(self, request, *args, **kwargs):
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
|
@ -270,6 +269,7 @@ class AdventureViewSet(viewsets.ModelViewSet):
|
||||||
serializer.save()
|
serializer.save()
|
||||||
|
|
||||||
# when creating an adventure, make sure the user is the owner of the collection or shared with the collection
|
# when creating an adventure, make sure the user is the owner of the collection or shared with the collection
|
||||||
|
@transaction.atomic
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
# Retrieve the collection from the validated data
|
# Retrieve the collection from the validated data
|
||||||
collection = serializer.validated_data.get('collection')
|
collection = serializer.validated_data.get('collection')
|
||||||
|
@ -619,7 +619,7 @@ class TransportationViewSet(viewsets.ModelViewSet):
|
||||||
# if the user is not authenticated return only public transportations for retrieve action
|
# if the user is not authenticated return only public transportations for retrieve action
|
||||||
if not self.request.user.is_authenticated:
|
if not self.request.user.is_authenticated:
|
||||||
if self.action == 'retrieve':
|
if self.action == 'retrieve':
|
||||||
return Transportation.objects.filter(is_public=True)
|
return Transportation.objects.filter(is_public=True).distinct().order_by('-updated_at')
|
||||||
return Transportation.objects.none()
|
return Transportation.objects.none()
|
||||||
|
|
||||||
|
|
||||||
|
@ -627,12 +627,12 @@ class TransportationViewSet(viewsets.ModelViewSet):
|
||||||
# For individual adventure retrieval, include public adventures
|
# For individual adventure retrieval, include public adventures
|
||||||
return Transportation.objects.filter(
|
return Transportation.objects.filter(
|
||||||
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
else:
|
else:
|
||||||
# For other actions, include user's own adventures and shared adventures
|
# For other actions, include user's own adventures and shared adventures
|
||||||
return Transportation.objects.filter(
|
return Transportation.objects.filter(
|
||||||
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
|
|
||||||
def partial_update(self, request, *args, **kwargs):
|
def partial_update(self, request, *args, **kwargs):
|
||||||
# Retrieve the current object
|
# Retrieve the current object
|
||||||
|
@ -741,7 +741,7 @@ class NoteViewSet(viewsets.ModelViewSet):
|
||||||
# if the user is not authenticated return only public transportations for retrieve action
|
# if the user is not authenticated return only public transportations for retrieve action
|
||||||
if not self.request.user.is_authenticated:
|
if not self.request.user.is_authenticated:
|
||||||
if self.action == 'retrieve':
|
if self.action == 'retrieve':
|
||||||
return Note.objects.filter(is_public=True)
|
return Note.objects.filter(is_public=True).distinct().order_by('-updated_at')
|
||||||
return Note.objects.none()
|
return Note.objects.none()
|
||||||
|
|
||||||
|
|
||||||
|
@ -749,12 +749,12 @@ class NoteViewSet(viewsets.ModelViewSet):
|
||||||
# For individual adventure retrieval, include public adventures
|
# For individual adventure retrieval, include public adventures
|
||||||
return Note.objects.filter(
|
return Note.objects.filter(
|
||||||
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
else:
|
else:
|
||||||
# For other actions, include user's own adventures and shared adventures
|
# For other actions, include user's own adventures and shared adventures
|
||||||
return Note.objects.filter(
|
return Note.objects.filter(
|
||||||
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
|
|
||||||
def partial_update(self, request, *args, **kwargs):
|
def partial_update(self, request, *args, **kwargs):
|
||||||
# Retrieve the current object
|
# Retrieve the current object
|
||||||
|
@ -863,7 +863,7 @@ class ChecklistViewSet(viewsets.ModelViewSet):
|
||||||
# if the user is not authenticated return only public transportations for retrieve action
|
# if the user is not authenticated return only public transportations for retrieve action
|
||||||
if not self.request.user.is_authenticated:
|
if not self.request.user.is_authenticated:
|
||||||
if self.action == 'retrieve':
|
if self.action == 'retrieve':
|
||||||
return Checklist.objects.filter(is_public=True)
|
return Checklist.objects.filter(is_public=True).distinct().order_by('-updated_at')
|
||||||
return Checklist.objects.none()
|
return Checklist.objects.none()
|
||||||
|
|
||||||
|
|
||||||
|
@ -871,12 +871,12 @@ class ChecklistViewSet(viewsets.ModelViewSet):
|
||||||
# For individual adventure retrieval, include public adventures
|
# For individual adventure retrieval, include public adventures
|
||||||
return Checklist.objects.filter(
|
return Checklist.objects.filter(
|
||||||
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
else:
|
else:
|
||||||
# For other actions, include user's own adventures and shared adventures
|
# For other actions, include user's own adventures and shared adventures
|
||||||
return Checklist.objects.filter(
|
return Checklist.objects.filter(
|
||||||
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
|
||||||
)
|
).distinct().order_by('-updated_at')
|
||||||
|
|
||||||
def partial_update(self, request, *args, **kwargs):
|
def partial_update(self, request, *args, **kwargs):
|
||||||
# Retrieve the current object
|
# Retrieve the current object
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue