Commit 16c678fe authored by Darshan Prabhu's avatar Darshan Prabhu

Latex generation and priorities of students and faculties

parent 4dbb4e6a
from pylatex import Document, Section, Subsection, Tabular,MiniPage,LargeText,FlushLeft,LineBreak, \
FlushRight,LongTabu,MultiColumn,MultiRow, LongTabularx, Figure,Center
from pylatex.package import Package
from pylatex.utils import bold, NoEscape
# Function to convert stored data to Latex pdf
def mappedResult(result,guide,studentApplied,fileLocation):
'''
Input:
result: mappings generated for every project
guide: List of guides and the projects proposed by them
studentApplied: Count of students partaking in the allocation
filelocation: path to store the latex file
'''
geometric_options = {
"margin":"0.4in"
}
doc = Document(geometry_options=geometric_options)
center = Center()
center.append(LargeText(bold("Summary")))
doc.append(center)
with doc.create(LongTabu('|c c|',row_height="2.0",col_space="1in")) as table:
totalAlloted = 0
num_offers = 0
for keys, values in result.items():
alloted = sum([len(i) for i in values.values() ])
totalAlloted += alloted
num_offers += guide[keys]['requirement']
table.add_hline()
table.add_row(bold("No. of Students applied"),studentApplied)
table.add_row(bold("No. of Slots Offered"),num_offers)
table.add_row(bold("No. of Students alloted"),totalAlloted)
table.add_hline()
with doc.create(LongTabu("|c c c|",row_height="2.0",col_space="0.35in")) as guideTable:
header_row = ["Guide Name", "Requirements", "Alloted"]
guideTable.add_hline()
guideTable.add_row(header_row,mapper=[bold])
guideTable.add_hline()
guideTable.add_hline()
for keys,values in result.items():
alloted = sum([len(i) for i in values.values() ])
guideTableRow = [guide[keys]['name'], guide[keys]['requirement'], bold(alloted)]
guideTable.add_row(guideTableRow)
guideTable.add_hline()
center = Center()
center.append(LargeText(bold("Student-Guide Mapping Result for MTP")))
doc.append(center)
with doc.create(LongTabu("|c|c|c|c|",booktabs=True,row_height="2.0",col_space="0.2in")) as dataTable:
header_row = ["GuideName","Topic_offered","AllotedStudentId","AllotedStudentName"]
dataTable.add_hline()
dataTable.add_row(header_row,mapper=[bold])
dataTable.add_hline()
dataTable.add_hline()
dataTable.end_table_header()
for keys,value in result.items():
idSpan = sum([len(i) for i in value.values() ])
# idRow = MultiRow(idSpan,data=keys)
nameRow = MultiRow(idSpan,data=guide[keys]['name'])
j = 0
for key,val in value.items():
topicSpan = len(val)
topicRow = MultiRow(topicSpan,data=key)
i = 0
for k,v in val.items():
if(i==0 and j==0):
dataTable.add_row(nameRow,topicRow,k,v)
dataTable.add_hline(3,4)
i += 1
j += 1
elif(i==0 and j>0):
dataTable.add_row('',topicRow,k,v)
dataTable.add_hline(3,4)
i += 1
j += 1
else:
dataTable.add_row('','',k,v)
dataTable.add_hline(3,4)
i += 1
j += 1
dataTable.add_hline(2,4)
dataTable.add_hline(1,4)
# doc.append(NoEscape(r'\end{adjustbox}'))
doc.generate_pdf(fileLocation,clean_tex=False)
if __name__ == '__main__':
result = {"GuideId1":{
"TopicId1":{
"1122":'piyush',
"2233":'sharma'
},
"TopicId2":{
"234":'darshan',
"432":'deepak',
"4567":'prabhu'
}},
"GuideId2":{
"TopicId1":{
"1122":'sandeep'
}},
"GuideId3":{
"TopicId1":{
"1123":'Parihar'
},
"TopicId2":{
"234":'Rajeev',
"432":'Vaidyanathan',
"4568":"Natarajan"
},
"TopicId3":{
"1":'abc',
"2":'bcd',
"3":'cde',
"4":'def'
}},
"GuideId4":{
}
}
guide = {
"GuideId1":{
"name":"Ajit Rajwade",
"requirement":5
},
"GuideId2":{
"name":"Preethi Jyothi",
"requirement":2
},
"GuideId3":{
"name":"Vinay Robeiro",
"requirement":10
},
"GuideId4":{
"name":"Suyash P. Awate",
"requirement":10
}
}
mappedResult(result,guide,27,"static/allocationResults")
......@@ -190,7 +190,76 @@
{% endif %}
</div>
<div class="ui tab " data-tab="second">
<div class="ui warning message">
<div class="header ui center aligned">
Instructions to use the priority window
</div>
<ul>
<li>Each card represents priorities to <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Individual projects</span> proposed by you. You can see the ribbon to understand which project you are working with.</li>
<li>Arrangement of the applications should be in <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Ascending order</span>.</li>
<li>You can <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">hold and move</span> the applications to change the priority arrangements. </li>
<li>Click on the <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Update priorities</span> to make changes permanent.</li>
</ul>
</div>
{% for shortlistedApplications in ProjectWiseShortlistedApplications %}
<div style="padding: 2em 0;margin: 2em 0;">
<div class="ui grid">
<div class="right floated four wide column">
<button class="fluid ui labeled {% get_table_color forloop.counter0 %} icon button" onclick="submit_priorities({{ forloop.counter0 }},{% with application=shortlistedApplications|index:0 %}{{ application.project.id }}{% endwith %})" >
<i class="plus icon"></i>
Update priorities
</button>
</div>
</div>
<div class="ui segment fluid raised card">
<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
<a class="left aligned floating ui {% get_table_color forloop.counter0 %} ribbon label">{% with application=shortlistedApplications|index:0 %} {{ application.project.title }} {% endwith %}</a>
<div class="ui grid center aligned divided" style="margin-top: 0px;">
<div class="four wide column ui tiny header">NAME</div>
<div class="four wide column ui tiny header ">POSITION</div>
<div class="two wide column ui tiny header">CGPA</div>
<div class="two wide column ui tiny header">SHORTLISTED ON</div>
<div class="four wide column ui tiny header">ACTIONS</div>
</div>
</div>
<div class="ui divider" style="margin-bottom: 0px;"></div>
</div>
<div class="ui middle aligned selection divided list" style="margin-top: 0px;" id="sortable-{{ forloop.counter0 }}">
{% for application in shortlistedApplications %}
<div class="item">
<div class="ui grid">
<input type="hidden" readonly="" disabled="" class="applied-student-id" value="{{ application.student.id }}">
<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ application.student.student.get_full_name }}</div></div>
<div class="column four wide center aligned middle aligned"><div class="ui medium ">{{ application.project.title }}</div></div>
<div class="column two wide center aligned middle aligned"><div class="ui star yellow rating" data-rating="{% get_normalized_grades application.student.get_cgpa %}" data-max-rating="5"></div></div>
<div class="column two wide center aligned middle aligned"><div>{{ application.date }}</div></div>
<div class="center aligned four wide column">
<div class="ui center aligned" style="display: inline-flex;">
<button class="ui vk button" onclick="show_student_detail( '{{ application.student.id }}-{{ application.project.id }}' )">
<i class="address card icon"></i>
Info
</button>
<form action="{% url 'gap:shortlist' %}" method="POST" class="ui column">
{% csrf_token %}
<input type="hidden" name="student_Id" value="{{ application.student.id }}">
<input type="hidden" name="project_Id" value="{{ application.project.id }}">
<input type="hidden" name="action" value="discard">
<button class="ui right labeled icon negative button" onclick="return confirm('Do you want to DISCARD this application?');">
<i class="trash icon"></i>
Discard
</button>
</form>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</div>
<div class="ui tab" data-tab="third">
<div class="ui warning message">
......@@ -1068,6 +1137,8 @@ $(document).ready(function() {
} );
function sync_total_forms(){
$('#updateforms .requisitesList').each(function(){
$(this).find('#id_requisites-TOTAL_FORMS').val($(this).find('.update-requisites-form').length);
......@@ -1177,7 +1248,47 @@ function deleteupdaterequisitesForm(btn,id,filled_row){
}
function submit_priorities(index,projectId){
$.ajax({
type: 'POST',
url: '{% url "gap:updatePriorities" %}',
data: {
user: 'faculty',
projectId: String(projectId),
priorities: JSON.stringify({'priority_list':$('#sortable-'+String(index)+' .applied-student-id').map(function(){return $(this).val()}).get()}),
csrfmiddlewaretoken: '{{ csrf_token }}',
},
success: function (json) {
$('body')
.toast({
class: "success",
title: "Priority Updation for "+json["title"],
displayTime: 3000,
closeIcon: true,
position: "top center",
showIcon: "check",
message: json["successMessage"],
className: {
toast: 'ui icon message'
}
});
},
error: function (error) {
error_message = error["responseJSON"]["detail"];
$('body')
.toast({
class: "red",
title: "Error updating priorities for <b>" + error["responseJSON"]["title"]+"</b>",
displayTime: 5000,
closeIcon: true,
position: "top center",
showIcon: "exclamation",
message: error_message,
className: {
toast: 'ui message'
}
});
}
});
}
......
......@@ -117,11 +117,150 @@
</div>
<div class="ui tab active" data-tab="first">
{% if applicationDetails %}
<div class="ui warning message">
<i class="close icon"></i>
<div class="header ui center aligned">
Instructions to Candidates
</div>
<ul>
<li>Use the <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); "> Info </span> button to know more about the project.</li>
<li>Click on <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); "> Apply </span> to submit your application for the said role.</li>
<li>You can find the shortlisted applications in the <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Applied Projects</span> tab</li>
</ul>
</div>
{% else %}
<div class="ui warning message">
<i class="close icon"></i>
<div class="header ui center aligned">
Create your profile
</div>
<ul>
<li>You have not built your profile. This will help faculties know you better</li>
<li>You must fill the <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Profile</span> before applying to faculties.</li>
<li>Thy shall go to the <span class="medium header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">My Profile</span> section to do the same.</li>
</ul>
</div>
{% endif %}
<table id="example" class="ui table raised segment center aligned" style="width:100%">
<thead>
<tr>
<th>FACULTY NAME</th>
<th>PROJECT TITLE</th>
<th>CONTACT DETAILS</th>
<th>OPEN POSITIONS</th>
<th class="last-th">ACTIONS</th>
</tr>
</thead>
<tbody>
{% for position in unappliedPositions %}
<tr>
<td>
<span class="ui" style="color: #b58105;">{{ position.faculty.get_full_name }}</span>
</td>
<td>
<span style="color: #5279a2;">{{ position.title }}</span>
</td>
<td>
{{ position.contact_details }}
</td>
<td>
<span class="ui orange header">{{ position.total_positions }}</span>
</td>
<td>
<div style="display: inline-flex;">
<button class="ui vk button column" onclick="show_project_detail({{ position.id }})">
<i class="address card icon"></i>
Info
</button>
{% if applicationDetails and not applicationDetails.alloted_project %}
<form action="{% url 'gap:shortlist' %}" method="POST" class="ui column">
{% csrf_token %}
<input type="hidden" name="project_Id" value="{{ position.id }}">
<input type="hidden" name="action" value="shortlist">
<button class="ui icon right labeled teal button" onclick="return confirm('Do you want to SHORTLIST this application?');" >
<i class="check icon"></i>
Apply
</button>
</form>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="ui tab " data-tab="second">
<div class="ui warning message">
<div class="header ui center aligned">
Instructions to use the priority window
</div>
<ul>
<li>Arrangement of the application should be in <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Ascending order</span>.</li>
<li>You can <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">hold and move</span> the applications to change the priority arrangements </li>
<li>Click on the <span class="header" style="display: inline;background-color:rgba(0, 0, 0, 0.06); ">Update priorities</span> to make changes permanent.</li>
</ul>
</div>
<div class="ui grid">
<div class="right floated four wide column">
{% if appliedPositions %}
<button class="fluid ui labeled teal icon button" onclick="submit_priorities()" >
<i class="plus icon"></i>
Update priorities
</button>
{% endif %}
</div>
</div>
<div class="ui segment fluid raised card">
<div class="ui middle aligned selection divided list" style="margin-bottom: 0px;">
<div class="item" style="padding-bottom: 0px;padding-top: 0px;background-color: rgb(0,0,0,0.03);">
<div class="ui grid center aligned divided" style="margin-top: 0px;">
<div class="three wide column ui tiny header">FACULTY NAME</div>
<div class="four wide column ui tiny header ">PROJECT TITLE</div>
<div class="four wide column ui tiny header">CONTACT DETAILS</div>
<div class="two wide column ui tiny header">OPEN POSITIONS</div>
<div class="three wide column ui tiny header">ACTIONS</div>
</div>
</div>
<div class="ui divider" style="margin-bottom: 0px;"></div>
</div>
<div class="ui middle aligned selection divided list" style="margin-top: 0px;" id="sortable">
{% for position in appliedPositions %}
<div class="item">
<div class="ui grid">
<input type="hidden" readonly="" disabled="" class="applied-project-id" value="{{ position.id }}">
<div class="column three wide center aligned middle aligned"><span class="ui" style="color: #b58105;">{{ position.faculty.get_full_name }}</span></div>
<div class="column four wide center aligned middle aligned"><span style="color: #5279a2;">{{ position.title }}</span></div>
<div class="column four wide center aligned middle aligned">{{ position.contact_details }}</div>
<div class="column two wide center aligned middle aligned"><span class="ui header" style="color: #f2711c;">{{ position.total_positions }}</span></div>
<div class="right floated three wide column">
<div class="ui center aligned" style="display: inline-flex;">
<button class="ui vk button" onclick="show_project_detail({{ position.id }})">
<i class="address card icon"></i>
Info
</button>
<form action="{% url 'gap:shortlist' %}" method="POST" class="ui column">
{% csrf_token %}
<input type="hidden" name="project_Id" value="{{ position.id }}">
<input type="hidden" name="action" value="discard">
<button class="ui right labeled icon negative button" onclick="return confirm('Do you want to DISCARD this application?');">
<i class="trash icon"></i>
Discard
</button>
</form>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<div class="ui tab" data-tab="third">
......@@ -993,6 +1132,45 @@ function deleteEducationDetailForm(btn,filled_row){
}
function submit_priorities(){
$.ajax({
type: 'POST',
url: '{% url "gap:updatePriorities" %}',
data: {
user: 'student',
priorities: JSON.stringify({'priority_list':$('.applied-project-id').map(function(){return $(this).val()}).get()}),
csrfmiddlewaretoken: '{{ csrf_token }}',
},
success: function (json) {
$('body')
.toast({
class: "success",
title: "Priority Updation",
displayTime: 3000,
closeIcon: true,
position: "top center",
showIcon: "check",
message: json["successMessage"],
className: {
toast: 'ui icon message'
}
});
},
error: function (error) {
error_message = error["responseJSON"]["detail"];
$('body')
.toast({
class: "red",
title: "Error updating priorities",
displayTime: 5000,
closeIcon: true,
position: "top center",
showIcon: "exclamation",
message: error_message,
className: {
toast: 'ui message'
}
});
}
});
}
{% endblock %}
\ No newline at end of file
from django.urls import path, include
from .views import LoginView, LogoutView, dashboardView, shortlistView, updatePriorityView, generateMappingsView
from .views import LoginView, LogoutView, dashboardView, shortlistView, updatePriorityView
urlpatterns = [
path('login',LoginView.as_view(),name="login"),
path('logout',LogoutView,name="logout"),
path('',dashboardView.as_view(),name="dashboard"),
path('generatemapping',generateMappingsView,name="generateMapping")
path('shortlist',shortlistView,name="shortlist"),
path('updatepriorities',updatePriorityView,name="updatePriorities")
]
......@@ -146,9 +146,6 @@ class dashboardView(LoginRequiredMixin,UserPassesTestMixin,View):
context = get_context(self.user_type,request)
return render(request,self.template_name,context)
else:
# Handle faculty and facad users
if request.POST.get('positionId'):
# Update the already present open positions
position = PositionsModel.objects.get(id=request.POST.get('positionId'))
......@@ -185,8 +182,118 @@ class dashboardView(LoginRequiredMixin,UserPassesTestMixin,View):
return render(request,self.template_name,context)
# View to handle shorlisting request
@login_required(login_url = 'gap:login')
def shortlistView(request):
user_type = get_user_type(request.user)
if request.method == 'POST':
# sanity check to avoid get requests
if user_type== 'student':
# Handle student shortlist requests
if not StudentDetailModel.objects.get(student=request.user).alloted_project:
student = StudentDetailModel.objects.get(student=request.user)
project = PositionsModel.objects.get(id=request.POST.get('project_Id'))
# Handle both shortlisting and discarding
if request.POST.get('action')=="shortlist":
if not StudentPriorities.objects.filter(student=student,project=project).exists():
current_priority = student.priorities.count()
StudentPriorities.objects.create(student=student,project=project,current_priority=current_priority)
else:
# Handle case where student has already shortlisted the project
messages.error(request,"The application you are trying to shortlist is already shortlisted")
context = get_context(user_type,request)
return render(request,'student_dashboard.html',context)
elif request.POST.get('action')=="discard":
if StudentPriorities.objects.filter(student=student,project=project).exists():
priority = StudentPriorities.objects.filter(student=student,project=project).first()
updatePrioritiesAfterDeletion(user_type,student,project,priority.current_priority)
priority.delete()
else:
# Handle case where student has already discarded the project
messages.error(request,"The application you are trying to discard is not shortlisted by you")
context = get_context(user_type,request)
return render(request,'student_dashboard.html',context)
else:
# Handle case where student is already a project
messages.error(request,"You cannot apply for any positions as you are already allocated")
context = get_context(user_type,request)
return render(request,'student_dashboard.html',context)
else:
# Handle project shortlist requests
student = StudentDetailModel.objects.get(id=request.POST.get('student_Id'))
if student.alloted_project:
# Handle case where student is already a project
messages.error(request,"The application you are trying to shortlist is already alloted to another project")
context = get_context(user_type,request)
return render(request,'faculty_dashboard.html',context)
project = PositionsModel.objects.get(id=request.POST.get('project_Id'))
if request.POST.get('action')=="shortlist":
if not ProjectPriorities.objects.filter(student=student,project=project).exists():
current_priority = project.priorities.count()
ProjectPriorities.objects.create(student=student,project=project,current_priority=current_priority)
else:
# Handle case where project has already shortlisted the student
messages.error(request,"The application you are trying to shortlist is already shortlisted")
context = get_context(user_type,request)
return render(request,'faculty_dashboard.html',context)
elif request.POST.get('action')=="discard":
if ProjectPriorities.objects.filter(student=student,project=project).exists():
priority = ProjectPriorities.objects.filter(student=student,project=project).first()
updatePrioritiesAfterDeletion(user_type,student,project,priority.current_priority)
priority.delete()
else:
# Handle case where project has already discarded the student
messages.error(request,"The application you are trying to discard is not shortlisted by you")
context = get_context(user_type,request)
return render(request,'faculty_dashboard.html',context)
return redirect('gap:dashboard')
# Update priorities of all the users
@login_required(login_url = 'gap:login')
def updatePriorityView(request):
if get_user_type(request.user) == 'student':
# Handles priorities sent by students
if StudentDetailModel.objects.get(student=request.user).alloted_project:
# Handles the case where student is already alloted a project
return JsonResponse({'status_code':400,'detail':'You are already alloted a project'})
# Get priority list from post request
priority_list = json.loads(request.POST.get('priorities'))['priority_list']
clauses = ' '.join(['WHEN project_id={} THEN {}'.format(pk, i) for i, pk in enumerate(priority_list)])
ordering = 'CASE {} END'.format(clauses)
priorities = StudentDetailModel.objects.get(student=request.user).priorities.all().extra(select={'ordering': ordering}, order_by=('ordering',))
if priorities.exists():
# Update priorities
for index,priority in enumerate(priorities):
priority.current_priority = index
priority.save()
return JsonResponse({'status_code':200,'successMessage':'Priorities are updated successfully'})
else:
return JsonResponse({'status_code':403,'detail':'You do not have permission to update priorities'})
elif get_user_type(request.user) in ['faculty','facad']:
# Handles priorities sent by faculties and facad
# Get priority list from post request
priority_list = json.loads(request.POST.get('priorities'))['priority_list']
project_id = request.POST.get('projectId')
clauses = ' '.join(['WHEN student_id={} THEN {}'.format(pk, i) for i, pk in enumerate(priority_list)])
ordering = 'CASE {} END'.format(clauses)
print(clauses)
priorities = ProjectPriorities.objects.filter(project_id=project_id).extra(select={'ordering': ordering}, order_by=('ordering',))
print(priorities)
if priorities.exists():
for index,priority in enumerate(priorities):
# Update priorities
priority.current_priority = index
priority.save()
return JsonResponse({'status_code':200,'successMessage':'Priorities are updated successfully','title':PositionsModel.objects.get(id=project_id).title})
else:
return JsonResponse({'status_code':403,'detail':'You do not have permission to update priorities','title':PositionsModel.objects.get(id=project_id).title})
return JsonResponse({'status_code':403,'detail':'You do not have permission to update priorities','title':PositionsModel.objects.get(id=project_id).title})
......@@ -275,7 +382,25 @@ def get_context(user_type,request):
context['studentProjects'] = StudentProjectFormset()
context['studentEducation'] = StudentEducationFormset()
# get list of applied and unapplied positions based on priority value
positions = PositionsModel.objects.filter(total_positions__gt=0)
if user_application.exists():
ids = user_application.first().priorities.order_by('current_priority').values_list('project', flat=True)
else:
ids = StudentDetailModel.objects.none()
clauses = ' '.join(['WHEN id={} THEN {}'.format(pk, i) for i, pk in enumerate(ids)])
ordering = 'CASE {} END'.format(clauses)
# List of all unapplied projects
context['unappliedPositions'] = positions.exclude(id__in=ids)
# List of all applied projects if it exists
if ids.exists():
context['appliedPositions'] = positions.filter(id__in=ids).extra(select={'ordering': ordering}, order_by=('ordering',))
else:
context['appliedPositions'] = None
else:
# Get context of faculty
# Prefilled forms
context['user_type'] = user_type
......@@ -292,6 +417,33 @@ def get_context(user_type,request):
context['updateforms'] = updateforms
context['updaterequisiteforms'] = updaterequisiteforms
# list of all un shortlisted applications
priorities = ProjectPriorities.objects.filter(project__in=context['availablePositions'])
exclude_conditions = priorities.values('student','project').distinct()
allapplications = StudentPriorities.objects.filter(project__in=context['availablePositions'])
for condition in exclude_conditions:
allapplications = allapplications.exclude(student=condition['student'],project=condition['project'])
context['allApplications'] = allapplications
# List of all priorities associated with each project
priority_groups = dict()
for priority in ProjectPriorities.objects.filter(project__in=context['availablePositions']).order_by('current_priority'):
priority_groups.setdefault(priority.project,[]).append(priority)
context['ProjectWiseShortlistedApplications'] = list(priority_groups.values())
# List of all alloted students
context['allotedStudents'] = GeneratedMappingsModel.objects.filter(faculty=request.user)
if user_type == "facad":
# Additional Data visible only to facad
print(RoundDetailsModel)
if not RoundDetailsModel.objects.all().exists():
RoundDetailsModel().save()
# Round update forms and details
context['RoundUpdateform'] = RoundDetailsModelForm(None,instance=RoundDetailsModel.objects.latest('roundNo'))
context['roundDetails'] = RoundDetailsModel.objects.all()
context['AllotmentsSoFar'] = GeneratedMappingsModel.objects.all()
return context
......@@ -308,3 +460,48 @@ def get_ids(data,prefix):
break
return ids
def updatePrioritiesAfterDeletion(user_type,student,project,current_priority):
# Function to update the priorities incase deletion is done not from end or start of the list
if user_type == 'student':
priorities = StudentPriorities.objects.filter(student=student,project=project).filter(current_priority__gt=current_priority)
else:
priorities = ProjectPriorities.objects.filter(student=student,project=project).filter(current_priority__gt=current_priority)
with transaction.atomic():
# Update priorities
for priority in priorities:
priority.current_priority = current_priority
current_priority += 1
priority.save()
# Function to generate pdf
def generate_pdf():
faculties = PositionsModel.objects.values_list('faculty',flat=True).distinct()
mappings = {}
guide_info = {}
# Extract data needed for latex file
for faculty_id in faculties:
faculty = User.objects.get(id=faculty_id)
requirement_count = 0
projects = PositionsModel.objects.filter(faculty=faculty).values_list('id',flat=True)
faculty_allocation = {}
# project associated with particular faculty
for project_id in projects:
project = PositionsModel.objects.get(id=project_id)
requirement_count += project.initial_total_positions
alloted_students = project.student_mappings.all()
project_allocation = {}
# student allocated to each project
for student in alloted_students:
project_allocation[student.student.id] = student.student.student.username
faculty_allocation[project.id] = project_allocation
mappings[faculty.username] = faculty_allocation
guide_info[faculty.username] = {"name":faculty.get_full_name(),"requirement":requirement_count}
print(mappings)
print(guide_info)
# Storage location for the file
filelocation = "guideAllocationPortal/static/guideAllocationPortal/allocationResults"
mappedResult(mappings,guide_info,StudentDetailModel.objects.all().count(),filelocation)
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