diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 5f8b050..9d39bdb 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -6,6 +6,7 @@ services: build: context: . dockerfile: containers/django/Dockerfile + restart: unless-stopped volumes: - .:/code - ./static:/static @@ -19,10 +20,10 @@ services: build: context: . dockerfile: containers/https-portal/Dockerfile + restart: unless-stopped ports: - 80:80 - 443:443 - restart: always environment: DOMAINS: 'tely.st.ie.u-ryukyu.ac.jp -> http://web:8000' STAGE: 'production' @@ -34,6 +35,7 @@ services: build: context: . dockerfile: containers/nginx/Dockerfile + restart: unless-stopped volumes: - ./static:/static ports: diff --git a/main_app/admin.py b/main_app/admin.py index 474edff..40a96ca 100644 --- a/main_app/admin.py +++ b/main_app/admin.py @@ -6,6 +6,8 @@ from .models.notice import Notice, UserNotice from .models.reservation import ReservationParent, ReservationChild +from .models.store import Store + class UserAdmin(BaseUserAdmin): ordering = ('id',) list_display = ('email', 'id', 'is_active', 'password') @@ -43,3 +45,4 @@ class UserActivateTokensAdmin(admin.ModelAdmin): admin.site.register(UserNotice) admin.site.register(ReservationParent) admin.site.register(ReservationChild) +admin.site.register(Store) diff --git a/main_app/call_manager.py b/main_app/call_manager.py index 231506a..b2de45f 100644 --- a/main_app/call_manager.py +++ b/main_app/call_manager.py @@ -44,4 +44,7 @@ def create_gather_response_xml(self, message, action): response += f'' return response - \ No newline at end of file + + def get_balance(self): + balance = self.__client.api.balance.fetch() + return balance.balance diff --git a/main_app/models/store.py b/main_app/models/store.py new file mode 100644 index 0000000..4b29932 --- /dev/null +++ b/main_app/models/store.py @@ -0,0 +1,17 @@ +import uuid +from django.db import models +from django.utils import timezone + +class Store(models.Model): + id = models.UUIDField(primary_key=True, editable=False, blank=False, null=False, default=uuid.uuid4) + place_id = models.CharField(max_length=1000, blank=False, null=False) + name = models.CharField(max_length=1000, blank=False, null=False) + type = models.CharField(max_length=1000, blank=False, null=False) + open = models.CharField(max_length=1000, blank=False, null=False) + photo_reference = models.CharField(max_length=1000, blank=False, null=False) + rating = models.CharField(max_length=10, blank=True, null=True) + price_level = models.CharField(max_length=10, blank=True, null=True) + record_datetime = models.DateTimeField(blank=False, null=False, default=timezone.now) + archive = models.BooleanField(blank=False, null=False, default=False) + recommend = models.BooleanField(blank=False, null=False, default=True) + number_of_reservation = models.PositiveIntegerField(blank=False, null=False, default=0) \ No newline at end of file diff --git a/main_app/store_manager.py b/main_app/store_manager.py index 0ad763f..b6cdf53 100644 --- a/main_app/store_manager.py +++ b/main_app/store_manager.py @@ -176,26 +176,36 @@ def search_store(self, keyword): stores_info = [] for place in search_response['results']: - detail_response = self.get_store_info(place["place_id"]) + store_info = {} try: - store_info = { - "place_id": place["place_id"], - "name": detail_response["name"], - "type": detail_response["types"], - "open": detail_response["opening_hours"]["weekday_text"], - "open_periods": detail_response["opening_hours"]["periods"], - "address": detail_response["formatted_address"], - "tel_number": detail_response["formatted_phone_number"], - "photos": self.get_store_photo_url(detail_response["photos"][0]["photo_reference"]), - "rating": detail_response["rating"], - "url": detail_response["url"] - } - stores_info.append(store_info) - + store_info["place_id"] = place["place_id"] + store_info["name"] = place["name"] except Exception as e: print(e) - pass - + continue + try: + store_info["type"] = place["types"] + except Exception as e: + store_info["type"] = [] + try: + store_info["open"] = place["opening_hours"]["open_now"] + except Exception as e: + store_info["open"] = None + try: + store_info["photos"] = self.get_store_photo_url(place["photos"][0]["photo_reference"]) + except Exception as e: + store_info["photos"] = "" + try: + store_info["rating"] = place["rating"] + except Exception as e: + store_info["rating"] = None + try: + store_info["price_level"] = place["price_level"] + except Exception as e: + store_info["price_level"] = None + + stores_info.append(store_info) + return stores_info def get_store_detail(self,place_id): diff --git a/main_app/views/shop.py b/main_app/views/shop.py index abc0ab4..bf7fa1b 100644 --- a/main_app/views/shop.py +++ b/main_app/views/shop.py @@ -26,6 +26,7 @@ def get_context_data(self, **kwargs): "open":"月〜土 9:00〜Last", "detail_url": f"{reverse('main_app:shop_detail')}", "add_url": f"{reverse('main_app:reservation_add')}", + "rating":float("3.0"), } shop_list.append(shop_detail_test) @@ -36,12 +37,7 @@ def get_context_data(self, **kwargs): detail = {} detail["place_id"] = store_info["place_id"] - detail["img"] = store_info["photos"] detail["name"] = store_info["name"] - detail["address"] = store_info["address"] - detail["tel_number"] = store_info["tel_number"] - detail["detail_url"] = f"{reverse('main_app:shop_detail')}?{urlencode({'place_id': store_info['place_id']})}" - detail["add_url"] = f"{reverse('main_app:reservation_add')}?{urlencode({'place_id': store_info['place_id']})}" store_types = "" for type in store_info["type"]: @@ -62,9 +58,12 @@ def get_context_data(self, **kwargs): pass detail["type"] = store_types - detail["open"] = "" - for hours in store_info["open"]: - detail["open"] += hours + "\n" + detail["open"] = store_info["open"] + detail["img"] = store_info["photos"] + detail["rating"] = float(store_info["rating"]) + detail["price_level"] = store_info["price_level"] + detail["detail_url"] = f"{reverse('main_app:shop_detail')}?{urlencode({'place_id': store_info['place_id']})}" + detail["add_url"] = f"{reverse('main_app:reservation_add')}?{urlencode({'place_id': store_info['place_id']})}" shop_list.append(detail) diff --git a/main_app/views/top.py b/main_app/views/top.py index de92d21..c9587c6 100644 --- a/main_app/views/top.py +++ b/main_app/views/top.py @@ -1,6 +1,78 @@ +from django.urls import reverse from django.views.generic import TemplateView from django.contrib.auth.mixins import LoginRequiredMixin +from urllib.parse import urlencode +from ..models.notice import Notice +from ..models.reservation import ReservationParent,ReservationChild +from ..models.store import Store +from ..store_manager import StoreManager class TopView(LoginRequiredMixin, TemplateView): template_name = 'main_app/index.html' - \ No newline at end of file + + def get_context_data(self, **kwargs): + store_manager = StoreManager() + context = super().get_context_data(**kwargs) + + context["notices"] = Notice.objects.order_by('-datetime').all()[:3] + reservation_parent = ReservationParent.objects.filter(user=self.request.user).order_by("-start_datetime").first() + context["reservation_title"] = reservation_parent.shop_name + context["reservation_id"] = reservation_parent.id + context["reservation_detail_items"] = ReservationChild.objects.filter(parent=reservation_parent).order_by("datetime") + + stores_info = [] + store_info_inner = [] + + for store in Store.objects.filter(archive=False): + store_info = {} + store_info["place_id"] = store.place_id + store_info["name"] = store.name + + store_types = "" + for type in store.type.split(" "): + match type: + case "bakery": + store_types += "パン屋" + ", " + case "bar": + store_types += "バー" + ", " + case "cafe": + store_types += "カフェ" + ", " + case "convenience_store": + store_types += "コンビニ" + ", " + case "food": + store_types += "飲食店" + ", " + case "restaurant": + store_types += "レストラン" + ", " + case _: + pass + + store_info["type"] = store_types + store_info["open"] = store.open + store_info["photo"] = store_manager.get_store_photo_url(store.photo_reference) + store_info["rating"] = store.rating + store_info["price_level"] = store.price_level + store_info["record_datetime"] = store.record_datetime + store_info["add_url"] = f"{reverse('main_app:reservation_add')}?{urlencode({'place_id': store_info['place_id']})}" + store_info["detail_url"] = f"{reverse('main_app:shop_detail')}?{urlencode({'place_id': store_info['place_id']})}" + store_info_inner.append(store_info) + print(store_info_inner) + + if len(store_info_inner) == 2: + stores_info.append(store_info_inner) + store_info_inner = [] + + if len(store_info_inner) >= 1: + stores_info.append(store_info_inner) + + context["stores_info"] = stores_info + + # histories_info = [] + # history_info_inner = [] + + # for history in ReservationParent.objects.all().filter(user=self.request.user).order_by("-start_datetime"): + # history_info = {} + + + # context["histories"] + + return context \ No newline at end of file diff --git a/templates/main_app/base.html b/templates/main_app/base.html index 330113e..ef4b885 100644 --- a/templates/main_app/base.html +++ b/templates/main_app/base.html @@ -121,99 +121,22 @@

{{ notice.title|truncatechars:20 }}

- {% comment %} {% endcomment %} -