Commit f6b64541 authored by amanjain2898@gmail.com's avatar amanjain2898@gmail.com

asd

parents d638ba4d 2d35b209
No preview for this file type
......@@ -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-25 21:03
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_plural': 'Allocated Choice',
'verbose_name': '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()),
('seats_filled', models.IntegerField(default=0)),
],
),
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_plural': 'Institutes',
'verbose_name': 'Institute',
},
),
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'),
),
]
......@@ -6,8 +6,6 @@ from django.core.validators import MaxValueValidator, MinValueValidator
import csv
import os
## Models file
# It contains all the models used to define the database
## Institute Model
# @brief Stores information about all institutes in a table
class Institute(models.Model):
......@@ -29,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,13 +11,31 @@
{% 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>
<form action="{% url 'allocation:choice-delete' choice.pk %}">
<input style="background-color: red;" type="submit" value="Delete" />
</form>
<br>
<p>List of Applicants who have been allocated {{ choice.choice_name }} choice: </p>
<ul>
{% for applicant in choice.alloted_applicant.all %}
<table style="width:100%">
<tr>
<th>Name</th>
<th>Rank</th>
</tr>
{% for applicant in choice.alloted_applicant.all %}
<tr>
<td> <a href="{% url 'allocation:applicant-detail' applicant.pk %}">{{ applicant.name }}</a></td>
<td> {{ applicant.rank }}</td>
</tr>
{% endfor %}
</table>
{% endfor %}
</ul>
{% else %}
Unauthorised access
{% endif %}
......
......@@ -16,7 +16,7 @@
<!-- Header -->
<div id="header">
<div id="branding">
<h1>Student Portal</h1>
<h1>Applicant Portal</h1>
</div>
{% block usertools %}
<div id="user-tools">
......@@ -55,24 +55,27 @@
</form>
{% endif %}
{% if success %}
<p style="color:green">update successfull</p>
<p style="color:green">Your choices have been registered.</p>
{% endif %}
<p> <b>Name:</b> {{applicant.name}}<br>
<b>Institute:</b> {{applicant.institute}}<br>
<b>Rank:</b> {{applicant.rank}}<br>
<b>Allocated choice:</b>
{% for choice in applicant.alloted_choice.all %}
{{choice}}
{% endfor %}
</p>
<p>Fill your choices and priorities:</p>
<form action="/allocation/" method="post">{% csrf_token %}
{{ formset.management_form }}
<ul>
{% for form in formset %}
{{ form.non_field_errors }}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
<li>
{% for field in form.visible_fields %}
<div class="fieldWrapper">
{{ field.errors }}
......@@ -82,6 +85,7 @@
<!-- {{ form.applicant }} {{ form.choice }} {{ form.priority }}<br> -->
<br>
{% endfor %}
</ul>
{% if not applicant.institute.is_allocated %}
<input type="submit" value="Submit">
{% endif %}
......
......@@ -16,8 +16,7 @@ urlpatterns = [
url(r'^admin/applicants$', views.ApplicantListView.as_view(), name='applicant_list'), #< creates URL to display all applicants in Institute Login
url(r'^choice/(?P<pk>\d+)$', views.ChoiceDetailView.as_view(), name='choice-detail'), #< creates URL to display a particular choice in Institute Login
url(r'^applicant/(?P<pk>\d+)$', views.ApplicantDetailView.as_view(), name='applicant-detail'), #< creates URL to display a particular applicant in Institute Login
url(r'^choice/create$', views.ChoiceCreateView.as_view(), name='choice-create'), #< creates URL to create a particular choice in Institute Login
url(r'^choice/(?P<pk>\d+)/update$', views.ChoiceUpdate.as_view(), name='choice-update'), #< creates URL to update a particular choice in Institute Login
url(r'^choice/(?P<pk>\d+)/update$', views.ChoiceUpdate.as_view(), name='choice-update'), #< creates URL to update a particular choice in Institute Login
url(r'^choice/(?P<pk>\d+)/delete$', views.ChoiceDelete.as_view(), name='choice-delete'), #< creates URL to deleten a particular choice in Institute Login
url(r'^applicant/(?P<pk>\d+)/update$', views.ApplicantUpdate.as_view(), name='applicant-update'), #< creates URL to update a particular applicant in Institute Login
url(r'^applicant/(?P<pk>\d+)/delete$', views.ApplicantDelete.as_view(), name='applicant-delete'), #< creates URL to delete a particular applicant in Institute Login
......
......@@ -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(
......@@ -181,99 +172,147 @@ def applicant_make(request):
return HttpResponseRedirect("/allocation/admin/applicants")
return HttpResponse("Error")
## Makes the "fill choices" for the student login
# @param applicant The applicant whose form has to be displayed
# @return returns the form for the corresponding applicant
# This view requires login to be displayed.
def make_application_form(applicant1):
# The inbuilt Model form class is used for the form
class ApplicationForm(forms.ModelForm):
choice = forms.ModelChoiceField(queryset=Choice.objects.filter(institute=applicant1.institute))
applicant = forms.ModelChoiceField(widget=forms.HiddenInput(), initial=applicant1, queryset=Applicant.objects.all() )
choice = forms.ModelChoiceField(queryset=Choice.objects.filter(institute=applicant1.institute))#< The queryset is the choices available in the dropdown in the form.
applicant = forms.ModelChoiceField(widget=forms.HiddenInput(), initial=applicant1, queryset=Applicant.objects.all() )#<this field is hidden since an applicant can apply for himself only.
class Meta:
model = Application
fields = ['applicant','choice', 'priority']
fields = ['applicant','choice', 'priority'] #< These are the fields to be displayed
return ApplicationForm
## View for applicant login
# @param rerquest
# This view requires login to be displayed.
@login_required(login_url='/admin/login')
def index(request):
applicant=get_object_or_404(Applicant,name=request.user.username)
applicant=get_object_or_404(Applicant,name=request.user.username) #< If an applicant exists with the username of the account, this returns the applicant. Else it returns 404 error.
ApplicationForm = make_application_form(applicant)
ApplicationFormSet = modelformset_factory(Application, form=ApplicationForm, extra=5)
ApplicationFormSet = modelformset_factory(Application, form=ApplicationForm, extra=5) # used inbuilt function to create a formset from a form.
if request.method == "POST":
formset = ApplicationFormSet(request.POST, queryset=Application.objects.filter(applicant=applicant))
if formset.is_valid():
if formset.is_valid():#< checks if the given information is valid.
#< if the formset is valid, then save the form and redirect to the same page giving success as the context
formset.save()
return render(request, 'allocation/index.html', {'applicant': applicant, 'formset': formset, 'success':True,})
else:
#< if the formset is invalid, then save the form and redirect to the same page giving errors as the context
form_errors = formset.errors
return render(request, 'allocation/index.html', {'applicant': applicant, 'formset': formset,'form_errors': form_errors})
else:
formset = ApplicationFormSet(queryset=Application.objects.filter(applicant=applicant),)
return render(request, 'allocation/index.html', {'applicant': applicant, 'formset': formset,})
## View for institute login
# @param rerquest
# This view requires login to be displayed.
@login_required(login_url='/admin/login')
def admin1(request):
institute=get_object_or_404(Institute,name=request.user.username)
institute=get_object_or_404(Institute,name=request.user.username)#< If an institute exists with the username of the account, this returns the institute. Else it returns 404 error.
return render(request, 'allocation/admin1.html',{'institute': institute})
## View for institute page which lists all the choices of the institute
# This is a generic list view provided by django to easily create views of models.
# The page also includes button for uploading csv file for creation of multiple choices at once
# The corresponding html file is choice_list.html
class ChoiceListView(generic.ListView):
model = Choice
model = Choice #< specifies the model for which the generic view is to be created
##Context
# Used to pass an additional context in the html file
def get_context_data(self, **kwargs):
institute=get_object_or_404(Institute,name=self.request.user.username)
context = super(ChoiceListView, self).get_context_data(**kwargs)
context['institute'] = institute
context['institute'] = institute #< Because of this line we can access the institute information through the variable named 'institute' in the html file
return context
##Queryset
# Used to specify the list of choices which are to be displayed
def get_queryset(self):
institute=get_object_or_404(Institute,name=self.request.user.username)
return Choice.objects.filter(institute__name=institute.name)
return Choice.objects.filter(institute__name=institute.name) #< this returns the list of choices corresponding to the institute which is logged in currently
## View for institute page which lists all the applicants of the institute
# This is a generic list view provided by django to easily create views of models.
# The page also includes button for uploading csv file for creation of multiple applicants at once
# The corresponding html file is applicants_list.html
class ApplicantListView(generic.ListView):
model = Applicant
def get_context_data(self, **kwargs):
institute=get_object_or_404(Institute,name=self.request.user.username)
context = super(ApplicantListView, self).get_context_data(**kwargs)
context['institute'] = institute
return context
def get_queryset(self):
institute=get_object_or_404(Institute,name=self.request.user.username)
return Applicant.objects.filter(institute__name=institute.name)
model = Applicant#< specifies the model for which the generic view is to be created
##Context
# Used to pass an additional context in the html file
def get_context_data(self, **kwargs):
institute=get_object_or_404(Institute,name=self.request.user.username)
context = super(ApplicantListView, self).get_context_data(**kwargs)
context['institute'] = institute #< Because of this line we can access the institute information through the variable named 'institute' in the html file
return context
##Queryset
# Used to specify the list of applicants which are to be displayed
def get_queryset(self):
institute=get_object_or_404(Institute,name=self.request.user.username)
return Applicant.objects.filter(institute__name=institute.name) #< this returns the list of choices corresponding to the institute which is logged in currently
## View for institute page which displays a particular choice of the institute in detail
# This is a generic detail view provided by django to easily create detail views of models.
# The page also includes update choice and delete choice buttons
# The corresponding html file is choice_detail.html
class ChoiceDetailView(generic.DetailView):
model = Choice
def get_context_data(self, **kwargs):
institute=get_object_or_404(Institute,name=self.request.user.username)
context = super(ChoiceDetailView, self).get_context_data(**kwargs)
context['institute'] = institute
return context
model = Choice #< specifies the model for which the generic view is to be created
##Context
# Used to pass an additional context in the html file
def get_context_data(self, **kwargs):
institute=get_object_or_404(Institute,name=self.request.user.username)
context = super(ChoiceDetailView, self).get_context_data(**kwargs)
context['institute'] = institute #< Because of this line we can access the institute information through the variable named 'institute' in the html file
return context
## View for institute page which displays profile of a particular applicant of the institute in detail
# This is a generic detail view provided by django to easily detail create views of models.
# The page also includes update applicant and delete applicant buttons
# The corresponding html file is applicant_detail.html
class ApplicantDetailView(generic.DetailView):
model = Applicant
def get_context_data(self, **kwargs):
institute=get_object_or_404(Institute,name=self.request.user.username)
context = super(ApplicantDetailView, self).get_context_data(**kwargs)
context['institute'] = institute
return context
class ChoiceCreateView(CreateView):
model = Choice
fields = ['choice_name', 'capacity', 'institute']
model = Applicant #< specifies the model for which the generic view is to be created
##Context
# Used to pass an additional context in the html file
def get_context_data(self, **kwargs):
institute=get_object_or_404(Institute,name=self.request.user.username)
context = super(ApplicantDetailView, self).get_context_data(**kwargs)
context['institute'] = institute #< Because of this line we can access the institute information through the variable named 'institute' in the html file
return context
## View for institute page which displays a form to update the details of choices
# This is a generic update view provided by django to easily create update views of models.
# The corresponding html file is choice_update.html
class ChoiceUpdate(UpdateView):
model = Choice
fields = ['choice_name','capacity']
template_name_suffix = '_update'
success_url = reverse_lazy('allocation:choice_list')
model = Choice #< specifies the model for which the generic view is to be created
fields = ['choice_name','capacity'] #< specifies the fields that will be displayed on the rendered form
template_name_suffix = '_update' # Specifies that the html file is choice_update.html
success_url = reverse_lazy('allocation:choice_list') #< this is the redirect URL upon successful updation of choice
## View for institute page which displays a form to delete the choices
# This is a generic delete view provided by django to easily create delete views of models.
# The html file for delete confirmation is choice_confirm_delete.html
class ChoiceDelete(DeleteView):
model = Choice
success_url = reverse_lazy('allocation:choice_list')
model = Choice #< specifies the model for which the generic view is to be created
success_url = reverse_lazy('allocation:choice_list') #< this is the redirect URL upon successful deletion of choice
## View for institute page which displays a form to update the details of applicants
# This is a generic update view provided by django to easily create update views of models.
# The corresponding html file is applicant_update.html
class ApplicantUpdate(UpdateView):
model = Applicant
fields = ['name','rank']
template_name_suffix = '_update'
success_url = reverse_lazy('allocation:applicant_list')
model = Applicant #< specifies the model for which the generic view is to be created
fields = ['name','rank']#< specifies the fields that will be displayed on the rendered form
template_name_suffix = '_update' # Specifies that the html file is choice_update.html
success_url = reverse_lazy('allocation:applicant_list')#< this is the redirect URL upon successful updation of applicant
## View for institute page which displays a form to delete the applicants
# This is a generic delete view provided by django to easily create delete views of models.
# The html file for delete confirmation is applicant_confirm_delete.html
class ApplicantDelete(DeleteView):
model = Applicant
success_url = reverse_lazy('allocation:applicant_list')
model = Applicant #< specifies the model for which the generic view is to be created
success_url = reverse_lazy('allocation:applicant_list')#< this is the redirect URL upon successful deletion of applicant
def freeze(request):
if request.method == "POST":
......@@ -290,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