Skip to content

Commit

Permalink
style: reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
aptarr committed Jun 16, 2024
1 parent 4596e81 commit f4f2aa3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/landmark/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.contrib import admin

from .models import (
Language,
Landmark,
LandmarkContent,
Language,
Location,
OpeningHour,
PhotoLandmark,
Expand Down Expand Up @@ -37,7 +37,7 @@ class LandmarkContentAdmin(admin.ModelAdmin):
# Register your models here.
admin.site.register(Landmark, LandmarkAdmin)
admin.site.register(Language)
admin.site.register(LandmarkContent,LandmarkContentAdmin)
admin.site.register(LandmarkContent, LandmarkContentAdmin)
admin.site.register(Location)
admin.site.register(OpeningHour)
admin.site.register(PhotoLandmark)
Expand Down
6 changes: 3 additions & 3 deletions app/landmark/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Language(models.Model):
def __str__(self):
return self.name


class Landmark(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
Expand All @@ -30,7 +30,7 @@ class Landmark(models.Model):
def __str__(self):
return self.name


class LandmarkContent(models.Model):
id = models.AutoField(primary_key=True)
description = models.TextField()
Expand All @@ -44,7 +44,7 @@ class LandmarkContent(models.Model):

def __str__(self):
return self.description


class PhotoLandmark(models.Model):
photo_url = models.URLField()
Expand Down
28 changes: 16 additions & 12 deletions app/landmark/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from rest_framework import serializers

from .models import Landmark, Location, LandmarkContent, Language
from .models import Landmark, LandmarkContent, Language, Location


class LandmarkListSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -72,13 +72,13 @@ def get_ticket_prices(self, obj):

def get_contact_info(self, obj):
return {"phone": obj.phone, "email": obj.email, "website": obj.website}

def get_description(self, obj):
request = self.context["request"]
accept_language_header = request.headers.get('Accept-Language')
accept_language_header = request.headers.get("Accept-Language")

user_language = "English"

user_language = 'English'

if accept_language_header:
user_language = accept_language_header

Expand All @@ -88,27 +88,31 @@ def get_description(self, obj):
language = Language.objects.get(id=1)

try:
landmark_content = LandmarkContent.objects.get(landmark=obj, language=language)
landmark_content = LandmarkContent.objects.get(
landmark=obj, language=language
)
return landmark_content.description
except LandmarkContent.DoesNotExist:
return None

def get_history(self, obj):
request = self.context["request"]
accept_language_header = request.headers.get('Accept-Language')
accept_language_header = request.headers.get("Accept-Language")

user_language = 'English'
user_language = "English"

if accept_language_header:
user_language = accept_language_header
user_language = accept_language_header

try:
language = Language.objects.get(name=user_language)
except Language.DoesNotExist:
language = Language.objects.get(id=1)

try:
landmark_content = LandmarkContent.objects.get(landmark=obj, language=language)
landmark_content = LandmarkContent.objects.get(
landmark=obj, language=language
)
return landmark_content.history
except LandmarkContent.DoesNotExist:
return None
Expand Down
2 changes: 1 addition & 1 deletion app/landmark/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def get(self, request, pk):
except Landmark.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

serializer = LandmarkDetailSerializer(landmark, context={'request': request})
serializer = LandmarkDetailSerializer(landmark, context={"request": request})
return Response({"landmark": serializer.data})
2 changes: 1 addition & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def get(self, request, pk):
except Landmark.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

serializer = LandmarkDetailSerializer(landmark, context={'request': request})
serializer = LandmarkDetailSerializer(landmark, context={"request": request})
return Response({"landmark": serializer.data})

0 comments on commit f4f2aa3

Please sign in to comment.