Commit 0e3734bf authored by EASHAN GUPTA's avatar EASHAN GUPTA

Freeze Float Drop

parents f7835183 d036f361
from allocation.models import * from allocation.models import *
def allocator(univ): def allocator(univ):
insti=Institute.objects.filter(name=univ)[0]
insti.is_allocated=True
insti.save()
a=Applicant.objects.filter(institute__name=univ).order_by('rank') a=Applicant.objects.filter(institute__name=univ).order_by('rank')
c=Choice.objects.filter(institute__name=univ) # c=Choice.objects.filter(institute__name=univ)
my_dict=dict([(x,0) for x in c]) # my_dict=dict([(x,0) for x in c])
for x in a: for x in a:
choices=x.ordered_choices() choices=x.ordered_choices()
temp=0
i=0 i=0
while temp==0 and i<len(choices): flag=True
if(choices[i].capacity>my_dict[choices[i]]): while x.is_float and flag and i<len(choices):
my_dict[choices[i]]=my_dict[choices[i]]+1 if choices[i].capacity>choices[i].seats_filled :
temp=1 given_choice=x.alloted_choice.all()
x.alloted_choice.clear() if given_choice:
g=given_choice[0]
g.seats_filled=g.seats_filled-1
x.alloted_choice.clear()
x.save()
g.save()
clalloc=Allocationcl(choice=choices[i],applicant=x) clalloc=Allocationcl(choice=choices[i],applicant=x)
clalloc.save() clalloc.save()
choices[i].seats_filled=choices[i].seats_filled+1
choices[i].save()
flag=False
# x.alloted_choice.clear() # x.alloted_choice.clear()
# x.alloted_choice.create(choices[i]) # x.alloted_choice.create(choices[i])
# if(temp!=1) # if(temp!=1)
......
...@@ -19,16 +19,17 @@ class AllotedChoiceToAppInLine(admin.TabularInline): ...@@ -19,16 +19,17 @@ class AllotedChoiceToAppInLine(admin.TabularInline):
extra=0 extra=0
class ApplicantAdmin(admin.ModelAdmin): class ApplicantAdmin(admin.ModelAdmin):
fields = ['name', 'rank','institute'] fields = ['name', 'rank','institute', 'is_float']
list_display=['name','institute'] list_display=['name','institute']
inlines = [ChoiceInline, AllotedChoiceToAppInLine] inlines = [ChoiceInline, AllotedChoiceToAppInLine]
class InstituteAdmin(admin.ModelAdmin): class InstituteAdmin(admin.ModelAdmin):
fields=['name'] fields=['name', 'is_allocated']
list_display=['name','is_allocated']
class ChoiceAdmin(admin.ModelAdmin): class ChoiceAdmin(admin.ModelAdmin):
fields=['choice_name', 'capacity','institute'] fields=['choice_name', 'capacity','institute', 'seats_filled']
list_display=['choice_name', 'capacity', 'institute'] list_display=['choice_name','institute', 'capacity', 'seats_filled' ]
# inlines=[UnivChoiceInLine] # inlines=[UnivChoiceInLine]
admin.site.register(Institute, InstituteAdmin) admin.site.register(Institute, InstituteAdmin)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-25 13:03 # Generated by Django 1.11.5 on 2017-10-25 14:07
from __future__ import unicode_literals from __future__ import unicode_literals
import django.core.validators import django.core.validators
...@@ -21,9 +21,9 @@ class Migration(migrations.Migration): ...@@ -21,9 +21,9 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
], ],
options={ options={
'verbose_name': 'Allocated Choice',
'ordering': ['applicant__rank'],
'verbose_name_plural': 'Allocated Choice', 'verbose_name_plural': 'Allocated Choice',
'ordering': ['applicant__rank'],
'verbose_name': 'Allocated Choice',
}, },
), ),
migrations.CreateModel( migrations.CreateModel(
...@@ -51,6 +51,7 @@ class Migration(migrations.Migration): ...@@ -51,6 +51,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('choice_name', models.CharField(max_length=200)), ('choice_name', models.CharField(max_length=200)),
('capacity', models.IntegerField()), ('capacity', models.IntegerField()),
('seats_left', models.IntegerField(default=0)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
...@@ -60,8 +61,8 @@ class Migration(migrations.Migration): ...@@ -60,8 +61,8 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=200)), ('name', models.CharField(max_length=200)),
], ],
options={ options={
'verbose_name': 'Institute',
'verbose_name_plural': 'Institutes', 'verbose_name_plural': 'Institutes',
'verbose_name': 'Institute',
}, },
), ),
migrations.AddField( migrations.AddField(
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-25 14:21
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('allocation', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='choice',
old_name='seats_left',
new_name='seats_filled',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-25 14:37
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('allocation', '0002_auto_20171025_1951'),
]
operations = [
migrations.RemoveField(
model_name='choice',
name='seats_filled',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-25 14:51
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0003_remove_choice_seats_filled'),
]
operations = [
migrations.AddField(
model_name='choice',
name='seats_filled',
field=models.IntegerField(default=0),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-25 15:38
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0004_choice_seats_filled'),
]
operations = [
migrations.AddField(
model_name='institute',
name='is_allocated',
field=models.BooleanField(default=True),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-25 15:40
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0005_institute_is_allocated'),
]
operations = [
migrations.AddField(
model_name='applicant',
name='is_float',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='institute',
name='is_allocated',
field=models.BooleanField(default=False),
),
]
...@@ -8,6 +8,7 @@ import os ...@@ -8,6 +8,7 @@ import os
class Institute(models.Model): class Institute(models.Model):
name=models.CharField(max_length=200) name=models.CharField(max_length=200)
is_allocated=models.BooleanField(default=False)
# username=models.CharField(max_length=200) # username=models.CharField(max_length=200)
# email=models.EmailField(max_length=200) # email=models.EmailField(max_length=200)
def __str__(self): def __str__(self):
...@@ -25,7 +26,7 @@ class Choice(models.Model): ...@@ -25,7 +26,7 @@ class Choice(models.Model):
choice_name = models.CharField(max_length=200) choice_name = models.CharField(max_length=200)
institute=models.ForeignKey(Institute, on_delete=models.CASCADE, related_name='choices') institute=models.ForeignKey(Institute, on_delete=models.CASCADE, related_name='choices')
capacity = models.IntegerField() capacity = models.IntegerField()
seats_left=models.IntegerField(default=0) seats_filled=models.IntegerField(default=0)
def __str__(self): def __str__(self):
return self.choice_name return self.choice_name
...@@ -38,6 +39,7 @@ class Applicant(models.Model): ...@@ -38,6 +39,7 @@ class Applicant(models.Model):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
alloted_choice = models.ManyToManyField(Choice, through='Allocationcl', related_name='alloted_applicant') alloted_choice = models.ManyToManyField(Choice, through='Allocationcl', related_name='alloted_applicant')
rank = models.IntegerField(validators=[MinValueValidator(1)]) rank = models.IntegerField(validators=[MinValueValidator(1)])
is_float=models.BooleanField(default=True)
def __str__(self): def __str__(self):
return self.name return self.name
def ordered_choices(self): def ordered_choices(self):
......
...@@ -30,20 +30,19 @@ ...@@ -30,20 +30,19 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<p style="font-size: 30px;"><a href="{% url 'allocation:applicant_list' %}">Applicants</a></p>
<p style="font-size: 30px;"><a href="{% url 'allocation:choice_list' %}">Choices</a></p>
{% if request.get_full_path == "/allocation/admin" %} {% if request.get_full_path == "/allocation/admin" %}
<div style="float:right; vertical-align: top; margin-top: -140px"> <div style="float:right; vertical-align: top;">
<form method="POST" action="/allocation/button_action" enctype="multipart/form-data"> <form method="POST" action="/allocation/button_action" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="prikey" value="{{ request.get_full_path }}">
<button type="submit" style="width: 180px; height: 40px; font-size: 25px"> Allocate</button> <button type="submit" style="width: 180px; height: 40px; font-size: 25px"> Allocate</button>
</form> </form>
<div> </div>
{% endif %}
<ul>
<li><p style="font-size: 20px;"><a href="{% url 'allocation:applicant_list' %}">Applicants</a></p>
<li><p style="font-size: 20px;"><a href="{% url 'allocation:choice_list' %}">Choices</a></p>
</ul>
{% endif %}
{% endblock %} {% endblock %}
{% extends "allocation/admin1.html" %}
{% load i18n admin_urls static admin_list %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'allocation:admin1' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'allocation:applicant_list' %}">{% trans 'Applicants' %}</a>
&rsaquo; {{ applicant.name }}
</div>
{% endblock %}
{% block content %}
{% if applicant.institute.name == request.user.username %}
<form action="" method="post">{% csrf_token %}
<p>Are you sure you want to delete "{{ object }}"?</p>
<input type="submit" value="Confirm" />
</form>
{% else %}
Unauthorised access
{% endif %}
{% endblock %}
...@@ -15,6 +15,12 @@ ...@@ -15,6 +15,12 @@
{% for choice in applicant.alloted_choice.all %} {% for choice in applicant.alloted_choice.all %}
{{choice}} {{choice}}
{% endfor %} {% endfor %}
<form action="{% url 'allocation:applicant-update' applicant.pk %}">
<input type="submit" value="Update" />
</form>
<form action="{% url 'allocation:applicant-delete' applicant.pk %}">
<input style="background-color: red;" type="submit" value="Delete" />
</form>
{% else %} {% else %}
Unauthorised access Unauthorised access
{% endif %} {% endif %}
......
{% extends "allocation/admin1.html" %}
{% load i18n admin_urls static admin_list %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'allocation:admin1' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'allocation:applicant_list' %}">{% trans 'Applicants' %}</a>
&rsaquo; {{ applicant.name }}
</div>
{% endblock %}
{% block content %}
{% if applicant.institute.name == request.user.username %}
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update" />
</form>
{% else %}
Unauthorised access
{% endif %}
{% endblock %}
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
{% if choice.institute.name == request.user.username %} {% if choice.institute.name == request.user.username %}
<p><b>Choice name:</b> {{ choice.choice_name }}</p> <p><b>Choice name:</b> {{ choice.choice_name }}</p>
<p><b>Capacity:</b> {{ choice.capacity }}</p> <p><b>Capacity:</b> {{ choice.capacity }}</p>
<p><b>Seats Filled:</b> {{ choice.seats_filled }}</p>
<form action="{% url 'allocation:choice-update' choice.pk %}"> <form action="{% url 'allocation:choice-update' choice.pk %}">
<input type="submit" value="Update" /> <input type="submit" value="Update" />
</form> </form>
......
<html>
<head>
<link rel="stylesheet" type="text/css" href="core/home_page.css">
</head>
<body>
<table >
<tr>
<td rowspan="2"><a class="logoText"><img src="logo.png" width="150" height="150" alt="logo"></a></td>
<td style="vertical-align: bottom; padding-left:5px; padding-bottom: 2px; font-size: 20px"><a class="logoText" ><B>codeMAFIA</B></a></td>
</tr>
<tr>
<td style="vertical-align: top; padding-left:20px; font-size:20px"><a class="tagLine" ><B><I>the journey begins... </I></B></a></td>
</tr>
</table>
<div class="container">
<div class="content"><h1 align="center" style="color:black">General Allocation Portal</h1></div>
</div>
<div class="tool1" style="margin-top: 570px; text-align: center; font-size: 30px;">
</div>
<div class="tool2" style="margin-top: 10px; text-align: center; font-size: 50px; color: white">
Institute login
</div>
<div class="tool3" style="margin-top: 5px; text-align: center; font-size: 50px; color:white">
Applicant login
</div>
<div class="tool4" style="margin-top: 5px; text-align: center; font-size: 50px; color:white">
Admin login
</div>
</body>
</html>
\ No newline at end of file
...@@ -37,6 +37,23 @@ ...@@ -37,6 +37,23 @@
<!-- Content --> <!-- Content -->
<div id="content" class="{% block coltype %}colM{% endblock %}"> <div id="content" class="{% block coltype %}colM{% endblock %}">
{% block content %} {% block content %}
{% if applicant.is_float %}
<form method="POST" action="/allocation/freeze" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="applicant" value="{{ applicant.pk }}">
<button type="submit" style="float: right; width: 180px; height: 30px; font-size: 20px"> Freeze</button>
</form>
<form method="POST" action="/allocation/float" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="applicant" value="{{ applicant.pk }}">
<button type="submit" style="float: right; width: 180px; height: 30px; font-size: 20px"> Float</button>
</form>
<form method="POST" action="/allocation/drop" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="applicant" value="{{ applicant.pk }}">
<button type="submit" style="float: right; width: 180px; height: 30px; font-size: 20px"> Drop</button>
</form>
{% endif %}
{% if success %} {% if success %}
<p style="color:green">update successfull</p> <p style="color:green">update successfull</p>
{% endif %} {% endif %}
...@@ -47,6 +64,7 @@ ...@@ -47,6 +64,7 @@
{{choice}} {{choice}}
{% endfor %} {% endfor %}
</p> </p>
<form action="/allocation/" method="post">{% csrf_token %} <form action="/allocation/" method="post">{% csrf_token %}
{{ formset.management_form }} {{ formset.management_form }}
...@@ -64,7 +82,9 @@ ...@@ -64,7 +82,9 @@
<!-- {{ form.applicant }} {{ form.choice }} {{ form.priority }}<br> --> <!-- {{ form.applicant }} {{ form.choice }} {{ form.priority }}<br> -->
<br> <br>
{% endfor %} {% endfor %}
{% if not applicant.institute.is_allocated %}
<input type="submit" value="Submit"> <input type="submit" value="Submit">
{% endif %}
</form> </form>
{% endblock %} {% endblock %}
<br class="clear" /> <br class="clear" />
......
{% extends 'admin/base.html' %} {% extends 'admin/base.html' %}
{% load i18n admin_urls static admin_list %}
{% load tag %}
<!-- -->
{% block branding %}
<h1 id="site-name">Institute Registration</h1>
{% endblock %}
{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'index1' %}">{% trans 'Home' %}</a>
</div>
{% endblock %}
{% block content %} {% block content %}
<h2>Sign up</h2>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {% for field in form %}
<button type="submit">Sign up</button> <div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }} <br>{{ field }}
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
</div>
{% endfor %}
<button type="submit" style="width: 180px; height: 30px; font-size: 20px">Sign up</button>
</form> </form>
{% endblock %} {% endblock %}
...@@ -15,10 +15,15 @@ urlpatterns = [ ...@@ -15,10 +15,15 @@ urlpatterns = [
url(r'^choice/create$', views.ChoiceCreateView.as_view(), name='choice-create'), url(r'^choice/create$', views.ChoiceCreateView.as_view(), name='choice-create'),
url(r'^choice/(?P<pk>\d+)/update$', views.ChoiceUpdate.as_view(), name='choice-update'), url(r'^choice/(?P<pk>\d+)/update$', views.ChoiceUpdate.as_view(), name='choice-update'),
url(r'^choice/(?P<pk>\d+)/delete$', views.ChoiceDelete.as_view(), name='choice-delete'), url(r'^choice/(?P<pk>\d+)/delete$', views.ChoiceDelete.as_view(), name='choice-delete'),
url(r'^applicant/(?P<pk>\d+)/update$', views.ApplicantUpdate.as_view(), name='applicant-update'),
url(r'^applicant/(?P<pk>\d+)/delete$', views.ApplicantDelete.as_view(), name='applicant-delete'),
url(r'^choice_make$', views.choice_make, name='choice_make'), url(r'^choice_make$', views.choice_make, name='choice_make'),
url(r'^applicant_make$', views.applicant_make, name='applicant_make'), url(r'^applicant_make$', views.applicant_make, name='applicant_make'),
url(r'^button_action$', views.button_action, name='button_action'), url(r'^button_action$', views.button_action, name='button_action'),
url(r'^register/$', views.signup), url(r'^register/$', views.signup),
url(r'^freeze$', views.freeze, name='freeze'),
url(r'^float$', views.float, name='float'),
url(r'^drop$', views.drop, name='drop'),
#url(r'^admin/choices$', views.ChoiceListView.as_view(), name='choice_list'), #url(r'^admin/choices$', views.ChoiceListView.as_view(), name='choice_list'),
#url(r'^admin/applicants$', views.ApplicantListView.as_view(), name='applicant_list'), #url(r'^admin/applicants$', views.ApplicantListView.as_view(), name='applicant_list'),
......
...@@ -212,5 +212,39 @@ class ChoiceDelete(DeleteView): ...@@ -212,5 +212,39 @@ class ChoiceDelete(DeleteView):
model = Choice model = Choice
success_url = reverse_lazy('allocation:choice_list') success_url = reverse_lazy('allocation:choice_list')
class ApplicantUpdate(UpdateView):
model = Applicant
fields = ['name','rank']
template_name_suffix = '_update'
success_url = reverse_lazy('allocation:applicant_list')
class ApplicantDelete(DeleteView):
model = Applicant
success_url = reverse_lazy('allocation:applicant_list')
def freeze(request):
if request.method == "POST":
applicant=Applicant.objects.get(pk=request.POST["applicant"])
applicant.is_float=False
applicant.save()
return HttpResponseRedirect('/allocation')
else:
return HttpResponseRedirect('/allocation')
def drop(request):
if request.method == "POST":
applicant=Applicant.objects.get(pk=request.POST["applicant"])
applicant.is_float=False
given_choice=applicant.alloted_choice.all()
if given_choice:
g=given_choice[0]
g.seats_filled=g.seats_filled-1
applicant.alloted_choice.clear()
g.save()
applicant.save()
return HttpResponseRedirect('/allocation')
else:
return HttpResponseRedirect('/allocation')
def float(request):
return HttpResponseRedirect('/allocation')
\ No newline at end of file
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment