From d242581d249ba05d3b33e62335d29e70df21e14e Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 24 Nov 2021 16:49:15 +0000 Subject: [PATCH] add-quiz Former-commit-id: b4892efbd4f5e42384f5a93ac8cc7a03ee97bb1b --- db.sqlite3 | Bin 376832 -> 376832 bytes movies/admin.py | 3 +- movies/forms.py | 9 +- movies/migrations/0012_quiz.py | 26 +++ movies/models.py | 8 +- movies/templates/movies/quiz.html | 136 +++++++++++++ movies/templates/movies/quiz_create.html | 235 +++++++++++++++++++++++ movies/urls.py | 4 + movies/views.py | 108 ++++++++++- templates/base.html | 2 +- 10 files changed, 524 insertions(+), 7 deletions(-) create mode 100644 movies/migrations/0012_quiz.py create mode 100644 movies/templates/movies/quiz.html create mode 100644 movies/templates/movies/quiz_create.html diff --git a/db.sqlite3 b/db.sqlite3 index fc3e7f74aa2485b4d756c0725edebb8e868352bc..3e580a8954d083a942f3cc80f489dd3a7ae83959 100644 GIT binary patch delta 3650 zcma)9eNYo;8sB$!lMP9B-*5^D2rOR;qriTKkd{h{h@yNdTKu>ek`M?GAp{VnGZ4;c z?b%vu>g-)V9NTH_IcIycQMY%~ySD$F9cS!$wY}2Xv7R$GW0mXIblOg>_TJqHMX9IR zd7fe4=Xrn6?|DC-eHb548y`>GmzkW6Vc1qAc}N%}zk6c22(n+@{uHDe(Q8UJjWlaw zW0Y+LZerujwke7$Wer$*j;nXaP?vvz<9NZ{KiD-YZ~|Y#^Cg1B@^+^vJ4K;XcG&p} zIo`DB_o-lE>~iU9V2X)l4XK$6NMafA3`RQLeg1H7*T6v6j*t{n%AA0Wy;oL}Pn%I( zn)wccU%*e`pW!?38R&;YFpv2Tu7^%Y!H46y+y{&elIbZR!9*iL$EX$8vT5d941NyJ z!ISWH_%wV74niMnffXVS}WH}Y1nmi`Ub<4EnW6LSz zy4g|RQk>AOFw692X%`=VR0bkI7VJ%BFs#&Z8{| zQDciG0|s)I{!FUc6Jj-nthNfQh^+a`=2Fz`3C0NzA>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EC~gN$dXMy^r^ zts@_kT|Z4EXw5eBJSo>DR~xk0R4C zd0zHQ26><4;eL43w%htA$!@tQh()s+IhXNtinS59rj?YyHwI(fkv-9Y=x}GJ4uvVo zXQPyjTeg>no64O{;j(SzPS>)+`2GNPGHW9wT==x{$0GQo#GkH*e}c?LL{~!t5lL?WxP$_n8+2_b2jzn|#8Zo?s%&++>+MW0{+n ze(30u?6YrSuxFd*P?FS(>2)$|>q~MbQe2slkBX%*4y)6K^D@4pBusfoxatDgGzaU& zCUIxQNXl~`|jd(;!;qk-9OG`KclA+$ix6||JC5cV2uZkjgjD3s6 znZe#>KVfH&XG!I@Khn=coS;$Tc`9u(-$3a$G(n9^RJw%Gl5vVjnMvrbNdim+?b}Q$ z;o>qre3d)9BuD+MT?Q>%xJw{YF)tBrnwNGd=jkVs7xmw~`?+JVP zv8{47=A~Eg!@%d~@LJf2(1gpS)I8M~{-X3W2CL=sm92F>q447^b(JH%{i8dcD35iv z6}5QUgChf5`-;nYe6fn+`l_w%T3f6lzq&d2e-n~dR?B;(+=-kNad<=ciwcNwZw{ZY zYz~B~hYpQ4w2$-#n>>;H>PFuaLwo%B?uuZe?@)L5$gY-fP1{hz{>OUU!M&e5`+sT$ zzg8=6=vJA+k?K)6X=d$)eP%g7rWAv}ArCpcpD!SuVsF3*&B|`r#rMq0Uos1|pwx;( zzF>jh>-BkpeEw(h1W4m+nen{~@>;|HhCH@hNf~R9*h{RJz02l#@>_Bdo2n$F diff --git a/movies/admin.py b/movies/admin.py index 26e9efc..2f7dbb3 100644 --- a/movies/admin.py +++ b/movies/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Movie, Color, MovieComment, Review, ReviewComment, UserColorRecord +from .models import Movie, Color, MovieComment, Review, ReviewComment, UserColorRecord,Quiz # Register your models here. admin.site.register(Movie) @@ -8,3 +8,4 @@ admin.site.register(Review) admin.site.register(ReviewComment) admin.site.register(UserColorRecord) +admin.site.register(Quiz) \ No newline at end of file diff --git a/movies/forms.py b/movies/forms.py index d65ab66..cf64c64 100644 --- a/movies/forms.py +++ b/movies/forms.py @@ -1,6 +1,6 @@ from django.db.models.base import Model from django.forms import ModelForm -from .models import MovieComment, Review, ReviewComment +from .models import MovieComment, Review, ReviewComment, Quiz class MovieCommentForm(ModelForm): class Meta: @@ -15,4 +15,9 @@ class Meta: class ReviewCommentForm(ModelForm): class Meta: model = ReviewComment - fields = ('content',) \ No newline at end of file + fields = ('content',) + +class QuizForm(ModelForm): + class Meta: + model = Quiz + fields = ('movie', 'draw') \ No newline at end of file diff --git a/movies/migrations/0012_quiz.py b/movies/migrations/0012_quiz.py new file mode 100644 index 0000000..d56f0c9 --- /dev/null +++ b/movies/migrations/0012_quiz.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.9 on 2021-11-24 16:35 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('movies', '0011_review_draw'), + ] + + operations = [ + migrations.CreateModel( + name='Quiz', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('draw', models.ImageField(blank=True, upload_to='images/')), + ('correct_user', models.ManyToManyField(related_name='corrected_quizs', to=settings.AUTH_USER_MODEL)), + ('movie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='movies.movie')), + ('user', models.ForeignKey(default=13, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/movies/models.py b/movies/models.py index 4d8106c..09a528c 100644 --- a/movies/models.py +++ b/movies/models.py @@ -65,4 +65,10 @@ class ReviewComment(models.Model): class UserColorRecord(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - color = models.CharField(max_length=50) \ No newline at end of file + color = models.CharField(max_length=50) + +class Quiz(models.Model): + movie = models.ForeignKey(Movie, on_delete=models.CASCADE) + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=13) + draw = models.ImageField(blank=True, upload_to='images/') + correct_user = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name="corrected_quizs") \ No newline at end of file diff --git a/movies/templates/movies/quiz.html b/movies/templates/movies/quiz.html new file mode 100644 index 0000000..befa86b --- /dev/null +++ b/movies/templates/movies/quiz.html @@ -0,0 +1,136 @@ +{% extends 'base.html' %} +{% load static %} + +{% block back_URL %} "{% url 'movies:index' 2 %}" {% endblock back_URL %} + +{% block content %} +

+
+
+
+ +
+
+ +
+

티어는 총 5단계이며, 일정 포인트를 충족하면 티어가 상승합니다.

+
+
+
+
+ +
+
+ +
+

당신의 포인트는 {{ request.user.point }}점 + {% if required_point %} + 이며, {{ required_point }}점을 올리면 다음 단계로 상승합니다. + {% else %} + 입니다. + {% endif %} +

+

리뷰 작성은 30점, 한줄평은 10점, 리뷰 댓글 작성은 5점이 부여됩니다.

+

문제 제출 시 30점이 부여됩니다.

+

밑의 문제들을 맞추면 각각 20점이 부여됩니다.

+
+
+
+
+ {% for quiz,quiz_examples in quizs_list %} + {% with solved_user=quiz.correct_user.all%} + {% if user in solved_user %} + {% else %} +
+
+
+
+
+
+ 로고 +
+
+
+
+

답을 알려주세요

+
+
+ {% csrf_token %} + {% for example in quiz_examples %} + {% if example == quiz %} + + {% else %} + + {% endif %} + {% endfor %} +
+ +
+
+
+
+ +
+
+ +
+
+
+ + {% endif %} + {% endwith %} + {% endfor %} +
+
+ +{% endblock content %} + +{% block option_js %} + +{% endblock option_js %} \ No newline at end of file diff --git a/movies/templates/movies/quiz_create.html b/movies/templates/movies/quiz_create.html new file mode 100644 index 0000000..014b938 --- /dev/null +++ b/movies/templates/movies/quiz_create.html @@ -0,0 +1,235 @@ +{% extends 'base.html' %} +{% load static %} +{% load bootstrap5 %} + +{% block option_import %} {% endblock option_import %} + +{% block back_URL %} "{% url 'movies:quiz' %}" {% endblock back_URL %} + +{% block content %} +
+
+
+
+
+ {% csrf_token %} +
+

영화고르기

+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+ +
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+{% endblock content %} + + +{% block option_js %} + +{% endblock option_js %} \ No newline at end of file diff --git a/movies/urls.py b/movies/urls.py index e87f12e..69a0aa4 100644 --- a/movies/urls.py +++ b/movies/urls.py @@ -22,4 +22,8 @@ path('usercolor_update//', views.usercolor_update, name="usercolor_update"), path('voice_process/', views.voice_process, name="voice_process"), + + path('quiz_create/', views.quiz_create, name="quiz_create"), + path('quiz/', views.quiz, name="quiz"), + path('quiz_check/', views.quiz_check, name="quiz_check"), ] diff --git a/movies/views.py b/movies/views.py index bdc42c2..a751c4b 100644 --- a/movies/views.py +++ b/movies/views.py @@ -1,11 +1,13 @@ from django.shortcuts import render,redirect -from .models import Movie, MovieComment, Review, ReviewComment, UserColorRecord -from .forms import ReviewCommentForm, ReviewForm, MovieCommentForm +from .models import Movie, MovieComment, Review, ReviewComment, UserColorRecord, Quiz +from .forms import ReviewCommentForm, ReviewForm, MovieCommentForm, QuizForm from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_POST, require_http_methods, require_safe import math from django.http import JsonResponse from django.db.models import Count +import json +import random @login_required @require_safe @@ -348,3 +350,105 @@ def review_update(request,review_pk): } return render(request,'movies/review_update.html', context) +@login_required +@require_http_methods(['GET','POST']) +def quiz_create(request): + # 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) + + movies = Movie.objects.all() + + if request.method == "POST": + form = QuizForm(request.POST, request.FILES) + if form.is_valid(): + quiz = form.save(commit=False) + quiz.user = request.user + quiz.save() + request.user.point += 30 + request.user.save() + return redirect('movies:index', 2) + else: + form = QuizForm() + context = { + 'form': form, + 'last_color': last_color, + 'colors': colors, + 'movies': movies, + } + return render(request, 'movies/quiz_create.html', context) + +@login_required +@require_http_methods(['GET','POST']) +def quiz(request): + quizs = Quiz.objects.all() + point = request.user.point + + required_point = 0 + if request.user.is_staff or point > 201: + pass + elif point > 120: + required_point = 201 - point + elif point > 60: + required_point = 121 - point + elif point > 20: + required_point = 61 - point + else: + required_point = 21 - point + + if request.method == "POST": + form = QuizForm(request.POST) + if form.is_valid(): + form.save() + else: + pass + + movies = Movie.objects.all() + movies_ints = [i for i in range(6,106)] + + quizs_list = [] + for i in quizs: + examples = random.sample(movies_ints,4) # Random for 1 Quiz + ran_num = random.choice([1,2,3,4,5,6]) + examples.insert(ran_num,200) + + temps = [] + for x in examples: + if x == 200: + temps.append(i) + else: + temps.append(movies[x-6]) + quizs_list.append([i,temps]) + + context = { + 'quizs_list': quizs_list, + 'required_point': required_point, + } + + return render(request,'movies/quiz.html',context) + +@login_required +@require_http_methods(['GET','POST']) +def quiz_check(request): + post_body = json.loads(request.body.decode('utf-8')) + + question_pk = post_body.get('question_pk') + answer = post_body.get('answer') + + quiz = Quiz.objects.get(pk=question_pk) + correct = False + + if int(quiz.movie.pk) == int(answer): + print("정답") + correct = True + + request.user.point += 20 + quiz.correct_user.add(request.user) + request.user.save() + + context = { + "correct": correct, + } + + return JsonResponse(context) \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index e8c879a..12dc8f7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -81,7 +81,7 @@ {% comment %} User & Login Button {% endcomment %}
- + 티어 올리기 {% comment %} User Tier {% endcomment %} {% if user.is_staff %}