Skip to content

Commit

Permalink
Either accept or reject in nomination answers
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketp committed Jul 12, 2017
1 parent 128fd21 commit baa5595
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 132 deletions.
Binary file modified db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions nomi/migrations/0113_auto_20170712_0920.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
6 changes: 3 additions & 3 deletions nomi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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):
Expand Down
73 changes: 58 additions & 15 deletions nomi/templates/nomi_answer.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,36 @@ <h4>Response</h4>
{% if result_approval.0 %}
{% if nomi.nomination.status == 'Interview period' and nomi.interview_status == 'Interview Done' %}

<div class="row text-center">
<div class="col-lg-6">
<a href="{% url 'accept' nomi.pk %} "><div class="btn btn-info read-more-button " >Accept</div></a>
</div>
{% if nomi.status %}
{% if nomi.status == 'Accepted' %}
<div class="row text-center">
<div class="col-lg-12">
<a href="{% url 'reject' nomi.pk %}"><div class="btn btn-danger
read-more-button">Reject</div></a>
</div>
</div>
{% elif nomi.status == 'Rejected' %}
<div class="row text-center">
<div class="col-lg-12">
<a href="{% url 'accept' nomi.pk %} "><div class="btn btn-info
read-more-button">Accept</div></a>
</div>
</div>
{% endif %}
{% else %}
<div class="row text-center">
<div class="col-lg-6">
<a href="{% url 'accept' nomi.pk %} "><div class="btn btn-info
read-more-button">Accept</div></a>
</div>

<div class="col-lg-6">
<a href="{% url 'reject' nomi.pk %}"><div class="btn btn-danger
read-more-button">Reject</div></a>
</div>
</div>
{% endif %}

<div class="col-lg-6">
<a href="{% url 'reject' nomi.pk %}"><div class="btn btn-danger read-more-button ">Reject</div></a>
</div>
</div>
{% elif nomi.nomination.status == 'Interview period' and nomi.interview_status == 'Interview Not Done' %}
<div class="row text-center">
<div class="col-lg-12">
Expand All @@ -120,13 +141,35 @@ <h4>Response</h4>
</div>
{% elif senate_perm %}
<div class="row text-center">
<div class="col-lg-6 text-center">
<a href="{% url 'accept' nomi.pk %} "><div class="btn btn-info read-more-button " >Accept</div></a>
</div>

<div class="col-lg-6 text-center">
<a href="{% url 'reject' nomi.pk %}"><div class="btn btn-danger read-more-button ">Reject</div></a>
</div>
{% if nomi.status %}
{% if nomi.status == 'Accepted' %}
<div class="row text-center">
<div class="col-lg-12">
<a href="{% url 'reject' nomi.pk %}"><div class="btn btn-danger
read-more-button">Reject</div></a>
</div>
</div>
{% elif nomi.status == 'Rejected' %}
<div class="row text-center">
<div class="col-lg-12">
<a href="{% url 'accept' nomi.pk %} "><div class="btn btn-info
read-more-button">Accept</div></a>
</div>
</div>
{% endif %}
{% else %}
<div class="row text-center">
<div class="col-lg-6">
<a href="{% url 'accept' nomi.pk %} "><div class="btn btn-info
read-more-button">Accept</div></a>
</div>

<div class="col-lg-6">
<a href="{% url 'reject' nomi.pk %}"><div class="btn btn-danger
read-more-button">Reject</div></a>
</div>
</div>
{% endif %}
</div>
{% endif %}
{% endif %}
Expand Down
225 changes: 111 additions & 114 deletions nomi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ################################################
## ------------------------------------------------------------------------------------------------------------------ ##
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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 ###################################################
## ------------------------------------------------------------------------------------------------------------------ ##
Expand Down

0 comments on commit baa5595

Please sign in to comment.