From 7acdd8265e504c6539fee3ecddd241cf253d8757 Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Fri, 26 Jul 2024 13:22:37 +0900 Subject: [PATCH 01/10] =?UTF-8?q?#72=20Feat:=20Debug=20Toolbar=20=EC=84=A4?= =?UTF-8?q?=EC=B9=98=20=EB=B0=8F=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wtnt/wtnt/settings.py | 3 +++ wtnt/wtnt/urls.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/wtnt/wtnt/settings.py b/wtnt/wtnt/settings.py index 528dfbd..71616de 100644 --- a/wtnt/wtnt/settings.py +++ b/wtnt/wtnt/settings.py @@ -86,6 +86,7 @@ ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_AUTHENTICATION_METHOD = "email" +INTERNAL_IPS = ["127.0.0.1", "localhost"] # Application definition @@ -112,6 +113,7 @@ "celery", "django_celery_beat", "django_celery_results", + "debug_toolbar", ] MIDDLEWARE = [ @@ -126,6 +128,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", "allauth.account.middleware.AccountMiddleware", "core.middleware.AttachJWTFromHeaderToCookieMiddleware", + "debug_toolbar.middleware.DebugToolbarMiddleware", ] ROOT_URLCONF = "wtnt.urls" diff --git a/wtnt/wtnt/urls.py b/wtnt/wtnt/urls.py index 9733d17..d46e5ae 100644 --- a/wtnt/wtnt/urls.py +++ b/wtnt/wtnt/urls.py @@ -14,6 +14,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings from django.contrib import admin from django.urls import path, include, re_path @@ -41,3 +42,10 @@ path("api/", include("admin.urls")), path("admin/", admin.site.urls), ] + +if settings.DEBUG: + import debug_toolbar + + urlpatterns.append( + re_path(r"^__debug__/", include(debug_toolbar.urls)), + ) From 77b1c190ffbe511126fd97f248cc5199a285413a Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 10:24:11 +0900 Subject: [PATCH 02/10] #72 Docs: Update requirements.txt --- requirements.txt | Bin 3692 -> 3886 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index bfbda812e6e968a71c415270e91405e436eba746..03a8021f9bdd69231f949b04a55408c34608268d 100644 GIT binary patch delta 173 zcmaDOvrcY95sP{XLn=cOLn%W#gDyh}Lp~7Z0QrdwMGUq;Xu_Ze#%7b_S#kx7fofA3 zQou3>KpEr78=1v7pJ7p8lyn1X$p%V7v>7p&0i{7o3^qS!^<|MRW~gLH2AW*}w8sdn m-v}sa3BsFoxqdQ9f~4{pih;NY=nRn6hCoR}pniE?Uq%2w Date: Thu, 1 Aug 2024 10:25:14 +0900 Subject: [PATCH 03/10] =?UTF-8?q?#72=20Feat:=20=ED=8C=80=20=EB=8D=94?= =?UTF-8?q?=EB=AF=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A3=BC=EC=9E=85=20?= =?UTF-8?q?=EC=BB=A4=EB=A7=A8=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Team, TeamUser, TeamTech에 연속적으로 데이터가 들어간다 --- wtnt/team/management/__init__.py | 0 wtnt/team/management/commands/create_team.py | 95 ++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 wtnt/team/management/__init__.py create mode 100644 wtnt/team/management/commands/create_team.py diff --git a/wtnt/team/management/__init__.py b/wtnt/team/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wtnt/team/management/commands/create_team.py b/wtnt/team/management/commands/create_team.py new file mode 100644 index 0000000..55017b8 --- /dev/null +++ b/wtnt/team/management/commands/create_team.py @@ -0,0 +1,95 @@ +from django.core.management.base import BaseCommand, CommandParser, CommandError +from team.models import Team, TeamUser, TeamTech +from user.models import CustomUser +from django_seed import Seed +from faker import Faker + +from itertools import cycle +import random +import uuid + + +class Command(BaseCommand): + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("--number", default=1, type=int, help="추가하려고 하는 팀의 수, 최대 100개까지") + + def handle(self, *args, **options): + faker = Faker("ko_KR") + number = options.get("number") + if number > 100: + raise CommandError("number의 최대 인풋은 100입니다.") + seeder = Seed.seeder() + genres = ["웹", "앱", "게임"] + leader_ids = [CustomUser.objects.order_by("?").first() for _ in range(number)] + leader_cycle = cycle(leader_ids) + + seeder.add_entity( + Team, + number, + { + "leader": lambda x: next(leader_cycle), + "title": lambda x: faker.catch_phrase(), + "explain": lambda x: faker.catch_phrase().encode(), + "uuid": lambda x: uuid.uuid4(), + "genre": lambda x: random.choice(genres), + "like": 0, + "view": 0, + "version": 0, + "url": lambda x: faker.url().encode(), + "is_approved": True, + "is_accomplished": False, + "image": "https://wtnt-bucket.s3.ap-northeast-2.amazonaws.com/default/", + }, + ) + + team_ids = seeder.execute()[Team] + team_objects = Team.objects.filter(id__in=team_ids) + team_cycle = cycle(team_objects) + + seeder.add_entity( + TeamUser, + number, + { + "user": lambda x: next(leader_cycle), + "team": lambda x: next(team_cycle), + "tech": "팀장", + }, + ) + + seeder.execute() + + categories = [ + "웹", + "IOS", + "안드로이드", + "크로스플랫폼", + "자바", + "파이썬", + "노드", + "UI/UX 기획", + "게임 기획", + "컨텐츠 기획", + "프로젝트 매니저", + "유니티", + "언리얼", + "딥러닝", + "머신러닝", + "데이터 엔지니어", + "게임 그래픽 디자인", + "UI/UX 디자인", + ] + + seeder.add_entity( + TeamTech, + number, + { + "current_num": 0, + "need_num": lambda x: random.randint(1, 10), + "team": lambda x: next(team_cycle), + "tech": lambda x: random.choice(categories), + }, + ) + + seeder.execute() + + self.stdout.write(self.style.SUCCESS(f"{number}개의 더미 팀 생성 완료. 팀 ID: {team_ids}")) From baba5180c7061fac0ace998391322b4c77eaba24 Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 10:25:32 +0900 Subject: [PATCH 04/10] =?UTF-8?q?#72=20Feat:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EB=8D=94=EB=AF=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=20=EC=BB=A4=EB=A7=A8=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wtnt/user/management/__init__.py | 0 wtnt/user/management/commands/create_user.py | 41 ++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 wtnt/user/management/__init__.py create mode 100644 wtnt/user/management/commands/create_user.py diff --git a/wtnt/user/management/__init__.py b/wtnt/user/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wtnt/user/management/commands/create_user.py b/wtnt/user/management/commands/create_user.py new file mode 100644 index 0000000..59519cb --- /dev/null +++ b/wtnt/user/management/commands/create_user.py @@ -0,0 +1,41 @@ +from django.core.management.base import BaseCommand, CommandParser +from user.models import CustomUser +from django_seed import Seed +from faker import Faker +import random + + +class Command(BaseCommand): + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("--number", default=1, type=int, help="추가하려고 하는 유저의 수") + + def handle(self, *args, **options): + faker = Faker("ko_KR") + number = options.get("number") + seeder = Seed.seeder() + positions = ["백엔드", "프론트엔드", "AI", "디자이너"] + + seeder.add_entity( + CustomUser, + number, + { + "email": lambda x: faker.unique.email(), + "social_id": lambda x: faker.unique.random_number(digits=9, fix_len=True), + "name": lambda x: faker.name(), + "student_num": lambda x: faker.unique.random_number(digits=9, fix_len=True), + "position": lambda x: random.choice(positions), + "explain": "열심히 하겠습니다!", + "university": "부경대학교", + "club": "WAP", + "password": "password", + "is_superuser": False, + "is_approved": True, + "is_active": True, + "is_staff": False, + "image": "default/", + }, + ) + + seeder.execute() + + self.stdout.write(self.style.SUCCESS(f"{number}명의 더미 유저 생성 완료.")) From f2c43b6def8a583aea289540dd77e04a064a1663 Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 10:26:07 +0900 Subject: [PATCH 05/10] =?UTF-8?q?#72=20Feat:=20settings=EC=97=90=20django?= =?UTF-8?q?=5Fseed=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wtnt/wtnt/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wtnt/wtnt/settings.py b/wtnt/wtnt/settings.py index 71616de..66e49f8 100644 --- a/wtnt/wtnt/settings.py +++ b/wtnt/wtnt/settings.py @@ -114,6 +114,7 @@ "django_celery_beat", "django_celery_results", "debug_toolbar", + "django_seed", ] MIDDLEWARE = [ From d21a28cec3eb851afa86109b79167012186dd7ac Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 10:56:25 +0900 Subject: [PATCH 06/10] =?UTF-8?q?#72=20Feat:=20=ED=8C=80=20=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=8B=A0=EC=B2=AD=20=EB=8D=94=EB=AF=B8=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=A3=BC=EC=9E=85=20=EC=BB=A4=EB=A7=A8?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/create_team_apply.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 wtnt/team/management/commands/create_team_apply.py diff --git a/wtnt/team/management/commands/create_team_apply.py b/wtnt/team/management/commands/create_team_apply.py new file mode 100644 index 0000000..6cca58f --- /dev/null +++ b/wtnt/team/management/commands/create_team_apply.py @@ -0,0 +1,45 @@ +from django.core.management.base import BaseCommand, CommandParser, CommandError +from django.db import IntegrityError +from team.models import TeamApply, Team, TeamTech +from user.models import CustomUser +from django_seed import Seed + +import random + + +class Command(BaseCommand): + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("--number", default=1, type=int, help="추가하려고 하는 가입 신청의 수, 최대 100개까지") + + def handle(self, *args, **options): + number = options.get("number") + if number > 100: + raise CommandError("number의 최대 인풋은 100입니다.") + seeder = Seed.seeder() + + for _ in range(number): + team = Team.objects.order_by("?").first() + user = CustomUser.objects.order_by("?").first() + tech_list = TeamTech.objects.filter(team_id=team.id).values_list("tech", flat=True) + seeder.add_entity( + TeamApply, + 1, + { + "team": team, + "user": user, + "bio": "열심히 하겠습니다", + "is_approved": False, + "tech": random.choice(tech_list), + }, + ) + + try: + seeder.execute() + except IntegrityError: + print(f"중복된 데이터 발생, 예상 데이터 주입 개수 {number-1}개") + number -= 1 + continue + if number: + self.stdout.write(self.style.SUCCESS(f"{number}개의 더미 팀 가입신청 생성 완료")) + else: + self.stdout.write(self.style.ERROR("데이터 주입 실패")) From 09b05603fbd291c227d8ddfe692e2f21370cfa51 Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 10:56:47 +0900 Subject: [PATCH 07/10] =?UTF-8?q?#72=20Feat:=20=ED=8C=80=EC=9B=90=20?= =?UTF-8?q?=EB=8D=94=EB=AF=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=20=EC=BB=A4=EB=A7=A8=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/create_team_user.py | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 wtnt/team/management/commands/create_team_user.py diff --git a/wtnt/team/management/commands/create_team_user.py b/wtnt/team/management/commands/create_team_user.py new file mode 100644 index 0000000..2e9b640 --- /dev/null +++ b/wtnt/team/management/commands/create_team_user.py @@ -0,0 +1,66 @@ +from django.core.management.base import BaseCommand, CommandParser, CommandError +from django.db import IntegrityError +from team.models import TeamApply, Team, TeamTech, TeamUser +from user.models import CustomUser +from django_seed import Seed + +import random + + +class Command(BaseCommand): + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("--number", default=1, type=int, help="추가하려고 하는 팀원의 수, 최대 100개까지") + + def handle(self, *args, **options): + number = options.get("number") + if number > 100: + raise CommandError("number의 최대 인풋은 100입니다.") + seeder = Seed.seeder() + + for _ in range(number): + team = Team.objects.order_by("?").first() + user = CustomUser.objects.order_by("?").first() + try: + team_user = TeamUser.objects.get(team_id=team.id, user_id=user.id) + if team_user is not None and team_user.tech == "팀장": + print(f"중복된 데이터 발생, 예상 데이터 주입 개수 {number-1}개") + number -= 1 + continue + except TeamUser.DoesNotExist: + pass + + tech_list = TeamTech.objects.filter(team_id=team.id).values_list("tech", flat=True) + tech = random.choice(tech_list) + seeder.add_entity( + TeamApply, + 1, + { + "team": team, + "user": user, + "bio": "열심히 하겠습니다", + "is_approved": True, + "tech": tech, + }, + ) + + seeder.add_entity( + TeamUser, + 1, + { + "team": team, + "user": user, + "tech": tech, + }, + ) + + try: + seeder.execute() + except IntegrityError: + print(f"중복된 데이터 발생, 예상 데이터 주입 개수 {number-1}개") + number -= 1 + continue + + if number: + self.stdout.write(self.style.SUCCESS(f"{number}개의 더미 팀원 생성 완료")) + else: + self.stdout.write(self.style.ERROR("데이터 주입 실패")) From c6a3b10798b0e0bdff3fe2bb42a817d417d81f44 Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 11:51:57 +0900 Subject: [PATCH 08/10] =?UTF-8?q?#72=20Feat:=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=ED=85=8C=EC=9D=B4=EB=B8=94=EC=97=90=20=EC=A0=9C=EC=95=BD?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wtnt/team/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wtnt/team/models.py b/wtnt/team/models.py index fa0c5f0..12eecbd 100644 --- a/wtnt/team/models.py +++ b/wtnt/team/models.py @@ -94,6 +94,9 @@ class Likes(TimestampedModel): user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) objects = LikesManager() + class Meta: + constraints = [models.UniqueConstraint(fields=["user", "team"], name="teamlike_unique")] + class TeamUser(models.Model): team = models.ForeignKey(Team, on_delete=models.CASCADE) From 2fa9c1acb828169bb9c3f617cb09738b8763ec12 Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 11:52:53 +0900 Subject: [PATCH 09/10] =?UTF-8?q?#72=20Feat:=20=ED=8C=80=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20TeamTech=EC=9D=98?= =?UTF-8?q?=20=ED=98=84=EC=9E=AC=20=EC=9D=B8=EC=9B=90=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wtnt/team/management/commands/create_team_user.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wtnt/team/management/commands/create_team_user.py b/wtnt/team/management/commands/create_team_user.py index 2e9b640..394b849 100644 --- a/wtnt/team/management/commands/create_team_user.py +++ b/wtnt/team/management/commands/create_team_user.py @@ -31,6 +31,8 @@ def handle(self, *args, **options): tech_list = TeamTech.objects.filter(team_id=team.id).values_list("tech", flat=True) tech = random.choice(tech_list) + team_tech = TeamTech.objects.get(team_id=team.id, tech=tech) + seeder.add_entity( TeamApply, 1, @@ -54,7 +56,14 @@ def handle(self, *args, **options): ) try: + if team_tech.need_num <= team_tech.current_num: + print(f"중복된 데이터 발생, 예상 데이터 주입 개수 {number-1}개") + number -= 1 + continue seeder.execute() + team_tech.current_num += 1 + team_tech.save() + except IntegrityError: print(f"중복된 데이터 발생, 예상 데이터 주입 개수 {number-1}개") number -= 1 From 4072a18037bc98d7664eefcc5ecc6fc9f29bb98a Mon Sep 17 00:00:00 2001 From: fnzksxl Date: Thu, 1 Aug 2024 11:53:23 +0900 Subject: [PATCH 10/10] =?UTF-8?q?#72=20Feat:=20=EC=A2=8B=EC=95=84=EC=9A=94?= =?UTF-8?q?=20=EB=8D=94=EB=AF=B8=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85=20=EC=BB=A4=EB=A7=A8=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/create_team_like.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 wtnt/team/management/commands/create_team_like.py diff --git a/wtnt/team/management/commands/create_team_like.py b/wtnt/team/management/commands/create_team_like.py new file mode 100644 index 0000000..984c7b2 --- /dev/null +++ b/wtnt/team/management/commands/create_team_like.py @@ -0,0 +1,44 @@ +from django.core.management.base import BaseCommand, CommandParser, CommandError +from django.db import IntegrityError +from team.models import Likes, Team +from user.models import CustomUser +from django_seed import Seed + + +class Command(BaseCommand): + def add_arguments(self, parser: CommandParser) -> None: + parser.add_argument("--number", default=1, type=int, help="추가하려고 하는 좋아요의 수, 최대 100개까지") + + def handle(self, *args, **options): + number = options.get("number") + if number > 100: + raise CommandError("number의 최대 인풋은 100입니다.") + seeder = Seed.seeder() + + for _ in range(number): + team = Team.objects.order_by("?").first() + user = CustomUser.objects.order_by("?").first() + + seeder.add_entity( + Likes, + 1, + { + "team": team, + "user": user, + }, + ) + + try: + seeder.execute() + team.like += 1 + team.version += 1 + team.save() + + except IntegrityError: + print(f"중복된 데이터 발생, 예상 데이터 주입 개수 {number-1}개") + number -= 1 + continue + if number: + self.stdout.write(self.style.SUCCESS(f"{number}개의 더미 좋아요 생성 완료")) + else: + self.stdout.write(self.style.ERROR("데이터 주입 실패"))