Skip to content

Commit

Permalink
Merge pull request #93 from crab85193/dev_crab
Browse files Browse the repository at this point in the history
バグ修正
  • Loading branch information
crab85193 authored Dec 14, 2023
2 parents 8985d30 + a929d05 commit 2cfbc58
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 548 deletions.
4 changes: 3 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
build:
context: .
dockerfile: containers/django/Dockerfile
restart: unless-stopped
volumes:
- .:/code
- ./static:/static
Expand All @@ -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'
Expand All @@ -34,6 +35,7 @@ services:
build:
context: .
dockerfile: containers/nginx/Dockerfile
restart: unless-stopped
volumes:
- ./static:/static
ports:
Expand Down
3 changes: 3 additions & 0 deletions main_app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -43,3 +45,4 @@ class UserActivateTokensAdmin(admin.ModelAdmin):
admin.site.register(UserNotice)
admin.site.register(ReservationParent)
admin.site.register(ReservationChild)
admin.site.register(Store)
5 changes: 4 additions & 1 deletion main_app/call_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ def create_gather_response_xml(self, message, action):
response += f'</Response>'

return response


def get_balance(self):
balance = self.__client.api.balance.fetch()
return balance.balance
17 changes: 17 additions & 0 deletions main_app/models/store.py
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 27 additions & 17 deletions main_app/store_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 7 additions & 8 deletions main_app/views/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]:
Expand All @@ -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)

Expand Down
74 changes: 73 additions & 1 deletion main_app/views/top.py
Original file line number Diff line number Diff line change
@@ -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'


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
81 changes: 2 additions & 79 deletions templates/main_app/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,99 +121,22 @@ <h4>{{ notice.title|truncatechars:20 }}</h4>

</li><!-- End Notification Nav -->

{% comment %} <li class="nav-item dropdown">

<a class="nav-link nav-icon" href="#" data-bs-toggle="dropdown">
<i class="bi bi-chat-left-text"></i>
<span class="badge bg-success badge-number">3</span>
</a><!-- End Messages Icon -->

<ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow messages">
<li class="dropdown-header">
You have 3 new messages
<a href="#"><span class="badge rounded-pill bg-primary p-2 ms-2">全て見る</span></a>
</li>
<li>
<hr class="dropdown-divider">
</li>


<li class="message-item">
<a href="#">
<img src="{% static 'img/messages-1.jpg' %}" alt="" class="rounded-circle">
<div>
<h4>Maria Hudson</h4>
<p>Velit asperiores et ducimus soluta repudiandae labore officia est ut...</p>
<p>4 hrs. ago</p>
</div>
</a>
</li>
<li>
<hr class="dropdown-divider">
</li>

<li class="message-item">
<a href="#">
<img src="{% static 'img/messages-2.jpg' %}" alt="" class="rounded-circle">
<div>
<h4>Anna Nelson</h4>
<p>Velit asperiores et ducimus soluta repudiandae labore officia est ut...</p>
<p>6 hrs. ago</p>
</div>
</a>
</li>
<li>
<hr class="dropdown-divider">
</li>

<li class="message-item">
<a href="#">
<img src="{% static 'img/messages-3.jpg' %}" alt="" class="rounded-circle">
<div>
<h4>David Muldon</h4>
<p>Velit asperiores et ducimus soluta repudiandae labore officia est ut...</p>
<p>8 hrs. ago</p>
</div>
</a>
</li>
<li>
<hr class="dropdown-divider">
</li>

<li class="dropdown-footer">
<a href="#">全てのメッセージを見る</a>
</li>

</ul><!-- End Messages Dropdown Items -->

</li><!-- End Messages Nav --> {% endcomment %}

<li class="nav-item dropdown pe-3">

<a class="nav-link nav-profile d-flex align-items-center pe-0" href="#" data-bs-toggle="dropdown">
<img src="{% static 'img/profile-img.jpg' %}" alt="Profile" class="rounded-circle">
<span class="d-none d-md-block dropdown-toggle ps-2">{{ request.user.username }}</span>
<span class="d-none d-md-block dropdown-toggle ps-2">{{ request.user.username }}{% if request.user.is_superuser %}(ADMIN){% endif %}</span>
</a><!-- End Profile Iamge Icon -->

<ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow profile">
<li class="dropdown-header">
<h6>{{ request.user.username }}</h6>
<h6>{{ request.user.username }} {% if request.user.is_superuser %}(ADMIN){% endif %}</h6>
{% comment %} <span>Web Designer</span> {% endcomment %}
</li>
<li>
<hr class="dropdown-divider">
</li>

{% comment %} <li>
<a class="dropdown-item d-flex align-items-center" href="users-profile.html">
<i class="bi bi-person"></i>
<span>My Profile</span>
</a>
</li>
<li>
<hr class="dropdown-divider">
</li> {% endcomment %}

<li>
<a class="dropdown-item d-flex align-items-center" href="{% url 'main_app:user_settings' %}">
<i class="bi bi-gear"></i>
Expand Down
Loading

0 comments on commit 2cfbc58

Please sign in to comment.