From 6534b172e2abc679621c47a90f28c1bbfd1a5470 Mon Sep 17 00:00:00 2001 From: yoneyan Date: Mon, 9 Sep 2024 01:40:19 +0900 Subject: [PATCH] =?UTF-8?q?#43=20=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=AB=E9=96=A2=E3=81=99=E3=82=8B=E6=83=85=E5=A0=B1=E3=82=92?= =?UTF-8?q?=E3=83=88=E3=83=83=E3=83=97=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=AB?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=AA=E3=81=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0005_alter_group_status.py | 18 ++++ custom_auth/models.py | 2 +- custom_auth/signals.py | 61 +++-------- custom_auth/tool.py | 42 ++++++++ dsbd/templates/home.html | 40 ++++--- dsbd/views.py | 3 + ticket/signals.py | 102 ++---------------- ticket/tool.py | 85 +++++++++++++++ 8 files changed, 194 insertions(+), 159 deletions(-) create mode 100644 custom_auth/migrations/0005_alter_group_status.py create mode 100644 ticket/tool.py diff --git a/custom_auth/migrations/0005_alter_group_status.py b/custom_auth/migrations/0005_alter_group_status.py new file mode 100644 index 0000000..e3ff3af --- /dev/null +++ b/custom_auth/migrations/0005_alter_group_status.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.1 on 2024-09-08 15:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('custom_auth', '0004_group_users_alter_user_groups'), + ] + + operations = [ + migrations.AlterField( + model_name='group', + name='status', + field=models.IntegerField(choices=[(1, '有効'), (10, 'ユーザより廃止'), (11, '運営委員より廃止'), (12, '審査落ち')], default=1, verbose_name='ステータス'), + ), + ] diff --git a/custom_auth/models.py b/custom_auth/models.py index e99803b..124bfbf 100644 --- a/custom_auth/models.py +++ b/custom_auth/models.py @@ -80,7 +80,7 @@ class Group(models.Model): # noqa: F811 name = models.CharField("name", max_length=150, unique=True) name_jp = models.CharField("name(japanese)", max_length=150, unique=True) comment = models.CharField("comment", max_length=250, default="", blank=True) - status = models.IntegerField("ステータス", default=0, choices=GROUP_STATUS_CHOICES) + status = models.IntegerField("ステータス", default=1, choices=GROUP_STATUS_CHOICES) allow_service_add = models.BooleanField("サービス追加許可", default=False) membership_type = models.IntegerField("会員種別", default=1, choices=MEMBERSHIP_TYPE_CHOICES) membership_expired_at = models.DateTimeField("有効期限", blank=True, null=True) diff --git a/custom_auth/signals.py b/custom_auth/signals.py index ebee9de..696fd53 100644 --- a/custom_auth/signals.py +++ b/custom_auth/signals.py @@ -1,7 +1,8 @@ from django.db.models.signals import post_save, pre_delete, pre_save from django.dispatch import receiver -from custom_auth.models import User +from custom_auth.models import Group, User +from custom_auth.tool import SignalTool from dsbd.notify import notify_db_save @@ -16,58 +17,26 @@ def user_model_pre_save(sender, instance, **kwargs): @receiver(post_save, sender=User) def post_user(sender, instance, created, **kwargs): if created: - text = get_create_user(True, instance) + text = SignalTool().get_create_user(True, instance) notify_db_save(table_name="User", type=0, data=text) else: - text = get_update_user(instance._pre_save_instance, instance) + text = SignalTool().get_update_user(instance._pre_save_instance, instance) notify_db_save(table_name="User", type=1, data=text) @receiver(pre_delete, sender=User) def delete_user(sender, instance, **kwargs): - text = get_create_user(False, instance) + text = SignalTool().get_create_user(False, instance) notify_db_save(table_name="User", type=2, data=text) -def get_create_user(short, instance): - text = "--%d[%s]--\n" % ( - instance.id, - instance.username, - ) - return text if not short else text + "有効: %r\nE-Mail: %s\n" % (instance.is_active, instance.email) - - -def get_update_user(before, after): - text = "%s----更新状況----\n" % (get_create_user(True, before),) - if before.username != after.username: - text += "username: %s => %s\n" % (before.username, after.username) - if before.username_jp != after.username_jp: - text += "username(jp): %s => %s\n" % (before.username, after.username) - if before.email != after.email: - text += "E-Mail: %s => %s\n" % (before.email, after.email) - if before.is_active != after.is_active: - text += "有効: %r => %r\n" % (before.is_active, after.is_active) - text += "------------\n" - return text - - -def get_create_signup_key(short, instance): - text = "--%d[%s]--\n" % ( - instance.id, - instance.key, - ) - return text if not short else text + "利用済み: %r\n有効期限: %s\n" % (instance.is_used, instance.expired_at) - - -def get_update_signup_key(before, after): - text = "%s----更新状況----\n" % (get_create_signup_key(True, before),) - if before.key != after.key: - text += "key: %s => %s\n" % (before.key, after.key) - if before.is_used != after.is_used: - text += "使用済み: %r => %r\n" % (before.is_used, after.is_used) - if before.expired_at != after.expired_at: - text += "有効期限: %s => %s\n" % (before.expired_at, after.expired_at) - if before.comment != after.comment: - text += "comment: %r => %r\n" % (before.comment, after.comment) - text += "------------\n" - return text +@receiver(post_save, sender=Group) +def update_group(sender, instance, created, **kwargs): + # 審査OKステータス変更時にサービス追加許可にする + if instance.is_pass and not instance.allow_service_add: + instance.allow_service_add = True + instance.save(update_fields=["allow_service_add"]) + # 審査NGステータス変更時にサービス追加拒否設定にする + if not instance.is_pass and instance.allow_service_add: + instance.allow_service_add = False + instance.save(update_fields=["allow_service_add"]) diff --git a/custom_auth/tool.py b/custom_auth/tool.py index 0b85aeb..5a489a8 100644 --- a/custom_auth/tool.py +++ b/custom_auth/tool.py @@ -5,3 +5,45 @@ def random_string(num): random_list = [random.choice(string.ascii_letters + string.digits) for i in range(num)] return "".join(random_list) + + +class SignalTool: + def get_create_user(self, short, instance): + text = "--%d[%s]--\n" % ( + instance.id, + instance.username, + ) + return text if not short else text + "有効: %r\nE-Mail: %s\n" % (instance.is_active, instance.email) + + def get_update_user(self, before, after): + text = "%s----更新状況----\n" % (self.get_create_user(True, before),) + if before.username != after.username: + text += "username: %s => %s\n" % (before.username, after.username) + if before.username_jp != after.username_jp: + text += "username(jp): %s => %s\n" % (before.username, after.username) + if before.email != after.email: + text += "E-Mail: %s => %s\n" % (before.email, after.email) + if before.is_active != after.is_active: + text += "有効: %r => %r\n" % (before.is_active, after.is_active) + text += "------------\n" + return text + + def get_create_signup_key(self, short, instance): + text = "--%d[%s]--\n" % ( + instance.id, + instance.key, + ) + return text if not short else text + "利用済み: %r\n有効期限: %s\n" % (instance.is_used, instance.expired_at) + + def get_update_signup_key(self, before, after): + text = "%s----更新状況----\n" % (self.get_create_signup_key(True, before),) + if before.key != after.key: + text += "key: %s => %s\n" % (before.key, after.key) + if before.is_used != after.is_used: + text += "使用済み: %r => %r\n" % (before.is_used, after.is_used) + if before.expired_at != after.expired_at: + text += "有効期限: %s => %s\n" % (before.expired_at, after.expired_at) + if before.comment != after.comment: + text += "comment: %r => %r\n" % (before.comment, after.comment) + text += "------------\n" + return text diff --git a/dsbd/templates/home.html b/dsbd/templates/home.html index 49a4c1c..7d74a11 100644 --- a/dsbd/templates/home.html +++ b/dsbd/templates/home.html @@ -17,24 +17,32 @@

お知らせ

-
-
-
Warning card title
-

Some quick example text to build on - the card title and make up the - bulk of the card's content.

+ {% if request.user.groups.count == 0 %} +
+
+
グループの新規申請手続き
+

グループの新規申請手続きを行ってください

+ 申請はこちらから +
-
+ {% endif %} + {% if is_new_group_request %} +
+
+
グループの申請処理中
+

現在、グループの申請処理中です。
この作業には時間が掛かる可能性があります。

+
+
+ {% endif %} {% for notice in notices %}
- {{ notice.start_at }}~ - {% if notice.end_at != None %} - {{ notice.end_at }}{% else %} - 無期限{% endif %} - + {{ notice.start_at }} ~ + {% if notice.end_at != None %}{{ notice.end_at }}{% else %} + 無期限{% endif %} + {% if notice.is_info %} 情報 {% endif %} @@ -60,10 +68,8 @@
{{ notice.title }}