From c49cec7dd1fee89030f14b6c9e32f76118bdacc0 Mon Sep 17 00:00:00 2001
From: kushbatla <kushbatla123@gmail.com>
Date: Fri, 2 Aug 2024 01:03:42 +0530
Subject: [PATCH] final

---
 .../applications/placement_cell/models.py     |    2 +-
 .../applications/placement_cell/urls.py       |    1 +
 .../applications/placement_cell/views.py      | 3469 +++++++++--------
 .../placementModule/add_placement_record.html |    2 +-
 .../placementModule/placementstatistics.html  |   10 +-
 .../placementModule/studentrecords.html       |   28 +-
 6 files changed, 1778 insertions(+), 1734 deletions(-)

diff --git a/FusionIIIT/applications/placement_cell/models.py b/FusionIIIT/applications/placement_cell/models.py
index 552c4655d..f808a947d 100644
--- a/FusionIIIT/applications/placement_cell/models.py
+++ b/FusionIIIT/applications/placement_cell/models.py
@@ -37,7 +37,7 @@ class Constants:
         ('PLACEMENT', 'Placement'),
         ('PBI', 'PBI'),
         ('HIGHER STUDIES', 'Higher Studies'),
-        ('OTHER', 'Other'),
+        
     )
 
     PLACED_TYPE = (
diff --git a/FusionIIIT/applications/placement_cell/urls.py b/FusionIIIT/applications/placement_cell/urls.py
index 190638861..ad59f6d44 100644
--- a/FusionIIIT/applications/placement_cell/urls.py
+++ b/FusionIIIT/applications/placement_cell/urls.py
@@ -26,4 +26,5 @@
     url(r'^placement_record_save/$', views.placement_record_save, name='placement_record_save'),
     url(r'^add_placement_visit/$', views.add_placement_visit, name='add_placement_visit'),
     url(r'^placement_visit_save/$', views.placement_visit_save, name='placement_visit_save'),
+     url(r'^generate_excel/$', views.generate_excel, name='generate_excel'),
 ]
diff --git a/FusionIIIT/applications/placement_cell/views.py b/FusionIIIT/applications/placement_cell/views.py
index 283e34076..b9673c960 100644
--- a/FusionIIIT/applications/placement_cell/views.py
+++ b/FusionIIIT/applications/placement_cell/views.py
@@ -5,7 +5,7 @@
 import zipfile
 import xlwt
 import logging
-
+from openpyxl import Workbook
 from html import escape
 from datetime import date
 from io import BytesIO
@@ -291,7 +291,7 @@ def placement__Statistics(request):
                     Q(user__in=User.objects.filter(
                         first_name__icontains=first_name,
                         last_name__icontains=last_name),
-                       id__icontains=rollno))
+                       id__startswith=rollno))
                     )))
 
                 p = PlacementRecord.objects.filter(Q(placement_type="PLACEMENT", name__icontains=stuname, ctc__icontains=ctc, year__icontains=year))
@@ -375,7 +375,7 @@ def placement__Statistics(request):
                         Q(user__in=User.objects.filter(
                         Q(first_name__icontains=request.session['first_name'],
                         last_name__icontains=request.session['last_name'])),
-                       id__icontains=request.session['rollno']))
+                       id__startswith=request.session['rollno']))
                     )))
 
                     p = PlacementRecord.objects.filter(
@@ -825,7 +825,36 @@ def placement__Statistics(request):
 
     return render(request, 'placementModule/placementstatistics.html', context)
 
+def generate_excel(request):
+    # Assuming placementstatus_placement contains the data you want to display
+    students = placementstatus_placement.filter(notify_id__placement_type='PLACEMENT')
+
+    # Create a new Excel workbook
+    wb = Workbook()
+    ws = wb.active
+
+    # Define headers
+    headers = ['Student Name', 'Company Name', 'CTC', 'Invitation']
+
+    # Write headers to the first row of the worksheet
+    for col, header in enumerate(headers, start=1):
+        ws.cell(row=1, column=col, value=header)
+
+    # Write data to subsequent rows
+    for row, student in enumerate(students, start=2):
+        ws.cell(row=row, column=1, value=f"{student.unique_id.id.user.first_name} {student.unique_id.id.user.last_name}")
+        ws.cell(row=row, column=2, value=student.notify_id.company_name)
+        ws.cell(row=row, column=3, value=student.notify_id.ctc)
+        ws.cell(row=row, column=4, value=student.invitation)
+
+    # Create a response object
+    response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
+    response['Content-Disposition'] = 'attachment; filename=placement_data.xlsx'
 
+    # Save the workbook to the response object
+    wb.save(response)
+
+    return response
 
 def get_reference_list(request):
     if request.method == 'POST':
@@ -1166,1738 +1195,1738 @@ def Placement__Schedule(request):
 
 
 
-def invite_status(request):
-    '''
-    function to check the invitation status
-    '''
-    user = request.user
-    strecord_tab = 1
-    mnpbi_tab = 0
-    mnplacement_post = 0
-    mnpbi_post = 0
-    invitation_status_tab = 1
-    placementstatus_placement = []
-    placementstatus_pbi = []
-    mnplacement_tab = 1
+# def invite_status(request):
+#     '''
+#     function to check the invitation status
+#     '''
+#     user = request.user
+#     strecord_tab = 1
+#     mnpbi_tab = 0
+#     mnplacement_post = 0
+#     mnpbi_post = 0
+#     invitation_status_tab = 1
+#     placementstatus_placement = []
+#     placementstatus_pbi = []
+#     mnplacement_tab = 1
+
+#     no_pagination = 1
+#     is_disabled = 0
+#     paginator = ''
+#     page_range = ''
+#     placement_get_request = False
+#     pbi_get_request = False
+
+#     # invitation status for placement
+#     if 'studentplacementsearchsubmit' in request.POST:
+#         mnplacement_post = 1
+#         mnpbi_post = 0
+#         form = ManagePlacementRecord(request.POST)
+
+#         if form.is_valid():
+#             if form.cleaned_data['stuname']:
+#                 stuname = form.cleaned_data['stuname']
+#             else:
+#                 stuname = ''
+#             if form.cleaned_data['ctc']:
+#                 ctc = form.cleaned_data['ctc']
+#             else:
+#                 ctc = 0
+#             if form.cleaned_data['company']:
+#                 cname = form.cleaned_data['company']
+#             else:
+#                 cname = ''
+#             if form.cleaned_data['roll']:
+#                 rollno = form.cleaned_data['roll']
+#             else:
+#                 rollno = ''
+
+#             request.session['mn_stuname'] = stuname
+#             request.session['mn_ctc'] = ctc
+#             request.session['mn_cname'] = cname
+#             request.session['mn_rollno'] = rollno
+
+#             placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                        (Q(placement_type="PLACEMENT",
+#                                                           company_name__icontains=cname,
+#                                                           ctc__gte=ctc)),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=stuname)),
+#                                                               id__icontains=rollno))
+#                                                            )))))
+#             # pagination stuff starts from here
+#             total_query = placementstatus_placement.count()
+
+#             if total_query > 30:
+#                 no_pagination = 1
+#                 paginator = Paginator(placementstatus_placement, 30)
+#                 page = request.GET.get('page', 1)
+#                 placementstatus_placement = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+#     else:
+#         # when the request from pagination with some page number
+#         if request.GET.get('placement_page') != None:
+#             mnplacement_post = 1
+#             mnpbi_post = 0
+#             no_pagination = 1
+#             try:
+#                 placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                        (Q(placement_type="PLACEMENT",
+#                                                           company_name__icontains=request.session['mn_cname'],
+#                                                           ctc__gte=request.session['mn_ctc'])),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=request.session['mn_stuname'])),
+#                                                               id__icontains=request.session['mn_rollno']))
+#                                                            )))))
+#             except:
+#                 placementstatus_placement = []
+
+#             if placementstatus_placement != '':
+#                 total_query = placementstatus_placement.count()
+#             else:
+#                 total_query = 0
+
+#             if total_query > 30:
+#                 paginator = Paginator(placementstatus_placement, 30)
+#                 page = request.GET.get('placement_page', 1)
+#                 placementstatus_placement = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+
+#     # invitation status for pbi
+#     if 'studentpbisearchsubmit' in request.POST:
+#         mnpbi_tab = 1
+#         mnpbi_post = 1
+#         mnplacement_post = 0
+#         form = ManagePbiRecord(request.POST)
+#         if form.is_valid():
+#             if form.cleaned_data['stuname']:
+#                 stuname = form.cleaned_data['stuname']
+#             else:
+#                 stuname = ''
+#             if form.cleaned_data['ctc']:
+#                 ctc = form.cleaned_data['ctc']
+#             else:
+#                 ctc = 0
+#             if form.cleaned_data['company']:
+#                 cname = form.cleaned_data['company']
+#             else:
+#                 cname = ''
+#             if form.cleaned_data['roll']:
+#                 rollno = form.cleaned_data['roll']
+#             else:
+#                 rollno = ''
+#             request.session['mn_pbi_stuname'] = stuname
+#             request.session['mn_pbi_ctc'] = ctc
+#             request.session['mn_pbi_cname'] = cname
+#             request.session['mn_pbi_rollno'] = rollno
+#             placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                 Q(notify_id__in=NotifyStudent.objects.filter(
+#                 Q(placement_type="PBI",
+#                 company_name__icontains=cname,
+#                 ctc__gte=ctc)),
+#                 unique_id__in=Student.objects.filter(
+#                 (Q(id__in=ExtraInfo.objects.filter(
+#                 Q(user__in=User.objects.filter(
+#                 Q(first_name__icontains=stuname)),
+#                 id__icontains=rollno))))))).order_by('id')
+
+#             total_query = placementstatus_pbi.count()
+
+#             if total_query > 30:
+#                 no_pagination = 1
+#                 paginator = Paginator(placementstatus_pbi, 30)
+#                 page = request.GET.get('pbi_page', 1)
+#                 placementstatus_pbi = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+#     else:
+#         if request.GET.get('pbi_page') != None:
+#             mnpbi_tab = 1
+#             mnpbi_post = 1
+#             no_pagination = 1
+#             try:
+#                 placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                     Q(notify_id__in=NotifyStudent.objects.filter(
+#                     Q(placement_type="PBI",
+#                     company_name__icontains=request.session['mn_pbi_cname'],
+#                                               ctc__gte=request.session['mn_pbi_ctc'])),
+#                                            unique_id__in=Student.objects.filter(
+#                                             (Q(id__in=ExtraInfo.objects.filter(
+#                                                 Q(user__in=User.objects.filter(
+#                     Q(first_name__icontains=request.session['mn_pbi_stuname'])),
+#                                                   id__icontains=request.session['mn_pbi_rollno']))
+#                                                )))))
+#             except:
+#                 placementstatus_pbi = ''
+
+#             if placementstatus_pbi != '':
+#                 total_query = placementstatus_pbi.count()
+#             else:
+#                 total_query = 0
+#             if total_query > 30:
+#                 paginator = Paginator(placementstatus_pbi, 30)
+#                 page = request.GET.get('pbi_page', 1)
+#                 placementstatus_pbi = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+
+
+#     if 'pdf_gen_invitation_status' in request.POST:
+
+#         placementstatus = None
+#         if 'pdf_gen_invitation_status_placement' in request.POST:
+#             stuname = request.session['mn_stuname']
+#             ctc = request.session['mn_ctc']
+#             cname = request.session['mn_cname']
+#             rollno = request.session['mn_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                            (Q(placement_type="PLACEMENT",
+#                                                               company_name__icontains=cname,
+#                                                               ctc__gte=ctc)),
+#                                                            unique_id__in=Student.objects.filter
+#                                                            ((Q(id__in=ExtraInfo.objects.filter
+#                                                                (Q(user__in=User.objects.filter
+#                                                                   (Q(first_name__icontains=stuname)),
+#                                                                   id__icontains=rollno))
+#                                                                )))))
+
+#         if 'pdf_gen_invitation_status_pbi' in request.POST:
+#             stuname = request.session['mn_pbi_stuname']
+#             ctc = request.session['mn_pbi_ctc']
+#             cname = request.session['mn_pbi_cname']
+#             rollno = request.session['mn_pbi_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                 Q(notify_id__in=NotifyStudent.objects.filter(
+#                 Q(placement_type="PBI",
+#                 company_name__icontains=cname,
+#                 ctc__gte=ctc)),
+#                 unique_id__in=Student.objects.filter(
+#                 (Q(id__in=ExtraInfo.objects.filter(
+#                 Q(user__in=User.objects.filter(
+#                 Q(first_name__icontains=stuname)),
+#                 id__icontains=rollno))))))).order_by('id')
+
+#         context = {
+#             'placementstatus' : placementstatus
+#         }
+
+#         return render_to_pdf('placementModule/pdf_invitation_status.html', context)
+
+#     if 'excel_gen_invitation_status' in request.POST:
+
+#         placementstatus = None
+#         if 'excel_gen_invitation_status_placement' in request.POST:
+#             stuname = request.session['mn_stuname']
+#             ctc = request.session['mn_ctc']
+#             cname = request.session['mn_cname']
+#             rollno = request.session['mn_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                            (Q(placement_type="PLACEMENT",
+#                                                               company_name__icontains=cname,
+#                                                               ctc__gte=ctc)),
+#                                                            unique_id__in=Student.objects.filter
+#                                                            ((Q(id__in=ExtraInfo.objects.filter
+#                                                                (Q(user__in=User.objects.filter
+#                                                                   (Q(first_name__icontains=stuname)),
+#                                                                   id__icontains=rollno))
+#                                                                )))))
+
+#         if 'excel_gen_invitation_status_pbi' in request.POST:
+#             stuname = request.session['mn_pbi_stuname']
+#             ctc = request.session['mn_pbi_ctc']
+#             cname = request.session['mn_pbi_cname']
+#             rollno = request.session['mn_pbi_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                 Q(notify_id__in=NotifyStudent.objects.filter(
+#                 Q(placement_type="PBI",
+#                 company_name__icontains=cname,
+#                 ctc__gte=ctc)),
+#                 unique_id__in=Student.objects.filter(
+#                 (Q(id__in=ExtraInfo.objects.filter(
+#                 Q(user__in=User.objects.filter(
+#                 Q(first_name__icontains=stuname)),
+#                 id__icontains=rollno))))))).order_by('id')
+
+#         context = {
+#             'placementstatus' : placementstatus
+#         }
+
+
+#         years = PlacementRecord.objects.filter(~Q(placement_type="HIGHER STUDIES")).values('year').annotate(Count('year'))
+#         records = PlacementRecord.objects.values('name', 'year', 'ctc', 'placement_type').annotate(Count('name'), Count('year'), Count('placement_type'), Count('ctc'))
+
+
+#         return export_to_xls_invitation_status(placementstatus)
+
+#     form1 = SearchStudentRecord(initial={})
+#     form9 = ManagePbiRecord(initial={})
+#     form11 = ManagePlacementRecord(initial={})
+#     form13 = SendInvite(initial={})
+#     current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
+#     current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
+
+#     context = {
+#         'form1': form1,
+#         'form9': form9,
+#         'form11': form11,
+#         'form13': form13,
+#         'invitation_status_tab': invitation_status_tab,
+#         'mnplacement_post': mnplacement_post,
+#         'mnpbi_tab': mnpbi_tab,
+#         'mnplacement_tab': mnplacement_tab,
+#         'placementstatus_placement': placementstatus_placement,
+#         'placementstatus_pbi': placementstatus_pbi,
+#         'current1': current1,
+#         'current2': current2,
+#         'strecord_tab': strecord_tab,
+#         'mnpbi_post': mnpbi_post,
+#         'page_range': page_range,
+#         'paginator': paginator,
+#         'no_pagination': no_pagination,
+#         'is_disabled': is_disabled,
+#     }
+
+#     return render(request, 'placementModule/studentrecords.html', context)
+
+
+
+
+
+
+
+#     invitecheck=0
+#     for r in records:
+#         r['name__count'] = 0
+#         r['year__count'] = 0
+#         r['placement_type__count'] = 0
+#     tcse = dict()
+#     tece = dict()
+#     tme = dict()
+#     tadd = dict()
+#     for y in years:
+#         tcse[y['year']] = 0
+#         tece[y['year']] = 0
+#         tme[y['year']] = 0
+#         for r in records:
+#             if r['year'] == y['year']:
+#                 if r['placement_type'] != "HIGHER STUDIES":
+#                     for z in studentrecord:
+#                         if z.record_id.name == r['name'] and z.record_id.year == r['year'] and z.unique_id.id.department.name == "CSE":
+#                             tcse[y['year']] = tcse[y['year']]+1
+#                             r['name__count'] = r['name__count']+1
+#                         if z.record_id.name == r['name'] and z.record_id.year == r['year'] and z.unique_id.id.department.name == "ECE":
+#                             tece[y['year']] = tece[y['year']]+1
+#                             r['year__count'] = r['year__count']+1
+#                         if z.record_id.name == r['name'] and z.record_id.year == r['year'] and z.unique_id.id.department.name == "ME":
+#                             tme[y['year']] = tme[y['year']]+1
+#                             r['placement_type__count'] = r['placement_type__count']+1
+#         tadd[y['year']] = tcse[y['year']]+tece[y['year']]+tme[y['year']]
+#         y['year__count'] = [tadd[y['year']], tcse[y['year']], tece[y['year']], tme[y['year']]]
+
+#     form2 = SearchPlacementRecord(initial={})
+#     form3 = SearchPbiRecord(initial={})
+#     form4 = SearchHigherRecord(initial={})
+
+
+#     current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
+#     current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
+#     current = HoldsDesignation.objects.filter(Q(working=user, designation__name="student"))
+#     print(current)
+
+#     if len(current1)!=0 or len(current2)!=0:
+#         delete_operation = 1
+#     if len(current) == 0:
+#         current = None
+#     pbirecord= ''
+#     placementrecord= ''
+#     higherrecord= ''
+#     total_query=0
+#     total_query1 = 0
+#     total_query2= 0
+#     p=""
+#     p1=""
+#     p2=""
+#     placement_search_record=" "
+#     pbi_search_record=" "
+#     higher_search_record=" "
+#     # results of the searched query under placement tab
+#     if 'studentplacementrecordsubmit' in request.POST:
+#         officer_statistics_past = 1
+#         form = SearchPlacementRecord(request.POST)
+#         if form.is_valid():
+
+
+
+
+#             print("IS VALID")
+
+
+
+#             #for student name
+#             if form.cleaned_data['stuname']:
+#                 stuname = form.cleaned_data['stuname']
+#                 try:
+#                     first_name = stuname.split(" ")[0]
+#                     last_name = stuname.split(" ")[1]
+#                 except Exception as e:
+#                     print("Error")
+#                     print(e)
+#                     first_name = stuname
+#                     last_name = ''
+#             else:
+#                 stuname = ''
+#                 first_name = ''
+#                 last_name = ''
+
+
+#             # for student CTC
+#             if form.cleaned_data['ctc']:
+#                 ctc = form.cleaned_data['ctc']
+#             else:
+#                 ctc = 0
+
+#             #for company name
+#             if form.cleaned_data['cname']:
+#                 cname = form.cleaned_data['cname']
+#             else:
+#                 cname = ''
+
+#             #for student roll
+#             if form.cleaned_data['roll']:
+#                 rollno = form.cleaned_data['roll']
+#             else:
+#                 rollno = ''
+
+#             #for admission year
+#             if form.cleaned_data['year']:
+#                 year = form.cleaned_data['year']
+#                 s = Student.objects.filter((Q(id__in=ExtraInfo.objects.filter(
+#                     Q(user__in=User.objects.filter(
+#                         first_name__icontains=first_name,
+#                         last_name__icontains=last_name),
+#                        id__icontains=rollno))
+#                     )))
+
+#                 p = PlacementRecord.objects.filter(Q(placement_type="PLACEMENT", name__icontains=stuname, ctc__icontains=ctc, year__icontains=year))
+
+
+
+
+#             """placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                     Q(record_id__in=PlacementRecord.objects.filter(
+#                         Q(placement_type="PLACEMENT", name__icontains=cname, ctc__gte=ctc, year=year)),
+#                     unique_id__in=Student.objects.filter(
+#                         (Q(id__in=ExtraInfo.objects.filter(
+#                             Q(user__in=User.objects.filter(
+#                                 first_name__icontains=first_name,
+#                                 last_name__icontains=last_name,
+#                             id__icontains=rollno))))))))
+#                 #print("In if:", placementrecord)
+#             else:
+#                 s = Student.objects.filter((Q(id__in=ExtraInfo.objects.filter(
+#                     Q(user__in=User.objects.filter(
+#                         first_name__icontains=first_name,
+#                         last_name__icontains=last_name),
+#                         id__icontains=rollno))
+#                     )))
+
+#                 p = PlacementRecord.objects.filter(Q(placement_type="PLACEMENT", name__icontains=cname, ctc__gte=ctc))
+#                 print("Agein p:",p)
+#                 placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                     Q(record_id__in=PlacementRecord.objects.filter(
+#                     Q(placement_type="PLACEMENT", name__icontains=cname, ctc__gte=ctc)),
+#                     unique_id__in=Student.objects.filter(
+#                     (Q(id__in=ExtraInfo.objects.filter(
+#                     Q(user__in=User.objects.filter(
+#                         first_name__icontains=first_name,
+#                         last_name__icontains=last_name),
+#                     id__icontains=rollno)))))))
+
+#             request.session['first_name'] = first_name
+#             request.session['last_name'] = last_name
+#             request.session['ctc'] = ctc
+#             request.session['cname'] = cname
+#             request.session['rollno'] = rollno
+#             request.session['year'] = form.cleaned_data['year']"""
+
+#             print(p)
+
+
+#             total_query = p.count()
+
+#             if total_query > 30:
+#                 pagination_placement = 1
+#                 paginator = Paginator(placementrecord, 30)
+#                 page = request.GET.get('page', 1)
+#                 placementrecord = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 pagination_placement = 0
+#     else:
+#         if request.GET.get('page') != None:
+#             try:
+#                 if request.session['year']:
+#                     s = Student.objects.filter(
+#                         (Q(id__in=ExtraInfo.objects.filter(
+#                         Q(user__in=User.objects.filter(
+#                         Q(first_name__icontains=request.session['first_name'],
+#                         last_name__icontains=request.session['last_name'])),
+#                        id__icontains=request.session['rollno']))
+#                     )))
+
+#                     p = PlacementRecord.objects.filter(
+#                         Q(placement_type="PLACEMENT",
+#                         name__icontains=request.session['cname'],
+#                         ctc__gte=request.session['ctc'],
+#                         year=request.session['year']))
+
+
+#                     placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                         Q(record_id__in=PlacementRecord.objects.filter(
+#                             Q(placement_type="PLACEMENT",
+#                             name__icontains=request.session['cname'],
+#                             ctc__gte=request.session['ctc'],
+#                             year=request.session['year'])),
+#                             unique_id__in=Student.objects.filter(
+#                             (Q(id__in=ExtraInfo.objects.filter(
+#                             Q(user__in=User.objects.filter(
+#                             Q(first_name__icontains=request.session['first_name'],
+#                             last_name__icontains=request.session['last_name'])),
+#                             id__icontains=request.session['rollno'])))))))
+#                 else:
+#                     s = Student.objects.filter((Q(id__in=ExtraInfo.objects.filter
+#                     (Q(user__in=User.objects.filter
+#                        (Q(first_name__icontains=request.session['first_name'],
+#                         last_name__icontains=request.session['last_name'])),
+#                        id__icontains=request.session['rollno']))
+#                     )))
+
+#                     p = PlacementRecord.objects.filter(
+#                         Q(placement_type="PLACEMENT",
+#                             name__icontains=request.session['cname'],
+#                             ctc__gte=request.session['ctc']))
+
+#                     placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                         Q(record_id__in=PlacementRecord.objects.filter(
+#                         Q(placement_type="PLACEMENT",
+#                             name__icontains=request.session['cname'],
+#                             ctc__gte=request.session['ctc'])),
+#                         unique_id__in=Student.objects.filter(
+#                         (Q(id__in=ExtraInfo.objects.filter(
+#                         Q(user__in=User.objects.filter(
+#                         Q(first_name__icontains=request.session['first_name'],
+#                         last_name__icontains=request.session['last_name'])),
+#                         id__icontains=request.session['rollno'])))))))
+#             except Exception as e:
+#                 print(e)
+#                 placementrecord = ''
+
+#             if placementrecord != '':
+#                 total_query = placementrecord.count()
+#             else:
+#                 total_query = 0
+#                 no_records=1
+#             print(placementrecord)
+#             if total_query > 30:
+#                 pagination_placement = 1
+#                 paginator = Paginator(placementrecord, 30)
+#                 page = request.GET.get('page', 1)
+#                 placementrecord = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 pagination_placement = 0
+#         else:
+#             placementrecord = ''
+
+#     if total_query!=0:
+#         placement_search_record=p
+#     # results of the searched query under pbi tab
+#     if 'studentpbirecordsubmit' in request.POST:
+#         officer_statistics_past_pbi_search = 1
+#         form = SearchPbiRecord(request.POST)
+#         if form.is_valid():
+#             if form.cleaned_data['stuname']:
+#                 stuname = form.cleaned_data['stuname']
+#                 try:
+#                     first_name = stuname.split(" ")[0]
+#                     last_name = stuname.split(" ")[1]
+#                 except:
+#                     first_name = stuname
+#                     last_name = ''
+#             else:
+#                 stuname = ''
+#                 first_name = ''
+#                 last_name = ''
+#             if form.cleaned_data['ctc']:
+#                 ctc = form.cleaned_data['ctc']
+#             else:
+#                 ctc = 0
+#             if form.cleaned_data['cname']:
+#                 cname = form.cleaned_data['cname']
+#             else:
+#                 cname = ''
+#             if form.cleaned_data['roll']:
+#                 rollno = form.cleaned_data['roll']
+#             else:
+#                 rollno = ''
+#             if form.cleaned_data['year']:
+#                 year = form.cleaned_data['year']
+#                 pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(Q(record_id__in=PlacementRecord.objects.filter
+#                                                        (Q(placement_type="PBI",
+#                                                           name__icontains=cname,
+#                                                           ctc__gte=ctc, year=year)),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=first_name,
+#                                                             last_name__icontains=last_name)),
+#                                                               id__icontains=rollno))
+#                                                            )))))
+#                 p1 = PlacementRecord.objects.filter(
+#                     Q(placement_type="PBI", name__icontains=stuname, ctc__icontains=ctc, year__icontains=year))
+#             """else:
+#                 pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(Q(record_id__in=PlacementRecord.objects.filter
+#                                                        (Q(placement_type="PBI",
+#                                                           name__icontains=cname,
+#                                                           ctc__gte=ctc)),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=first_name,
+#                                                             last_name__icontains=last_name)),
+#                                                               id__icontains=rollno))
+#                                                            )))))
+#             request.session['first_name'] = first_name
+#             request.session['last_name'] = last_name
+#             request.session['ctc'] = ctc
+#             request.session['cname'] = cname
+#             request.session['rollno'] = rollno
+#             request.session['year'] = form.cleaned_data['year']
+# """
+#             total_query1 = p1.count()
+
+#             if total_query1 > 30:
+#                 pagination_pbi = 1
+#                 paginator = Paginator(pbirecord, 30)
+#                 page = request.GET.get('page', 1)
+#                 pbirecord = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query1 > 30 and total_query1 <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 pagination_pbi = 0
+#     else:
+#         if request.GET.get('page') != None:
+#             try:
+#                 if request.session['year']:
+#                     pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                         Q(record_id__in=PlacementRecord.objects.filter(
+#                         Q(placement_type="PBI",
+#                         name__icontains=request.session['cname'],
+#                         ctc__gte=ctc, year=request.session['year'])),
+#                         unique_id__in=Student.objects.filter((
+#                         Q(id__in=ExtraInfo.objects.filter(
+#                         Q(user__in=User.objects.filter(
+#                         Q(first_name__icontains=request.session['first_name'],
+#                         last_name__icontains=request.session['last_name'])),
+#                         id__icontains=request.session['rollno'])))))))
+#                 else:
+#                     pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                         Q(record_id__in=PlacementRecord.objects.filter(Q(placement_type="PBI",
+#                                                               name__icontains=request.session['cname'],
+#                                                               ctc__gte=request.session['ctc'])),
+#                                                            unique_id__in=Student.objects.filter(
+#                                                             (Q(id__in=ExtraInfo.objects.filter(
+#                                                             Q(user__in=User.objects.filter(
+#                         Q(first_name__icontains=request.session['first_name'],
+#                         last_name__icontains=request.session['last_name'])),
+#                         id__icontains=request.session['rollno'])))))))
+#             except:
+#                 print('except')
+#                 pbirecord = ''
+
+#             if pbirecord != '':
+#                 total_query = pbirecord.count()
+#             else:
+#                 total_query = 0
+
+#             if total_query > 30:
+#                 pagination_pbi = 1
+#                 paginator = Paginator(pbirecord, 30)
+#                 page = request.GET.get('page', 1)
+#                 pbirecord = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 pagination_pbi = 0
+#         else:
+#             pbirecord = ''
+#     if total_query1!=0:
+#         pbi_search_record=p1
+
+#     # results of the searched query under higher studies tab
+#     if 'studenthigherrecordsubmit' in request.POST:
+#         officer_statistics_past_higher_search = 1
+#         form = SearchHigherRecord(request.POST)
+#         if form.is_valid():
+#             # getting all the variables send through form
+#             if form.cleaned_data['stuname']:
+#                 stuname = form.cleaned_data['stuname']
+#                 try:
+#                     first_name = stuname.split(" ")[0]
+#                     last_name = stuname.split(" ")[1]
+#                 except:
+#                     first_name = stuname
+#                     last_name = ''
+#             else:
+#                 stuname = ''
+#                 first_name = ''
+#                 last_name = ''
+#             if form.cleaned_data['test_type']:
+#                 test_type = form.cleaned_data['test_type']
+#             else:
+#                 test_type = ''
+#             if form.cleaned_data['uname']:
+#                 uname = form.cleaned_data['uname']
+#             else:
+#                 uname = ''
+#             if form.cleaned_data['test_score']:
+#                 test_score = form.cleaned_data['test_score']
+#             else:
+#                 test_score = 0
+#             if form.cleaned_data['roll']:
+#                 rollno = form.cleaned_data['roll']
+#             else:
+#                 rollno = ''
+#             if form.cleaned_data['year']:
+#                 year = form.cleaned_data['year']
+#                 # result of the query when year is given
+#                 higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(Q(record_id__in=PlacementRecord.objects.filter
+#                                                        (Q(placement_type="HIGHER STUDIES",
+#                                                           test_type__icontains=test_type,
+#                                                           name__icontains=uname, year=year,
+#                                                           test_score__gte=test_score)),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=first_name,
+#                                                             last_name__icontains=last_name)),
+#                                                               id__icontains=rollno))
+#                                                            )))))
+
+#                 p2 = PlacementRecord.objects.filter(
+#                     Q(placement_type="HIGHER STUDIES", name__icontains=stuname, year__icontains=year))
+
+#             """else:
+#                 # result of the query when year is not given
+#                 higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                     Q(record_id__in=PlacementRecord.objects.filter
+#                                                        (Q(placement_type="HIGHER STUDIES",
+#                                                           test_type__icontains=test_type,
+#                                                           name__icontains=uname,
+#                                                           test_score__gte=test_score)),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=first_name,
+#                                                                 last_name__icontains=last_name)),
+#                                                               id__icontains=rollno))
+#                                                            )))))
+#             request.session['first_name'] = first_name
+#             request.session['last_name'] = last_name
+#             request.session['test_score'] = test_score
+#             request.session['uname'] = uname
+#             request.session['test_type'] = test_type
+#             request.session['rollno'] = rollno
+#             request.session['year'] = form.cleaned_data['year']"""
+
+#             total_query2 = p2.count()
+
+#             if total_query2 > 30:
+#                 pagination_higher = 1
+#                 paginator = Paginator(p2, 30)
+#                 page = request.GET.get('page', 1)
+#                 p2 = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page+3)
+
+#                 if page < (paginator.num_pages-3):
+#                     if total_query2 > 30 and total_query2 <= 60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(page-2, paginator.num_pages+1)
+#             else:
+#                 pagination_higher = 0
+#     else:
+#         if request.GET.get('page') != None:
+#             try:
+#                 if request.session['year']:
+#                     higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                         Q(record_id__in=PlacementRecord.objects.filter(
+#                             Q(placement_type="HIGHER STUDIES",
+#                               test_type__icontains=request.session['test_type'],
+#                               name__icontains=request.session['uname'],
+#                               year=request.session['year'],
+#                               test_score__gte=request.session['test_score'])),
+#                            unique_id__in=Student.objects.filter(
+#                             (Q(id__in=ExtraInfo.objects.filter(
+#                                 Q(user__in=User.objects.filter(
+#                                 Q(first_name__icontains=request.session['first_name'],
+#                                 last_name__icontains=request.session['last_name'])),
+#                                 id__icontains=request.session['rollno']))
+#                                )))))
+#                 else:
+#                     higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
+#                         Q(record_id__in=PlacementRecord.objects.filter(
+#                             Q(placement_type="HIGHER STUDIES",
+#                           test_type__icontains=request.session['test_type'],
+#                           name__icontains=request.session['uname'],
+#                           test_score__gte=request.session['test_score'])),
+#                        unique_id__in=Student.objects.filter
+#                        ((Q(id__in=ExtraInfo.objects.filter(
+#                         Q(user__in=User.objects.filter(
+#                             Q(first_name__icontains=request.session['first_name'],
+#                         last_name__icontains=request.session['last_name'])),
+#                               id__icontains=request.session['rollno']))
+#                            )))))
+#             except:
+#                 higherrecord = ''
+
+#             if higherrecord != '':
+#                 total_query = higherrecord.count()
+#             else:
+#                 total_query = 0
+
+#             if total_query > 30:
+#                 no_pagination = 1
+#                 paginator = Paginator(higherrecord, 30)
+#                 page = request.GET.get('page', 1)
+#                 higherrecord = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+#         else:
+#             higherrecord = ''
+#     if total_query2!=0:
+#         higher_search_record=p2
+
+#     context = {
+#         'form2'             :            form2,
+#         'form3'             :            form3,
+#         'form4'             :            form4,
+#         'current'           :          current,
+#         'current1'          :         current1,
+#         'current2'          :         current2,
+
+
+#         'all_records':          all_records,   #for flashing all placement Schedule
+
+#         'placement_search_record': placement_search_record,
+#         'pbi_search_record': pbi_search_record,
+#         'higher_search_record': higher_search_record,
+
+
+
+#         'statistics_tab'    :   statistics_tab,
+#         'pbirecord'         :        pbirecord,
+#         'placementrecord'   :  placementrecord,
+#         'higherrecord'      :     higherrecord,
+#         'years'             :            years,
+#         'records'           :          records,
+#         'delete_operation'  :       delete_operation,
+#         'page_range': page_range,
+#         'paginator': paginator,
+#         'pagination_placement': pagination_placement,
+#         'pagination_pbi': pagination_pbi,
+#         'pagination_higher': pagination_higher,
+#         'is_disabled': is_disabled,
+#         'officer_statistics_past_pbi_search': officer_statistics_past_pbi_search,
+#         'officer_statistics_past_higher_search': officer_statistics_past_higher_search
+#     }
+
+#     return render(request, 'placementModule/placementstatistics.html', context)
 
-    no_pagination = 1
-    is_disabled = 0
-    paginator = ''
-    page_range = ''
-    placement_get_request = False
-    pbi_get_request = False
 
-    # invitation status for placement
-    if 'studentplacementsearchsubmit' in request.POST:
-        mnplacement_post = 1
-        mnpbi_post = 0
-        form = ManagePlacementRecord(request.POST)
 
-        if form.is_valid():
-            if form.cleaned_data['stuname']:
-                stuname = form.cleaned_data['stuname']
-            else:
-                stuname = ''
-            if form.cleaned_data['ctc']:
-                ctc = form.cleaned_data['ctc']
-            else:
-                ctc = 0
-            if form.cleaned_data['company']:
-                cname = form.cleaned_data['company']
-            else:
-                cname = ''
-            if form.cleaned_data['roll']:
-                rollno = form.cleaned_data['roll']
-            else:
-                rollno = ''
+def get_reference_list(request):
+    if request.method == 'POST':
 
-            request.session['mn_stuname'] = stuname
-            request.session['mn_ctc'] = ctc
-            request.session['mn_cname'] = cname
-            request.session['mn_rollno'] = rollno
+        user = request.user
+        profile = get_object_or_404(ExtraInfo, Q(user=user))
+        student = get_object_or_404(Student, Q(id=profile.id))
+        print(student)
+        reference_objects = Reference.select_related('unique_id').objects.filter(unique_id=student)
+        reference_objects = serializers.serialize('json', list(reference_objects))
 
-            placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                       (Q(placement_type="PLACEMENT",
-                                                          company_name__icontains=cname,
-                                                          ctc__gte=ctc)),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=stuname)),
-                                                              id__icontains=rollno))
-                                                           )))))
-            # pagination stuff starts from here
-            total_query = placementstatus_placement.count()
+        context = {
+            'reference_objs': reference_objects
+        }
+        return JsonResponse(context)
 
-            if total_query > 30:
-                no_pagination = 1
-                paginator = Paginator(placementstatus_placement, 30)
-                page = request.GET.get('page', 1)
-                placementstatus_placement = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
 
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
+# Ajax for the company name dropdown for CompanyName when filling AddSchedule
+def company_name_dropdown(request):
+    if request.method == 'POST':
+        current_value = request.POST.get('current_value')
+        company_names = CompanyDetails.objects.filter(Q(company_name__startswith=current_value))
+        company_name = []
+        for name in company_names:
+            company_name.append(name.company_name)
 
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
-    else:
-        # when the request from pagination with some page number
-        if request.GET.get('placement_page') != None:
-            mnplacement_post = 1
-            mnpbi_post = 0
-            no_pagination = 1
-            try:
-                placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                       (Q(placement_type="PLACEMENT",
-                                                          company_name__icontains=request.session['mn_cname'],
-                                                          ctc__gte=request.session['mn_ctc'])),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=request.session['mn_stuname'])),
-                                                              id__icontains=request.session['mn_rollno']))
-                                                           )))))
-            except:
-                placementstatus_placement = []
+        context = {
+            'company_names': company_name
+        }
 
-            if placementstatus_placement != '':
-                total_query = placementstatus_placement.count()
-            else:
-                total_query = 0
+        return JsonResponse(context)
 
-            if total_query > 30:
-                paginator = Paginator(placementstatus_placement, 30)
-                page = request.GET.get('placement_page', 1)
-                placementstatus_placement = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
 
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
+# Ajax for all the roles in the dropdown
+def checking_roles(request):
+    if request.method == 'POST':
+        current_value = request.POST.get('current_value')
+        all_roles = Role.objects.filter(Q(role__startswith=current_value))
+        role_name = []
+        for role in all_roles:
+            role_name.append(role.role)
+        return JsonResponse({'all_roles': role_name})
 
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
+@login_required
+def Placement__Schedule(request):
+    '''
+    function include the functionality of first tab of UI
+    for student, placement officer & placement chairman
 
-    # invitation status for pbi
-    if 'studentpbisearchsubmit' in request.POST:
-        mnpbi_tab = 1
-        mnpbi_post = 1
-        mnplacement_post = 0
-        form = ManagePbiRecord(request.POST)
-        if form.is_valid():
-            if form.cleaned_data['stuname']:
-                stuname = form.cleaned_data['stuname']
-            else:
-                stuname = ''
-            if form.cleaned_data['ctc']:
-                ctc = form.cleaned_data['ctc']
-            else:
-                ctc = 0
-            if form.cleaned_data['company']:
-                cname = form.cleaned_data['company']
-            else:
-                cname = ''
-            if form.cleaned_data['roll']:
-                rollno = form.cleaned_data['roll']
-            else:
-                rollno = ''
-            request.session['mn_pbi_stuname'] = stuname
-            request.session['mn_pbi_ctc'] = ctc
-            request.session['mn_pbi_cname'] = cname
-            request.session['mn_pbi_rollno'] = rollno
-            placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                Q(notify_id__in=NotifyStudent.objects.filter(
-                Q(placement_type="PBI",
-                company_name__icontains=cname,
-                ctc__gte=ctc)),
-                unique_id__in=Student.objects.filter(
-                (Q(id__in=ExtraInfo.objects.filter(
-                Q(user__in=User.objects.filter(
-                Q(first_name__icontains=stuname)),
-                id__icontains=rollno))))))).order_by('id')
+    placement officer & placement chairman
+        - can add schedule
+        - can delete schedule
+    student
+        - accepted or declined schedule
 
-            total_query = placementstatus_pbi.count()
+    '''
+    user = request.user
+    profile = get_object_or_404(ExtraInfo, Q(user=user))
+    schedule_tab = 1
+    placementstatus = ''
 
-            if total_query > 30:
-                no_pagination = 1
-                paginator = Paginator(placementstatus_pbi, 30)
-                page = request.GET.get('pbi_page', 1)
-                placementstatus_pbi = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
 
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
+    form5 = AddSchedule(initial={})
+    current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
+    current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
+    current = HoldsDesignation.objects.filter(Q(working=user, designation__name="student"))
+    print(current)
 
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
-    else:
-        if request.GET.get('pbi_page') != None:
-            mnpbi_tab = 1
-            mnpbi_post = 1
-            no_pagination = 1
-            try:
-                placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                    Q(notify_id__in=NotifyStudent.objects.filter(
-                    Q(placement_type="PBI",
-                    company_name__icontains=request.session['mn_pbi_cname'],
-                                              ctc__gte=request.session['mn_pbi_ctc'])),
-                                           unique_id__in=Student.objects.filter(
-                                            (Q(id__in=ExtraInfo.objects.filter(
-                                                Q(user__in=User.objects.filter(
-                    Q(first_name__icontains=request.session['mn_pbi_stuname'])),
-                                                  id__icontains=request.session['mn_pbi_rollno']))
-                                               )))))
-            except:
-                placementstatus_pbi = ''
-
-            if placementstatus_pbi != '':
-                total_query = placementstatus_pbi.count()
-            else:
-                total_query = 0
-            if total_query > 30:
-                paginator = Paginator(placementstatus_pbi, 30)
-                page = request.GET.get('pbi_page', 1)
-                placementstatus_pbi = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
-
-
-    if 'pdf_gen_invitation_status' in request.POST:
-
-        placementstatus = None
-        if 'pdf_gen_invitation_status_placement' in request.POST:
-            stuname = request.session['mn_stuname']
-            ctc = request.session['mn_ctc']
-            cname = request.session['mn_cname']
-            rollno = request.session['mn_rollno']
-
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                           (Q(placement_type="PLACEMENT",
-                                                              company_name__icontains=cname,
-                                                              ctc__gte=ctc)),
-                                                           unique_id__in=Student.objects.filter
-                                                           ((Q(id__in=ExtraInfo.objects.filter
-                                                               (Q(user__in=User.objects.filter
-                                                                  (Q(first_name__icontains=stuname)),
-                                                                  id__icontains=rollno))
-                                                               )))))
-
-        if 'pdf_gen_invitation_status_pbi' in request.POST:
-            stuname = request.session['mn_pbi_stuname']
-            ctc = request.session['mn_pbi_ctc']
-            cname = request.session['mn_pbi_cname']
-            rollno = request.session['mn_pbi_rollno']
-
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                Q(notify_id__in=NotifyStudent.objects.filter(
-                Q(placement_type="PBI",
-                company_name__icontains=cname,
-                ctc__gte=ctc)),
-                unique_id__in=Student.objects.filter(
-                (Q(id__in=ExtraInfo.objects.filter(
-                Q(user__in=User.objects.filter(
-                Q(first_name__icontains=stuname)),
-                id__icontains=rollno))))))).order_by('id')
-
-        context = {
-            'placementstatus' : placementstatus
-        }
-
-        return render_to_pdf('placementModule/pdf_invitation_status.html', context)
-
-    if 'excel_gen_invitation_status' in request.POST:
-
-        placementstatus = None
-        if 'excel_gen_invitation_status_placement' in request.POST:
-            stuname = request.session['mn_stuname']
-            ctc = request.session['mn_ctc']
-            cname = request.session['mn_cname']
-            rollno = request.session['mn_rollno']
-
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                           (Q(placement_type="PLACEMENT",
-                                                              company_name__icontains=cname,
-                                                              ctc__gte=ctc)),
-                                                           unique_id__in=Student.objects.filter
-                                                           ((Q(id__in=ExtraInfo.objects.filter
-                                                               (Q(user__in=User.objects.filter
-                                                                  (Q(first_name__icontains=stuname)),
-                                                                  id__icontains=rollno))
-                                                               )))))
-
-        if 'excel_gen_invitation_status_pbi' in request.POST:
-            stuname = request.session['mn_pbi_stuname']
-            ctc = request.session['mn_pbi_ctc']
-            cname = request.session['mn_pbi_cname']
-            rollno = request.session['mn_pbi_rollno']
-
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                Q(notify_id__in=NotifyStudent.objects.filter(
-                Q(placement_type="PBI",
-                company_name__icontains=cname,
-                ctc__gte=ctc)),
-                unique_id__in=Student.objects.filter(
-                (Q(id__in=ExtraInfo.objects.filter(
-                Q(user__in=User.objects.filter(
-                Q(first_name__icontains=stuname)),
-                id__icontains=rollno))))))).order_by('id')
-
-        context = {
-            'placementstatus' : placementstatus
-        }
-
-
-        years = PlacementRecord.objects.filter(~Q(placement_type="HIGHER STUDIES")).values('year').annotate(Count('year'))
-        records = PlacementRecord.objects.values('name', 'year', 'ctc', 'placement_type').annotate(Count('name'), Count('year'), Count('placement_type'), Count('ctc'))
-
-
-        return export_to_xls_invitation_status(placementstatus)
-
-    form1 = SearchStudentRecord(initial={})
-    form9 = ManagePbiRecord(initial={})
-    form11 = ManagePlacementRecord(initial={})
-    form13 = SendInvite(initial={})
-    current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
-    current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
-
-    context = {
-        'form1': form1,
-        'form9': form9,
-        'form11': form11,
-        'form13': form13,
-        'invitation_status_tab': invitation_status_tab,
-        'mnplacement_post': mnplacement_post,
-        'mnpbi_tab': mnpbi_tab,
-        'mnplacement_tab': mnplacement_tab,
-        'placementstatus_placement': placementstatus_placement,
-        'placementstatus_pbi': placementstatus_pbi,
-        'current1': current1,
-        'current2': current2,
-        'strecord_tab': strecord_tab,
-        'mnpbi_post': mnpbi_post,
-        'page_range': page_range,
-        'paginator': paginator,
-        'no_pagination': no_pagination,
-        'is_disabled': is_disabled,
-    }
-
-    return render(request, 'placementModule/studentrecords.html', context)
-
-
-
-
-
-
-
-    invitecheck=0
-    for r in records:
-        r['name__count'] = 0
-        r['year__count'] = 0
-        r['placement_type__count'] = 0
-    tcse = dict()
-    tece = dict()
-    tme = dict()
-    tadd = dict()
-    for y in years:
-        tcse[y['year']] = 0
-        tece[y['year']] = 0
-        tme[y['year']] = 0
-        for r in records:
-            if r['year'] == y['year']:
-                if r['placement_type'] != "HIGHER STUDIES":
-                    for z in studentrecord:
-                        if z.record_id.name == r['name'] and z.record_id.year == r['year'] and z.unique_id.id.department.name == "CSE":
-                            tcse[y['year']] = tcse[y['year']]+1
-                            r['name__count'] = r['name__count']+1
-                        if z.record_id.name == r['name'] and z.record_id.year == r['year'] and z.unique_id.id.department.name == "ECE":
-                            tece[y['year']] = tece[y['year']]+1
-                            r['year__count'] = r['year__count']+1
-                        if z.record_id.name == r['name'] and z.record_id.year == r['year'] and z.unique_id.id.department.name == "ME":
-                            tme[y['year']] = tme[y['year']]+1
-                            r['placement_type__count'] = r['placement_type__count']+1
-        tadd[y['year']] = tcse[y['year']]+tece[y['year']]+tme[y['year']]
-        y['year__count'] = [tadd[y['year']], tcse[y['year']], tece[y['year']], tme[y['year']]]
-
-    form2 = SearchPlacementRecord(initial={})
-    form3 = SearchPbiRecord(initial={})
-    form4 = SearchHigherRecord(initial={})
-
-
-    current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
-    current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
-    current = HoldsDesignation.objects.filter(Q(working=user, designation__name="student"))
-    print(current)
-
-    if len(current1)!=0 or len(current2)!=0:
-        delete_operation = 1
-    if len(current) == 0:
-        current = None
-    pbirecord= ''
-    placementrecord= ''
-    higherrecord= ''
-    total_query=0
-    total_query1 = 0
-    total_query2= 0
-    p=""
-    p1=""
-    p2=""
-    placement_search_record=" "
-    pbi_search_record=" "
-    higher_search_record=" "
-    # results of the searched query under placement tab
-    if 'studentplacementrecordsubmit' in request.POST:
-        officer_statistics_past = 1
-        form = SearchPlacementRecord(request.POST)
-        if form.is_valid():
-
-
-
-
-            print("IS VALID")
-
-
-
-            #for student name
-            if form.cleaned_data['stuname']:
-                stuname = form.cleaned_data['stuname']
-                try:
-                    first_name = stuname.split(" ")[0]
-                    last_name = stuname.split(" ")[1]
-                except Exception as e:
-                    print("Error")
-                    print(e)
-                    first_name = stuname
-                    last_name = ''
-            else:
-                stuname = ''
-                first_name = ''
-                last_name = ''
-
-
-            # for student CTC
-            if form.cleaned_data['ctc']:
-                ctc = form.cleaned_data['ctc']
-            else:
-                ctc = 0
-
-            #for company name
-            if form.cleaned_data['cname']:
-                cname = form.cleaned_data['cname']
-            else:
-                cname = ''
-
-            #for student roll
-            if form.cleaned_data['roll']:
-                rollno = form.cleaned_data['roll']
-            else:
-                rollno = ''
-
-            #for admission year
-            if form.cleaned_data['year']:
-                year = form.cleaned_data['year']
-                s = Student.objects.filter((Q(id__in=ExtraInfo.objects.filter(
-                    Q(user__in=User.objects.filter(
-                        first_name__icontains=first_name,
-                        last_name__icontains=last_name),
-                       id__icontains=rollno))
-                    )))
-
-                p = PlacementRecord.objects.filter(Q(placement_type="PLACEMENT", name__icontains=stuname, ctc__icontains=ctc, year__icontains=year))
-
-
-
-
-            """placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                    Q(record_id__in=PlacementRecord.objects.filter(
-                        Q(placement_type="PLACEMENT", name__icontains=cname, ctc__gte=ctc, year=year)),
-                    unique_id__in=Student.objects.filter(
-                        (Q(id__in=ExtraInfo.objects.filter(
-                            Q(user__in=User.objects.filter(
-                                first_name__icontains=first_name,
-                                last_name__icontains=last_name,
-                            id__icontains=rollno))))))))
-                #print("In if:", placementrecord)
-            else:
-                s = Student.objects.filter((Q(id__in=ExtraInfo.objects.filter(
-                    Q(user__in=User.objects.filter(
-                        first_name__icontains=first_name,
-                        last_name__icontains=last_name),
-                        id__icontains=rollno))
-                    )))
-
-                p = PlacementRecord.objects.filter(Q(placement_type="PLACEMENT", name__icontains=cname, ctc__gte=ctc))
-                print("Agein p:",p)
-                placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                    Q(record_id__in=PlacementRecord.objects.filter(
-                    Q(placement_type="PLACEMENT", name__icontains=cname, ctc__gte=ctc)),
-                    unique_id__in=Student.objects.filter(
-                    (Q(id__in=ExtraInfo.objects.filter(
-                    Q(user__in=User.objects.filter(
-                        first_name__icontains=first_name,
-                        last_name__icontains=last_name),
-                    id__icontains=rollno)))))))
-
-            request.session['first_name'] = first_name
-            request.session['last_name'] = last_name
-            request.session['ctc'] = ctc
-            request.session['cname'] = cname
-            request.session['rollno'] = rollno
-            request.session['year'] = form.cleaned_data['year']"""
-
-            print(p)
-
-
-            total_query = p.count()
-
-            if total_query > 30:
-                pagination_placement = 1
-                paginator = Paginator(placementrecord, 30)
-                page = request.GET.get('page', 1)
-                placementrecord = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                pagination_placement = 0
-    else:
-        if request.GET.get('page') != None:
-            try:
-                if request.session['year']:
-                    s = Student.objects.filter(
-                        (Q(id__in=ExtraInfo.objects.filter(
-                        Q(user__in=User.objects.filter(
-                        Q(first_name__icontains=request.session['first_name'],
-                        last_name__icontains=request.session['last_name'])),
-                       id__icontains=request.session['rollno']))
-                    )))
-
-                    p = PlacementRecord.objects.filter(
-                        Q(placement_type="PLACEMENT",
-                        name__icontains=request.session['cname'],
-                        ctc__gte=request.session['ctc'],
-                        year=request.session['year']))
-
-
-                    placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                        Q(record_id__in=PlacementRecord.objects.filter(
-                            Q(placement_type="PLACEMENT",
-                            name__icontains=request.session['cname'],
-                            ctc__gte=request.session['ctc'],
-                            year=request.session['year'])),
-                            unique_id__in=Student.objects.filter(
-                            (Q(id__in=ExtraInfo.objects.filter(
-                            Q(user__in=User.objects.filter(
-                            Q(first_name__icontains=request.session['first_name'],
-                            last_name__icontains=request.session['last_name'])),
-                            id__icontains=request.session['rollno'])))))))
-                else:
-                    s = Student.objects.filter((Q(id__in=ExtraInfo.objects.filter
-                    (Q(user__in=User.objects.filter
-                       (Q(first_name__icontains=request.session['first_name'],
-                        last_name__icontains=request.session['last_name'])),
-                       id__icontains=request.session['rollno']))
-                    )))
-
-                    p = PlacementRecord.objects.filter(
-                        Q(placement_type="PLACEMENT",
-                            name__icontains=request.session['cname'],
-                            ctc__gte=request.session['ctc']))
-
-                    placementrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                        Q(record_id__in=PlacementRecord.objects.filter(
-                        Q(placement_type="PLACEMENT",
-                            name__icontains=request.session['cname'],
-                            ctc__gte=request.session['ctc'])),
-                        unique_id__in=Student.objects.filter(
-                        (Q(id__in=ExtraInfo.objects.filter(
-                        Q(user__in=User.objects.filter(
-                        Q(first_name__icontains=request.session['first_name'],
-                        last_name__icontains=request.session['last_name'])),
-                        id__icontains=request.session['rollno'])))))))
-            except Exception as e:
-                print(e)
-                placementrecord = ''
-
-            if placementrecord != '':
-                total_query = placementrecord.count()
-            else:
-                total_query = 0
-                no_records=1
-            print(placementrecord)
-            if total_query > 30:
-                pagination_placement = 1
-                paginator = Paginator(placementrecord, 30)
-                page = request.GET.get('page', 1)
-                placementrecord = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                pagination_placement = 0
-        else:
-            placementrecord = ''
-
-    if total_query!=0:
-        placement_search_record=p
-    # results of the searched query under pbi tab
-    if 'studentpbirecordsubmit' in request.POST:
-        officer_statistics_past_pbi_search = 1
-        form = SearchPbiRecord(request.POST)
-        if form.is_valid():
-            if form.cleaned_data['stuname']:
-                stuname = form.cleaned_data['stuname']
-                try:
-                    first_name = stuname.split(" ")[0]
-                    last_name = stuname.split(" ")[1]
-                except:
-                    first_name = stuname
-                    last_name = ''
-            else:
-                stuname = ''
-                first_name = ''
-                last_name = ''
-            if form.cleaned_data['ctc']:
-                ctc = form.cleaned_data['ctc']
-            else:
-                ctc = 0
-            if form.cleaned_data['cname']:
-                cname = form.cleaned_data['cname']
-            else:
-                cname = ''
-            if form.cleaned_data['roll']:
-                rollno = form.cleaned_data['roll']
-            else:
-                rollno = ''
-            if form.cleaned_data['year']:
-                year = form.cleaned_data['year']
-                pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(Q(record_id__in=PlacementRecord.objects.filter
-                                                       (Q(placement_type="PBI",
-                                                          name__icontains=cname,
-                                                          ctc__gte=ctc, year=year)),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=first_name,
-                                                            last_name__icontains=last_name)),
-                                                              id__icontains=rollno))
-                                                           )))))
-                p1 = PlacementRecord.objects.filter(
-                    Q(placement_type="PBI", name__icontains=stuname, ctc__icontains=ctc, year__icontains=year))
-            """else:
-                pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(Q(record_id__in=PlacementRecord.objects.filter
-                                                       (Q(placement_type="PBI",
-                                                          name__icontains=cname,
-                                                          ctc__gte=ctc)),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=first_name,
-                                                            last_name__icontains=last_name)),
-                                                              id__icontains=rollno))
-                                                           )))))
-            request.session['first_name'] = first_name
-            request.session['last_name'] = last_name
-            request.session['ctc'] = ctc
-            request.session['cname'] = cname
-            request.session['rollno'] = rollno
-            request.session['year'] = form.cleaned_data['year']
-"""
-            total_query1 = p1.count()
-
-            if total_query1 > 30:
-                pagination_pbi = 1
-                paginator = Paginator(pbirecord, 30)
-                page = request.GET.get('page', 1)
-                pbirecord = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query1 > 30 and total_query1 <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                pagination_pbi = 0
-    else:
-        if request.GET.get('page') != None:
-            try:
-                if request.session['year']:
-                    pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                        Q(record_id__in=PlacementRecord.objects.filter(
-                        Q(placement_type="PBI",
-                        name__icontains=request.session['cname'],
-                        ctc__gte=ctc, year=request.session['year'])),
-                        unique_id__in=Student.objects.filter((
-                        Q(id__in=ExtraInfo.objects.filter(
-                        Q(user__in=User.objects.filter(
-                        Q(first_name__icontains=request.session['first_name'],
-                        last_name__icontains=request.session['last_name'])),
-                        id__icontains=request.session['rollno'])))))))
-                else:
-                    pbirecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                        Q(record_id__in=PlacementRecord.objects.filter(Q(placement_type="PBI",
-                                                              name__icontains=request.session['cname'],
-                                                              ctc__gte=request.session['ctc'])),
-                                                           unique_id__in=Student.objects.filter(
-                                                            (Q(id__in=ExtraInfo.objects.filter(
-                                                            Q(user__in=User.objects.filter(
-                        Q(first_name__icontains=request.session['first_name'],
-                        last_name__icontains=request.session['last_name'])),
-                        id__icontains=request.session['rollno'])))))))
-            except:
-                print('except')
-                pbirecord = ''
-
-            if pbirecord != '':
-                total_query = pbirecord.count()
-            else:
-                total_query = 0
-
-            if total_query > 30:
-                pagination_pbi = 1
-                paginator = Paginator(pbirecord, 30)
-                page = request.GET.get('page', 1)
-                pbirecord = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                pagination_pbi = 0
-        else:
-            pbirecord = ''
-    if total_query1!=0:
-        pbi_search_record=p1
-
-    # results of the searched query under higher studies tab
-    if 'studenthigherrecordsubmit' in request.POST:
-        officer_statistics_past_higher_search = 1
-        form = SearchHigherRecord(request.POST)
-        if form.is_valid():
-            # getting all the variables send through form
-            if form.cleaned_data['stuname']:
-                stuname = form.cleaned_data['stuname']
-                try:
-                    first_name = stuname.split(" ")[0]
-                    last_name = stuname.split(" ")[1]
-                except:
-                    first_name = stuname
-                    last_name = ''
-            else:
-                stuname = ''
-                first_name = ''
-                last_name = ''
-            if form.cleaned_data['test_type']:
-                test_type = form.cleaned_data['test_type']
-            else:
-                test_type = ''
-            if form.cleaned_data['uname']:
-                uname = form.cleaned_data['uname']
-            else:
-                uname = ''
-            if form.cleaned_data['test_score']:
-                test_score = form.cleaned_data['test_score']
-            else:
-                test_score = 0
-            if form.cleaned_data['roll']:
-                rollno = form.cleaned_data['roll']
-            else:
-                rollno = ''
-            if form.cleaned_data['year']:
-                year = form.cleaned_data['year']
-                # result of the query when year is given
-                higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(Q(record_id__in=PlacementRecord.objects.filter
-                                                       (Q(placement_type="HIGHER STUDIES",
-                                                          test_type__icontains=test_type,
-                                                          name__icontains=uname, year=year,
-                                                          test_score__gte=test_score)),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=first_name,
-                                                            last_name__icontains=last_name)),
-                                                              id__icontains=rollno))
-                                                           )))))
-
-                p2 = PlacementRecord.objects.filter(
-                    Q(placement_type="HIGHER STUDIES", name__icontains=stuname, year__icontains=year))
-
-            """else:
-                # result of the query when year is not given
-                higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                    Q(record_id__in=PlacementRecord.objects.filter
-                                                       (Q(placement_type="HIGHER STUDIES",
-                                                          test_type__icontains=test_type,
-                                                          name__icontains=uname,
-                                                          test_score__gte=test_score)),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=first_name,
-                                                                last_name__icontains=last_name)),
-                                                              id__icontains=rollno))
-                                                           )))))
-            request.session['first_name'] = first_name
-            request.session['last_name'] = last_name
-            request.session['test_score'] = test_score
-            request.session['uname'] = uname
-            request.session['test_type'] = test_type
-            request.session['rollno'] = rollno
-            request.session['year'] = form.cleaned_data['year']"""
-
-            total_query2 = p2.count()
-
-            if total_query2 > 30:
-                pagination_higher = 1
-                paginator = Paginator(p2, 30)
-                page = request.GET.get('page', 1)
-                p2 = paginator.page(page)
-                page = int(page)
-                total_page = int(page+3)
-
-                if page < (paginator.num_pages-3):
-                    if total_query2 > 30 and total_query2 <= 60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(page-2, paginator.num_pages+1)
-            else:
-                pagination_higher = 0
-    else:
-        if request.GET.get('page') != None:
-            try:
-                if request.session['year']:
-                    higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                        Q(record_id__in=PlacementRecord.objects.filter(
-                            Q(placement_type="HIGHER STUDIES",
-                              test_type__icontains=request.session['test_type'],
-                              name__icontains=request.session['uname'],
-                              year=request.session['year'],
-                              test_score__gte=request.session['test_score'])),
-                           unique_id__in=Student.objects.filter(
-                            (Q(id__in=ExtraInfo.objects.filter(
-                                Q(user__in=User.objects.filter(
-                                Q(first_name__icontains=request.session['first_name'],
-                                last_name__icontains=request.session['last_name'])),
-                                id__icontains=request.session['rollno']))
-                               )))))
-                else:
-                    higherrecord = StudentRecord.objects.select_related('unique_id','record_id').filter(
-                        Q(record_id__in=PlacementRecord.objects.filter(
-                            Q(placement_type="HIGHER STUDIES",
-                          test_type__icontains=request.session['test_type'],
-                          name__icontains=request.session['uname'],
-                          test_score__gte=request.session['test_score'])),
-                       unique_id__in=Student.objects.filter
-                       ((Q(id__in=ExtraInfo.objects.filter(
-                        Q(user__in=User.objects.filter(
-                            Q(first_name__icontains=request.session['first_name'],
-                        last_name__icontains=request.session['last_name'])),
-                              id__icontains=request.session['rollno']))
-                           )))))
-            except:
-                higherrecord = ''
-
-            if higherrecord != '':
-                total_query = higherrecord.count()
-            else:
-                total_query = 0
-
-            if total_query > 30:
-                no_pagination = 1
-                paginator = Paginator(higherrecord, 30)
-                page = request.GET.get('page', 1)
-                higherrecord = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
-        else:
-            higherrecord = ''
-    if total_query2!=0:
-        higher_search_record=p2
-
-    context = {
-        'form2'             :            form2,
-        'form3'             :            form3,
-        'form4'             :            form4,
-        'current'           :          current,
-        'current1'          :         current1,
-        'current2'          :         current2,
-
-
-        'all_records':          all_records,   #for flashing all placement Schedule
-
-        'placement_search_record': placement_search_record,
-        'pbi_search_record': pbi_search_record,
-        'higher_search_record': higher_search_record,
-
-
-
-        'statistics_tab'    :   statistics_tab,
-        'pbirecord'         :        pbirecord,
-        'placementrecord'   :  placementrecord,
-        'higherrecord'      :     higherrecord,
-        'years'             :            years,
-        'records'           :          records,
-        'delete_operation'  :       delete_operation,
-        'page_range': page_range,
-        'paginator': paginator,
-        'pagination_placement': pagination_placement,
-        'pagination_pbi': pagination_pbi,
-        'pagination_higher': pagination_higher,
-        'is_disabled': is_disabled,
-        'officer_statistics_past_pbi_search': officer_statistics_past_pbi_search,
-        'officer_statistics_past_higher_search': officer_statistics_past_higher_search
-    }
-
-    return render(request, 'placementModule/placementstatistics.html', context)
-
-
-
-def get_reference_list(request):
-    if request.method == 'POST':
-
-        user = request.user
-        profile = get_object_or_404(ExtraInfo, Q(user=user))
-        student = get_object_or_404(Student, Q(id=profile.id))
-        print(student)
-        reference_objects = Reference.select_related('unique_id').objects.filter(unique_id=student)
-        reference_objects = serializers.serialize('json', list(reference_objects))
-
-        context = {
-            'reference_objs': reference_objects
-        }
-        return JsonResponse(context)
-
-
-# Ajax for the company name dropdown for CompanyName when filling AddSchedule
-def company_name_dropdown(request):
-    if request.method == 'POST':
-        current_value = request.POST.get('current_value')
-        company_names = CompanyDetails.objects.filter(Q(company_name__startswith=current_value))
-        company_name = []
-        for name in company_names:
-            company_name.append(name.company_name)
-
-        context = {
-            'company_names': company_name
-        }
-
-        return JsonResponse(context)
-
-
-# Ajax for all the roles in the dropdown
-def checking_roles(request):
-    if request.method == 'POST':
-        current_value = request.POST.get('current_value')
-        all_roles = Role.objects.filter(Q(role__startswith=current_value))
-        role_name = []
-        for role in all_roles:
-            role_name.append(role.role)
-        return JsonResponse({'all_roles': role_name})
-
-@login_required
-def Placement__Schedule(request):
-    '''
-    function include the functionality of first tab of UI
-    for student, placement officer & placement chairman
-
-    placement officer & placement chairman
-        - can add schedule
-        - can delete schedule
-    student
-        - accepted or declined schedule
-
-    '''
-    user = request.user
-    profile = get_object_or_404(ExtraInfo, Q(user=user))
-    schedule_tab = 1
-    placementstatus = ''
-
-
-    form5 = AddSchedule(initial={})
-    current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
-    current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
-    current = HoldsDesignation.objects.filter(Q(working=user, designation__name="student"))
-    print(current)
-
-    # If the user is Student
-    if current:
-        student = get_object_or_404(Student, Q(id=profile.id))
-
-        # Student view for showing accepted or declined schedule
-        if request.method == 'POST':
-            if 'studentapprovesubmit' in request.POST:
-                status = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                    pk=request.POST['studentapprovesubmit']).update(
-                    invitation='ACCEPTED',
-                    timestamp=timezone.now())
-            if 'studentdeclinesubmit' in request.POST:
-                status = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                    Q(pk=request.POST['studentdeclinesubmit'])).update(
-                    invitation='REJECTED',
-                    timestamp=timezone.now())
-
-            if 'educationsubmit' in request.POST:
-                form = AddEducation(request.POST)
-                if form.is_valid():
-                    institute = form.cleaned_data['institute']
-                    degree = form.cleaned_data['degree']
-                    grade = form.cleaned_data['grade']
-                    stream = form.cleaned_data['stream']
-                    sdate = form.cleaned_data['sdate']
-                    edate = form.cleaned_data['edate']
-                    education_obj = Education.objects.select_related('unique_id').create(
-                        unique_id=student, degree=degree,
-                        grade=grade, institute=institute,
-                        stream=stream, sdate=sdate, edate=edate)
-                    education_obj.save()
-            if 'profilesubmit' in request.POST:
-                about_me = request.POST.get('about')
-                age = request.POST.get('age')
-                address = request.POST.get('address')
-                contact = request.POST.get('contact')
-                pic = request.POST.get('pic')
-                # futu = request.POST.get('futu')
-                # print(studentplacement_obj.future_aspect)
-                # print('fut=', fut)
-                # print('futu=', futu)
-                # if studentplacement_obj.future_aspect == "HIGHER STUDIES":
-                #     if futu == 2:
-                #         studentplacement_obj.future_aspect = "PLACEMENT"
-                # elif studentplacement_obj.future_aspect == "PLACEMENT":
-                #     if futu == None:
-                #         studentplacement_obj.future_aspect = "HIGHER STUDIES"
-                extrainfo_obj = ExtraInfo.objects.get(user=user)
-                extrainfo_obj.about_me = about_me
-                extrainfo_obj.age = age
-                extrainfo_obj.address = address
-                extrainfo_obj.phone_no = contact
-                extrainfo_obj.profile_picture = pic
-                extrainfo_obj.save()
-                profile = get_object_or_404(ExtraInfo, Q(user=user))
-            if 'skillsubmit' in request.POST:
-                form = AddSkill(request.POST)
-                if form.is_valid():
-                    skill = form.cleaned_data['skill']
-                    skill_rating = form.cleaned_data['skill_rating']
-                    has_obj = Has.objects.select_related('skill_id','unique_id').create(unique_id=student,
-                                                 skill_id=Skill.objects.get(skill=skill),
-                                                 skill_rating = skill_rating)
-                    has_obj.save()
-            if 'achievementsubmit' in request.POST:
-                form = AddAchievement(request.POST)
-                if form.is_valid():
-                    achievement = form.cleaned_data['achievement']
-                    achievement_type = form.cleaned_data['achievement_type']
-                    description = form.cleaned_data['description']
-                    issuer = form.cleaned_data['issuer']
-                    date_earned = form.cleaned_data['date_earned']
-                    achievement_obj = Achievement.objects.select_related('unique_id').create(unique_id=student,
-                                                                 achievement=achievement,
-                                                                 achievement_type=achievement_type,
-                                                                 description=description,
-                                                                 issuer=issuer,
-                                                                 date_earned=date_earned)
-                    achievement_obj.save()
-            if 'publicationsubmit' in request.POST:
-                form = AddPublication(request.POST)
-                if form.is_valid():
-                    publication_title = form.cleaned_data['publication_title']
-                    description = form.cleaned_data['description']
-                    publisher = form.cleaned_data['publisher']
-                    publication_date = form.cleaned_data['publication_date']
-                    publication_obj = Publication.objects.select_related('unique_id').create(unique_id=student,
-                                                                 publication_title=
-                                                                 publication_title,
-                                                                 publisher=publisher,
-                                                                 description=description,
-                                                                 publication_date=publication_date)
-                    publication_obj.save()
-            if 'patentsubmit' in request.POST:
-                form = AddPatent(request.POST)
-                if form.is_valid():
-                    patent_name = form.cleaned_data['patent_name']
-                    description = form.cleaned_data['description']
-                    patent_office = form.cleaned_data['patent_office']
-                    patent_date = form.cleaned_data['patent_date']
-                    patent_obj = Patent.objects.select_related('unique_id').create(unique_id=student, patent_name=patent_name,
-                                                       patent_office=patent_office,
-                                                       description=description,
-                                                       patent_date=patent_date)
-                    patent_obj.save()
-            if 'coursesubmit' in request.POST:
-                form = AddCourse(request.POST)
-                if form.is_valid():
-                    course_name = form.cleaned_data['course_name']
-                    description = form.cleaned_data['description']
-                    license_no = form.cleaned_data['license_no']
-                    sdate = form.cleaned_data['sdate']
-                    edate = form.cleaned_data['edate']
-                    course_obj = Course.objects.select_related('unique_id').create(unique_id=student, course_name=course_name,
-                                                       license_no=license_no,
-                                                       description=description,
-                                                       sdate=sdate, edate=edate)
-                    course_obj.save()
-            if 'projectsubmit' in request.POST:
-                form = AddProject(request.POST)
-                if form.is_valid():
-                    project_name = form.cleaned_data['project_name']
-                    project_status = form.cleaned_data['project_status']
-                    summary = form.cleaned_data['summary']
-                    project_link = form.cleaned_data['project_link']
-                    sdate = form.cleaned_data['sdate']
-                    edate = form.cleaned_data['edate']
-                    project_obj = Project.objects.create(unique_id=student, summary=summary,
-                                                         project_name=project_name,
-                                                         project_status=project_status,
-                                                         project_link=project_link,
-                                                         sdate=sdate, edate=edate)
-                    project_obj.save()
-            if 'experiencesubmit' in request.POST:
-                form = AddExperience(request.POST)
-                if form.is_valid():
-                    title = form.cleaned_data['title']
-                    status = form.cleaned_data['status']
-                    company = form.cleaned_data['company']
-                    location = form.cleaned_data['location']
-                    description = form.cleaned_data['description']
-                    sdate = form.cleaned_data['sdate']
-                    edate = form.cleaned_data['edate']
-                    experience_obj = Experience.objects.select_related('unique_id').create(unique_id=student, title=title,
-                                                               company=company, location=location,
-                                                               status=status,
-                                                               description=description,
-                                                               sdate=sdate, edate=edate)
-                    experience_obj.save()
-
-            if 'deleteskill' in request.POST:
-                hid = request.POST['deleteskill']
-                hs = Has.objects.select_related('skill_id','unique_id').get(Q(pk=hid))
-                hs.delete()
-            if 'deleteedu' in request.POST:
-                hid = request.POST['deleteedu']
-                hs = Education.objects.select_related('unique_id').get(Q(pk=hid))
-                hs.delete()
-            if 'deletecourse' in request.POST:
-                hid = request.POST['deletecourse']
-                hs = Course.objects.get(Q(pk=hid))
-                hs.delete()
-            if 'deleteexp' in request.POST:
-                hid = request.POST['deleteexp']
-                hs = Experience.objects.get(Q(pk=hid))
-                hs.delete()
-            if 'deletepro' in request.POST:
-                hid = request.POST['deletepro']
-                hs = Project.objects.get(Q(pk=hid))
-                hs.delete()
-            if 'deleteach' in request.POST:
-                hid = request.POST['deleteach']
-                hs = Achievement.objects.get(Q(pk=hid))
-                hs.delete()
-            if 'deletepub' in request.POST:
-                hid = request.POST['deletepub']
-                hs = Publication.objects.select_related('unique_id').get(Q(pk=hid))
-                hs.delete()
-            if 'deletepat' in request.POST:
-                hid = request.POST['deletepat']
-                hs = Patent.objects.get(Q(pk=hid))
-                hs.delete()
-
-        placementschedule = PlacementSchedule.objects.select_related('notify_id').filter(
-            Q(placement_date__gte=date.today())).values_list('notify_id', flat=True)
-
-        placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-            Q(unique_id=student,
-            notify_id__in=placementschedule)).order_by('-timestamp')
-
-
-        check_invitation_date(placementstatus)
-
-    # facult and other staff view only statistics
-    if not (current or current1 or current2):
-        return redirect('/placement/statistics/')
-
-    # delete the schedule
-    if 'deletesch' in request.POST:
-        delete_sch_key = request.POST['delete_sch_key']
-        try:
-            placement_schedule = PlacementSchedule.objects.select_related('notify_id').get(pk = delete_sch_key)
-            NotifyStudent.objects.get(pk=placement_schedule.notify_id.id).delete()
-            placement_schedule.delete()
-            messages.success(request, 'Schedule Deleted Successfully')
-        except Exception as e:
-            messages.error(request, 'Problem Occurred for Schedule Delete!!!')
-
-    # saving all the schedule details
-    if 'schedulesubmit' in request.POST:
-        form5 = AddSchedule(request.POST, request.FILES)
-        if form5.is_valid():
-            company_name = form5.cleaned_data['company_name']
-            placement_date = form5.cleaned_data['placement_date']
-            location = form5.cleaned_data['location']
-            ctc = form5.cleaned_data['ctc']
-            time = form5.cleaned_data['time']
-            attached_file = form5.cleaned_data['attached_file']
-            placement_type = form5.cleaned_data['placement_type']
-            role_offered = request.POST.get('role')
-            description = form5.cleaned_data['description']
-
-            try:
-                comp_name = CompanyDetails.objects.filter(company_name=company_name)[0]
-            except:
-                CompanyDetails.objects.create(company_name=company_name)
-
-            try:
-                role = Role.objects.filter(role=role_offered)[0]
-            except:
-                role = Role.objects.create(role=role_offered)
-                role.save()
-
-
-            notify = NotifyStudent.objects.create(placement_type=placement_type,
-                                                  company_name=company_name,
-                                                  description=description,
-                                                  ctc=ctc,
-                                                  timestamp=timezone.now())
-
-            schedule = PlacementSchedule.objects.select_related('notify_id').create(notify_id=notify,
-                                                        title=company_name,
-                                                        description=description,
-                                                        placement_date=placement_date,
-                                                        attached_file = attached_file,
-                                                        role=role,
-                                                        location=location, time=time)
-
-            notify.save()
-            schedule.save()
-            messages.success(request, "Schedule Added Successfull!!")
-
-
-    schedules = PlacementSchedule.objects.select_related('notify_id').all()
-
-
-    context = {
-        'current': current,
-        'current1': current1,
-        'current2': current2,
-        'schedule_tab': schedule_tab,
-        'schedules': schedules,
-        'placementstatus': placementstatus,
-        'form5': form5,
-    }
-
-    return render(request, 'placementModule/placement.html', context)
-
-
-
-def invite_status(request):
-    '''
-    function to check the invitation status
-    '''
-    user = request.user
-    strecord_tab = 1
-    mnpbi_tab = 0
-    mnplacement_post = 0
-    mnpbi_post = 0
-    invitation_status_tab = 1
-    placementstatus_placement = []
-    placementstatus_pbi = []
-    mnplacement_tab = 1
-
-    no_pagination = 1
-    is_disabled = 0
-    paginator = ''
-    page_range = ''
-    placement_get_request = False
-    pbi_get_request = False
-
-    # invitation status for placement
-    if 'studentplacementsearchsubmit' in request.POST:
-        mnplacement_post = 1
-        mnpbi_post = 0
-        form = ManagePlacementRecord(request.POST)
-
-        if form.is_valid():
-            if form.cleaned_data['stuname']:
-                stuname = form.cleaned_data['stuname']
-            else:
-                stuname = ''
-            if form.cleaned_data['ctc']:
-                ctc = form.cleaned_data['ctc']
-            else:
-                ctc = 0
-            if form.cleaned_data['company']:
-                cname = form.cleaned_data['company']
-            else:
-                cname = ''
-            if form.cleaned_data['roll']:
-                rollno = form.cleaned_data['roll']
-            else:
-                rollno = ''
-
-            request.session['mn_stuname'] = stuname
-            request.session['mn_ctc'] = ctc
-            request.session['mn_cname'] = cname
-            request.session['mn_rollno'] = rollno
-
-            placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                       (Q(placement_type="PLACEMENT",
-                                                          company_name__icontains=cname,
-                                                          ctc__gte=ctc)),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=stuname)),
-                                                              id__icontains=rollno))
-                                                           )))))
-            # pagination stuff starts from here
-            total_query = placementstatus_placement.count()
-
-            if total_query > 30:
-                no_pagination = 1
-                paginator = Paginator(placementstatus_placement, 30)
-                page = request.GET.get('page', 1)
-                placementstatus_placement = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
-    else:
-        # when the request from pagination with some page number
-        if request.GET.get('placement_page') != None:
-            mnplacement_post = 1
-            mnpbi_post = 0
-            no_pagination = 1
-            try:
-                placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                       (Q(placement_type="PLACEMENT",
-                                                          company_name__icontains=request.session['mn_cname'],
-                                                          ctc__gte=request.session['mn_ctc'])),
-                                                       unique_id__in=Student.objects.filter
-                                                       ((Q(id__in=ExtraInfo.objects.filter
-                                                           (Q(user__in=User.objects.filter
-                                                              (Q(first_name__icontains=request.session['mn_stuname'])),
-                                                              id__icontains=request.session['mn_rollno']))
-                                                           )))))
-            except:
-                placementstatus_placement = []
-
-            if placementstatus_placement != '':
-                total_query = placementstatus_placement.count()
-            else:
-                total_query = 0
-
-            if total_query > 30:
-                paginator = Paginator(placementstatus_placement, 30)
-                page = request.GET.get('placement_page', 1)
-                placementstatus_placement = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
-
-    # invitation status for pbi
-    if 'studentpbisearchsubmit' in request.POST:
-        mnpbi_tab = 1
-        mnpbi_post = 1
-        mnplacement_post = 0
-        form = ManagePbiRecord(request.POST)
-        if form.is_valid():
-            if form.cleaned_data['stuname']:
-                stuname = form.cleaned_data['stuname']
-            else:
-                stuname = ''
-            if form.cleaned_data['ctc']:
-                ctc = form.cleaned_data['ctc']
-            else:
-                ctc = 0
-            if form.cleaned_data['company']:
-                cname = form.cleaned_data['company']
-            else:
-                cname = ''
-            if form.cleaned_data['roll']:
-                rollno = form.cleaned_data['roll']
-            else:
-                rollno = ''
-            request.session['mn_pbi_stuname'] = stuname
-            request.session['mn_pbi_ctc'] = ctc
-            request.session['mn_pbi_cname'] = cname
-            request.session['mn_pbi_rollno'] = rollno
-            placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                Q(notify_id__in=NotifyStudent.objects.filter(
-                Q(placement_type="PBI",
-                company_name__icontains=cname,
-                ctc__gte=ctc)),
-                unique_id__in=Student.objects.filter(
-                (Q(id__in=ExtraInfo.objects.filter(
-                Q(user__in=User.objects.filter(
-                Q(first_name__icontains=stuname)),
-                id__icontains=rollno))))))).order_by('id')
-
-            total_query = placementstatus_pbi.count()
-
-            if total_query > 30:
-                no_pagination = 1
-                paginator = Paginator(placementstatus_pbi, 30)
-                page = request.GET.get('pbi_page', 1)
-                placementstatus_pbi = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
-
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
-
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
-    else:
-        if request.GET.get('pbi_page') != None:
-            mnpbi_tab = 1
-            mnpbi_post = 1
-            no_pagination = 1
-            try:
-                placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                    Q(notify_id__in=NotifyStudent.objects.filter(
-                    Q(placement_type="PBI",
-                    company_name__icontains=request.session['mn_pbi_cname'],
-                                              ctc__gte=request.session['mn_pbi_ctc'])),
-                                           unique_id__in=Student.objects.filter(
-                                            (Q(id__in=ExtraInfo.objects.filter(
-                                                Q(user__in=User.objects.filter(
-                    Q(first_name__icontains=request.session['mn_pbi_stuname'])),
-                                                  id__icontains=request.session['mn_pbi_rollno']))
-                                               )))))
-            except:
-                placementstatus_pbi = ''
-
-            if placementstatus_pbi != '':
-                total_query = placementstatus_pbi.count()
-            else:
-                total_query = 0
-            if total_query > 30:
-                paginator = Paginator(placementstatus_pbi, 30)
-                page = request.GET.get('pbi_page', 1)
-                placementstatus_pbi = paginator.page(page)
-                page = int(page)
-                total_page = int(page + 3)
+    # If the user is Student
+    if current:
+        student = get_object_or_404(Student, Q(id=profile.id))
 
-                if page<(paginator.num_pages-3):
-                    if total_query > 30 and total_query <=60:
-                        page_range = range(1, 3)
-                    else:
-                        page_range = range(1, total_page+1)
+        # Student view for showing accepted or declined schedule
+        if request.method == 'POST':
+            if 'studentapprovesubmit' in request.POST:
+                status = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+                    pk=request.POST['studentapprovesubmit']).update(
+                    invitation='ACCEPTED',
+                    timestamp=timezone.now())
+            if 'studentdeclinesubmit' in request.POST:
+                status = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+                    Q(pk=request.POST['studentdeclinesubmit'])).update(
+                    invitation='REJECTED',
+                    timestamp=timezone.now())
 
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, total_page)
-                else:
-                    if page >= 5:
-                        is_disabled = 1
-                        page_range = range(page-2, paginator.num_pages+1)
-                    else:
-                        page_range = range(1, paginator.num_pages+1)
-            else:
-                no_pagination = 0
+            if 'educationsubmit' in request.POST:
+                form = AddEducation(request.POST)
+                if form.is_valid():
+                    institute = form.cleaned_data['institute']
+                    degree = form.cleaned_data['degree']
+                    grade = form.cleaned_data['grade']
+                    stream = form.cleaned_data['stream']
+                    sdate = form.cleaned_data['sdate']
+                    edate = form.cleaned_data['edate']
+                    education_obj = Education.objects.select_related('unique_id').create(
+                        unique_id=student, degree=degree,
+                        grade=grade, institute=institute,
+                        stream=stream, sdate=sdate, edate=edate)
+                    education_obj.save()
+            if 'profilesubmit' in request.POST:
+                about_me = request.POST.get('about')
+                age = request.POST.get('age')
+                address = request.POST.get('address')
+                contact = request.POST.get('contact')
+                pic = request.POST.get('pic')
+                # futu = request.POST.get('futu')
+                # print(studentplacement_obj.future_aspect)
+                # print('fut=', fut)
+                # print('futu=', futu)
+                # if studentplacement_obj.future_aspect == "HIGHER STUDIES":
+                #     if futu == 2:
+                #         studentplacement_obj.future_aspect = "PLACEMENT"
+                # elif studentplacement_obj.future_aspect == "PLACEMENT":
+                #     if futu == None:
+                #         studentplacement_obj.future_aspect = "HIGHER STUDIES"
+                extrainfo_obj = ExtraInfo.objects.get(user=user)
+                extrainfo_obj.about_me = about_me
+                extrainfo_obj.age = age
+                extrainfo_obj.address = address
+                extrainfo_obj.phone_no = contact
+                extrainfo_obj.profile_picture = pic
+                extrainfo_obj.save()
+                profile = get_object_or_404(ExtraInfo, Q(user=user))
+            if 'skillsubmit' in request.POST:
+                form = AddSkill(request.POST)
+                if form.is_valid():
+                    skill = form.cleaned_data['skill']
+                    skill_rating = form.cleaned_data['skill_rating']
+                    has_obj = Has.objects.select_related('skill_id','unique_id').create(unique_id=student,
+                                                 skill_id=Skill.objects.get(skill=skill),
+                                                 skill_rating = skill_rating)
+                    has_obj.save()
+            if 'achievementsubmit' in request.POST:
+                form = AddAchievement(request.POST)
+                if form.is_valid():
+                    achievement = form.cleaned_data['achievement']
+                    achievement_type = form.cleaned_data['achievement_type']
+                    description = form.cleaned_data['description']
+                    issuer = form.cleaned_data['issuer']
+                    date_earned = form.cleaned_data['date_earned']
+                    achievement_obj = Achievement.objects.select_related('unique_id').create(unique_id=student,
+                                                                 achievement=achievement,
+                                                                 achievement_type=achievement_type,
+                                                                 description=description,
+                                                                 issuer=issuer,
+                                                                 date_earned=date_earned)
+                    achievement_obj.save()
+            if 'publicationsubmit' in request.POST:
+                form = AddPublication(request.POST)
+                if form.is_valid():
+                    publication_title = form.cleaned_data['publication_title']
+                    description = form.cleaned_data['description']
+                    publisher = form.cleaned_data['publisher']
+                    publication_date = form.cleaned_data['publication_date']
+                    publication_obj = Publication.objects.select_related('unique_id').create(unique_id=student,
+                                                                 publication_title=
+                                                                 publication_title,
+                                                                 publisher=publisher,
+                                                                 description=description,
+                                                                 publication_date=publication_date)
+                    publication_obj.save()
+            if 'patentsubmit' in request.POST:
+                form = AddPatent(request.POST)
+                if form.is_valid():
+                    patent_name = form.cleaned_data['patent_name']
+                    description = form.cleaned_data['description']
+                    patent_office = form.cleaned_data['patent_office']
+                    patent_date = form.cleaned_data['patent_date']
+                    patent_obj = Patent.objects.select_related('unique_id').create(unique_id=student, patent_name=patent_name,
+                                                       patent_office=patent_office,
+                                                       description=description,
+                                                       patent_date=patent_date)
+                    patent_obj.save()
+            if 'coursesubmit' in request.POST:
+                form = AddCourse(request.POST)
+                if form.is_valid():
+                    course_name = form.cleaned_data['course_name']
+                    description = form.cleaned_data['description']
+                    license_no = form.cleaned_data['license_no']
+                    sdate = form.cleaned_data['sdate']
+                    edate = form.cleaned_data['edate']
+                    course_obj = Course.objects.select_related('unique_id').create(unique_id=student, course_name=course_name,
+                                                       license_no=license_no,
+                                                       description=description,
+                                                       sdate=sdate, edate=edate)
+                    course_obj.save()
+            if 'projectsubmit' in request.POST:
+                form = AddProject(request.POST)
+                if form.is_valid():
+                    project_name = form.cleaned_data['project_name']
+                    project_status = form.cleaned_data['project_status']
+                    summary = form.cleaned_data['summary']
+                    project_link = form.cleaned_data['project_link']
+                    sdate = form.cleaned_data['sdate']
+                    edate = form.cleaned_data['edate']
+                    project_obj = Project.objects.create(unique_id=student, summary=summary,
+                                                         project_name=project_name,
+                                                         project_status=project_status,
+                                                         project_link=project_link,
+                                                         sdate=sdate, edate=edate)
+                    project_obj.save()
+            if 'experiencesubmit' in request.POST:
+                form = AddExperience(request.POST)
+                if form.is_valid():
+                    title = form.cleaned_data['title']
+                    status = form.cleaned_data['status']
+                    company = form.cleaned_data['company']
+                    location = form.cleaned_data['location']
+                    description = form.cleaned_data['description']
+                    sdate = form.cleaned_data['sdate']
+                    edate = form.cleaned_data['edate']
+                    experience_obj = Experience.objects.select_related('unique_id').create(unique_id=student, title=title,
+                                                               company=company, location=location,
+                                                               status=status,
+                                                               description=description,
+                                                               sdate=sdate, edate=edate)
+                    experience_obj.save()
 
+            if 'deleteskill' in request.POST:
+                hid = request.POST['deleteskill']
+                hs = Has.objects.select_related('skill_id','unique_id').get(Q(pk=hid))
+                hs.delete()
+            if 'deleteedu' in request.POST:
+                hid = request.POST['deleteedu']
+                hs = Education.objects.select_related('unique_id').get(Q(pk=hid))
+                hs.delete()
+            if 'deletecourse' in request.POST:
+                hid = request.POST['deletecourse']
+                hs = Course.objects.get(Q(pk=hid))
+                hs.delete()
+            if 'deleteexp' in request.POST:
+                hid = request.POST['deleteexp']
+                hs = Experience.objects.get(Q(pk=hid))
+                hs.delete()
+            if 'deletepro' in request.POST:
+                hid = request.POST['deletepro']
+                hs = Project.objects.get(Q(pk=hid))
+                hs.delete()
+            if 'deleteach' in request.POST:
+                hid = request.POST['deleteach']
+                hs = Achievement.objects.get(Q(pk=hid))
+                hs.delete()
+            if 'deletepub' in request.POST:
+                hid = request.POST['deletepub']
+                hs = Publication.objects.select_related('unique_id').get(Q(pk=hid))
+                hs.delete()
+            if 'deletepat' in request.POST:
+                hid = request.POST['deletepat']
+                hs = Patent.objects.get(Q(pk=hid))
+                hs.delete()
 
-    if 'pdf_gen_invitation_status' in request.POST:
+        placementschedule = PlacementSchedule.objects.select_related('notify_id').filter(
+            Q(placement_date__gte=date.today())).values_list('notify_id', flat=True)
 
-        placementstatus = None
-        if 'pdf_gen_invitation_status_placement' in request.POST:
-            stuname = request.session['mn_stuname']
-            ctc = request.session['mn_ctc']
-            cname = request.session['mn_cname']
-            rollno = request.session['mn_rollno']
+        placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+            Q(unique_id=student,
+            notify_id__in=placementschedule)).order_by('-timestamp')
 
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                           (Q(placement_type="PLACEMENT",
-                                                              company_name__icontains=cname,
-                                                              ctc__gte=ctc)),
-                                                           unique_id__in=Student.objects.filter
-                                                           ((Q(id__in=ExtraInfo.objects.filter
-                                                               (Q(user__in=User.objects.filter
-                                                                  (Q(first_name__icontains=stuname)),
-                                                                  id__icontains=rollno))
-                                                               )))))
 
-        if 'pdf_gen_invitation_status_pbi' in request.POST:
-            stuname = request.session['mn_pbi_stuname']
-            ctc = request.session['mn_pbi_ctc']
-            cname = request.session['mn_pbi_cname']
-            rollno = request.session['mn_pbi_rollno']
+        check_invitation_date(placementstatus)
 
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                Q(notify_id__in=NotifyStudent.objects.filter(
-                Q(placement_type="PBI",
-                company_name__icontains=cname,
-                ctc__gte=ctc)),
-                unique_id__in=Student.objects.filter(
-                (Q(id__in=ExtraInfo.objects.filter(
-                Q(user__in=User.objects.filter(
-                Q(first_name__icontains=stuname)),
-                id__icontains=rollno))))))).order_by('id')
+    # facult and other staff view only statistics
+    if not (current or current1 or current2):
+        return redirect('/placement/statistics/')
 
-        context = {
-            'placementstatus' : placementstatus
-        }
+    # delete the schedule
+    if 'deletesch' in request.POST:
+        delete_sch_key = request.POST['delete_sch_key']
+        try:
+            placement_schedule = PlacementSchedule.objects.select_related('notify_id').get(pk = delete_sch_key)
+            NotifyStudent.objects.get(pk=placement_schedule.notify_id.id).delete()
+            placement_schedule.delete()
+            messages.success(request, 'Schedule Deleted Successfully')
+        except Exception as e:
+            messages.error(request, 'Problem Occurred for Schedule Delete!!!')
 
-        return render_to_pdf('placementModule/pdf_invitation_status.html', context)
+    # saving all the schedule details
+    if 'schedulesubmit' in request.POST:
+        form5 = AddSchedule(request.POST, request.FILES)
+        if form5.is_valid():
+            company_name = form5.cleaned_data['company_name']
+            placement_date = form5.cleaned_data['placement_date']
+            location = form5.cleaned_data['location']
+            ctc = form5.cleaned_data['ctc']
+            time = form5.cleaned_data['time']
+            attached_file = form5.cleaned_data['attached_file']
+            placement_type = form5.cleaned_data['placement_type']
+            role_offered = request.POST.get('role')
+            description = form5.cleaned_data['description']
 
-    if 'excel_gen_invitation_status' in request.POST:
+            try:
+                comp_name = CompanyDetails.objects.filter(company_name=company_name)[0]
+            except:
+                CompanyDetails.objects.create(company_name=company_name)
 
-        placementstatus = None
-        if 'excel_gen_invitation_status_placement' in request.POST:
-            stuname = request.session['mn_stuname']
-            ctc = request.session['mn_ctc']
-            cname = request.session['mn_cname']
-            rollno = request.session['mn_rollno']
+            try:
+                role = Role.objects.filter(role=role_offered)[0]
+            except:
+                role = Role.objects.create(role=role_offered)
+                role.save()
 
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
-                                                           (Q(placement_type="PLACEMENT",
-                                                              company_name__icontains=cname,
-                                                              ctc__gte=ctc)),
-                                                           unique_id__in=Student.objects.filter
-                                                           ((Q(id__in=ExtraInfo.objects.filter
-                                                               (Q(user__in=User.objects.filter
-                                                                  (Q(first_name__icontains=stuname)),
-                                                                  id__icontains=rollno))
-                                                               )))))
 
-        if 'excel_gen_invitation_status_pbi' in request.POST:
-            stuname = request.session['mn_pbi_stuname']
-            ctc = request.session['mn_pbi_ctc']
-            cname = request.session['mn_pbi_cname']
-            rollno = request.session['mn_pbi_rollno']
+            notify = NotifyStudent.objects.create(placement_type=placement_type,
+                                                  company_name=company_name,
+                                                  description=description,
+                                                  ctc=ctc,
+                                                  timestamp=timezone.now())
 
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
-                Q(notify_id__in=NotifyStudent.objects.filter(
-                Q(placement_type="PBI",
-                company_name__icontains=cname,
-                ctc__gte=ctc)),
-                unique_id__in=Student.objects.filter(
-                (Q(id__in=ExtraInfo.objects.filter(
-                Q(user__in=User.objects.filter(
-                Q(first_name__icontains=stuname)),
-                id__icontains=rollno))))))).order_by('id')
+            schedule = PlacementSchedule.objects.select_related('notify_id').create(notify_id=notify,
+                                                        title=company_name,
+                                                        description=description,
+                                                        placement_date=placement_date,
+                                                        attached_file = attached_file,
+                                                        role=role,
+                                                        location=location, time=time)
 
-        context = {
-            'placementstatus' : placementstatus
-        }
+            notify.save()
+            schedule.save()
+            messages.success(request, "Schedule Added Successfull!!")
 
 
-        return export_to_xls_invitation_status(placementstatus)
+    schedules = PlacementSchedule.objects.select_related('notify_id').all()
 
-    form1 = SearchStudentRecord(initial={})
-    form9 = ManagePbiRecord(initial={})
-    form11 = ManagePlacementRecord(initial={})
-    form13 = SendInvite(initial={})
-    current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
-    current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
 
     context = {
-        'form1': form1,
-        'form9': form9,
-        'form11': form11,
-        'form13': form13,
-        'invitation_status_tab': invitation_status_tab,
-        'mnplacement_post': mnplacement_post,
-        'mnpbi_tab': mnpbi_tab,
-        'mnplacement_tab': mnplacement_tab,
-        'placementstatus_placement': placementstatus_placement,
-        'placementstatus_pbi': placementstatus_pbi,
+        'current': current,
         'current1': current1,
         'current2': current2,
-        'strecord_tab': strecord_tab,
-        'mnpbi_post': mnpbi_post,
-        'page_range': page_range,
-        'paginator': paginator,
-        'no_pagination': no_pagination,
-        'is_disabled': is_disabled,
+        'schedule_tab': schedule_tab,
+        'schedules': schedules,
+        'placementstatus': placementstatus,
+        'form5': form5,
     }
 
-    return render(request, 'placementModule/studentrecords.html', context)
+    return render(request, 'placementModule/placement.html', context)
+
+
+
+# def invite_status(request):
+#     '''
+#     function to check the invitation status
+#     '''
+#     user = request.user
+#     strecord_tab = 1
+#     mnpbi_tab = 0
+#     mnplacement_post = 0
+#     mnpbi_post = 0
+#     invitation_status_tab = 1
+#     placementstatus_placement = []
+#     placementstatus_pbi = []
+#     mnplacement_tab = 1
+
+#     no_pagination = 1
+#     is_disabled = 0
+#     paginator = ''
+#     page_range = ''
+#     placement_get_request = False
+#     pbi_get_request = False
+
+#     # invitation status for placement
+#     if 'studentplacementsearchsubmit' in request.POST:
+#         mnplacement_post = 1
+#         mnpbi_post = 0
+#         form = ManagePlacementRecord(request.POST)
+
+#         if form.is_valid():
+#             if form.cleaned_data['stuname']:
+#                 stuname = form.cleaned_data['stuname']
+#             else:
+#                 stuname = ''
+#             if form.cleaned_data['ctc']:
+#                 ctc = form.cleaned_data['ctc']
+#             else:
+#                 ctc = 0
+#             if form.cleaned_data['company']:
+#                 cname = form.cleaned_data['company']
+#             else:
+#                 cname = ''
+#             if form.cleaned_data['roll']:
+#                 rollno = form.cleaned_data['roll']
+#             else:
+#                 rollno = ''
+
+#             request.session['mn_stuname'] = stuname
+#             request.session['mn_ctc'] = ctc
+#             request.session['mn_cname'] = cname
+#             request.session['mn_rollno'] = rollno
+
+#             placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                        (Q(placement_type="PLACEMENT",
+#                                                           company_name__icontains=cname,
+#                                                           ctc__gte=ctc)),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=stuname)),
+#                                                               id__icontains=rollno))
+#                                                            )))))
+#             # pagination stuff starts from here
+#             total_query = placementstatus_placement.count()
+
+#             if total_query > 30:
+#                 no_pagination = 1
+#                 paginator = Paginator(placementstatus_placement, 30)
+#                 page = request.GET.get('page', 1)
+#                 placementstatus_placement = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+#     else:
+#         # when the request from pagination with some page number
+#         if request.GET.get('placement_page') != None:
+#             mnplacement_post = 1
+#             mnpbi_post = 0
+#             no_pagination = 1
+#             try:
+#                 placementstatus_placement = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                        (Q(placement_type="PLACEMENT",
+#                                                           company_name__icontains=request.session['mn_cname'],
+#                                                           ctc__gte=request.session['mn_ctc'])),
+#                                                        unique_id__in=Student.objects.filter
+#                                                        ((Q(id__in=ExtraInfo.objects.filter
+#                                                            (Q(user__in=User.objects.filter
+#                                                               (Q(first_name__icontains=request.session['mn_stuname'])),
+#                                                               id__icontains=request.session['mn_rollno']))
+#                                                            )))))
+#             except:
+#                 placementstatus_placement = []
+
+#             if placementstatus_placement != '':
+#                 total_query = placementstatus_placement.count()
+#             else:
+#                 total_query = 0
+
+#             if total_query > 30:
+#                 paginator = Paginator(placementstatus_placement, 30)
+#                 page = request.GET.get('placement_page', 1)
+#                 placementstatus_placement = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+
+#     # invitation status for pbi
+#     if 'studentpbisearchsubmit' in request.POST:
+#         mnpbi_tab = 1
+#         mnpbi_post = 1
+#         mnplacement_post = 0
+#         form = ManagePbiRecord(request.POST)
+#         if form.is_valid():
+#             if form.cleaned_data['stuname']:
+#                 stuname = form.cleaned_data['stuname']
+#             else:
+#                 stuname = ''
+#             if form.cleaned_data['ctc']:
+#                 ctc = form.cleaned_data['ctc']
+#             else:
+#                 ctc = 0
+#             if form.cleaned_data['company']:
+#                 cname = form.cleaned_data['company']
+#             else:
+#                 cname = ''
+#             if form.cleaned_data['roll']:
+#                 rollno = form.cleaned_data['roll']
+#             else:
+#                 rollno = ''
+#             request.session['mn_pbi_stuname'] = stuname
+#             request.session['mn_pbi_ctc'] = ctc
+#             request.session['mn_pbi_cname'] = cname
+#             request.session['mn_pbi_rollno'] = rollno
+#             placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                 Q(notify_id__in=NotifyStudent.objects.filter(
+#                 Q(placement_type="PBI",
+#                 company_name__icontains=cname,
+#                 ctc__gte=ctc)),
+#                 unique_id__in=Student.objects.filter(
+#                 (Q(id__in=ExtraInfo.objects.filter(
+#                 Q(user__in=User.objects.filter(
+#                 Q(first_name__icontains=stuname)),
+#                 id__icontains=rollno))))))).order_by('id')
+
+#             total_query = placementstatus_pbi.count()
+
+#             if total_query > 30:
+#                 no_pagination = 1
+#                 paginator = Paginator(placementstatus_pbi, 30)
+#                 page = request.GET.get('pbi_page', 1)
+#                 placementstatus_pbi = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+#     else:
+#         if request.GET.get('pbi_page') != None:
+#             mnpbi_tab = 1
+#             mnpbi_post = 1
+#             no_pagination = 1
+#             try:
+#                 placementstatus_pbi = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                     Q(notify_id__in=NotifyStudent.objects.filter(
+#                     Q(placement_type="PBI",
+#                     company_name__icontains=request.session['mn_pbi_cname'],
+#                                               ctc__gte=request.session['mn_pbi_ctc'])),
+#                                            unique_id__in=Student.objects.filter(
+#                                             (Q(id__in=ExtraInfo.objects.filter(
+#                                                 Q(user__in=User.objects.filter(
+#                     Q(first_name__icontains=request.session['mn_pbi_stuname'])),
+#                                                   id__icontains=request.session['mn_pbi_rollno']))
+#                                                )))))
+#             except:
+#                 placementstatus_pbi = ''
+
+#             if placementstatus_pbi != '':
+#                 total_query = placementstatus_pbi.count()
+#             else:
+#                 total_query = 0
+#             if total_query > 30:
+#                 paginator = Paginator(placementstatus_pbi, 30)
+#                 page = request.GET.get('pbi_page', 1)
+#                 placementstatus_pbi = paginator.page(page)
+#                 page = int(page)
+#                 total_page = int(page + 3)
+
+#                 if page<(paginator.num_pages-3):
+#                     if total_query > 30 and total_query <=60:
+#                         page_range = range(1, 3)
+#                     else:
+#                         page_range = range(1, total_page+1)
+
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, total_page)
+#                 else:
+#                     if page >= 5:
+#                         is_disabled = 1
+#                         page_range = range(page-2, paginator.num_pages+1)
+#                     else:
+#                         page_range = range(1, paginator.num_pages+1)
+#             else:
+#                 no_pagination = 0
+
+
+#     if 'pdf_gen_invitation_status' in request.POST:
+
+#         placementstatus = None
+#         if 'pdf_gen_invitation_status_placement' in request.POST:
+#             stuname = request.session['mn_stuname']
+#             ctc = request.session['mn_ctc']
+#             cname = request.session['mn_cname']
+#             rollno = request.session['mn_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                            (Q(placement_type="PLACEMENT",
+#                                                               company_name__icontains=cname,
+#                                                               ctc__gte=ctc)),
+#                                                            unique_id__in=Student.objects.filter
+#                                                            ((Q(id__in=ExtraInfo.objects.filter
+#                                                                (Q(user__in=User.objects.filter
+#                                                                   (Q(first_name__icontains=stuname)),
+#                                                                   id__icontains=rollno))
+#                                                                )))))
+
+#         if 'pdf_gen_invitation_status_pbi' in request.POST:
+#             stuname = request.session['mn_pbi_stuname']
+#             ctc = request.session['mn_pbi_ctc']
+#             cname = request.session['mn_pbi_cname']
+#             rollno = request.session['mn_pbi_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                 Q(notify_id__in=NotifyStudent.objects.filter(
+#                 Q(placement_type="PBI",
+#                 company_name__icontains=cname,
+#                 ctc__gte=ctc)),
+#                 unique_id__in=Student.objects.filter(
+#                 (Q(id__in=ExtraInfo.objects.filter(
+#                 Q(user__in=User.objects.filter(
+#                 Q(first_name__icontains=stuname)),
+#                 id__icontains=rollno))))))).order_by('id')
+
+#         context = {
+#             'placementstatus' : placementstatus
+#         }
+
+#         return render_to_pdf('placementModule/pdf_invitation_status.html', context)
+
+#     if 'excel_gen_invitation_status' in request.POST:
+
+#         placementstatus = None
+#         if 'excel_gen_invitation_status_placement' in request.POST:
+#             stuname = request.session['mn_stuname']
+#             ctc = request.session['mn_ctc']
+#             cname = request.session['mn_cname']
+#             rollno = request.session['mn_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+#                                                            (Q(placement_type="PLACEMENT",
+#                                                               company_name__icontains=cname,
+#                                                               ctc__gte=ctc)),
+#                                                            unique_id__in=Student.objects.filter
+#                                                            ((Q(id__in=ExtraInfo.objects.filter
+#                                                                (Q(user__in=User.objects.filter
+#                                                                   (Q(first_name__icontains=stuname)),
+#                                                                   id__icontains=rollno))
+#                                                                )))))
+
+#         if 'excel_gen_invitation_status_pbi' in request.POST:
+#             stuname = request.session['mn_pbi_stuname']
+#             ctc = request.session['mn_pbi_ctc']
+#             cname = request.session['mn_pbi_cname']
+#             rollno = request.session['mn_pbi_rollno']
+
+#             placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+#                 Q(notify_id__in=NotifyStudent.objects.filter(
+#                 Q(placement_type="PBI",
+#                 company_name__icontains=cname,
+#                 ctc__gte=ctc)),
+#                 unique_id__in=Student.objects.filter(
+#                 (Q(id__in=ExtraInfo.objects.filter(
+#                 Q(user__in=User.objects.filter(
+#                 Q(first_name__icontains=stuname)),
+#                 id__icontains=rollno))))))).order_by('id')
+
+#         context = {
+#             'placementstatus' : placementstatus
+#         }
+
+
+#         return export_to_xls_invitation_status(placementstatus)
+
+#     form1 = SearchStudentRecord(initial={})
+#     form9 = ManagePbiRecord(initial={})
+#     form11 = ManagePlacementRecord(initial={})
+#     form13 = SendInvite(initial={})
+#     current1 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement chairman"))
+#     current2 = HoldsDesignation.objects.filter(Q(working=user, designation__name="placement officer"))
+
+#     context = {
+#         'form1': form1,
+#         'form9': form9,
+#         'form11': form11,
+#         'form13': form13,
+#         'invitation_status_tab': invitation_status_tab,
+#         'mnplacement_post': mnplacement_post,
+#         'mnpbi_tab': mnpbi_tab,
+#         'mnplacement_tab': mnplacement_tab,
+#         'placementstatus_placement': placementstatus_placement,
+#         'placementstatus_pbi': placementstatus_pbi,
+#         'current1': current1,
+#         'current2': current2,
+#         'strecord_tab': strecord_tab,
+#         'mnpbi_post': mnpbi_post,
+#         'page_range': page_range,
+#         'paginator': paginator,
+#         'no_pagination': no_pagination,
+#         'is_disabled': is_disabled,
+#     }
+
+#     return render(request, 'placementModule/studentrecords.html', context)
 
 
 
@@ -3546,16 +3575,15 @@ def invitation_status(request):
 
         return render_to_pdf('placementModule/pdf_invitation_status.html', context)
 
-    if 'excel_gen_invitation_status' in request.POST:
 
-        placementstatus = None
-        if 'excel_gen_invitation_status_placement' in request.POST:
-            stuname = request.session['mn_stuname']
-            ctc = request.session['mn_ctc']
-            cname = request.session['mn_cname']
-            rollno = request.session['mn_rollno']
+    placementstatus = None
+    if 'excel_gen_invitation_status_placement' in request.POST:
+        stuname = request.session['mn_stuname']
+        ctc = request.session['mn_ctc']
+        cname = request.session['mn_cname']
+        rollno = request.session['mn_rollno']
 
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
+        placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(Q(notify_id__in=NotifyStudent.objects.filter
                                                            (Q(placement_type="PLACEMENT",
                                                               company_name__icontains=cname,
                                                               ctc__gte=ctc)),
@@ -3565,18 +3593,25 @@ def invitation_status(request):
                                                                   (Q(first_name__icontains=stuname)),
                                                                   id__icontains=rollno))
                                                                )))))
+        context = {
+            'placementstatus' : placementstatus
+        }
 
-        if 'excel_gen_invitation_status_pbi' in request.POST:
-            stuname = request.session['mn_pbi_stuname']
-            ctc = request.session['mn_pbi_ctc']
-            cname = request.session['mn_pbi_cname']
-            rollno = request.session['mn_pbi_rollno']
 
-            placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
+        return export_to_xls_invitation_status(placementstatus)
+
+    if 'excel_gen_invitation_status_pbi' in request.POST:
+    # if True:
+        stuname = request.session['mn_pbi_stuname']
+        ctc = request.session['mn_pbi_ctc']
+        cname = request.session['mn_pbi_cname']
+        rollno = request.session['mn_pbi_rollno']
+
+        placementstatus = PlacementStatus.objects.select_related('unique_id','notify_id').filter(
                 Q(notify_id__in=NotifyStudent.objects.filter(
                 Q(placement_type="PBI",
                 company_name__icontains=cname,
-                ctc__gte=ctc)),
+                ctc__gte=ctc,)),
                 unique_id__in=Student.objects.filter(
                 (Q(id__in=ExtraInfo.objects.filter(
                 Q(user__in=User.objects.filter(
@@ -5596,21 +5631,23 @@ def export_to_xls_invitation_status(qs):
 
     columns = ['Roll No.', 'Name', 'Company', 'CTC', 'Invitation Status']
 
-    for col_num in range(len(columns)):
+    for col_num in range(len(columns)): 
+
         ws.write(row_num, col_num, columns[col_num], font_style)
 
 
     font_style = xlwt.XFStyle()
 
     for student in qs:
-        row_num += 1
-
+       
         row = []
-        row.append(student.unique_id.id.id)
-        row.append(student.unique_id.id.user.first_name+' '+student.unique_id.id.user.last_name)
-        row.append(student.notify_id.company_name)
-        row.append(student.notify_id.ctc)
-        row.append(student.invitation)
+        if student.invitation=="ACCEPTED":
+            row_num += 1
+            row.append(student.unique_id.id.id)
+            row.append(student.unique_id.id.user.first_name+' '+student.unique_id.id.user.last_name)
+            row.append(student.notify_id.company_name)
+            row.append(student.notify_id.ctc)
+            row.append(student.invitation)
 
         for col_num in range(len(row)):
             ws.write(row_num, col_num, row[col_num], font_style)
diff --git a/FusionIIIT/templates/placementModule/add_placement_record.html b/FusionIIIT/templates/placementModule/add_placement_record.html
index 5bbe10290..461982804 100644
--- a/FusionIIIT/templates/placementModule/add_placement_record.html
+++ b/FusionIIIT/templates/placementModule/add_placement_record.html
@@ -173,7 +173,7 @@ <h1>New Placement Record</h1>
                           <option value="PLACEMENT" >Placement</option>
                           <option value="PBI" >PBI</option>
                           <option value="HIGHER STUDIES" >Higher Studies</option>
-                          <option value="OTHER">Other</option>
+                         
                         </select>
 
                         <label for="student_name"><b>Roll No.:</b></label>
diff --git a/FusionIIIT/templates/placementModule/placementstatistics.html b/FusionIIIT/templates/placementModule/placementstatistics.html
index dbb418f73..0d1d804f6 100644
--- a/FusionIIIT/templates/placementModule/placementstatistics.html
+++ b/FusionIIIT/templates/placementModule/placementstatistics.html
@@ -186,12 +186,12 @@
                   {% comment %}The tab menu starts here!{% endcomment %}
                   <div class="ui pointing secondary menu">
                       <a class="active item" data-tab="pastrecords">
-                          Past Records
+                          Placement Records
                       </a>
 
-                      <a class="item" data-tab="batchstats">
+                      <!-- <a class="item" data-tab="batchstats">
                           Batch Statistics
-                      </a>
+                      </a> -->
                   </div>
 
                   <div class="ui active tab" data-tab="pastrecords">
@@ -627,7 +627,7 @@ <h4 class="ui image header">
                                     </table>
                                     {% else %}
                                     <h2>No Data Found.</h2>
-                                    {% if current1 %}
+                                    {% if current2 %}
                                     <a href="{% url 'placement:add_placement_record' %}">Add Student Record</a>
                                     {% endif %}
                                     {% endif %}
@@ -836,7 +836,7 @@ <h4 class="ui image header">
                                     </table>
                                     {% else %}
                                     <h2>No Data Found.</h2>
-                                    {% if isStaff %}
+                                    {% if current2 %}
                                     <a href="{% url 'placement:add_placement_record' %}">Add Student Record</a>
                                     {% endif %}
                                     {% endif %}
diff --git a/FusionIIIT/templates/placementModule/studentrecords.html b/FusionIIIT/templates/placementModule/studentrecords.html
index a9527975b..65cf4346d 100644
--- a/FusionIIIT/templates/placementModule/studentrecords.html
+++ b/FusionIIIT/templates/placementModule/studentrecords.html
@@ -711,6 +711,8 @@
                                         <button name="studentplacementsearchsubmit" value="studentplacementsearchsubmit" class="ui fluid large primary button" type="submit">
                                             Search
                                         </button>
+                                        <!-- <a class="{% if strecord_tab %}active item{% else %}item{% endif %}" href="{% url 'placement:student_records' %}"> -->
+                                        <!-- <a href="{% url 'placement:generate_excel' %}" class="btn btn-primary">Download Excel</a> -->
                                     </div>
                                   </div>
                                 </div>
@@ -721,6 +723,12 @@
                     {% if placementstatus_placement %}
                       <br>
                       <!-- Pagination Section starts here  --->
+                      <form method="post" target="_blank" action="{% url 'placement:invitation_status' %}" class="ui form" role="form">
+                        {% csrf_token %}
+                        <input type="hidden" name="excel_gen_invitation_status_placement" value="excel_gen_invitation_status_placement">
+                        <button name="excel_gen_invitation_status_placement" value="excel_gen_invitation_status_placement" class="ui medium positive button right floated" type="submit">
+                        Excel Sheet
+                      </button></form>
                       {% if no_pagination %}
                         <center>
                           <div class="ui pagination menu">
@@ -769,17 +777,20 @@
                                 <th class="two wide">Invitation</th>
                                 <th class="two wide">Delete</th>
                             </tr>
+
                             </thead>
 
                             <tbody>
                               {% for student in placementstatus_placement %}
                                 {% if student.notify_id.placement_type == 'PLACEMENT'  %}
                                 
+                                
                                 <tr>
+                      
                                     <td>
                                         <h4 class="ui image header">
 
-                                            <div class="content">
+                                            <div class="content"> 
                                               {{ student.unique_id.id.user.first_name }} {{ student.unique_id.id.user.last_name }}
                                                 <div class="sub header">
                                                   {{ student.unique_id.id.id }}
@@ -896,21 +907,16 @@ <h4 class="ui image header">
                     {% if placementstatus_pbi %}
                       <br>
 
-                      <!--
-                      <form method="post" target="_blank" action="{% url 'placement:invitation_status' %}" class="ui form" role="form">
-                        {% csrf_token %}
-                        <input type="hidden" name="pdf_gen_invitation_status_placement" value="pdf_gen_invitation_status_placement">
-                        <button name="pdf_gen_invitation_status" value="pdf_gen_invitation_status" class="ui medium positive button right floated" type="submit">
-                        PDF
-                      </button></form>
+                      
+                     
 
                       <form method="post" target="_blank" action="{% url 'placement:invitation_status' %}" class="ui form" role="form">
                         {% csrf_token %}
-                        <input type="hidden" name="excel_gen_invitation_status_placement" value="excel_gen_invitation_status_placement">
-                        <button name="excel_gen_invitation_status" value="excel_gen_invitation_status" class="ui medium positive button right floated" type="submit">
+                        <input type="hidden" name="excel_gen_invitation_status_pbi" value="excel_gen_invitation_status_pbi">
+                        <button name="excel_gen_invitation_status_pbi" value="excel_gen_invitation_status_pbi" class="ui medium positive button right floated" type="submit">
                         Excel Sheet
                       </button></form>
-                      -->
+                     
 
                       <!-- Pagination Section starts here  --->
                     {% if no_pagination %}