Skip to content

Commit

Permalink
stisfied-docket
Browse files Browse the repository at this point in the history
Former-commit-id: c45180e212dc7c5dfe68e47c88845a6631ed3072
  • Loading branch information
Gkuer committed Nov 21, 2021
1 parent 47ccf64 commit dec867b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 34 deletions.
Binary file modified db.sqlite3
Binary file not shown.
47 changes: 47 additions & 0 deletions movies/migrations/0009_auto_20211122_0042.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 3.2.9 on 2021-11-21 15:42

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('movies', '0008_alter_color_movie'),
]

operations = [
migrations.AddField(
model_name='moviecomment',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='moviecomment',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='review',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='review',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='reviewcomment',
name='created_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='reviewcomment',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
]
7 changes: 7 additions & 0 deletions movies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,24 @@ class MovieComment(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)
grade = models.IntegerField()
content = models.CharField(max_length=50)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Review(models.Model):
movie = models.ForeignKey(Movie, on_delete=models.CASCADE, related_name="reviews")
title = models.CharField(max_length=50)
content = models.TextField()
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class ReviewComment(models.Model):
review = models.ForeignKey(Review, on_delete=models.CASCADE, related_name="comments")
content = models.CharField(max_length=50)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)


class UserColorRecord(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
Expand Down
31 changes: 1 addition & 30 deletions movies/templates/movies/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1> {{ movie.title }} </h1>
{{ movie.overview }}
</div>
<div style="font-size: 17px; font-weight: 400; line-height: 1.6em; border-bottom: 1px solid var(--border-color); padding: 10px;">
<h5>평균 평점 : {{ movie.naver_grade }} 점</h5>
<h5>평균 평점 : {{ movie.naver_grade }} 점 / 유저 평점 : {{ user_grade }} 점</h5>
</div>
<div style="font-size: 17px; font-weight: 400; line-height: 1.6em; border-bottom: 1px solid var(--border-color); padding: 10px;">
<h5>개봉일 : {{ movie.release_date }}</h5>
Expand Down Expand Up @@ -196,35 +196,6 @@ <h5> <{{ review.title }}> </h5>
</div>
</div>
</div>
{% comment %} 음성인식 Modal {% endcomment %}
<div class="modal" id="voiceModal2">
<div class="modal-dialog" style="margin-top:200px; margin-left: 600px;">
<div class="modal-content" style="width: 700px; height: 350px; border-radius: 30px; background-color: rgba(255,255,192,0.1); backdrop-filter: blur(10px); box-shadow: 2px 7px 15px 8px rgba(0,0,0,0.3);">

<!-- Modal body -->
<div class="modal-body">
<div class="row">
<div class="col-6">
<video src="{% static 'videos/background.mp4'%}" class='w-100' style="border-radius:20%; opacity:0.6;" autoplay loop muted></video>
</div>

<div class="col-6 d-flex flex-column justify-content-center align-items-center">
<h4 id="voiceText" style="color:white;"> 음성을 기다리고 있어요...</h4>
<h4 class="d-none" id="voiceAnswer" style="color: rgb(242, 206, 85); margin-top:30px;"> 알겠어요, 지금 바로 실행할게요.</h4>
</div>
</div>
</div>

<!-- Modal footer -->
<div class="modal-footer d-flex justify-content-center align-items-center">
<button id="voiceBtn" type="button" class="btn btn-danger w-50 h-75 d-flex justify-content-center align-items-center" style="opacity: 0.8; border-radius: 20px;">
<i class="fas fa-microphone-alt" style="font-size:35px;"></i>
</button>
</div>

</div>
</div>
</div>
{% endblock content %}

{% comment %} Frame Expansion Modal{% endcomment %}
Expand Down
41 changes: 37 additions & 4 deletions movies/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render,redirect
from .models import Movie, Color, MovieComment, Review, ReviewComment, UserColorRecord
from .models import Movie, MovieComment, Review, ReviewComment, UserColorRecord
from .forms import ReviewCommentForm, ReviewForm, MovieCommentForm
from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_POST, require_http_methods, require_safe
Expand All @@ -17,19 +17,40 @@ def index(request, mode): # mode : Sort
if not request.user.usercolorrecord_set.all():
return redirect('movies:choice')

movies = Movie.objects.all()
temp_movies = Movie.objects.all()

# Profile Color Create
colors = request.user.usercolorrecord_set.all() # Color List
last_color = colors[len(colors)-1] # Picked Color
colors = reversed(colors) # Color Sort(Recently)

# Exclude Already Watched Movies
movies = []
for movie in temp_movies:
for comment in movie.comments.all(): # Exist request.user Comment
if request.user == comment.user:
break
else:
for review in movie.reviews.all(): # Exist request.user Review
if request.user == review.user:
break
else:
movies.append(movie)

res_movies = []

# Order by TMDB_Grade
# Order by TMDB_Grade + User_Grade
if mode == 2:
for movie in movies:
score = movie.naver_grade
naver_score = movie.naver_grade
user_score = 0
for comment in movie.comments.all():
user_score += comment.grade
if user_score:
user_score = round((user_score / movie.comments.all().count()),1) * 2
score = (naver_score + user_score) / 2
else:
score = naver_score
res_movies.append([movie, score])

# Order by Release Date
Expand Down Expand Up @@ -112,10 +133,22 @@ def detail(request, movie_pk):
last_color = colors[len(colors)-1] # Picked Color
colors = reversed(colors) # Color Sort(Recently)

# User Grade
comments = movie.comments.all()

user_grade = 0
if comments:
for comment in comments:
user_grade += comment.grade
user_grade = 2*round(user_grade / len(comments),1)
else:
user_grade = "-"

context = {
'movie': movie,
'colors': colors,
'last_color': last_color,
'user_grade': user_grade,
}
return render(request,'movies/detail.html', context)

Expand Down

0 comments on commit dec867b

Please sign in to comment.