diff options
author | Alwin1847207 | 2019-11-04 17:03:10 +0530 |
---|---|---|
committer | Alwin1847207 | 2019-11-04 17:03:10 +0530 |
commit | 7c650b158109a9d59882365d26f0327390268f13 (patch) | |
tree | 1140bf6b65c75b9b175adb08d9206104f60104a5 /fossee_manim/views.py | |
parent | 9a63fcaff0974fa6401d48c5dae53782f50c4ddc (diff) | |
parent | cfdc41deed280bddbcc6c3cf45e30f33ea139e88 (diff) | |
download | FOSSEE_animations-7c650b158109a9d59882365d26f0327390268f13.tar.gz FOSSEE_animations-7c650b158109a9d59882365d26f0327390268f13.tar.bz2 FOSSEE_animations-7c650b158109a9d59882365d26f0327390268f13.zip |
removed merge conflicts
Diffstat (limited to 'fossee_manim/views.py')
-rw-r--r-- | fossee_manim/views.py | 370 |
1 files changed, 307 insertions, 63 deletions
diff --git a/fossee_manim/views.py b/fossee_manim/views.py index faa93b9..3ea851e 100644 --- a/fossee_manim/views.py +++ b/fossee_manim/views.py @@ -2,7 +2,8 @@ from os import listdir, path, sep, makedirs, remove from .forms import ( UserRegistrationForm, UserLoginForm, ProfileForm, AnimationProposal, - CommentForm, UploadAnimationForm + CommentForm, UploadAnimationForm, + AnimationProposal_edit ) from .models import ( Profile, User, AnimationStats, @@ -35,9 +36,14 @@ except ImportError: from io import BytesIO as string_io __author__ = "Akshen Doke" -__credits__ = ["Prabhu Ramachandran", "Aditya P.", "KhushalSingh Rajput", - "Prathamesh Salunke", "Purusharth Saxsena", "Sharanya Achut", "Ankit Javalkar" - ] +__credits__ = [ + "Prabhu Ramachandran", + "Aditya P.", + "KhushalSingh Rajput", + "Prathamesh Salunke", + "Purusharth Saxsena", + "Sharanya Achut", + "Ankit Javalkar"] def makepath(proposal_data, reject=None): @@ -52,10 +58,9 @@ def makepath(proposal_data, reject=None): settings.MEDIA_ROOT, proposal_data.category.name, proposal_data.title.replace(" ", "_") )) - except: + except BaseException: logging.info("Proposal rejected") - else: makedirs(path.join(settings.MEDIA_ROOT, proposal_data.category.name, proposal_data.title.replace(" ", "_") @@ -65,7 +70,7 @@ def makepath(proposal_data, reject=None): def check_repo(link): try: return (get(link).status_code == 200) - except: + except BaseException: return False @@ -88,7 +93,9 @@ def index(request): categories = Category.objects.all() if user.is_authenticated() and is_email_checked(user): return redirect('/proposal_status/') - return render(request, "fossee_manim/index.html", {"categories": categories}) + return render(request, + "fossee_manim/index.html", + {"categories": categories}) def is_reviewer(user): @@ -119,8 +126,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, - 'categories': categories}) + return render(request, 'fossee_manim/login.html', + {"form": form, 'categories': categories}) def user_logout(request): @@ -154,7 +161,7 @@ def activate_user(request, key=None): try: user = Profile.objects.get(activation_key=key) - except: + except BaseException: return redirect('/register/') if key == user.activation_key: @@ -198,14 +205,18 @@ def user_register(request): elif request.user.is_authenticated(): return render(request, 'fossee_manim/activation.html') form = UserRegistrationForm() - return render(request, "fossee_manim/register.html", {'form': form, 'categories': categories}) + return render(request, "fossee_manim/register.html", + {'form': form, 'categories': categories}) def explore(request, category): categories = Category.objects.all() # not related to category below - videos = AnimationStats.objects.filter(animation__category__name=category, animation__status="released") + videos = AnimationStats.objects.filter( + animation__category__name=category, + animation__status="released") - return render(request, "fossee_manim/explore.html", {"videos": videos, "categories": categories}) + return render(request, "fossee_manim/explore.html", + {"videos": videos, "categories": categories}) @login_required @@ -225,7 +236,7 @@ def view_profile(request): try: logout(request) return redirect('/login/') - except: + except BaseException: return redirect('/register/') @@ -246,7 +257,7 @@ def edit_profile(request): try: logout(request) return redirect('/login/') - except: + except BaseException: return redirect('/register/') context = {'template': template} @@ -274,9 +285,8 @@ def edit_profile(request): 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, - 'categories': categories} - ) + return render(request, 'fossee_manim/edit_profile.html', + {'form': form, 'categories': categories}) @login_required @@ -310,7 +320,8 @@ def proposal_status(request): profile = Profile.objects.get(user_id=user) categories = Category.objects.all() if profile.position == 'contributor': - animations = Animation.objects.filter(contributor_id=user).order_by('-created') + animations = Animation.objects.filter( + contributor_id=user).order_by('-created') else: animations = Animation.objects.order_by('-created') # print(animations) @@ -336,24 +347,161 @@ def proposal_status(request): @login_required +def sortproposal_released(request): + user = request.user + if is_email_checked(user) and user.is_authenticated(): + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + if profile.position == 'contributor': + animations = Animation.objects.filter( + contributor_id=user, status='released').order_by('-created') + else: + animations = Animation.objects.filter( + status='released').order_by('-created') + # print(animations) + + # Show upto 9 proposals per page + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + anime = paginator.page(1) + except EmptyPage: + # If page is out of range(e.g 999999), deliver last page. + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', + {'anime': anime, + 'categories': categories}) + else: + return redirect('/login/') + + +@login_required +def sortproposal_rejected(request): + user = request.user + if is_email_checked(user) and user.is_authenticated(): + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + if profile.position == 'contributor': + animations = Animation.objects.filter( + contributor_id=user, status='rejected').order_by('-created') + else: + animations = Animation.objects.filter( + status='rejected').order_by('-created') + # print(animations) + + # Show upto 9 proposals per page + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + anime = paginator.page(1) + except EmptyPage: + # If page is out of range(e.g 999999), deliver last page. + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', + {'anime': anime, + 'categories': categories}) + else: + return redirect('/login/') + + +@login_required +def sortproposal_changes(request): + user = request.user + if is_email_checked(user) and user.is_authenticated(): + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + if profile.position == 'contributor': + animations = Animation.objects.filter( + contributor_id=user, status='changes').order_by('-created') + else: + animations = Animation.objects.filter( + status='changes').order_by('-created') + # print(animations) + + # Show upto 9 proposals per page + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + anime = paginator.page(1) + except EmptyPage: + # If page is out of range(e.g 999999), deliver last page. + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', + {'anime': anime, + 'categories': categories}) + else: + return redirect('/login/') + + +@login_required +def sortproposal_pending(request): + user = request.user + if is_email_checked(user) and user.is_authenticated(): + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + if profile.position == 'contributor': + animations = Animation.objects.filter( + contributor_id=user, status='pending').order_by('-created') + else: + animations = Animation.objects.filter( + status='pending').order_by('-created') + # print(animations) + + # Show upto 9 proposals per page + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + anime = paginator.page(1) + except EmptyPage: + # If page is out of range(e.g 999999), deliver last page. + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', + {'anime': anime, + 'categories': categories}) + else: + return redirect('/login/') + + +@login_required def edit_proposal(request, proposal_id=None): user = request.user if is_email_checked(user) and user.is_authenticated(): comment_form = CommentForm() proposal = Animation.objects.get(id=proposal_id) - proposal_form = AnimationProposal(instance=proposal) + proposal_form = AnimationProposal_edit(instance=proposal) upload_form = UploadAnimationForm() categories = Category.objects.all() video = AnimationStats.objects.filter(animation=proposal_id) if len(video) > 0: - msg = ('Previously a video was uploaded for ' + video[0].animation.title) + msg = ( + 'Previously a video was uploaded for ' + + video[0].animation.title) else: msg = ('No video uploaded') try: - comments = Comment.objects.filter(animation_id=proposal_id).order_by( - '-created_date' - ) - except: + comments = Comment.objects.filter( + animation_id=proposal_id).order_by('-created_date') + except BaseException: comments = None if request.method == 'POST': text = request.POST.get('comment') @@ -393,7 +541,8 @@ def edit_proposal(request, proposal_id=None): proposal=proposal) form_data.save() return redirect('/edit_proposal/{}'.format(proposal_id)) - proposal_form = AnimationProposal(request.POST, instance=proposal) + proposal_form = AnimationProposal_edit( + request.POST, instance=proposal) if proposal_form.is_valid(): p_f = proposal_form.save(commit=False) p_f.contributor = user @@ -429,39 +578,85 @@ def edit_proposal(request, proposal_id=None): @login_required -def delete_proposal(request, proposal_id=None): +def show_proposal_detail(request, proposal_id=None): user = request.user if is_email_checked(user) and user.is_authenticated(): - proposal = Animation.objects.get(id=proposal_id) - - return render(request, 'fossee_manim/delete_proposal.html', {'proposal': proposal}) + try: + proposal = Animation.objects.get(id=proposal_id) + return render(request, 'fossee_manim/delete_proposal.html', {'proposal': proposal}) + except: + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + if profile.position == 'contributor': + animations = Animation.objects.filter( + contributor_id=user).order_by('-created') + else: + animations = Animation.objects.order_by('-created') + + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + anime = paginator.page(1) + except EmptyPage: + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', + {'anime': anime, + 'categories': categories}) else: return redirect('/register/') @login_required -def delete_proposal_info(request, proposal_id=None): +def delete_proposal(request, proposal_id=None): user = request.user if is_email_checked(user) and user.is_authenticated(): - proposal = Animation.objects.get(id=proposal_id) - proposal.delete() - profile = Profile.objects.get(user_id=user) - categories = Category.objects.all() - if profile.position == 'contributor': - animations = Animation.objects.filter(contributor_id=user).order_by('-created') - else: - animations = Animation.objects.order_by('-created') - paginator = Paginator(list(animations), 9) - page = request.GET.get('page') try: - anime = paginator.page(page) - print(animations.count(), anime) - except PageNotAnInteger: - anime = paginator.page(1) - except EmptyPage: - anime = paginator.page(paginator.num_pages) + proposal = Animation.objects.get(id=proposal_id) + proposal.delete() + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + if profile.position == 'contributor': + animations = Animation.objects.filter( + contributor_id=user).order_by('-created') + else: + animations = Animation.objects.order_by('-created') + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + anime = paginator.page(1) + except EmptyPage: + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', {'anime': anime, 'categories': categories}) + except: + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + if profile.position == 'contributor': + animations = Animation.objects.filter( + contributor_id=user).order_by('-created') + else: + animations = Animation.objects.order_by('-created') - return render(request, 'fossee_manim/proposal_status.html',{'anime': anime,'categories': categories}) + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + anime = paginator.page(1) + except EmptyPage: + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', + {'anime': anime, + 'categories': categories}) else: return redirect('/login/') @@ -471,13 +666,44 @@ def search(request): if request.method == 'POST': word = request.POST.get('sbox') anime_list = AnimationStats.objects.filter( - Q(animation__title__contains=word) | Q(animation__outline__contains=word) - | Q(animation__category__name__contains=word) | Q(animation__subcategory__contains=word), + Q( + animation__title__contains=word) | Q( + animation__outline__contains=word) | Q( + animation__category__name__contains=word) | Q( + animation__subcategory__contains=word), animation__status='released') return render(request, 'fossee_manim/search_results.html', {'s_result': anime_list, 'categories': categories}) +# search results for proposal + + +def search_proposal(request): + user = request.user + if is_email_checked(user) and user.is_authenticated(): + profile = Profile.objects.get(user_id=user) + categories = Category.objects.all() + word = request.POST.get('sbox') + animations = Animation.objects.filter(title=word) + paginator = Paginator(list(animations), 9) + page = request.GET.get('page') + try: + anime = paginator.page(page) + print(animations.count(), anime) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + anime = paginator.page(1) + except EmptyPage: + # If page is out of range(e.g 999999), deliver last page. + anime = paginator.page(paginator.num_pages) + + return render(request, 'fossee_manim/proposal_status.html', + {'anime': anime, + 'categories': categories}) + else: + return redirect('/login/') + @login_required def upload_animation(request, proposal_id=None): @@ -495,7 +721,7 @@ def upload_animation(request, proposal_id=None): anobj = anim.first() try: remove(anobj.thumbnail.path) - except: + except BaseException: pass remove(anobj.video_path.path) anobj.delete() @@ -506,7 +732,7 @@ def upload_animation(request, proposal_id=None): animation=proposal, video_path=request.FILES['video_path']) anobj._create_thumbnail() return render(request, 'fossee_manim/upload_success.html') - except: + except BaseException: messages.warning(request, 'Please Upload a valid File') return redirect('/edit_proposal/{}'.format(proposal_id)) @@ -526,7 +752,7 @@ def video(request, aid=None): 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)] + 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 not in @@ -569,44 +795,62 @@ def search_category(request, cat=None): def guidelines(request): categories = Category.objects.all() - return render(request, 'fossee_manim/guidelines.html', {'categories': categories}) + return render(request, + 'fossee_manim/guidelines.html', + {'categories': categories}) def about(request): categories = Category.objects.all() - return render(request, 'fossee_manim/about.html', {'categories': categories}) + return render(request, + 'fossee_manim/about.html', + {'categories': categories}) def honorarium(request): categories = Category.objects.all() - return render(request, 'fossee_manim/honorarium.html', {'categories': categories}) + return render(request, + 'fossee_manim/honorarium.html', + {'categories': categories}) def faqs(request): categories = Category.objects.all() - return render(request, 'fossee_manim/faqs.html', {'categories': categories}) + return render(request, + 'fossee_manim/faqs.html', + {'categories': categories}) def outreach(request): categories = Category.objects.all() - return render(request, 'fossee_manim/outreach.html', {'categories': categories}) + return render(request, + 'fossee_manim/outreach.html', + {'categories': categories}) def library(request): categories = Category.objects.all() - return render(request, 'fossee_manim/library.html', {'categories': categories}) + return render(request, + 'fossee_manim/library.html', + {'categories': categories}) def libraryMath(request): categories = Category.objects.all() - return render(request, 'fossee_manim/libraryMath.html', {'categories': categories}) + return render(request, + 'fossee_manim/libraryMath.html', + {'categories': categories}) def libraryPhys(request): categories = Category.objects.all() - return render(request, 'fossee_manim/libraryPhys.html', {'categories': categories}) + return render(request, + 'fossee_manim/libraryPhys.html', + {'categories': categories}) def libraryCS(request): categories = Category.objects.all() - return render(request, 'fossee_manim/libraryCS.html', {'categories': categories}) + return render(request, + 'fossee_manim/libraryCS.html', + {'categories': categories}) |