Skip to content

Commit

Permalink
#43 コード整形.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Sep 7, 2024
1 parent 6edbbd0 commit 0975a7f
Show file tree
Hide file tree
Showing 118 changed files with 5,477 additions and 4,522 deletions.
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## 変更内容

- なにか

## 変更理由

- なにか

## 動作確認

1. hogehoge1
2. hogehoge2
3. hogehoge3
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ urllib3 = "==2.*"
"zope.interface" = "==7.*"

[dev-packages]
black = "*"
ruff = "*"
ruff-lsp = "*"

[requires]
python_version = "3.12"
105 changes: 60 additions & 45 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# dsbd

Home NOC Dashboard

[![Publish Docker image(dev)](https://github.com/homenoc/dsbd/actions/workflows/build-dev.yaml/badge.svg)](https://github.com/homenoc/dsbd/actions/workflows/build-dev.yaml)
[![Publish Docker image(prod)](https://github.com/homenoc/dsbd/actions/workflows/build-prod.yaml/badge.svg)](https://github.com/homenoc/dsbd/actions/workflows/build-prod.yaml)

### develop environment

```
Expand Down
54 changes: 31 additions & 23 deletions custom_admin/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
import json

from asgiref.sync import sync_to_async
from channels.generic.websocket import AsyncWebsocketConsumer
from django.conf import settings
from django.utils import timezone
from pytz import timezone

from ticket.consumers import ChatConsumer
from ticket.models import Ticket, Chat
from ticket.models import Chat, Ticket


@sync_to_async()
Expand Down Expand Up @@ -44,18 +42,24 @@ async def receive(self, text_data=None, bytes_data=None):
await self.add_chat(message)

time_format = "%Y/%m/%d %H:%M:%S"
time = datetime.datetime.now(tz=datetime.timezone.utc if settings.USE_TZ else None).astimezone(
timezone(settings.TIME_ZONE)).strftime(time_format)

await self.channel_layer.group_send(self.chat_group_name, {
"type": "broadcast_message",
"time": time,
"user_id": self.user.id,
"username": self.user.username,
"group": 0,
"message": message,
"is_admin": True
})
time = (
datetime.datetime.now(tz=datetime.timezone.utc if settings.USE_TZ else None)
.astimezone(timezone(settings.TIME_ZONE))
.strftime(time_format)
)

await self.channel_layer.group_send(
self.chat_group_name,
{
"type": "broadcast_message",
"time": time,
"user_id": self.user.id,
"username": self.user.username,
"group": 0,
"message": message,
"is_admin": True,
},
)

async def broadcast_message(self, event):
time = event["time"]
Expand All @@ -65,11 +69,15 @@ async def broadcast_message(self, event):
message = event["message"]
is_admin = event["is_admin"]

await self.send(text_data=json.dumps({
"time": time,
"user_id": user_id,
"username": username,
"group": group,
"message": message,
"is_admin": is_admin
}))
await self.send(
text_data=json.dumps(
{
"time": time,
"user_id": user_id,
"username": username,
"group": group,
"message": message,
"is_admin": is_admin,
}
)
)
3 changes: 2 additions & 1 deletion custom_admin/routing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import path

from . import consumers

urlpatterns = [
path('ws/admin/custom/ticket/<int:ticket_id>/chat', consumers.AdminChatConsumer.as_asgi()),
path("ws/admin/custom/ticket/<int:ticket_id>/chat", consumers.AdminChatConsumer.as_asgi()),
]
2 changes: 1 addition & 1 deletion custom_admin/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import path, include
from django.urls import path

from . import views

Expand Down
18 changes: 7 additions & 11 deletions custom_admin/views.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
import json

from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
from django.core.paginator import EmptyPage, InvalidPage, Paginator
from django.shortcuts import render, redirect
from django.shortcuts import redirect, render

from ticket.models import Ticket


@login_required
@staff_member_required
def index(request):
context = {
"tickets": Ticket.objects.all()
}
context = {"tickets": Ticket.objects.all()}
return render(request, "custom_admin/index.html", context)


@login_required
@staff_member_required
def ticket_list(request):
if request.method == 'POST':
id = request.POST.get('id', 0)
if request.method == "POST":
id = request.POST.get("id", 0)
ticket = Ticket.objects.get(id=int(id))
if "no_solved" in request.POST:
ticket.is_solved = False
ticket.save()
elif "solved" in request.POST:
ticket.is_solved = True
ticket.save()
return redirect('/admin/custom/ticket')
return redirect("/admin/custom/ticket")

is_solved = request.GET.get('is_solved', "false")
is_solved = request.GET.get("is_solved", "false")
ticket_objects = Ticket.objects.filter(is_solved=True if is_solved == "true" else False)

paginator = Paginator(ticket_objects, int(request.GET.get("per_page", "5")))
Expand All @@ -53,5 +49,5 @@ def chat(request, ticket_id):
ticket = Ticket.objects.get(id=ticket_id)
if not ticket:
return render(request, "ticket/chat_error.html", {})
context = {"ticket": ticket, "chats": ticket.chat_set.order_by('created_at').all()}
context = {"ticket": ticket, "chats": ticket.chat_set.order_by("created_at").all()}
return render(request, "custom_admin/ticket/chat.html", context)
Loading

0 comments on commit 0975a7f

Please sign in to comment.