From a7844e4135f1452b5156561882e4ccb754ac1dd3 Mon Sep 17 00:00:00 2001 From: Akshen Date: Tue, 19 Mar 2019 13:43:58 +0530 Subject: Major Update 2 - Contributor can add animation videos --- fossee_manim/views.py | 142 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 105 insertions(+), 37 deletions(-) (limited to 'fossee_manim/views.py') diff --git a/fossee_manim/views.py b/fossee_manim/views.py index d9b27b2..58cc794 100644 --- a/fossee_manim/views.py +++ b/fossee_manim/views.py @@ -1,12 +1,13 @@ -from django.shortcuts import render +from os import listdir, path, sep, makedirs, remove from .forms import ( UserRegistrationForm, UserLoginForm, - ProfileForm, AnimationProposal, - CommentForm + ProfileForm, AnimationProposal, + CommentForm, UploadAnimationForm ) from .models import ( Profile, User, AnimationStats, - has_profile, Animation, Comment + has_profile, Animation, Comment, + Category ) from datetime import datetime, date from django.contrib.auth import login, logout, authenticate @@ -15,24 +16,42 @@ from django.contrib import messages from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.shortcuts import render, redirect from django.utils import timezone -from .send_mails import send_email from django.http import HttpResponse, HttpResponseRedirect -from textwrap import dedent from django.conf import settings -from os import listdir, path, sep -from zipfile import ZipFile +from django.core.files.uploadhandler import FileUploadHandler from django.contrib import messages -from django.db.models import Q +from django.db.models import F, Subquery, OuterRef +from zipfile import ZipFile +from textwrap import dedent +from requests import get +from .send_mails import send_email import datetime as dt -import os +import shutil try: from StringIO import StringIO as string_io except ImportError: from io import BytesIO as string_io +def makepath(proposal_data, reject=None): + if not path.exists(path.join(settings.MEDIA_ROOT, + proposal_data.category.name)): + makedirs(path.join(settings.MEDIA_ROOT, + proposal_data.category.name)) + + if reject: + shutil.rmtree(path.join( + settings.MEDIA_ROOT, proposal_data.category.name, + proposal_data.title.replace(" ", "_") + + str(proposal_data.id))) + else: + makedirs(path.join(settings.MEDIA_ROOT, proposal_data.category.name, + proposal_data.title.replace(" ", "_") + + str(proposal_data.id))) + + def check_repo(link): - return True if 'github.com' in link else False + return (get(link).status_code == 200) def is_email_checked(user): @@ -43,7 +62,7 @@ def is_email_checked(user): def is_superuser(user): - return True if user.is_superuser else False + return user.is_superuser def index(request): @@ -52,8 +71,8 @@ def index(request): user = request.user form = UserLoginForm() if user.is_authenticated() and is_email_checked(user): - if user.groups.filter(name='reviewer').count() > 0: - return redirect('/view_profile/') + if user.groups.filter(name='reviewer').exists: + return redirect('/proposal_status/') return redirect('/view_profile/') elif request.method == "POST": form = UserLoginForm(request.POST) @@ -62,8 +81,8 @@ def index(request): login(request, user) if is_superuser(user): return redirect("/admin") - if user.groups.filter(name='reviewer').count() > 0: - return redirect('/view_profile/') + if user.groups.filter(name='reviewer').exists(): + return redirect('/proposal_status/') return redirect('/view_profile/') return render(request, "fossee_manim/index.html", {"form": form}) @@ -71,7 +90,7 @@ def index(request): def is_reviewer(user): '''Check if the user is having reviewer rights''' - return True if user.groups.filter(name='reviewer').count() > 0 else False + return user.groups.filter(name='reviewer').exists() def user_login(request): @@ -248,14 +267,15 @@ def send_proposal(request): if form.is_valid(): form_data = form.save(commit=False) form_data.contributor = user - form_data.status = "pending" + form_data.status = "pending" if check_repo(form_data.github): form_data.save() form.save_m2m() + # makepath(form_data) else: messages.warning(request, 'Please enter valid github details') return render(request, 'fossee_manim/send_proposal.html', - {'form': form}) + {'form': form}) return redirect('/proposal_status/') else: form = AnimationProposal() @@ -272,8 +292,7 @@ def proposal_status(request): if profile.position == 'contributor': anime = Animation.objects.filter(contributor_id=user) else: - anime_list = Animation.objects.filter(Q(status='pending') | - Q(status='changes')) + anime_list = Animation.objects.order_by('-created') return render(request, 'fossee_manim/proposal_status.html', {'anime': anime, 'anime_list': anime_list}) @@ -284,28 +303,30 @@ def edit_proposal(request, proposal_id=None): comment_form = CommentForm() proposal = Animation.objects.get(id=proposal_id) proposal_form = AnimationProposal(instance=proposal) + upload_form = UploadAnimationForm() try: - comments = Comment.objects.all().order_by('-created_date') + comments = Comment.objects.filter(animation_id=proposal_id).order_by( + '-created_date' + ) except: comments = None if request.method == 'POST': text = request.POST.get('comment') - s1 = request.POST.get('release') - s2 = request.POST.get('rejected') + status1 = request.POST.get('release') + status2 = request.POST.get('rejected') - if s1 or s2 is not None: - if s1: + if status1 or status2 is not None: + if status1: proposal.status = 'released' - proposal.reviewer = user - proposal.save() send_email(request, call_on='released', - contributor=proposal.contributor) + contributor=proposal.contributor) else: proposal.status = 'rejected' - proposal.reviewer = user - proposal.save() + makepath(proposal, reject=1) send_email(request, call_on='rejected', - contributor=proposal.contributor) + contributor=proposal.contributor) + proposal.reviewer = user + proposal.save() return redirect('/proposal_status/') if text is not None: @@ -315,9 +336,10 @@ def edit_proposal(request, proposal_id=None): form_data.animation = proposal if user.profile.position == 'reviewer': proposal.status = 'changes' + proposal.save() send_email(request, call_on='changes', - contributor=proposal.contributor, - proposal=proposal) + contributor=proposal.contributor, + proposal=proposal) form_data.save() return redirect('/edit_proposal/{}'.format(proposal_id)) proposal_form = AnimationProposal(request.POST, instance=proposal) @@ -345,13 +367,59 @@ def edit_proposal(request, proposal_id=None): comments = paginator.page(paginator.num_pages) return render(request, 'fossee_manim/edit_proposal.html', {'proposal_form': proposal_form, - "comments": comments, - "comment_form": comment_form}) + "comments": comments, + "comment_form": comment_form, + "upload_form": upload_form}) def search(request): if request.method == 'POST': word = request.POST.get('sbox') - return render(request, 'fossee_manim/search_results.html') + +@login_required +def upload_animation(request, proposal_id=None): + if request.method == 'POST': + proposal = Animation.objects.get(id=proposal_id) + anim_stats = UploadAnimationForm(request.POST or None, + request.FILES or None) + + # return redirect('/edit_proposal/{}'.format(proposal_id)) + if anim_stats.is_valid(): + anim = AnimationStats.objects.filter( + animation=proposal) + if anim.exists(): + anobj = anim.first() + try: + remove(anobj.thumbnail.path) + except: + pass + remove(anobj.video_path.path) + anobj.delete() + anobj = AnimationStats.objects.create( + animation=proposal, video_path=request.FILES['video_path']) + else: + anobj = AnimationStats.objects.create( + animation=proposal, video_path=request.FILES['video_path']) + anobj._create_thumbnail() + return render(request, 'fossee_manim/upload_success.html') + else: + return redirect('/view_profile/') + + +def video(request, id=None): + video = AnimationStats.objects.filter(id=id) + # if views crosses limit comment the line below + video.update(views=F('views')+1) + video.update(like=F('like')+1) + suggestion_list = AnimationStats.objects.filter() + return render(request, 'fossee_manim/video.html', {'video': video}) + + +def search_category(request, cat=None): + cat_id = Category.objects.get(name=cat) + anim_list = AnimationStats.objects.all() + cat_video_list = [x for x in anim_list if (x.animation.category == cat_id)] + return render(request, 'fossee_manim/categorical_list.html', + {'categorial_list': cat_video_list}) -- cgit From e29783687b992216bcd757db7f2bfa8a652d2e4d Mon Sep 17 00:00:00 2001 From: Akshen Date: Mon, 25 Mar 2019 11:33:50 +0530 Subject: Search Bar working - Search Bar is working - Category wise selection is possible via dropdown --- fossee_manim/views.py | 64 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 16 deletions(-) (limited to 'fossee_manim/views.py') diff --git a/fossee_manim/views.py b/fossee_manim/views.py index 58cc794..b274e63 100644 --- a/fossee_manim/views.py +++ b/fossee_manim/views.py @@ -20,7 +20,7 @@ from django.http import HttpResponse, HttpResponseRedirect from django.conf import settings from django.core.files.uploadhandler import FileUploadHandler from django.contrib import messages -from django.db.models import F, Subquery, OuterRef +from django.db.models import F, Subquery, OuterRef, Q from zipfile import ZipFile from textwrap import dedent from requests import get @@ -197,10 +197,12 @@ def user_register(request): def view_profile(request): """ view instructor and coordinator profile """ user = request.user + categories = Category.objects.all() if is_superuser(user): return redirect('/admin') if is_email_checked(user) and user.is_authenticated(): - return render(request, "fossee_manim/view_profile.html") + return render(request, "fossee_manim/view_profile.html", + {'categories': categories}) else: if user.is_authenticated(): return render(request, 'fossee_manim/activation.html') @@ -217,6 +219,7 @@ def edit_profile(request): """ edit profile details facility for reviewer and contributor """ user = request.user + categories = Category.objects.all() if is_superuser(user): return redirect('/admin') if is_email_checked(user): @@ -248,20 +251,23 @@ def edit_profile(request): form_data.save() return render( - request, 'fossee_manim/profile_updated.html' + request, 'fossee_manim/profile_updated.html', + {'categories': categories} ) else: context['form'] = form return render(request, 'fossee_manim/edit_profile.html', context) else: form = ProfileForm(user=user, instance=profile) - return render(request, 'fossee_manim/edit_profile.html', {'form': form} + return render(request, 'fossee_manim/edit_profile.html', {'form': form, + 'categories': categories} ) @login_required def send_proposal(request): user = request.user + categories = Category.objects.all() if request.method == 'POST': form = AnimationProposal(request.POST) if form.is_valid(): @@ -275,12 +281,12 @@ def send_proposal(request): else: messages.warning(request, 'Please enter valid github details') return render(request, 'fossee_manim/send_proposal.html', - {'form': form}) + {'form': form, 'categories': categories}) return redirect('/proposal_status/') else: form = AnimationProposal() return render(request, 'fossee_manim/send_proposal.html', - {'form': form}) + {'form': form, 'categories': categories}) @login_required @@ -289,12 +295,14 @@ def proposal_status(request): profile = Profile.objects.get(user_id=user) anime = {} anime_list = {} + categories = Category.objects.all() if profile.position == 'contributor': anime = Animation.objects.filter(contributor_id=user) else: anime_list = Animation.objects.order_by('-created') return render(request, 'fossee_manim/proposal_status.html', - {'anime': anime, 'anime_list': anime_list}) + {'anime': anime, 'anime_list': anime_list, + 'categories': categories}) @login_required @@ -304,6 +312,8 @@ def edit_proposal(request, proposal_id=None): proposal = Animation.objects.get(id=proposal_id) proposal_form = AnimationProposal(instance=proposal) upload_form = UploadAnimationForm() + categories = Category.objects.all() + video = AnimationStats.objects.filter(animation=proposal_id) try: comments = Comment.objects.filter(animation_id=proposal_id).order_by( '-created_date' @@ -334,6 +344,7 @@ def edit_proposal(request, proposal_id=None): form_data = comment_form.save(commit=False) form_data.commentor = user form_data.animation = proposal + form_data.animation__status = proposal.status if user.profile.position == 'reviewer': proposal.status = 'changes' proposal.save() @@ -368,14 +379,21 @@ def edit_proposal(request, proposal_id=None): return render(request, 'fossee_manim/edit_proposal.html', {'proposal_form': proposal_form, "comments": comments, - "comment_form": comment_form, - "upload_form": upload_form}) + "comment_form": comment_form, + "upload_form": upload_form, + 'video': video, + 'categories': categories}) def search(request): + categories = Category.objects.all() if request.method == 'POST': word = request.POST.get('sbox') - return render(request, 'fossee_manim/search_results.html') + anime_list = Animation.objects.filter( + Q(title__contains=word) | Q(description__contains=word)) + + return render(request, 'fossee_manim/search_results.html', + {'s_result': anime_list, 'categories': categories}) @login_required @@ -408,18 +426,32 @@ def upload_animation(request, proposal_id=None): return redirect('/view_profile/') -def video(request, id=None): - video = AnimationStats.objects.filter(id=id) +def video(request, aid=None): + video = AnimationStats.objects.filter(id=aid) + comment_form = CommentForm() # if views crosses limit comment the line below video.update(views=F('views')+1) video.update(like=F('like')+1) - suggestion_list = AnimationStats.objects.filter() - return render(request, 'fossee_manim/video.html', {'video': video}) + anim_list = AnimationStats.objects.filter(animation__status="released") + suggestion_list = [x for x in anim_list if ( + x.animation.category == video[0].animation.category)] + reviewer_id = video[0].animation.reviewer.id + comment_list = Comment.objects.filter(animation=video[0].animation) + comments = [x for x in comment_list if x.animation.status != + ('pending' or 'changes')] + categories = Category.objects.all() + return render(request, 'fossee_manim/video.html', + {'video': video, 'categories': categories, + 'suggestion_list': suggestion_list, + "comment_form": comment_form, + 'comments': comments}) def search_category(request, cat=None): cat_id = Category.objects.get(name=cat) - anim_list = AnimationStats.objects.all() + anim_list = AnimationStats.objects.filter(animation__status="released") cat_video_list = [x for x in anim_list if (x.animation.category == cat_id)] + categories = Category.objects.all() return render(request, 'fossee_manim/categorical_list.html', - {'categorial_list': cat_video_list}) + {'categorial_list': cat_video_list, 'categories': categories + }) -- cgit From e5a0299855a9367eb6e32abfd356ed53c3fb765b Mon Sep 17 00:00:00 2001 From: Akshen Date: Tue, 9 Apr 2019 11:47:42 +0530 Subject: Add play button to thumbnail --- fossee_manim/views.py | 63 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'fossee_manim/views.py') diff --git a/fossee_manim/views.py b/fossee_manim/views.py index b274e63..93a1763 100644 --- a/fossee_manim/views.py +++ b/fossee_manim/views.py @@ -19,7 +19,6 @@ from django.utils import timezone from django.http import HttpResponse, HttpResponseRedirect from django.conf import settings from django.core.files.uploadhandler import FileUploadHandler -from django.contrib import messages from django.db.models import F, Subquery, OuterRef, Q from zipfile import ZipFile from textwrap import dedent @@ -84,8 +83,10 @@ def index(request): if user.groups.filter(name='reviewer').exists(): return redirect('/proposal_status/') return redirect('/view_profile/') - - return render(request, "fossee_manim/index.html", {"form": form}) + anime = AnimationStats.objects.filter(animation__status='released').order_by('-id')[:5] + return render(request, "fossee_manim/index.html", {"form": form, + "anime" : anime + }) def is_reviewer(user): @@ -96,6 +97,7 @@ def is_reviewer(user): def user_login(request): '''User Login''' user = request.user + categories = Category.objects.all() if is_superuser(user): return redirect('/admin') if user.is_authenticated(): @@ -115,7 +117,8 @@ def user_login(request): return render(request, 'fossee_manim/login.html', {"form": form}) else: form = UserLoginForm() - return render(request, 'fossee_manim/login.html', {"form": form}) + return render(request, 'fossee_manim/login.html', {"form": form, + 'categories': categories }) def user_logout(request): @@ -344,7 +347,7 @@ def edit_proposal(request, proposal_id=None): form_data = comment_form.save(commit=False) form_data.commentor = user form_data.animation = proposal - form_data.animation__status = proposal.status + form_data.animation_status = proposal.status if user.profile.position == 'reviewer': proposal.status = 'changes' proposal.save() @@ -389,9 +392,10 @@ def search(request): categories = Category.objects.all() if request.method == 'POST': word = request.POST.get('sbox') - anime_list = Animation.objects.filter( - Q(title__contains=word) | Q(description__contains=word)) - + anime_list = AnimationStats.objects.filter( + Q(animation__title__contains=word) | Q(animation__description__contains=word) + | Q(animation__category__name__contains=word), animation__status='released') + return render(request, 'fossee_manim/search_results.html', {'s_result': anime_list, 'categories': categories}) @@ -421,24 +425,43 @@ def upload_animation(request, proposal_id=None): anobj = AnimationStats.objects.create( animation=proposal, video_path=request.FILES['video_path']) anobj._create_thumbnail() + return render(request, 'fossee_manim/upload_success.html') else: return redirect('/view_profile/') def video(request, aid=None): - video = AnimationStats.objects.filter(id=aid) - comment_form = CommentForm() - # if views crosses limit comment the line below - video.update(views=F('views')+1) - video.update(like=F('like')+1) - anim_list = AnimationStats.objects.filter(animation__status="released") - suggestion_list = [x for x in anim_list if ( - x.animation.category == video[0].animation.category)] - reviewer_id = video[0].animation.reviewer.id - comment_list = Comment.objects.filter(animation=video[0].animation) - comments = [x for x in comment_list if x.animation.status != - ('pending' or 'changes')] + user = request.user + video = AnimationStats.objects.filter(id=aid, animation__status="released") + if len(video): + comment_form = CommentForm() + # if views crosses limit comment the line below + video.update(views=F('views')+1) + video.update(like=F('like')+1) + anim_list = AnimationStats.objects.filter(animation__status="released") + suggestion_list = [x for x in anim_list if ( + x.animation.category == video[0].animation.category)] + reviewer_id = video[0].animation.reviewer.id + comment_list = Comment.objects.filter(animation=video[0].animation) + comments = [x for x in comment_list if x.animation.status != + ('pending' or 'changes')] + if request.method == 'POST': + if is_email_checked(user): + comment_form = CommentForm(request.POST) + form_data = comment_form.save(commit=False) + form_data.commentor = user + form_data.animation = video[0].animation + form_data.animation_status = video[0].animation.status + form_data.save() + return redirect('/video/{}'.format(aid)) + else: + return redirect('/login/') + else: + return redirect('/view_profile/') + + + categories = Category.objects.all() return render(request, 'fossee_manim/video.html', {'video': video, 'categories': categories, -- cgit From 126558d2dd503efdbdce7545dc4353388c1f405a Mon Sep 17 00:00:00 2001 From: Akshen Date: Wed, 10 Apr 2019 10:34:58 +0530 Subject: Adds how_to_contribute page and videos on index page --- fossee_manim/views.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'fossee_manim/views.py') diff --git a/fossee_manim/views.py b/fossee_manim/views.py index 93a1763..44f20c1 100644 --- a/fossee_manim/views.py +++ b/fossee_manim/views.py @@ -23,6 +23,7 @@ from django.db.models import F, Subquery, OuterRef, Q from zipfile import ZipFile from textwrap import dedent from requests import get +from random import sample from .send_mails import send_email import datetime as dt import shutil @@ -112,7 +113,7 @@ def user_login(request): login(request, user) if user.groups.filter(name='reviewer').count() > 0: return redirect('/view_profile/') - return redirect('/view_profile/') + return redirect('/how_to/') else: return render(request, 'fossee_manim/login.html', {"form": form}) else: @@ -460,12 +461,14 @@ def video(request, aid=None): else: return redirect('/view_profile/') - - + if len(suggestion_list)>3: + suggestion_list = sample(suggestion_list, 3) + else: + suggestion_list = [x for x in anim_list if x.id != int(aid)][:3] categories = Category.objects.all() return render(request, 'fossee_manim/video.html', {'video': video, 'categories': categories, - 'suggestion_list': suggestion_list, + 'reco': suggestion_list, "comment_form": comment_form, 'comments': comments}) @@ -478,3 +481,7 @@ def search_category(request, cat=None): return render(request, 'fossee_manim/categorical_list.html', {'categorial_list': cat_video_list, 'categories': categories }) + + +def how_to(request): + return render(request, 'fossee_manim/how_to.html') \ No newline at end of file -- cgit