From baa5595b9e0715e52e123fb0564a269671a61b61 Mon Sep 17 00:00:00 2001 From: lordaniket06 Date: Wed, 12 Jul 2017 15:00:17 +0530 Subject: [PATCH] Either accept or reject in nomination answers --- db.sqlite3 | Bin 423936 -> 423936 bytes nomi/migrations/0113_auto_20170712_0920.py | 22 ++ nomi/models.py | 6 +- nomi/templates/nomi_answer.html | 73 +++++-- nomi/views.py | 225 ++++++++++----------- 5 files changed, 194 insertions(+), 132 deletions(-) create mode 100644 nomi/migrations/0113_auto_20170712_0920.py diff --git a/db.sqlite3 b/db.sqlite3 index 5ffc30319a0f75497ebcaf6f557bb3ba7fc2d501..a309f460c522e7dc0ac2a79e86741ba8ec7352bd 100644 GIT binary patch delta 1438 zcmZuwYe-y26rMBZ-rd!^x~{J4Td$h>ips9mx3+HFwu%qvD}@r!t9#Y;u`AxyxESzJ zTT^OE?H1=(TcKrzM4L7XSwoUS0|g6hA%!ONM?sR%C#6Eu&=3X6DSC zIp^Hzt(57lly}n1!-T*G+z1~Z5`vb+;&K@Ntm^>a^k3Q1XXB!-ryu5EoZ zzeUDIreC0rkU9My%9iyYSXzrk1ZXLWU_k`)*uW%ovBpU#Wj{?qW>_%7!$IBu`cq3W zdom15M|M1=s0bP&sE?p7g5nP93WBGgdIbtlcvlv}!a6+sD-Ql7l>9*ODu*Hkb>BiSVMI$R^0eEWAS z^ESO@oR#Jh3`sKytuWiflnzK_aW|=nwcqC8zd;kj)*JNqC=+H9fiObbp_VY5;QsT% zOx9cydwP{NLKA!b4p`WGtF+Z%nzQPY^7ASCd6i~Ua+NKv(*%~jMjH}(yu-t)$EW4U zK6Sz;cf8!z#*VMi*PxKK-=f#~L&&TA%pN$=AuJauPjL+uQILt>r7;~jR}?Dq0bWz6U8EVJ3GY*qHMPFqcxZAX;Ys!Hr- zvaP1J%wB7=m)feT?G;tw`){B=CDN)()2Lg~eT)_uVET2;(!l_ng@usa_!Q*GZF-Uc z0ELd89(Ba0x{}kLY4P~f(Q&tWQg(VhYIxx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oed6K7mnwSWOTcy@nki@DtGPHfFevd6vw2J-S5s||#GJ$-)PX|*vJ zR$ak>FZS|vj8(&XOxZv?B{x~+24=&Jn0o`w{P%p9yN+_cz(4sde~xMV&iRMPS%{r~ UsOvvCWl&JzBf)3jsJQ;@zcuJzZ~y=R diff --git a/nomi/migrations/0113_auto_20170712_0920.py b/nomi/migrations/0113_auto_20170712_0920.py new file mode 100644 index 00000000..44b2a003 --- /dev/null +++ b/nomi/migrations/0113_auto_20170712_0920.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-07-12 09:20 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('nomi', '0112_auto_20170706_1008'), + ] + + operations = [ + migrations.AlterField( + model_name='commment', + name='user', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/nomi/models.py b/nomi/models.py index f3909d9d..fced645a 100644 --- a/nomi/models.py +++ b/nomi/models.py @@ -56,7 +56,7 @@ class Nomination(models.Model): status = models.CharField(max_length=50, choices=STATUS, default='Nomination created') result_approvals = models.ManyToManyField(Post, related_name='result_approvals', symmetrical=False, blank=True) nomi_approvals = models.ManyToManyField(Post, related_name='nomi_approvals', symmetrical=False, blank=True) - group_status = models.CharField(max_length=50, choices= GROUP_STATUS, default='normal') + group_status = models.CharField(max_length=50, choices=GROUP_STATUS, default='normal') tags = models.ManyToManyField(Club, related_name='club_nomi', symmetrical=False, blank=True) opening_date = models.DateField(null=True, blank=True) @@ -114,7 +114,7 @@ def __str__(self): class NominationInstance(models.Model): nomination = models.ForeignKey('Nomination', on_delete=models.CASCADE, null=True) - user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True) + user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True) status = models.CharField(max_length=20, choices=NOMI_STATUS, null=True, blank=True, default=None) interview_status = models.CharField(max_length=20, choices=INTERVIEW_STATUS, null=True, blank=True, default='Interview Not Done') @@ -127,7 +127,7 @@ def __str__(self): class Commment(models.Model): comments = models.TextField(max_length=1000, null=True, blank=True) nomi_instance = models.ForeignKey(NominationInstance, on_delete=models.CASCADE, null=True) - user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True) + user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) def user_directory_path(instance, filename): diff --git a/nomi/templates/nomi_answer.html b/nomi/templates/nomi_answer.html index c4f47644..56ac3b95 100644 --- a/nomi/templates/nomi_answer.html +++ b/nomi/templates/nomi_answer.html @@ -101,15 +101,36 @@

Response

{% if result_approval.0 %} {% if nomi.nomination.status == 'Interview period' and nomi.interview_status == 'Interview Done' %} -
-
-
Accept
-
+ {% if nomi.status %} + {% if nomi.status == 'Accepted' %} +
+
+
Reject
+
+
+ {% elif nomi.status == 'Rejected' %} +
+
+
Accept
+
+
+ {% endif %} + {% else %} +
+
+
Accept
+
+ +
+
Reject
+
+
+ {% endif %} -
-
Reject
-
-
{% elif nomi.nomination.status == 'Interview period' and nomi.interview_status == 'Interview Not Done' %}
@@ -120,13 +141,35 @@

Response

{% elif senate_perm %}
-
-
Accept
-
- -
-
Reject
-
+ {% if nomi.status %} + {% if nomi.status == 'Accepted' %} +
+
+
Reject
+
+
+ {% elif nomi.status == 'Rejected' %} +
+
+
Accept
+
+
+ {% endif %} + {% else %} +
+
+
Accept
+
+ +
+
Reject
+
+
+ {% endif %}
{% endif %} {% endif %} diff --git a/nomi/views.py b/nomi/views.py index bff0390b..d78f8bf8 100644 --- a/nomi/views.py +++ b/nomi/views.py @@ -64,11 +64,6 @@ def index(request): -# a view link for user who have some post.... -# It include the all nomination that the given user have perms to see whether it is being created or out or in interview period... -# is_safe -# to add ------- nomi that the user has been added as panel ******** - @login_required def admin_portal(request): posts = Post.objects.filter(post_holders=request.user) @@ -472,114 +467,6 @@ def copy_nomi_link(request, pk): return HttpResponseRedirect(reverse('admin_portal')) -## ------------------------------------------------------------------------------------------------------------------ ## -######################################### GROUP NOMINATION VIEWS ################################################ -## ------------------------------------------------------------------------------------------------------------------ ## - - -@login_required -def group_nominations(request, pk): - post = Post.objects.get(pk=pk) - child_posts = Post.objects.filter(parent=post) - child_posts_reverse = child_posts[::-1] - post_approvals = Post.objects.filter(post_approvals=post).filter(status='Post created') - nomi_approvals = Nomination.objects.filter(nomi_approvals=post).filter(status='Nomination created') - - if request.method == 'POST': - groupform = SelectNomiForm(post, request.POST) - title_form = GroupNominationForm(request.POST) - if title_form.is_valid(): - if groupform.is_valid(): - group = GroupNomination.objects.create(name=title_form.cleaned_data['title'], - description=title_form.cleaned_data['description']) - group.approvals.add(post) - for nomi_pk in groupform.cleaned_data['group']: - # things to be performed on nomination - nomi = Nomination.objects.get(pk=nomi_pk) - group.nominations.add(nomi) - for tag in nomi.tags.all(): - group.tags.add(tag) - nomi.group_status = 'grouped' - to_add = post.parent - nomi.nomi_approvals.add(to_add) - nomi.save() - nomi.open_to_users() - return HttpResponseRedirect(reverse('post_view', kwargs={'pk': pk})) - - else: - title_form = GroupNominationForm - groupform = SelectNomiForm(post) - - return render(request, 'nomi_group.html', context={'post': post, 'child_posts': child_posts_reverse, - 'post_approval': post_approvals, 'nomi_approval': nomi_approvals, - 'form': groupform, 'title_form': title_form}) - - -@login_required -def group_nomi_detail(request, pk): - group_nomi = GroupNomination.objects.get(pk=pk) - admin = 0 - for post in request.user.posts.all(): - if post in group_nomi.approvals.all(): - admin = post - - form_confirm = ConfirmApplication(request.POST or None) - if form_confirm.is_valid(): - group_nomi.status = 'out' - group_nomi.save() - - return render(request, 'group_detail.html', {'group_nomi': group_nomi, 'admin': admin, - 'form_confirm': form_confirm}) - - -@login_required -def add_to_group(request, pk, gr_pk): - post = Post.objects.get(pk=pk) - child_posts = Post.objects.filter(parent=post) - child_posts_reverse = child_posts[::-1] - post_approvals = Post.objects.filter(post_approvals=post).filter(status='Post created') - nomi_approvals = Nomination.objects.filter(nomi_approvals=post).filter(status='Nomination created') - - if request.method == 'POST': - groupform = SelectNomiForm(post, request.POST) - if groupform.is_valid(): - group = GroupNomination.objects.get(pk=gr_pk) - - for nomi_pk in groupform.cleaned_data['group']: - # things to be performed on nomination - nomi = Nomination.objects.get(pk=nomi_pk) - group.nominations.add(nomi) - for tag in nomi.tags.all(): - group.tags.add(tag) - nomi.group_status = 'grouped' - to_add = post.parent - nomi.nomi_approvals.add(to_add) - nomi.save() - nomi.open_to_users() - return HttpResponseRedirect(reverse('group_nomi_detail', kwargs={'pk': gr_pk})) - - else: - title_form = None - groupform = SelectNomiForm(post) - - return render(request, 'nomi_group.html', context={'post': post, 'child_posts': child_posts_reverse, - 'post_approval': post_approvals, 'nomi_approval': nomi_approvals, - 'form': groupform, 'title_form': title_form}) - - -@login_required -def remove_from_group(request, nomi_pk, gr_pk): - nomi = Nomination.objects.get(pk=nomi_pk) - group = GroupNomination.objects.get(pk=gr_pk) - group.nominations.remove(nomi) - - nomi.group_status = 'normal' - nomi.status = 'Nomination created' - nomi.save() - - return HttpResponseRedirect(reverse('group_nomi_detail', kwargs={'pk': gr_pk})) - - ## ------------------------------------------------------------------------------------------------------------------ ## ######################################### NOMINATION MONITOR VIEWS ################################################ ## ------------------------------------------------------------------------------------------------------------------ ## @@ -708,7 +595,6 @@ def nomination_answer(request, pk): questionnaire = application.nomination.nomi_form form = questionnaire.get_form(data) - comments = Commment.objects.filter(nomi_instance=application) comments_reverse = comments[::-1] comment_form = CommentForm(request.POST or None) @@ -761,6 +647,7 @@ def nomination_answer(request, pk): if comment_form.is_valid(): Commment.objects.create(comments=comment_form.cleaned_data['comment'], nomi_instance=application, user=request.user) + return HttpResponseRedirect(reverse('nomi_answer', kwargs={'pk': pk})) return render(request, 'nomi_answer.html', context={'form': form, 'nomi': application, 'nomi_user': applicant, @@ -769,6 +656,116 @@ def nomination_answer(request, pk): 'nomi_pk': nomination.pk, 'result_approval': results_approval, 'auth_user': auth_user}) + +## ------------------------------------------------------------------------------------------------------------------ ## +######################################### GROUP NOMINATION VIEWS ################################################ +## ------------------------------------------------------------------------------------------------------------------ ## + + +@login_required +def group_nominations(request, pk): + post = Post.objects.get(pk=pk) + child_posts = Post.objects.filter(parent=post) + child_posts_reverse = child_posts[::-1] + post_approvals = Post.objects.filter(post_approvals=post).filter(status='Post created') + nomi_approvals = Nomination.objects.filter(nomi_approvals=post).filter(status='Nomination created') + + if request.method == 'POST': + groupform = SelectNomiForm(post, request.POST) + title_form = GroupNominationForm(request.POST) + if title_form.is_valid(): + if groupform.is_valid(): + group = GroupNomination.objects.create(name=title_form.cleaned_data['title'], + description=title_form.cleaned_data['description']) + group.approvals.add(post) + for nomi_pk in groupform.cleaned_data['group']: + # tasks to be performed on nomination + nomi = Nomination.objects.get(pk=nomi_pk) + group.nominations.add(nomi) + for tag in nomi.tags.all(): + group.tags.add(tag) + nomi.group_status = 'grouped' + to_add = post.parent + nomi.nomi_approvals.add(to_add) + nomi.save() + nomi.open_to_users() + return HttpResponseRedirect(reverse('post_view', kwargs={'pk': pk})) + + else: + title_form = GroupNominationForm + groupform = SelectNomiForm(post) + + return render(request, 'nomi_group.html', context={'post': post, 'child_posts': child_posts_reverse, + 'post_approval': post_approvals, 'nomi_approval': nomi_approvals, + 'form': groupform, 'title_form': title_form}) + + +@login_required +def group_nomi_detail(request, pk): + group_nomi = GroupNomination.objects.get(pk=pk) + admin = 0 + for post in request.user.posts.all(): + if post in group_nomi.approvals.all(): + admin = post + + form_confirm = ConfirmApplication(request.POST or None) + if form_confirm.is_valid(): + group_nomi.status = 'out' + group_nomi.save() + + return render(request, 'group_detail.html', {'group_nomi': group_nomi, 'admin': admin, + 'form_confirm': form_confirm}) + + +@login_required +def add_to_group(request, pk, gr_pk): + post = Post.objects.get(pk=pk) + child_posts = Post.objects.filter(parent=post) + child_posts_reverse = child_posts[::-1] + post_approvals = Post.objects.filter(post_approvals=post).filter(status='Post created') + nomi_approvals = Nomination.objects.filter(nomi_approvals=post).filter(status='Nomination created') + + if request.method == 'POST': + groupform = SelectNomiForm(post, request.POST) + if groupform.is_valid(): + group = GroupNomination.objects.get(pk=gr_pk) + + for nomi_pk in groupform.cleaned_data['group']: + # things to be performed on nomination + nomi = Nomination.objects.get(pk=nomi_pk) + group.nominations.add(nomi) + for tag in nomi.tags.all(): + group.tags.add(tag) + nomi.group_status = 'grouped' + to_add = post.parent + nomi.nomi_approvals.add(to_add) + nomi.save() + nomi.open_to_users() + return HttpResponseRedirect(reverse('group_nomi_detail', kwargs={'pk': gr_pk})) + + else: + title_form = None + groupform = SelectNomiForm(post) + + return render(request, 'nomi_group.html', context={'post': post, 'child_posts': child_posts_reverse, + 'post_approval': post_approvals, 'nomi_approval': nomi_approvals, + 'form': groupform, 'title_form': title_form}) + + +@login_required +def remove_from_group(request, nomi_pk, gr_pk): + nomi = Nomination.objects.get(pk=nomi_pk) + group = GroupNomination.objects.get(pk=gr_pk) + group.nominations.remove(nomi) + + nomi.group_status = 'normal' + nomi.status = 'Nomination created' + nomi.save() + + return HttpResponseRedirect(reverse('group_nomi_detail', kwargs={'pk': gr_pk})) + + + ## ------------------------------------------------------------------------------------------------------------------ ## ########################################### RATIFICATION VIEWS ################################################### ## ------------------------------------------------------------------------------------------------------------------ ##