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

refactor: Readme 수정 1차 #184

Closed
wants to merge 13 commits into from
Closed
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
333 changes: 177 additions & 156 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ def __str__(self):
return self.email

def get_image_url(self):
if getattr(self, "image", None):
return self.image.image_url
if hasattr(self, "image") and hasattr(self.image, "url"):
return self.image.url
return "https://paullab.co.kr/images/weniv-licat.png"
Binary file added assets/images/유연우.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/유원길.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/이유정.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/임홍광.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class Course(models.Model):
updated_at = models.DateTimeField(auto_now=True, verbose_name="수정일")

def get_thumbnail(self):
if hasattr(self, "images") and self.images.exists():
return self.images.first().file.url
if hasattr(self, "image"):
return self.image.url
return "https://www.gravatar.com/avatar/205e460b479e2e5b48aec077"

def update(self, **kwargs):
Expand Down
11 changes: 7 additions & 4 deletions courses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Meta:

def get_video_url(self, obj):
if getattr(obj, "video", None):
return obj.video.video_url
return obj.video.url
return None

def get_video_duration(self, obj):
Expand Down Expand Up @@ -164,17 +164,16 @@ class Meta:
]

def get_author_image(self, obj):
print(obj.author.image.image_url)
if getattr(obj.author, "image", None):
return obj.author.image.image_url
return obj.author.image.url
return None

def get_author_name(self, obj):
return obj.author.nickname

def get_video_url(self, obj):
if getattr(obj, "video", None):
return obj.video.video_url
return obj.video.url
return None

def get_thumbnail_url(self, obj):
Expand Down Expand Up @@ -233,6 +232,8 @@ def get_thumbnail(self, obj):
return obj.get_thumbnail()

def get_author_image(self, obj):
if getattr(obj.author, "image", None):
return obj.author.image.url
return "https://paullab.co.kr/images/weniv-licat.png"

def get_author_name(self, obj):
Expand Down Expand Up @@ -314,6 +315,8 @@ class Meta:
]

def get_author_image(self, obj):
if getattr(obj.author, "image", None):
return obj.author.image.url
return "https://paullab.co.kr/images/weniv-licat.png"

def get_author_name(self, obj):
Expand Down
4 changes: 2 additions & 2 deletions courses/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def create_user():
user = User.objects.create_user(
email=TEST_USER_EMAIL, password=TEST_USER_PASSWORD, nickname="testuser"
)
Image.objects.create(user=user, image_url="test.jpg")
Image.objects.create(user=user, url="test.jpg")
return user


Expand All @@ -148,7 +148,7 @@ def create_staff_user():
is_staff=True,
nickname="staffuser",
)
Image.objects.create(user=user, image_url="test.jpg")
Image.objects.create(user=user, url="test.jpg")
return user


Expand Down
8 changes: 1 addition & 7 deletions jwtauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ class GoogleLogin(SocialLoginView):
callback_url = settings.GOOGLE_CALLBACK_URL
client_class = OAuth2Client

def get(self, request, *args, **kwargs):
"""
GET 요청: 구글 로그인 페이지로 리다이렉트
"""
return super().get(request, *args, **kwargs)

def get_response(self):
"""
소셜 로그인 완료 후 사용자 정보 처리
Expand All @@ -192,7 +186,7 @@ def get_response(self):

if not User.objects.filter(email=user.email).exists():
user = User.objects.create_user(
nickname=user.mail.split("@")[0],
nickname=user.email.split("@")[0],
email=user.email,
)
user.set_unusable_password()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.1.1 on 2024-10-14 06:31

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('materials', '0008_alter_image_options_alter_video_options_and_more'),
]

operations = [
migrations.RemoveField(
model_name='image',
name='image_url',
),
migrations.RemoveField(
model_name='video',
name='video_url',
),
]
23 changes: 23 additions & 0 deletions materials/migrations/0010_image_url_video_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.1 on 2024-10-14 06:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('materials', '0009_remove_image_image_url_remove_video_video_url'),
]

operations = [
migrations.AddField(
model_name='image',
name='url',
field=models.URLField(default='https://paullab.co.kr/images/weniv-licat.png', verbose_name='이미지 URL'),
),
migrations.AddField(
model_name='video',
name='url',
field=models.URLField(default='https://www.youtube.com/watch?v=bZh8oUIDfdI&t=1s', verbose_name='동영상 URL'),
),
]
28 changes: 15 additions & 13 deletions materials/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from accounts.models import CustomUser
from courses.models import Course, Topic
from django.conf import settings
from django.db import models

from accounts.models import CustomUser
from courses.models import Course, Topic


class Image(models.Model):
"""
Expand Down Expand Up @@ -34,9 +35,9 @@ class Image(models.Model):
null=True,
blank=True,
)

image_url = models.ImageField(
upload_to="images/", blank=True, null=True, verbose_name="이미지 파일"
url = models.URLField(
verbose_name="이미지 URL",
default="https://paullab.co.kr/images/weniv-licat.png",
)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
Expand All @@ -54,10 +55,10 @@ def __str__(self):

def save(self, *args, **kwargs):

if self.user and not self.image_url:
self.image_url = f"{settings.MEDIA_URL}images/default_user_image.jpg"
if self.course and not self.image_url:
self.image_url = f"{settings.MEDIA_URL}images/default_user_image.jpg"
if self.user and not self.url:
self.url = f"{settings.MEDIA_URL}images/default_user_image.jpg"
if self.course and not self.url:
self.url = f"{settings.MEDIA_URL}images/default_user_image.jpg"
super().save(*args, **kwargs)


Expand All @@ -75,8 +76,9 @@ class Video(models.Model):
course = models.OneToOneField(
Course, on_delete=models.CASCADE, related_name="video", null=True, blank=True
)
video_url = models.FileField(
upload_to="videos/", blank=True, null=True, verbose_name="비디오 파일"
url = models.URLField(
verbose_name="동영상 URL",
default="https://www.youtube.com/watch?v=bZh8oUIDfdI&t=1s",
)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
Expand All @@ -93,8 +95,8 @@ def __str__(self):
return "Video"

def save(self, *args, **kwargs):
if not self.video_url:
self.video_url = f"{settings.MEDIA_URL}videos/default_video.mp4"
if not self.url:
self.url = f"{settings.MEDIA_URL}videos/default_video.mp4"

super().save(*args, **kwargs)

Expand Down
56 changes: 31 additions & 25 deletions materials/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,33 @@ class ImageSerializer(serializers.ModelSerializer):
- 검사: 파일 형식과 손상 여부에 대해 유효성 검사를 합니다.
"""

file = serializers.ImageField(write_only=True)

class Meta:
model = Image
fields = [
"id",
"image_url",
"url",
"is_deleted",
"created_at",
"updated_at",
"file",
]
read_only_fields = [
"id",
"image_url",
"url",
"is_deleted",
"created_at",
"updated_at",
]

def validate_file(self, value):
allowed_image_extensions = (".png", ".jpg", ".jpeg")

if not value.name.endswith(allowed_image_extensions):
raise serializers.ValidationError(
"지원하지 않는 파일 형식입니다. PNG, JPG, JPEG만 가능합니다."
)

try:
img = PILImage.open(value)
img.verify()
Expand All @@ -51,44 +54,47 @@ class VideoSerializer(serializers.ModelSerializer):
- 검사: 파일 형식과 손상 여부에 대해 유효성 검사를 합니다.
"""

file = serializers.FileField(write_only=True)

class Meta:
model = Video
fields = [
"id",
"video_url",
"url",
"file",
"is_deleted",
"created_at",
"updated_at",
]
read_only_fields = ["id", "video_url", "is_deleted", "created_at", "updated_at"]
read_only_fields = ["id", "url", "is_deleted", "created_at", "updated_at"]

def validate_file(self, value):
allowed_extensions = ["mp4", "avi", "mov", "wmv"]

if not value.name.split(".")[-1] in allowed_extensions:
if value.name.split(".")[-1] not in allowed_extensions:
raise serializers.ValidationError(
f"허용되지 않는 파일 형식입니다. 다음 형식만 가능합니다: {', '.join(allowed_extensions)}."
)

try:
cap = cv2.VideoCapture(value)
if not cap.isOpened():
raise serializers.ValidationError(
"비디오 파일을 열 수 없습니다. 파일이 손상되었을 수 있습니다."
)

ret, frame = cap.read()
if not ret:
raise serializers.ValidationError(
"비디오 파일을 읽을 수 없습니다. 파일이 손상되었을 수 있습니다."
)

except Exception as e:
raise serializers.ValidationError(
f"비디오 파일 검사 중 오류가 발생했습니다: {str(e)}"
)
finally:
cap.release()
# try:
# cap = cv2.VideoCapture(value)
# if not cap.isOpened():
# raise serializers.ValidationError(
# "비디오 파일을 열 수 없습니다. 파일이 손상되었을 수 있습니다."
# )

# ret, frame = cap.read()
# if not ret:
# raise serializers.ValidationError(
# "비디오 파일을 읽을 수 없습니다. 파일이 손상되었을 수 있습니다."
# )

# except Exception as e:
# raise serializers.ValidationError(
# f"비디오 파일 검사 중 오류가 발생했습니다: {str(e)}"
# )
# finally:
# cap.release()

return value

Expand Down
Loading
Loading