Commit 0d405535 authored by amanjain2898@gmail.com's avatar amanjain2898@gmail.com

uploading

parents 76011664 b7d5c58d
No preview for this file type
from allocation.models import *
def f():
a=Applicant.objects.all().order_by('rank')
c=Choice.objects.all()
def allocator(univ):
a=Applicant.objects.filter(institute__name=univ).order_by('rank')
c=Choice.objects.filter(institute__name=univ)
my_dict=dict([(x,0) for x in c])
for x in a:
choices=x.ordered_choices()
......
from django.contrib import admin
from .models import Applicant,Choice,Application,Allocationcl
from .models import *
admin.site.register(Choice)
# class UnivAppInLine(admin.TabularInline):
# model=UnivApp
# extra=0
# class UnivChoiceInLine(admin.TabularInline):
# model=UnivChoice
# extra=0
class ChoiceInline(admin.TabularInline):
model = Application #https://stackoverflow.com/questions/5947843/django-how-does-manytomanyfield-with-through-appear-in-admin
extra = 2
class AllotedChoiceToAppInLine(admin.TabularInline):
model=Allocationcl
extra=0
class ApplicantAdmin(admin.ModelAdmin):
fields = ['name', 'rank']
inlines = [ChoiceInline]
fields = ['name', 'rank','institute']
inlines = [ChoiceInline, AllotedChoiceToAppInLine]
# class ChoiceAdmin(admin.ModelAdmin):
# fields=['choice_name', 'capacity']
# inlines=[UnivChoiceInLine]
admin.site.register(Institute)
admin.site.register(Choice)
admin.site.register(Applicant, ApplicantAdmin)
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-01 17:09
# Generated by Django 1.11.5 on 2017-10-17 06:12
from __future__ import unicode_literals
from django.db import migrations, models
......@@ -14,6 +14,17 @@ class Migration(migrations.Migration):
]
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=[
......@@ -29,6 +40,9 @@ class Migration(migrations.Migration):
('priority', models.IntegerField()),
('applicant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Applicant')),
],
options={
'ordering': ['priority'],
},
),
migrations.CreateModel(
name='Choice',
......@@ -38,14 +52,50 @@ class Migration(migrations.Migration):
('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)),
],
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(through='allocation.Application', to='allocation.Choice'),
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'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-09 20:28
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('allocation', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='application',
options={'ordering': ['priority']},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-14 12:11
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('allocation', '0002_auto_20171010_0158'),
]
operations = [
migrations.CreateModel(
name='Allocationcl',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('applicant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Applicant')),
('choice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='allocation.Choice')),
],
options={
'ordering': ['applicant__rank'],
},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-14 13:00
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0003_allocationcl'),
]
operations = [
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_choice', through='allocation.Allocationcl', to='allocation.Choice'),
),
migrations.AlterField(
model_name='applicant',
name='choices',
field=models.ManyToManyField(related_name='choices', through='allocation.Application', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 21:52
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('allocation', '0004_auto_20171014_1830'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 21:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0005_auto_20171016_0322'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 21:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0006_auto_20171016_0326'),
]
operations = [
migrations.AlterField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(default=None, related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 22:01
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('allocation', '0007_auto_20171016_0328'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='alloted_choice', to='allocation.Choice'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-15 22:14
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('allocation', '0008_auto_20171016_0331'),
]
operations = [
migrations.RemoveField(
model_name='applicant',
name='alloted_choice',
),
migrations.AddField(
model_name='applicant',
name='alloted_choice',
field=models.ManyToManyField(related_name='alloted_choice', through='allocation.Allocationcl', to='allocation.Choice'),
),
]
from __future__ import unicode_literals
from django.db import models
# import math
# import CsvModel
import csv
import os
class Institute(models.Model):
name=models.CharField(max_length=200)
def __str__(self):
return self.name
class Meta:
verbose_name='Institute'
verbose_name_plural='Institutes'
class Choice(models.Model):
choice_name = models.CharField(max_length=200)
# alloted_applicants = models.ManyToManyField(Applicant, through='Allocationcl')
institute=models.ForeignKey(Institute, on_delete=models.CASCADE, related_name='choices')
capacity = models.IntegerField()
def __str__(self):
return self.choice_name
......@@ -12,9 +24,10 @@ class Choice(models.Model):
# Null_Choice.save()
class Applicant(models.Model):
choices = models.ManyToManyField(Choice, through='Application', related_name='choices')
institute=models.ForeignKey(Institute,on_delete=models.CASCADE,related_name='applicants')
choices = models.ManyToManyField(Choice, through='Application', related_name='applicants')
name = models.CharField(max_length=200)
alloted_choice = models.ManyToManyField(Choice, through='Allocationcl', related_name='alloted_choice')
alloted_choice = models.ManyToManyField(Choice, through='Allocationcl', related_name='alloted_applicant')
rank = models.IntegerField()
def __str__(self):
return self.name
......@@ -24,12 +37,13 @@ class Applicant(models.Model):
return self.choices.all().order_by('application__priority')
class Application(models.Model):
choice = models.ForeignKey(Choice, on_delete=models.CASCADE)
applicant = models.ForeignKey(Applicant, on_delete=models.CASCADE)
choice = models.ForeignKey(Choice, on_delete=models.CASCADE)
priority = models.IntegerField()
class Meta:
# if you have an inline configured in the admin, this will
# make the roles order properly
ordering = ['priority']
......@@ -40,4 +54,17 @@ class Allocationcl(models.Model):
class Meta:
# if you have an inline configured in the admin, this will
# make the roles order properly
verbose_name='Allocated Choice'
verbose_name_plural='Allocated Choice'
ordering = ['applicant__rank']
# class UnivChoice(models.Model):
# ,limit_choices_to={'institute':applicant.institute}
# choice=models.ForeignKey(Choice,on_delete=models.CASCADE)
# university=models.ForeignKey(University,on_delete=models.CASCADE)
# , limit_choices_to={'university__name':'applicant_university__name'}
# class UnivApp(models.Model):
# applicant=models.ForeignKey(Applicant,on_delete=models.CASCADE)
# university=models.ForeignKey(University,on_delete=models.CASCADE)
# class Meta:
# ordering=['applicant__rank']
\ No newline at end of file
<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
......@@ -8,8 +8,11 @@ urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^submit$', views.submit, name='submit'),
url(r'^admin$', views.admin1, name='admin1'),
url(r'^admin/choices$', views.ChoiceListView, name='choice_list'),
url(r'^admin/applicants$', views.ApplicantListView, name='applicant_list'),
url(r'^import_db$', views.import_db, name='import_db1'),
url(r'^applicant_make$', views.applicant_make, name='applicant_make'),
#url(r'^admin/choices$', views.ChoiceListView.as_view(), name='choice_list'),
#url(r'^admin/applicants$', views.ApplicantListView.as_view(), name='applicant_list'),
#url(r'^login/$', auth_views.login,name='login'),
#url(r'^logout/$', auth_views.logout, name='logout1'),
]
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from allocation.models import Applicant,Application,Choice
from allocation.models import *
#from allocation.forms import PreferenceForm
from django.forms import modelform_factory
from django.forms import modelformset_factory
from django.views import generic
from allocation.models import Choice
from allocation.models import Applicant
from django.shortcuts import render, redirect
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.contrib.auth import authenticate, login
from django import forms
import csv
# @login_required(login_url='/admin/login')
# def index(request): #for /allocation
# applicant=Applicant.objects.filter(name=request.user.username)[0]
......@@ -18,6 +25,51 @@ from django.views import generic
# form = ArticleForm(instance=applicant)
# return render(request, 'allocation/index.html', {'applicant': applicant, 'form': form})
def index(request):
return HttpResponse("Hello, world. You're at the allocation index.")
def index1(request):
return render(request,'core/home_page.html')
def home(request):
documents = Document.objects.all()
return render(request, 'core/home.html', { 'documents': documents })
return HttpResponse("On home")
def import_db(request):
if request.method == "POST":
csvfile = request.FILES['myfile']
file_data = csvfile.read().decode("utf-8")
lines = file_data.split("\n")
user_name = request.user.username
institute = Institute.objects.filter(name=user_name)[0]
for line in lines:
line = line.split(',')
# tmp = Choice.objects.create(choice_name=line[0],capacity=line[1])
tmp = institute.choices.create(choice_name=line[0],capacity=line[1])
tmp.save()
return HttpResponse("successful")
return HttpResponse("Error")
def applicant_make(request):
if request.method == "POST":
csvfile = request.FILES['myfile']
file_data = csvfile.read().decode("utf-8")
user_name = request.user.username
institute = Institute.objects.filter(name=user_name)[0]
lines = file_data.split("\n")
for line in lines:
line = line.split(',')
# tmp = Applicant.objects.create(name = line[0],rank=line[1])
tmp = institute.applicants.create(name = line[0],rank = line[1])
tmp.save()
user = User.objects.create_user(username=line[2],email=line[3],password=line[4])
user.is_staff = True
user.save()
return HttpResponse("successful")
return HttpResponse("Error")
AppFormset = modelformset_factory(Application,fields=("choice", "priority" ), extra=5)
......@@ -54,11 +106,13 @@ def admin1(request):
return render(request, 'allocation/admin1.html')
class ChoiceListView(generic.ListView):
model = Choice
# class ChoiceListView(generic.ListView):
# model = Choice
# queryset = Choice.objects.filter(institute='IITB')
class ApplicantListView(generic.ListView):
model = Applicant
# class ApplicantListView(generic.ListView):
# model = Applicant
# queryset = Applicant.objects.filter(institute_name='IITB')
......
No preview for this file type
......@@ -16,8 +16,11 @@ Including another URLconf
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views
from allocation import views
urlpatterns = [
url(r'^allocation/', include('allocation.urls')),
url(r'^admin/', admin.site.urls),
url(r'^$',views.index1,name='index1'),
]
{% extends "admin/change_list.html" %}
{% load i18n %}
{% block object-tools-items %}
{{ block.super }}
{% if request.get_full_path == "/admin/allocation/choice/" %}
<li>
<form method="POST" action="/allocation/import_db" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile">
<button type="submit">Upload</button>
</form>
</li>
{% endif %}
{% if request.get_full_path == "/admin/allocation/applicant/" %}
<li>
<form method="POST" action="/allocation/applicant_make" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile">
<button type="submit">Upload</button>
</form>
</li>
{% endif %}
{% endblock %}
.container { position: relative; }
.container{
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
/*z-index: 1;*/
background-image: url('BG.png');
background-size: 2000px 700px;
background-repeat: no-repeat;
background-attachment: fixed;
opacity: 0.60;
}
.content {
position: relative;
margin-top: 300px;
font-size: 60px;
opacity: 20;
}
.tool1 {
margin-top: 680px;
background-color: green;
}
.tool2 {
margin-top: 700px;
background-color: #5DBCD2;
}
.tool3 {
margin-top: 720px;
background-color: #5DBCD2;
}
.tool4 {
margin-top: 720px;
background-color: #5DBCD2;
}
\ No newline at end of file
<html>
<head>
<link rel="stylesheet" type="text/css" href="allocation/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
{% extends 'base.html' %}
{% load static %}
{% block content %}
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile">
<button type="submit">Upload</button>
</form>
{% if uploaded_file_url %}
<p>File uploaded at: <a href="{{ uploaded_file_url }}">{{ uploaded_file_url }}</a></p>
{% endif %}
<p><a href="{% url 'home' %}">Return to home</a></p>
{% endblock %}
\ No newline at end of file
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