From f4f2aa3711d3bb0ff105974d3ebba0a4d0083df3 Mon Sep 17 00:00:00 2001 From: aptarr_ Date: Sun, 16 Jun 2024 22:55:52 +0700 Subject: [PATCH] style: reformat code --- app/landmark/admin.py | 4 ++-- app/landmark/models.py | 6 +++--- app/landmark/serializers.py | 28 ++++++++++++++++------------ app/landmark/views.py | 2 +- views.py | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/landmark/admin.py b/app/landmark/admin.py index dd740d3..7ccc4f7 100644 --- a/app/landmark/admin.py +++ b/app/landmark/admin.py @@ -1,9 +1,9 @@ from django.contrib import admin from .models import ( - Language, Landmark, LandmarkContent, + Language, Location, OpeningHour, PhotoLandmark, @@ -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) diff --git a/app/landmark/models.py b/app/landmark/models.py index aa62c84..e764a4c 100644 --- a/app/landmark/models.py +++ b/app/landmark/models.py @@ -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) @@ -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() @@ -44,7 +44,7 @@ class LandmarkContent(models.Model): def __str__(self): return self.description - + class PhotoLandmark(models.Model): photo_url = models.URLField() diff --git a/app/landmark/serializers.py b/app/landmark/serializers.py index 6fda91f..48a804a 100644 --- a/app/landmark/serializers.py +++ b/app/landmark/serializers.py @@ -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): @@ -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 @@ -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 diff --git a/app/landmark/views.py b/app/landmark/views.py index ca9e247..e834fe0 100644 --- a/app/landmark/views.py +++ b/app/landmark/views.py @@ -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}) diff --git a/views.py b/views.py index ca9e247..e834fe0 100644 --- a/views.py +++ b/views.py @@ -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})