Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ヘッダーにお知らせ表示機能を追加 #53

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main_app/models/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class ReservationChild(models.Model):
id = models.UUIDField(primary_key=True, editable=False, blank=False, null=False, default=uuid.uuid4)
parent = models.ForeignKey(ReservationParent, on_delete=models.CASCADE, blank=False, null=False, related_name="reservation_parent")
datetime = models.DateTimeField(blank=False, null=False, default=timezone.now)
status = models.IntegerField(default=0, choices=CHILDSTATUS)
status = models.IntegerField(blank=False, null=False, default=0, choices=CHILDSTATUS)
title = models.CharField(max_length=100, blank=False, null=False, default="No Title")
message = models.TextField(blank=False, null=False, default="No Message")
16 changes: 15 additions & 1 deletion main_app/models/user_notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
from .user import User

class UserNotice(models.Model):
WARNING = 0
DANGER = 1
SUCCESS = 2
PRIMARY = 3

NOTICETYPE = (
(WARNING, 'Warning'),
(DANGER , 'Danger' ),
(SUCCESS, 'Success'),
(PRIMARY, 'Primary'),
)

id = models.UUIDField(primary_key=True, editable=False, blank=False, null=False, default=uuid.uuid4)
datetime = models.DateTimeField(blank=False, null=False, default=timezone.now)
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=False, null=False, related_name="notice_user")
user = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, null=False, related_name="notice_user")
title = models.CharField(max_length=100, blank=False, null=False, default="No Title")
message = models.TextField(blank=False, null=False, default="No Message")
type = models.IntegerField(blank=False, null=False, default=0, choices=NOTICETYPE)
url = models.URLField(blank=True, null=True)
is_check = models.BooleanField(blank=False, null=False, default=False)
Empty file.
11 changes: 11 additions & 0 deletions main_app/templatetags/tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django import template

register = template.Library()

@register.filter
def is_not_check_count(array):
counter = 0
for i in array:
if not i.is_check:
counter += 1
return counter
1 change: 1 addition & 0 deletions tely/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tely',
]

MIDDLEWARE = [
Expand Down
82 changes: 30 additions & 52 deletions templates/main_app/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load static %}
{% load tags %}

<!DOCTYPE html>
<html lang="ja">
Expand Down Expand Up @@ -67,71 +68,49 @@

<a class="nav-link nav-icon" href="#" data-bs-toggle="dropdown">
<i class="bi bi-bell"></i>
{% comment %} <span class="badge bg-primary badge-number">4</span> {% endcomment %}
{% if request.user.notice_user.all|is_not_check_count %}
<span class="badge bg-primary badge-number">{{ request.user.notice_user.all|is_not_check_count }}</span>
{% endif %}
</a><!-- End Notification Icon -->

<ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow notifications">
<li class="dropdown-header">
{% comment %} You have 4 new notifications {% endcomment %}
{% if request.user.notice_user.all|is_not_check_count %}
新しいお知らせが {{ request.user.notice_user.all|is_not_check_count }} 件あります
{% else %}
新しいお知らせはありません
{% endif %}

{% comment %} <a href="#"><span class="badge rounded-pill bg-primary p-2 ms-2">全て見る</span></a> {% endcomment %}
</li>
<li>
<hr class="dropdown-divider">
</li>

{% comment %}
{% for notice in request.user.notice_user.all %}
{% if not notice.is_check %}
<li class="notification-item">
{% if notice.type == 0 %}
<i class="bi bi-exclamation-circle text-warning"></i>
<div>
<h4>Lorem Ipsum</h4>
<p>Quae dolorem earum veritatis oditseno</p>
<p>30 min. ago</p>
</div>
</li>

<li>
<hr class="dropdown-divider">
</li>

<li class="notification-item">
{% elif notice.type == 1 %}
<i class="bi bi-x-circle text-danger"></i>
<div>
<h4>Atque rerum nesciunt</h4>
<p>Quae dolorem earum veritatis oditseno</p>
<p>1 hr. ago</p>
</div>
</li>

<li>
<hr class="dropdown-divider">
</li>

<li class="notification-item">
{% elif notice.type == 2 %}
<i class="bi bi-check-circle text-success"></i>
{% elif notice.type == 3 %}
<i class="bi bi-info-circle text-primary"></i>
{% endif %}
<div>
<h4>Sit rerum fuga</h4>
<p>Quae dolorem earum veritatis oditseno</p>
<p>2 hrs. ago</p>
<h4>{{ notice.title }}</h4>
<p>{{ notice.message }}</p>
<p>{{ notice.datetime }}</p>
</div>
</li>

<li>
<hr class="dropdown-divider">
</li>

<li class="notification-item">
<i class="bi bi-info-circle text-primary"></i>
<div>
<h4>Dicta reprehenderit</h4>
<p>Quae dolorem earum veritatis oditseno</p>
<p>4 hrs. ago</p>
</div>
</li>

<li>
<hr class="dropdown-divider">
</li> {% endcomment %}
{% endif %}
{% endfor %}

<li class="dropdown-footer">
<a href="#">全てのお知らせを見る</a>
</li>
Expand All @@ -140,24 +119,23 @@ <h4>Dicta reprehenderit</h4>

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

<li class="nav-item dropdown">
{% 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>
{% comment %} <span class="badge bg-success badge-number">3</span> {% endcomment %}
<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">
{% comment %} You have 3 new messages {% endcomment %}
新しいメッセージはありません
{% comment %} <a href="#"><span class="badge rounded-pill bg-primary p-2 ms-2">全て見る</span></a> {% endcomment %}
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>

{% comment %}

<li class="message-item">
<a href="#">
<img src="{% static 'img/messages-1.jpg' %}" alt="" class="rounded-circle">
Expand Down Expand Up @@ -198,15 +176,15 @@ <h4>David Muldon</h4>
</li>
<li>
<hr class="dropdown-divider">
</li> {% endcomment %}
</li>

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

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

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

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

Expand Down