validators and corner-cases

parent 33dc204e
......@@ -18,31 +18,31 @@
.content {
position: relative;
margin-top: 300px;
margin-top: 16%;
font-size: 60px;
opacity: 20;
}
.tool1 {
margin-top: 680px;
/*margin-top: 680px;*/
background-color: green;
z-index: 1;
}
.tool2 {
margin-top: 700px;
/*margin-top: 700px;*/
background-color: #5DBCD2;
z-index: 1;
}
.tool3 {
margin-top: 720px;
/*margin-top: 720px;*/
background-color: #5DBCD2;
z-index: 1;
}
.tool4 {
margin-top: 720px;
/*margin-top: 720px;*/
background-color: #5DBCD2;
z-index: 1;
}
\ No newline at end of file
......@@ -30,20 +30,30 @@
{% endblock %}
{% 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" %}
<div style="float:right;">
<form method="POST" action="/allocation/button_action" enctype="multipart/form-data">
{% 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>
</form>
</div>
{% endif %}
<p style="font-size: 25px; text-align: left;"><a href="{% url 'allocation:applicant_list' %}">Applicants</a></p>
<p style="font-size: 25px; text-align: left"><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">
<form method="POST" action="/allocation/button_action" enctype="multipart/form-data">
{% 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>
</form>
<div>
<div> -->
{% endif %}
<!-- {% endif %} -->
{% endblock %}
......@@ -9,14 +9,57 @@
{% 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;">
<h3 style="margin-top: -50px"> For uploading Applicant</h3>
<form method="POST" action="/allocation/applicant_make" enctype="multipart/form-data">
<form name="myform" method="POST" action="/allocation/applicant_make" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile" title='Please upload file in .csv format only'>
<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">
{% if success %}
<p style="color:red">Invalid input</p>
{% endif %}
</div>
</form>
</li>
{% for applicant in applicant_list %}
......@@ -31,10 +74,12 @@
<h3 style="margin-top: -50px"> For uploading Applicant</h3>
<form method="POST" action="/allocation/applicant_make" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile" title='Please upload file in .csv format only'>
<input type="file" name="myfile" accept=".csv" title='Please upload file in .csv format only'>
<button type="submit">Upload</button>
</form>
</li>
<p>There are no applicants.</p>
{% endif %}
<!-- {% endif %} -->
{% endblock %}
......@@ -36,7 +36,7 @@
<h3 style="margin-top: -50px"> For uploading choices</h3>
<form method="POST" action="/allocation/choice_make" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="myfile" title='Please upload file in .csv format only'>
<input type="file" accept=".csv" name="myfile" title='Please upload file in .csv format only'>
<button type="submit">Upload</button>
</form>
</li>
......
......@@ -18,6 +18,7 @@ urlpatterns = [
url(r'^choice_make$', views.choice_make, name='choice_make'),
url(r'^applicant_make$', views.applicant_make, name='applicant_make'),
url(r'^button_action$', views.button_action, name='button_action'),
# url(r'^send_mail$', views.send_mail, name='mail_send'),
#url(r'^admin/choices$', views.ChoiceListView.as_view(), name='choice_list'),
#url(r'^admin/applicants$', views.ApplicantListView.as_view(), name='applicant_list'),
......
......@@ -19,7 +19,25 @@ from django import forms
import csv
from django.urls import reverse_lazy
from django.utils import lru_cache
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import lazy
from django.utils.html import format_html
from django.utils.module_loading import import_string
from django.utils.six import string_types, text_type
from django.utils.translation import ugettext as _, ungettext
from django.contrib.auth import *
from alloc import *
from difflib import SequenceMatcher
from django.core.mail import send_mail
from django.core.mail import EmailMessage
from django.core.exceptions import (
FieldDoesNotExist, ImproperlyConfigured, ValidationError,
)
# @login_required(login_url='/admin/login')
# def index(request): #for /allocation
......@@ -29,6 +47,16 @@ from alloc import *
# # )
# 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(
# 'subject_message',
# 'content_message',
# 'sender smtp gmail' +'<codemafia123@gmail.com>',
# ['codemafia123@gmail.com'],)
# email.send()
# return HttpResponse("success")
def button_action(request):
# value = request.POST["prikey"]
......@@ -52,15 +80,40 @@ def choice_make(request):
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(',')
number = len(line)
if number != 2:
return HttpResponse("Incorrect data format in uploaded .csv file.")
existing_no = institute.choices.filter(choice_name=line[0])
if existing_no.count() != 0:
return HttpResponse(".csv file has choices that already exists")
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 = institute.choices.create(choice_name=line[0],capacity=line[1])
tmp.save()
# tmp = Choice.objects.create(choice_name=line[0],capacity=line[1])
return HttpResponse("successful")
return HttpResponse("Error")
@lru_cache.lru_cache(maxsize=None)
def get_default_password_validators():
return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
def get_password_validators(validator_config):
validators = []
for validator in validator_config:
try:
klass = import_string(validator['NAME'])
except ImportError:
msg = "The module in NAME could not be imported: %s. Check your AUTH_PASSWORD_VALIDATORS setting."
raise ImproperlyConfigured(msg % validator['NAME'])
validators.append(klass(**validator.get('OPTIONS', {})))
return validators
def applicant_make(request):
if request.method == "POST":
csvfile = request.FILES['myfile']
......@@ -68,12 +121,33 @@ def applicant_make(request):
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(',')
number = len(line)
if number != 4:
return HttpResponse("Incorrect data format in uploaded .csv file")
existing_no_app = institute.applicants.filter(name = line[0],rank = line[1])
existing_no_user = User.objects.filter(username=line[0],email=line[2],password=line[3])
if existing_no_app.count() != 0:
return HttpResponse(".csv files has applicants that already exists")
if existing_no_user.count() != 0:
return HttpResponse("user with same username,password and email-id already exists")
errors = []
password_validators = get_default_password_validators()
for validator in password_validators:
try:
validator.validate(line[3])
except ValidationError as error:
errors.append(error)
if errors:
return HttpResponse("Invalid password given in .csv file")
# if validate_password(line[4]) != None:
# return HttpResponse("Invalid password given in .csv file")
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 = User.objects.create_user(username=line[0],email=line[2],password=line[3])
user.is_staff = True
user.save()
return HttpResponse("successful")
......
No preview for this file type
......@@ -9,7 +9,7 @@
right: 0;
z-index: -1;
/*background-image: url('BG.png');*/
background-size: 2000px 700px;
background-size: 100% 25%;
background-repeat: no-repeat;
background-attachment: fixed;
opacity: 0.60;
......
......@@ -18,7 +18,7 @@
<div class="content"><h1 align="center" style="color:black">General Allocation Portal</h1></div>
</div>
<div class="tool1" style="margin-top: 460px; text-align: center; font-size: 30px;">
<div class="tool1" style="margin-top: 29%; text-align: center; font-size: 30px;">
</div>
......
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