FusionIIIT/applications/hostel_management/views.py
def staff_edit_schedule(request):
    """
    This function is responsible for creating a new or updating an existing staff schedule.
    @param:
       request - HttpRequest object containing metadata about the user request.

    @variables:
       start_time - stores start time of the schedule.
       end_time - stores endtime of the schedule.
       staff_name - stores name of staff.
       staff_type - stores type of staff.
       day - stores assigned day of the schedule.
       staff - stores Staff instance related to staff_name.
       staff_schedule - stores StaffSchedule instance related to 'staff'.
       hall_caretakers - stores all hall caretakers.
    """
    if request.method == 'POST':
        start_time= datetime.datetime.strptime(request.POST["start_time"],'%H:%M').time()
        end_time= datetime.datetime.strptime(request.POST["end_time"],'%H:%M').time()
        staff_name=request.POST["Staff_name"]
        staff_type=request.POST["staff_type"]
        day=request.POST["day"]

        staff=Staff.objects.get(pk=staff_name)
        try:
            staff_schedule=StaffSchedule.objects.get(staff_id=staff)
            staff_schedule.day=day
            staff_schedule.start_time=start_time
            staff_schedule.end_time=end_time
            staff_schedule.staff_type=staff_type
            staff_schedule.save()
            messages.success(request, 'Staff schedule updated successfully.')
        except:
            hall_caretakers = HallCaretaker.objects.all()
            get_hall=""
            get_hall=get_caretaker_hall(hall_caretakers,request.user)
            StaffSchedule(hall=get_hall,staff_id=staff,day=day,staff_type=staff_type,start_time=start_time,end_time=end_time).save()
            messages.success(request, 'Staff schedule created successfully.')
    return HttpResponseRedirect(reverse("hostelmanagement:hostel_view"))

    This function is responsible for creating a new or updating an existing staff schedule.
    @param:
       request - HttpRequest object containing metadata about the user request.

    @variables:
       start_time - stores start time of the schedule.
       end_time - stores endtime of the schedule.
       staff_name - stores name of staff.
       staff_type - stores type of staff.
       day - stores assigned day of the schedule.
       staff - stores Staff instance related to staff_name.
       staff_schedule - stores StaffSchedule instance related to 'staff'.
       hall_caretakers - stores all hall caretakers.
    
This function is responsible for creating a new or updating an existing staff schedule.
@param:
request - HttpRequest object containing metadata about the user request.

@variables:
start_time - stores start time of the schedule.
end_time - stores endtime of the schedule.
staff_name - stores name of staff.
staff_type - stores type of staff.
day - stores assigned day of the schedule.
staff - stores Staff instance related to staff_name.
staff_schedule - stores StaffSchedule instance related to 'staff'.
hall_caretakers - stores all hall caretakers.
This function is responsible for creating a new or updating an existing staff schedule . @param : request - HttpRequest object containing metadata about the user request . @variables : start_time - stores start time of the schedule . end_time - stores endtime of the schedule . staff_name - stores name of staff . staff_type - stores type of staff . day - stores assigned day of the schedule . staff - stores Staff instance related to staff_name . staff_schedule - stores StaffSchedule instance related to ' staff ' . hall_caretakers - stores all hall caretakers .
def staff_edit_schedule(request):
    if request.method == 'POST':
        start_time= datetime.datetime.strptime(request.POST["start_time"],'%H:%M').time()
        end_time= datetime.datetime.strptime(request.POST["end_time"],'%H:%M').time()
        staff_name=request.POST["Staff_name"]
        staff_type=request.POST["staff_type"]
        day=request.POST["day"]
        staff=Staff.objects.get(pk=staff_name)
        try:
            staff_schedule=StaffSchedule.objects.get(staff_id=staff)
            staff_schedule.day=day
            staff_schedule.start_time=start_time
            staff_schedule.end_time=end_time
            staff_schedule.staff_type=staff_type
            staff_schedule.save()
            messages.success(request, 'Staff schedule updated successfully.')
        except:
            hall_caretakers = HallCaretaker.objects.all()
            get_hall=""
            get_hall=get_caretaker_hall(hall_caretakers,request.user)
            StaffSchedule(hall=get_hall,staff_id=staff,day=day,staff_type=staff_type,start_time=start_time,end_time=end_time).save()
            messages.success(request, 'Staff schedule created successfully.')
    return HttpResponseRedirect(reverse("hostelmanagement:hostel_view"))
def staff_edit_schedule ( request ) : if request . method == 'POST' : start_time = datetime . datetime . strptime ( request . POST [ "start_time" ] , '%H:%M' ) . time ( ) end_time = datetime . datetime . strptime ( request . POST [ "end_time" ] , '%H:%M' ) . time ( ) staff_name = request . POST [ "Staff_name" ] staff_type = request . POST [ "staff_type" ] day = request . POST [ "day" ] staff = Staff . objects . get ( pk = staff_name ) try : staff_schedule = StaffSchedule . objects . get ( staff_id = staff ) staff_schedule . day = day staff_schedule . start_time = start_time staff_schedule . end_time = end_time staff_schedule . staff_type = staff_type staff_schedule . save ( ) messages . success ( request , 'Staff schedule updated successfully.' ) except : hall_caretakers = HallCaretaker . objects . all ( ) get_hall = "" get_hall = get_caretaker_hall ( hall_caretakers , request . user ) StaffSchedule ( hall = get_hall , staff_id = staff , day = day , staff_type = staff_type , start_time = start_time , end_time = end_time ) . save ( ) messages . success ( request , 'Staff schedule created successfully.' ) return HttpResponseRedirect ( reverse ( "hostelmanagement:hostel_view" ) )
This function is responsible for creating a new or updating an existing staff schedule.
This function is responsible for creating a new or updating an existing staff schedule .
"""
    This function is responsible for creating a new or updating an existing staff schedule.
    @param:
       request - HttpRequest object containing metadata about the user request.

    @variables:
       start_time - stores start time of the schedule.
       end_time - stores endtime of the schedule.
       staff_name - stores name of staff.
       staff_type - stores type of staff.
       day - stores assigned day of the schedule.
       staff - stores Staff instance related to staff_name.
       staff_schedule - stores StaffSchedule instance related to 'staff'.
       hall_caretakers - stores all hall caretakers.
    """
request