Commenting

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