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/admin.py | 29 +++++++++- fossee_manim/forms.py | 3 +- fossee_manim/models.py | 1 + fossee_manim/static/css/sticky-footer.css | 14 ----- fossee_manim/templates/fossee_manim/base.html | 14 ++--- .../templates/fossee_manim/categorical_list.html | 29 ++++++---- .../templates/fossee_manim/edit_proposal.html | 6 +- .../templates/fossee_manim/search_results.html | 28 ++++++++-- fossee_manim/templates/fossee_manim/video.html | 62 +++++++++++++++++---- fossee_manim/views.py | 64 ++++++++++++++++------ 10 files changed, 182 insertions(+), 68 deletions(-) (limited to 'fossee_manim') diff --git a/fossee_manim/admin.py b/fossee_manim/admin.py index 35bf57b..121c487 100644 --- a/fossee_manim/admin.py +++ b/fossee_manim/admin.py @@ -46,5 +46,32 @@ class CategoryAdmin(admin.ModelAdmin): list_filter = ['name'] +class AnimationAdmin(admin.ModelAdmin): + list_display = ['title', 'status', 'contributor'] + list_filter = ['category'] + actions = ['download_data'] + + def download_data(self, request, queryset): + openfile = string_io() + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment;\ + filename=animations_data.csv' + + writer = csv.writer(response) + writer.writerow(['title', 'contributor', 'reviewer', 'description', + 'status', 'github link', 'category']) + + for q in queryset: + writer.writerow([q.title, q.contributor.get_full_name(), + q.reviewer.get_full_name(), q.description, q.status, q.github, + q.category]) + + openfile.seek(0) + response.write(openfile.read()) + return response + + download_data.short_description = "Download data CSV file." + admin.site.register(Category, CategoryAdmin) -admin.site.register(Profile, ProfileAdmin) \ No newline at end of file +admin.site.register(Profile, ProfileAdmin) +admin.site.register(Animation, AnimationAdmin) \ No newline at end of file diff --git a/fossee_manim/forms.py b/fossee_manim/forms.py index b3b33eb..72e5c83 100644 --- a/fossee_manim/forms.py +++ b/fossee_manim/forms.py @@ -263,7 +263,8 @@ class CommentForm(forms.ModelForm): class Meta: model = Comment - exclude = ['animation', 'created_date', 'commentor'] + exclude = ['animation', 'created_date', 'commentor', + 'animation_status'] widgets = { 'comments': forms.CharField(), } diff --git a/fossee_manim/models.py b/fossee_manim/models.py index 75f03da..240ec1b 100644 --- a/fossee_manim/models.py +++ b/fossee_manim/models.py @@ -179,6 +179,7 @@ class Comment(models.Model): commentor = models.ForeignKey(User, on_delete=models.CASCADE) animation = models.ForeignKey(Animation, on_delete=models.CASCADE) created_date = models.DateTimeField(default=timezone.now) + animation_status = models.CharField(max_length=255) def __str__(self): return u"{1} | {0}".format( diff --git a/fossee_manim/static/css/sticky-footer.css b/fossee_manim/static/css/sticky-footer.css index ea445db..d0054bd 100644 --- a/fossee_manim/static/css/sticky-footer.css +++ b/fossee_manim/static/css/sticky-footer.css @@ -70,17 +70,3 @@ margin-left: .1rem; margin-right: .1rem; } - - -/** - * Footer Styles - */ - -.footer { - position: fixed; - right: 0; - bottom: 0; - left: 0; - background-color: #efefef; - text-align: center; -} \ No newline at end of file diff --git a/fossee_manim/templates/fossee_manim/base.html b/fossee_manim/templates/fossee_manim/base.html index c9d6242..3fdd977 100644 --- a/fossee_manim/templates/fossee_manim/base.html +++ b/fossee_manim/templates/fossee_manim/base.html @@ -43,10 +43,11 @@ + @@ -93,10 +94,5 @@ {% endblock %} -

- +
\ No newline at end of file diff --git a/fossee_manim/templates/fossee_manim/categorical_list.html b/fossee_manim/templates/fossee_manim/categorical_list.html index a61ab40..c3bfacd 100644 --- a/fossee_manim/templates/fossee_manim/categorical_list.html +++ b/fossee_manim/templates/fossee_manim/categorical_list.html @@ -6,23 +6,30 @@ {% block content %}
-
+

-
+

{{ categorial_list.0.animation.category }}



-
- {% for video in categorial_list %} -
- + + {% for video in categorial_list %} +
+
+ +
+
+

{{ video.animation.title }}

+

{{ video.animation.description | truncatewords:5}}

+

{{ video.animation.github }}

-
- {% endfor %} -
-
-
+
+
+ {% endfor %} +
+
+
{% endblock %} \ No newline at end of file diff --git a/fossee_manim/templates/fossee_manim/edit_proposal.html b/fossee_manim/templates/fossee_manim/edit_proposal.html index 3edad99..4ca98cd 100644 --- a/fossee_manim/templates/fossee_manim/edit_proposal.html +++ b/fossee_manim/templates/fossee_manim/edit_proposal.html @@ -23,7 +23,7 @@
- {% if proposal_form.instance.status == 'changes' %} + {% if proposal_form.instance.status == 'changes' and request.user.profile.position == 'coordinator' %}
{% csrf_token %}
+ {% else %} + {% endif %}

diff --git a/fossee_manim/templates/fossee_manim/search_results.html b/fossee_manim/templates/fossee_manim/search_results.html index 2e70f78..5ade6d2 100644 --- a/fossee_manim/templates/fossee_manim/search_results.html +++ b/fossee_manim/templates/fossee_manim/search_results.html @@ -1,13 +1,31 @@ {% extends 'fossee_manim/base.html' %} {% block title %} - Login + Search Result {% endblock %} {% block content %} -
-
- {{ args }} -
+
+
+
+ +
+
+ {% for anime in s_result %} +
+
+ +
+
+

{{ anime.title }}

+

{{ anime.description | truncatewords:5}}

+

{{ anime.github }}

+
+
+
+ {% endfor %} +
+
+
{% endblock %} \ No newline at end of file diff --git a/fossee_manim/templates/fossee_manim/video.html b/fossee_manim/templates/fossee_manim/video.html index ff020e5..4ffcb47 100644 --- a/fossee_manim/templates/fossee_manim/video.html +++ b/fossee_manim/templates/fossee_manim/video.html @@ -5,20 +5,62 @@ {% endblock %} {% block content %} -
-
-
+
-
-
+
+
+

+ {{ video.0.animation.description }} +

+
+
-
+
+
+

+

Comments

+
+
+
+ {% csrf_token %} + {{ comment_form.as_p }} + +
+ +
+
+ + {% for comment in comments %} + + + + + + {% endfor %} +
+
{{ comment.commentor.profile.user.get_full_name }} | {{ comment.created_date | date }}
+
{{ comment.comment }}
+
+
+ +
+
{% endblock %} \ No newline at end of file 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