1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-05 05:05:17 +02:00

refactor(models, views, serializers): rename LocationImage and Attachment to ContentImage and ContentAttachment, update related references

This commit is contained in:
Sean Morley 2025-07-10 12:12:03 -04:00
parent 1b841f45a0
commit 7f80dad94b
13 changed files with 371 additions and 86 deletions

View file

@ -2,7 +2,7 @@ from rest_framework import viewsets, status
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from adventures.models import Location, Attachment
from adventures.models import Location, ContentAttachment
from adventures.serializers import AttachmentSerializer
class AttachmentViewSet(viewsets.ModelViewSet):
@ -10,7 +10,7 @@ class AttachmentViewSet(viewsets.ModelViewSet):
permission_classes = [IsAuthenticated]
def get_queryset(self):
return Attachment.objects.filter(user=self.request.user)
return ContentAttachment.objects.filter(user=self.request.user)
def create(self, request, *args, **kwargs):
if not request.user.is_authenticated:

View file

@ -18,7 +18,7 @@ from django.conf import settings
from adventures.models import (
Location, Collection, Transportation, Note, Checklist, ChecklistItem,
LocationImage, Attachment, Category, Lodging, Visit
ContentImage, ContentAttachment, Category, Lodging, Visit
)
from worldtravel.models import VisitedCity, VisitedRegion, City, Region, Country
@ -347,7 +347,7 @@ class BackupViewSet(viewsets.ViewSet):
user.lodging_set.all().delete()
# Delete location-related data
user.locationimage_set.all().delete()
user.contentimage_set.all().delete()
user.attachment_set.all().delete()
# Visits are deleted via cascade when locations are deleted
user.location_set.all().delete()
@ -487,7 +487,7 @@ class BackupViewSet(viewsets.ViewSet):
for img_data in adv_data.get('images', []):
immich_id = img_data.get('immich_id')
if immich_id:
LocationImage.objects.create(
ContentImage.objects.create(
user=user,
location=location,
immich_id=immich_id,
@ -500,7 +500,7 @@ class BackupViewSet(viewsets.ViewSet):
try:
img_content = zip_file.read(f'images/{filename}')
img_file = ContentFile(img_content, name=filename)
LocationImage.objects.create(
ContentImage.objects.create(
user=user,
location=location,
image=img_file,
@ -517,7 +517,7 @@ class BackupViewSet(viewsets.ViewSet):
try:
att_content = zip_file.read(f'attachments/{filename}')
att_file = ContentFile(att_content, name=filename)
Attachment.objects.create(
ContentAttachment.objects.create(
user=user,
location=location,
file=att_file,

View file

@ -4,14 +4,14 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from django.db.models import Q
from django.core.files.base import ContentFile
from adventures.models import Location, LocationImage
from adventures.serializers import LocationImageSerializer
from adventures.models import Location, ContentImage
from adventures.serializers import ContentImageSerializer
from integrations.models import ImmichIntegration
import uuid
import requests
class AdventureImageViewSet(viewsets.ModelViewSet):
serializer_class = LocationImageSerializer
serializer_class = ContentImageSerializer
permission_classes = [IsAuthenticated]
@action(detail=True, methods=['post'])
@ -34,7 +34,7 @@ class AdventureImageViewSet(viewsets.ModelViewSet):
return Response({"error": "Image is already the primary image"}, status=status.HTTP_400_BAD_REQUEST)
# Set the current primary image to false
LocationImage.objects.filter(location=location, is_primary=True).update(is_primary=False)
ContentImage.objects.filter(location=location, is_primary=True).update(is_primary=False)
# Set the new image to true
instance.is_primary = True
@ -190,7 +190,7 @@ class AdventureImageViewSet(viewsets.ModelViewSet):
return Response({"error": "Invalid location ID"}, status=status.HTTP_400_BAD_REQUEST)
# Updated queryset to include images from locations the user owns OR has shared access to
queryset = LocationImage.objects.filter(
queryset = ContentImage.objects.filter(
Q(location__id=location_uuid) & (
Q(location__user=request.user) | # User owns the location
Q(location__collections__shared_with=request.user) # User has shared access via collection
@ -202,7 +202,7 @@ class AdventureImageViewSet(viewsets.ModelViewSet):
def get_queryset(self):
# Updated to include images from locations the user owns OR has shared access to
return LocationImage.objects.filter(
return ContentImage.objects.filter(
Q(location__user=self.request.user) | # User owns the location
Q(location__collections__shared_with=self.request.user) # User has shared access via collection
).distinct()