def index(request): login_form = AuthenticationForm() signup_form = UserCustomCreationForm() context = { "login_form": login_form, "signup_form": signup_form, } return render(request, 'movie_review/index.html', context)
def actor_detail(request, id): actor = get_object_or_404(Actor, id=id) login_form = AuthenticationForm() signup_form = UserCustomCreationForm() context = { 'actor': actor, 'login_form': login_form, 'signup_form': signup_form, } return render(request, 'movie_review/actor_detail.html', context)
def list(request): # 해시태그별 hashtags = Hashtag.objects.all() # 영화정보 genres = [] movies = [] today = datetime.datetime.now() d = datetime.timedelta(days=90) before = today - d new_movies = Movie.objects.filter(open_date__range=[ str(before.strftime("%Y-%m-%d")), str(today.strftime("%Y-%m-%d")) ]).order_by('?')[:12] # print(new_movies) if request.user.is_authenticated: genres = request.user.like_genres.order_by('?')[:3] genre_movies = {} for genre in genres: # print(genre) # print(genre.movies.all().order_by('?')[:6]) genre_movies[genre.name] = genre.movies.all().order_by('?')[:6] # print(genre_movies[genre.name]) # print(genre_movies) movies = Movie.objects.all() # 로그인form if request.method == "POST": user_form = AuthenticationForm(request, request.POST) if user_form.is_valid(): user_form = auth_login(request, user_form.get_user()) return redirect('movies:list') else: user_form = AuthenticationForm() # 회원가입 모달을 위한 회원가입 form userlists = get_user_model().objects.all() signup_form = UserCustomCreationForm() context = { 'movies': movies, 'genres': genres, 'login_form': user_form, 'signup_form': signup_form, 'userlists': userlists, 'genre_movies': genre_movies, 'new_movies': new_movies, 'hashtags': hashtags } return render(request, 'movies/list.html', context)
def movie_select(request, id): if id == 0: movie_list = Movie.objects.all() else: movie_list = Movie.objects.filter(genres__id=id) genre_list = Genre.objects.all() login_form = AuthenticationForm() signup_form = UserCustomCreationForm() context = { 'movie_list': movie_list, 'genres': genre_list, 'gen_id': genre_list[id], 'login_form': login_form, 'signup_form': signup_form, } return render(request, 'movie_review/list.html', context)
def search(request): keyword = request.GET.get('keyword') movies = Movie.objects.filter(title__contains=keyword) actors = Actor.objects.filter(name__contains=keyword) genre_list = Genre.objects.all() login_form = AuthenticationForm() signup_form = UserCustomCreationForm() if not movies: movies = "" if not actors: actors = "" context = { 'movie_list': movies, 'actor_list': actors, 'genres': genre_list, 'gen_id': genre_list[0], 'login_form': login_form, 'signup_form': signup_form, } return render(request, 'movie_review/search_result.html', context)
def movie_detail(request, id): movie = get_object_or_404(Movie, id=id) form = ReviewForm() login_form = AuthenticationForm() signup_form = UserCustomCreationForm() all_rating = 0 if movie.review_set.count(): for review in movie.review_set.all(): all_rating += review.rating avg_rating = all_rating / movie.review_set.count() else: avg_rating = '평가가 없습니다.' context = { 'movie': movie, 'form': form, 'login_form': login_form, 'signup_form': signup_form, 'avg_rating': avg_rating, } return render(request, 'movie_review/detail.html', context)