Commit 2d35b209 authored by KUNAL GOYAL's avatar KUNAL GOYAL

changes1

parent 6feb884f
......@@ -15,18 +15,14 @@ def allocator(univ):
i=0
flag=True
while x.is_float and flag and i<len(choices): #< loop over all preferences till allocated
if choices[i].capacity>choices[i].seats_filled :
l=len(choices[i].alloted_applicant.all())
if choices[i].capacity>l:
given_choice=x.alloted_choice.all() #< \c given_choice\ stores already alloted choice
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) #< link Choice to Applicant using Application model
clalloc.save()
choices[i].seats_filled=choices[i].seats_filled+1
choices[i].save()
flag=False
i=i+1
return a
\ No newline at end of file
......@@ -21,8 +21,8 @@ class InstituteAdmin(admin.ModelAdmin):
list_display=['name','is_allocated']
class ChoiceAdmin(admin.ModelAdmin):
fields=['choice_name', 'capacity','institute', 'seats_filled']
list_display=['choice_name','institute', 'capacity', 'seats_filled' ]
fields=['choice_name', 'capacity','institute']
list_display=['choice_name','institute', 'capacity']
admin.site.register(Institute, InstituteAdmin)
admin.site.register(Choice, ChoiceAdmin)
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-26 09:33
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Allocationcl',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
options={
'verbose_name': 'Allocated Choice',
'verbose_name_plural': 'Allocated Choice',
'ordering': ['applicant__rank'],
},
),
migrations.CreateModel(
name='Applicant',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('rank', models.IntegerField(validators=[django.core.validators.MinValueValidator(1)])),
('is_float', models.BooleanField(default=True)),
],
),
migrations.CreateModel(
name='Application',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('priority', models.IntegerField(validators=[django.core.validators.MinValueValidator(1)])),
('applicant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Applicant')),
],
options={
'ordering': ['priority'],
},
),
migrations.CreateModel(
name='Choice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('choice_name', models.CharField(max_length=200)),
('capacity', models.IntegerField()),
],
),
migrations.CreateModel(
name='Institute',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('is_allocated', models.BooleanField(default=False)),
],
options={
'verbose_name': 'Institute',
'verbose_name_plural': 'Institutes',
},
),
migrations.AddField(
model_name='choice',
name='institute',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='choices', to='allocation.Institute'),
),
migrations.AddField(
model_name='application',
name='choice',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Choice'),
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_applicant', through='allocation.Allocationcl', to='allocation.Choice'),
),
migrations.AddField(
model_name='applicant',
name='choices',
field=models.ManyToManyField(related_name='applicants', through='allocation.Application', to='allocation.Choice'),
),
migrations.AddField(
model_name='applicant',
name='institute',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='applicants', to='allocation.Institute'),
),
migrations.AddField(
model_name='allocationcl',
name='applicant',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Applicant'),
),
migrations.AddField(
model_name='allocationcl',
name='choice',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Choice'),
),
]
......@@ -27,7 +27,6 @@ class Choice(models.Model):
choice_name = models.CharField(max_length=200) #< object containing name of choice
institute=models.ForeignKey(Institute, on_delete=models.CASCADE, related_name='choices') #< Object containing related institute primary key
capacity = models.IntegerField() #< Object containing maximum number of applicants allowed
seats_filled=models.IntegerField(default=0) #< Object containing number of seats currently occupied
## String Conversion
# @param self Pointer to itself
# @return name Name of Choice
......
......@@ -9,44 +9,6 @@
{% block content %}
<h1>Applicants</h1>
<!-- <script>
function validate_fileupload(fileName){
var allowed_extensions = "csv";
var file_extension = fileName.split('.').pop();
// document.getElementById('errfn').innerHTML = file_extension;
if(allowed_extensions==file_extension){
return true; // valid file extension
}
// document.getElementById('errfn').innerHTML = "This is not a valid file format";
alert("Sorry, only .txt files are allowed");
return false;
}
</script> -->
<!--
{% if success %}
<ul>
<li style="float:right; vertical-align: top;">
<h3 style="margin-top: -50px"> For uploading Applicant</h3>
<form name="myform" method="POST" action="/allocation/applicant_make" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile" accept=".csv" id="upload_file" title='Please upload file in .csv format only'>
<button type="submit">Upload</button>
<div id="errfn">
<p style="color:red">Invalid input</p>
</div>
</form>
</li>
{% for applicant in applicant_list %}
<li>
<a href="{% url 'allocation:applicant-detail' applicant.pk %}">{{ applicant.name }}</a>
</li>
{% endfor %}
</ul>
{% else %} -->
{% if applicant_list %}
<ul>
<li style="float:right; vertical-align: top;">
......
......@@ -11,7 +11,7 @@
{% if choice.institute.name == request.user.username %}
<p><b>Choice name:</b> {{ choice.choice_name }}</p>
<p><b>Capacity:</b> {{ choice.capacity }}</p>
<p><b>Seats Filled:</b> {{ choice.seats_filled }}</p>
<p><b>Seats Filled:</b> {{ choice.alloted_applicant.all|length }}</p>
<form action="{% url 'allocation:choice-update' choice.pk %}">
<input type="submit" value="Update" />
</form>
......
......@@ -34,15 +34,6 @@ from django.core.exceptions import (
)
# @login_required(login_url='/admin/login')
# def index(request): #for /allocation
# applicant=Applicant.objects.filter(name=request.user.username)[0]
# # form = PreferenceForm(
# # initial={'name': applicant.name , 'rank': applicant.rank}
# # )
# form = ArticleForm(instance=applicant)
# return render(request, 'allocation/index.html', {'applicant': applicant, 'form': form})
# def send_mail(request):
# # send_mail('Subject here', 'Here is the message.', settings.EMAIL_HOST_USER,['to@example.com'], fail_silently=False)
# email = EmailMessage(
......@@ -338,10 +329,7 @@ def drop(request):
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:
......
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