Commenting

parent 23d31ed2
......@@ -52,6 +52,7 @@ from django.core.exceptions import (
# ['codemafia123@gmail.com'],)
# email.send()
# return HttpResponse("success")
def signup(request):
if request.method == 'POST':
form = InstiForm(request.POST)
......@@ -66,29 +67,33 @@ def signup(request):
form = InstiForm()
return render(request, 'registration/register.html', {'form': form})
## View for the button 'Allocate'
# @brief On clicking the button 'Allocate' user is directed to this view and its url "/allocation/button_action"
def button_action(request):
institute=request.user.username
allocator(institute)
institute=request.user.username #< login institute name
allocator(institute) #< calls the function allocator in 'alloc.py'
return HttpResponseRedirect("/allocation/admin")
## View for the button 'Upload' in choice_list.html
# @brief On clicking the button 'Upload' all the .csv choices are validated and the uploaded
def choice_make(request):
if request.method == "POST":
csvfile = request.FILES['myfile']
csvfile = request.FILES['myfile'] #< Uploaded csv file
file_data = csvfile.read().decode("utf-8")
lines = file_data.split("\n")
user_name = request.user.username
institute = get_object_or_404(Institute, name=user_name)
repeated = []
lines = file_data.split("\n") #< split the csv file into lines
user_name = request.user.username #< logged in institute name
institute = get_object_or_404(Institute, name=user_name) #< Institute object corresponding to logged in institute
repeated = [] #< this list keeps track of repeated choices
for line in lines:
line = line.split(',')
number = len(line)
if number != 2:
if number != 2: #< If the number of columns is not equal to two then display error
return HttpResponse("Incorrect data format in uploaded .csv file.")
existing_no = institute.choices.filter(choice_name=line[0])
existing_no = institute.choices.filter(choice_name=line[0]) #< Get existing choices(if exist) of the particular institute
if existing_no.count() != 0:
repeated.append(line[0])
# return HttpResponse(".csv file choice: '"+ line[0] + "' already exists")
if len(repeated) != 0:
if len(repeated) != 0: #< If there exists Repeating choices then display all the repeated choices
str = ""
for rep in repeated:
str += rep + ","
......@@ -98,13 +103,14 @@ def choice_make(request):
tmp = institute.choices.create(choice_name=line[0],capacity=line[1])
tmp.save()
return HttpResponseRedirect("/allocation/admin/choices")
return HttpResponse("Error")
return HttpResponse("Error") #< If not a 'POST' query then display error
## Django function for getting default password validators
@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:
......@@ -117,64 +123,60 @@ def get_password_validators(validator_config):
return validators
## View for the button 'Upload' in applciant_list.html
def applicant_make(request):
if request.method == "POST":
csvfile = request.FILES['myfile']
csvfile = request.FILES['myfile'] #< Uploaded csv file
file_data = csvfile.read().decode("utf-8")
user_name = request.user.username
institute = get_object_or_404(Institute, name=user_name)
lines = file_data.split("\n")
rep_users = []
rep_applicant = []
errors = []
user_name = request.user.username #< Name of the logged in institute
institute = get_object_or_404(Institute, name=user_name) #< Institute object corresponding to the logged in institute
lines = file_data.split("\n") #< splits csv file into lines
rep_users = [] #< This list keeps track of the repeated users
rep_applicant = [] #< This list keeps track of the repeated applicants
errors = [] #< This list keeps track of the users with invalid passwords
for line in lines:
line = line.split(',')
number = len(line)
if number != 4:
if number != 4: #< Checks whether the number of columns is equal to 4 or not
return HttpResponse("Incorrect data format in uploaded .csv file")
existing_no_app = institute.applicants.filter(name = line[0])
existing_no_user = User.objects.filter(username=line[0])
existing_no_app = institute.applicants.filter(name = line[0]) #< Query set of applicants that already exist and match with the name of the applicant in csv file
existing_no_user = User.objects.filter(username=line[0]) #< Query set of users that already exist and match with the name of the applicant in csv file
if existing_no_app.count() != 0:
rep_applicant.append(line[0])
# return HttpResponse(".csv files has applicants that already exists")
if existing_no_user.count() != 0:
rep_users.append(line[0])
# return HttpResponse("user with same username already exists")
password_validators = get_default_password_validators()
password_validators = get_default_password_validators() #< Get validators for validating the passwords
for validator in password_validators:
try:
validator.validate(line[3])
except ValidationError as error:
errors.append(line[0])
if len(rep_applicant) != 0:
if len(rep_applicant) != 0: #< if there already exist applicants matching our .csv file
str = ""
for appl in rep_applicant:
str += appl + ","
return HttpResponse(".csv file has applicants: '"+ str + "' that already exists")
if len(rep_users) != 0:
if len(rep_users) != 0: #< if there already exist users matching our .csv file
str = ""
for appl in rep_users:
str += appl + ","
return HttpResponse(".csv file has user with usernames : '"+ str + "' that already exists")
if len(errors) != 0:
if len(errors) != 0: #< if some passwords are invalid
str = ""
for appl in errors:
str += appl + ","
return HttpResponse(".csv file usernames : '"+ str + "' have incorrect format of password")
# 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:
for line in lines: #< All fields provided are valid and hence create Applicants and users
line = line.split(',')
tmp = institute.applicants.create(name = line[0],rank = line[1])
tmp = institute.applicants.create(name = line[0],rank = line[1]) #< Creating Applicant
tmp.save()
user = User.objects.create_user(username=line[0],email=line[2],password=line[3])
user.is_staff = True
user = User.objects.create_user(username=line[0],email=line[2],password=line[3]) #< Creating user
user.is_staff = True #< Giving staff permission to the user
user.save()
return HttpResponseRedirect("/allocation/admin/applicants")
return HttpResponse("Error")
......
......@@ -27,12 +27,12 @@
</tr>
</table> -->
<img src ="{% static 'allocation/logo.png' %}" class="fixed" width="30%" height="30%" alt="logo" >
<img src ="{% static 'allocation/logo.png' %}" class="fixed" width="20%" height="20%" alt="logo" >
<div class="container">
<div class="content"><h1 align="center" style="color:black">General Allocation Portal</h1></div>
</div>
<div class="tool1" style="margin-top: 45%; text-align: center; font-size: 30px;">
<div class="tool1" style="margin-top: 52%;">
</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