FusionIIIT/applications/hostel_management/views.py
def hostel_view(request, context={}):
    """
    This is a general function which is used for all the views functions.
    This function renders all the contexts required in templates.
    @param:
        request - HttpRequest object containing metadata about the user request.
        context - stores any data passed during request,by default is empty.

    @variables:
        hall_1_student - stores all hall 1 students
        hall_3_student - stores all hall 3 students
        hall_4_student - stores all hall 4 students
        all_hall - stores all the hall of residence
        all_notice - stores all notices of hostels (latest first)
    """
    
    all_hall = Hall.objects.all()
    halls_student = {}
    for hall in all_hall:
        halls_student[hall.hall_id] = Student.objects.filter(hall_no=int(hall.hall_id[4])).select_related('id__user')

    hall_staffs = {}
    for hall in all_hall:
        hall_staffs[hall.hall_id] = StaffSchedule.objects.filter(hall=hall).select_related('staff_id__id__user')

    all_notice = HostelNoticeBoard.objects.all().order_by("-id")
    hall_notices = {}
    for hall in all_hall:
        hall_notices[hall.hall_id] = HostelNoticeBoard.objects.filter(hall=hall).select_related('hall','posted_by__user')

    Staff_obj = Staff.objects.all().select_related('id__user')
    hall1 = Hall.objects.get(hall_id='hall1')
    hall3=Hall.objects.get(hall_id='hall3')
    hall4=Hall.objects.get(hall_id='hall4')
    hall1_staff = StaffSchedule.objects.filter(hall=hall1)
    hall3_staff = StaffSchedule.objects.filter(hall=hall3)
    hall4_staff = StaffSchedule.objects.filter(hall=hall4)
    hall_caretakers = HallCaretaker.objects.all()

    hall_student=""
    current_hall=""
    get_avail_room=[]
    get_hall=get_caretaker_hall(hall_caretakers,request.user) 
    if get_hall:
        total_rooms=HallRoom.objects.filter(hall=get_hall)
        for room in total_rooms:
            if(room.room_cap>room.room_occupied):
                get_avail_room.append(room)

        get_hall_num=re.findall('[0-9]+',str(get_hall.hall_id))
        hall_student=Student.objects.filter(hall_no=int(str(get_hall_num[0]))).select_related('id__user')
        current_hall='hall'+str(get_hall_num[0])
    

    hall_caretaker_user=[]
    for caretaker in hall_caretakers:
        hall_caretaker_user.append(caretaker.staff.id.user)      

    todays_date = date.today()
    current_year = todays_date.year
    current_month = todays_date.month

    if current_month != 1:
        worker_report = WorkerReport.objects.filter(Q(hall__hall_id=current_hall, year=current_year, month=current_month) | Q(hall__hall_id=current_hall, year=current_year, month=current_month-1))
    else:
        worker_report = WorkerReport.objects.filter(hall__hall_id=current_hall, year=current_year-1, month=12)

    attendance = HostelStudentAttendence.objects.all().select_related()
    halls_attendance = {}
    for hall in all_hall:
        halls_attendance[hall.hall_id] = HostelStudentAttendence.objects.filter(hall=hall).select_related()


    context = {
        
        'all_hall': all_hall,
        'all_notice': all_notice,
        'staff':Staff_obj,
        'hall1_staff' : hall1_staff,
        'hall3_staff' : hall3_staff,
        'hall4_staff' : hall4_staff,
        'hall_caretaker' : hall_caretaker_user,
        'room_avail' : get_avail_room,
        'hall_student':hall_student,
        'worker_report': worker_report,
        'halls_student': halls_student,
        'current_hall' : current_hall,
        'hall_staffs': hall_staffs,
        'hall_notices': hall_notices,
        'attendance': halls_attendance,
        **context
    }

    return render(request, 'hostelmanagement/hostel.html', context)

    This is a general function which is used for all the views functions.
    This function renders all the contexts required in templates.
    @param:
        request - HttpRequest object containing metadata about the user request.
        context - stores any data passed during request,by default is empty.

    @variables:
        hall_1_student - stores all hall 1 students
        hall_3_student - stores all hall 3 students
        hall_4_student - stores all hall 4 students
        all_hall - stores all the hall of residence
        all_notice - stores all notices of hostels (latest first)
    
This is a general function which is used for all the views functions.
This function renders all the contexts required in templates.
@param:
request - HttpRequest object containing metadata about the user request.
context - stores any data passed during request,by default is empty.


This is a general function which is used for all the views functions . This function renders all the contexts required in templates . @param : request - HttpRequest object containing metadata about the user request . context - stores any data passed during request by default is empty .
def hostel_view(request, context={}):
    all_hall = Hall.objects.all()
    halls_student = {}
    for hall in all_hall:
        halls_student[hall.hall_id] = Student.objects.filter(hall_no=int(hall.hall_id[4])).select_related('id__user')
    hall_staffs = {}
    for hall in all_hall:
        hall_staffs[hall.hall_id] = StaffSchedule.objects.filter(hall=hall).select_related('staff_id__id__user')
    all_notice = HostelNoticeBoard.objects.all().order_by("-id")
    hall_notices = {}
    for hall in all_hall:
        hall_notices[hall.hall_id] = HostelNoticeBoard.objects.filter(hall=hall).select_related('hall','posted_by__user')
    Staff_obj = Staff.objects.all().select_related('id__user')
    hall1 = Hall.objects.get(hall_id='hall1')
    hall3=Hall.objects.get(hall_id='hall3')
    hall4=Hall.objects.get(hall_id='hall4')
    hall1_staff = StaffSchedule.objects.filter(hall=hall1)
    hall3_staff = StaffSchedule.objects.filter(hall=hall3)
    hall4_staff = StaffSchedule.objects.filter(hall=hall4)
    hall_caretakers = HallCaretaker.objects.all()
    hall_student=""
    current_hall=""
    get_avail_room=[]
    get_hall=get_caretaker_hall(hall_caretakers,request.user) 
    if get_hall:
        total_rooms=HallRoom.objects.filter(hall=get_hall)
        for room in total_rooms:
            if(room.room_cap>room.room_occupied):
                get_avail_room.append(room)
        get_hall_num=re.findall('[0-9]+',str(get_hall.hall_id))
        hall_student=Student.objects.filter(hall_no=int(str(get_hall_num[0]))).select_related('id__user')
        current_hall='hall'+str(get_hall_num[0])
    hall_caretaker_user=[]
    for caretaker in hall_caretakers:
        hall_caretaker_user.append(caretaker.staff.id.user)      
    todays_date = date.today()
    current_year = todays_date.year
    current_month = todays_date.month
    if current_month != 1:
        worker_report = WorkerReport.objects.filter(Q(hall__hall_id=current_hall, year=current_year, month=current_month) | Q(hall__hall_id=current_hall, year=current_year, month=current_month-1))
    else:
        worker_report = WorkerReport.objects.filter(hall__hall_id=current_hall, year=current_year-1, month=12)
    attendance = HostelStudentAttendence.objects.all().select_related()
    halls_attendance = {}
    for hall in all_hall:
        halls_attendance[hall.hall_id] = HostelStudentAttendence.objects.filter(hall=hall).select_related()
    context = {
        'all_hall': all_hall,
        'all_notice': all_notice,
        'staff':Staff_obj,
        'hall1_staff' : hall1_staff,
        'hall3_staff' : hall3_staff,
        'hall4_staff' : hall4_staff,
        'hall_caretaker' : hall_caretaker_user,
        'room_avail' : get_avail_room,
        'hall_student':hall_student,
        'worker_report': worker_report,
        'halls_student': halls_student,
        'current_hall' : current_hall,
        'hall_staffs': hall_staffs,
        'hall_notices': hall_notices,
        'attendance': halls_attendance,
        **context
    }
    return render(request, 'hostelmanagement/hostel.html', context)
def hostel_view ( request , context = { } ) : all_hall = Hall . objects . all ( ) halls_student = { } for hall in all_hall : halls_student [ hall . hall_id ] = Student . objects . filter ( hall_no = int ( hall . hall_id [ 4 ] ) ) . select_related ( 'id__user' ) hall_staffs = { } for hall in all_hall : hall_staffs [ hall . hall_id ] = StaffSchedule . objects . filter ( hall = hall ) . select_related ( 'staff_id__id__user' ) all_notice = HostelNoticeBoard . objects . all ( ) . order_by ( "-id" ) hall_notices = { } for hall in all_hall : hall_notices [ hall . hall_id ] = HostelNoticeBoard . objects . filter ( hall = hall ) . select_related ( 'hall' , 'posted_by__user' ) Staff_obj = Staff . objects . all ( ) . select_related ( 'id__user' ) hall1 = Hall . objects . get ( hall_id = 'hall1' ) hall3 = Hall . objects . get ( hall_id = 'hall3' ) hall4 = Hall . objects . get ( hall_id = 'hall4' ) hall1_staff = StaffSchedule . objects . filter ( hall = hall1 ) hall3_staff = StaffSchedule . objects . filter ( hall = hall3 ) hall4_staff = StaffSchedule . objects . filter ( hall = hall4 ) hall_caretakers = HallCaretaker . objects . all ( ) hall_student = "" current_hall = "" get_avail_room = [ ] get_hall = get_caretaker_hall ( hall_caretakers , request . user ) if get_hall : total_rooms = HallRoom . objects . filter ( hall = get_hall ) for room in total_rooms : if ( room . room_cap > room . room_occupied ) : get_avail_room . append ( room ) get_hall_num = re . findall ( '[0-9]+' , str ( get_hall . hall_id ) ) hall_student = Student . objects . filter ( hall_no = int ( str ( get_hall_num [ 0 ] ) ) ) . select_related ( 'id__user' ) current_hall = 'hall' + str ( get_hall_num [ 0 ] ) hall_caretaker_user = [ ] for caretaker in hall_caretakers : hall_caretaker_user . append ( caretaker . staff . id . user ) todays_date = date . today ( ) current_year = todays_date . year current_month = todays_date . month if current_month != 1 : worker_report = WorkerReport . objects . filter ( Q ( hall__hall_id = current_hall , year = current_year , month = current_month ) | Q ( hall__hall_id = current_hall , year = current_year , month = current_month - 1 ) ) else : worker_report = WorkerReport . objects . filter ( hall__hall_id = current_hall , year = current_year - 1 , month = 12 ) attendance = HostelStudentAttendence . objects . all ( ) . select_related ( ) halls_attendance = { } for hall in all_hall : halls_attendance [ hall . hall_id ] = HostelStudentAttendence . objects . filter ( hall = hall ) . select_related ( ) context = { 'all_hall' : all_hall , 'all_notice' : all_notice , 'staff' : Staff_obj , 'hall1_staff' : hall1_staff , 'hall3_staff' : hall3_staff , 'hall4_staff' : hall4_staff , 'hall_caretaker' : hall_caretaker_user , 'room_avail' : get_avail_room , 'hall_student' : hall_student , 'worker_report' : worker_report , 'halls_student' : halls_student , 'current_hall' : current_hall , 'hall_staffs' : hall_staffs , 'hall_notices' : hall_notices , 'attendance' : halls_attendance , ** context } return render ( request , 'hostelmanagement/hostel.html' , context )
This is a general function which is used for all the views functions.
This is a general function which is used for all the views functions .
"""
    This is a general function which is used for all the views functions.
    This function renders all the contexts required in templates.
    @param:
        request - HttpRequest object containing metadata about the user request.
        context - stores any data passed during request,by default is empty.

    @variables:
        hall_1_student - stores all hall 1 students
        hall_3_student - stores all hall 3 students
        hall_4_student - stores all hall 4 students
        all_hall - stores all the hall of residence
        all_notice - stores all notices of hostels (latest first)
    """
request
context