diff --git a/mtypes.py b/mtypes.py index f2871a3..f7d93ef 100644 --- a/mtypes.py +++ b/mtypes.py @@ -50,34 +50,50 @@ class Event_State_Status(StrEnum): @strawberry.type class Event_Status: - state: Event_State_Status = Event_State_Status.incomplete + state: Event_State_Status = Event_State_Status.incomplete # type: ignore # room: Event_Room_Status = Event_Room_Status.unapproved # budget: Event_Budget_Status = Event_Budget_Status.unapproved room: bool = False budget: bool = False + cc_approver: str | None = None + cc_approver_time: str | None = None + slo_approver: str | None = None + slo_approver_time: str | None = None + slc_approver: str | None = None + slc_approver_time: str | None = None # def __init__ (self, state: Event_State_Status = None, room: Event_Room_Status = None, budget: Event_Budget_Status = None) : # self.state: Event_State_Status = Event_State_Status.incomplete if state is None else state # self.room: Event_Room_Status = Event_Room_Status.unapproved if room is None else room # self.budget: Event_Budget_Status = Event_Budget_Status.unapproved if budget is None else budget + def __init__( self, - state: Event_State_Status = Event_State_Status.incomplete, + state: Event_State_Status = Event_State_Status.incomplete, # type: ignore room: bool = False, budget: bool = False, cc_approver: str | None = None, + cc_approver_time: str | None = None, slo_approver: str | None = None, + slo_approver_time: str | None = None, slc_approver: str | None = None, + slc_approver_time: str | None = None, ): self.state = state self.room = room self.budget = budget + self.cc_approver = cc_approver + self.cc_approver_time = cc_approver_time + self.slo_approver = slo_approver + self.slo_approver_time = slo_approver_time + self.slc_approver = slc_approver + self.slc_approver_time = slc_approver_time # Event Modes diff --git a/mutations.py b/mutations.py index 5cac37b..ed23eeb 100644 --- a/mutations.py +++ b/mutations.py @@ -1,5 +1,5 @@ import strawberry -from datetime import timedelta +from datetime import timedelta, datetime from pydantic import HttpUrl, parse_obj_as from fastapi.encoders import jsonable_encoder import os @@ -254,6 +254,10 @@ def progressEvent( raise noaccess_error event_instance = Event.parse_obj(event_ref) + # get current time + current_time = datetime.now() + time_str = current_time.strftime("%d-%m-%Y %I:%M %p") + if event_instance.status.state == Event_State_Status.incomplete: if user["role"] != "club" or user["uid"] != event_instance.clubid: raise noaccess_error @@ -263,9 +267,13 @@ def progressEvent( "room": False, # or len(event_instance.location) == 0, "state": Event_State_Status.pending_cc.value, - "cc_approver": event_instance.status.cc_approver, - "slc_approver": event_instance.status.slc_approver, - "slo_approver": event_instance.status.slo_approver, + + "cc_approver": None, + "slc_approver": None, + "slo_approver": None, + "cc_approver_time": "Not Approved", + "slc_approver_time": "Not Approved", + "slo_approver_time": "Not Approved", } elif event_instance.status.state == Event_State_Status.pending_cc: @@ -279,6 +287,9 @@ def progressEvent( "cc_approver": user["uid"], "slc_approver": event_instance.status.slc_approver, "slo_approver": event_instance.status.slo_approver, + "cc_approver_time": time_str, + "slc_approver_time": event_instance.status.slc_approver_time, + "slo_approver_time": event_instance.status.slo_approver_time, } if cc_progress_budget is not None: updation["budget"] = cc_progress_budget @@ -292,8 +303,13 @@ def progressEvent( if not updation["budget"]: updation["state"] = Event_State_Status.pending_budget.value elif not updation["room"]: + # if budget is approved + updation["slc_approver_time"] = None updation["state"] = Event_State_Status.pending_room.value else: + # if both are approved + updation["slc_approver_time"] = None + updation["slo_approver_time"] = None updation["state"] = Event_State_Status.approved.value elif event_instance.status.state == Event_State_Status.pending_budget: @@ -307,11 +323,15 @@ def progressEvent( "slc_approver": user["uid"], "slo_approver": event_instance.status.slo_approver, "cc_approver": event_instance.status.cc_approver, + "cc_approver_time": event_instance.status.cc_approver_time, + "slc_approver_time": time_str, + "slo_approver_time": event_instance.status.slo_approver_time, } if not updation["room"]: updation["state"] = Event_State_Status.pending_room.value else: + updation["slo_approver_time"] = time_str updation["state"] = Event_State_Status.approved.value elif event_instance.status.state == Event_State_Status.pending_room: @@ -326,6 +346,9 @@ def progressEvent( "slo_approver": user["uid"], "slc_approver": event_instance.status.slc_approver, "cc_approver": event_instance.status.cc_approver, + "cc_approver_time": event_instance.status.cc_approver_time, + "slc_approver_time": event_instance.status.slc_approver_time, + "slo_approver_time": time_str, } elif event_instance.status.state == Event_State_Status.approved: @@ -341,6 +364,9 @@ def progressEvent( "cc_approver": event_instance.status.cc_approver, "slc_approver": event_instance.status.slc_approver, "slo_approver": event_instance.status.slo_approver, + "cc_approver_time": event_instance.status.cc_approver_time, + "slc_approver_time": event_instance.status.slc_approver_time, + "slo_approver_time": event_instance.status.slo_approver_time, } upd_ref = eventsdb.update_one({"_id": eventid}, {"$set": {"status": updation}}) @@ -348,44 +374,44 @@ def progressEvent( raise noaccess_error event_ref = eventsdb.find_one({"_id": eventid}) - event = Event.parse_obj(event_ref) + updated_event_instance = Event.parse_obj(event_ref) # trigger mail notification # Data Preparation for the mailing mail_uid = user["uid"] - mail_club = getClubNameEmail(event.clubid, email=True, name=True) + mail_club = getClubNameEmail(updated_event_instance.clubid, email=True, name=True) if mail_club is None: raise Exception("Club does not exist.") else: clubname, mail_club = mail_club - mail_event_title = event.name - mail_eventlink = getEventLink(event.code) - mail_description = event.description + mail_event_title = updated_event_instance.name + mail_eventlink = getEventLink(updated_event_instance.code) + mail_description = updated_event_instance.description if mail_description == "": mail_description = "N/A" - student_count = event.population + student_count = updated_event_instance.population mail_location = "" - if event.mode == Event_Mode.online: + if updated_event_instance.mode == Event_Mode.online: mail_location = "online" student_count = "N/A" else: mail_location = ", ".join( - [getattr(Event_Full_Location, loc) for loc in event.location] + [getattr(Event_Full_Location, loc) for loc in updated_event_instance.location] ) equipment, additional = "N/A", "N/A" - if event.equipment: - equipment = event.equipment - if event.additional: - additional = event.additional + if updated_event_instance.equipment: + equipment = updated_event_instance.equipment + if updated_event_instance.additional: + additional = updated_event_instance.additional ist_offset = timedelta(hours=5, minutes=30) - start_dt = event.datetimeperiod[0] + ist_offset - end_dt = event.datetimeperiod[1] + ist_offset + start_dt = updated_event_instance.datetimeperiod[0] + ist_offset + end_dt = updated_event_instance.datetimeperiod[1] + ist_offset event_start_time = ( str(start_dt.strftime("%d-%m-%Y")) + " " + str(start_dt.strftime("%H:%M")) ) @@ -393,7 +419,10 @@ def progressEvent( str(end_dt.strftime("%d-%m-%Y")) + " " + str(end_dt.strftime("%H:%M")) ) - poc_details, poc_phone = getUser(event.poc, info.context.cookies) + poc = getUser(updated_event_instance.poc, info.context.cookies) + if not poc: + raise Exception("POC does not exist.") + poc_details, poc_phone = poc poc_name = poc_details["firstName"] + " " + poc_details["lastName"] poc_email = poc_details["email"] poc_roll = poc_details["rollno"] @@ -413,9 +442,9 @@ def progressEvent( eventlink=mail_eventlink, ) - if event.status.state == Event_State_Status.pending_room: + if updated_event_instance.status.state == Event_State_Status.pending_room: mail_body = PROGRESS_EVENT_BODY_FOR_SLO.safe_substitute( - event_id=event.code, + event_id=updated_event_instance.code, club=clubname, event=mail_event_title, description=mail_description, @@ -432,7 +461,7 @@ def progressEvent( ) mail_to = [] - if event.status.state == Event_State_Status.pending_cc: + if updated_event_instance.status.state == Event_State_Status.pending_cc: mail_to = getRoleEmails("cc") # Mail to club also for the successful submission of the event @@ -440,13 +469,13 @@ def progressEvent( mail_club, ] mail_subject_club = CLUB_EVENT_SUBJECT.safe_substitute( - event_id=event.code, + event_id=updated_event_instance.code, event=mail_event_title, ) mail_body_club = SUBMIT_EVENT_BODY_FOR_CLUB.safe_substitute( event=mail_event_title, eventlink=mail_eventlink, - event_id=event.code, + event_id=updated_event_instance.code, club=clubname, description=mail_description, start_time=event_start_time, @@ -465,17 +494,17 @@ def progressEvent( toRecipients=mail_to_club, cookies=info.context.cookies, ) - if event.status.state == Event_State_Status.pending_budget: + if updated_event_instance.status.state == Event_State_Status.pending_budget: mail_to = getRoleEmails("slc") - if event.status.state == Event_State_Status.pending_room: + if updated_event_instance.status.state == Event_State_Status.pending_room: mail_to = getRoleEmails("slo") - if event.status.state == Event_State_Status.approved: + if updated_event_instance.status.state == Event_State_Status.approved: # mail to the club email mail_to = [ mail_club, ] mail_subject = CLUB_EVENT_SUBJECT.safe_substitute( - event_id=event.code, + event_id=updated_event_instance.code, event=mail_event_title, ) mail_body = APPROVED_EVENT_BODY_FOR_CLUB.safe_substitute( @@ -493,7 +522,7 @@ def progressEvent( cookies=info.context.cookies, ) - return EventType.from_pydantic(event) + return EventType.from_pydantic(updated_event_instance) @strawberry.mutation