def create_new_model(self, *args, **kwargs) -> Model: location_id = kwargs.get('location_id', None) if location_id: location_service = LocationFormService() location = location_service.get_model(_id=location_id) if isinstance(location, Location): meeting_started_datetime = kwargs['started_time'] meeting_finished_datetime = kwargs['finished_time'] if self.__check_valid_meeting_datetime( meeting_started_datetime, meeting_finished_datetime): # check location boundary time location_boundary_checker = LocationBoundaryChecker() if location_boundary_checker.execute( location, meeting_started_datetime, meeting_finished_datetime): # check available location if location.is_multi_access: return self.__create_meeting(*args, **kwargs) meeting_service = self._get_service() location_meetings = meeting_service.get_available_meetings( location_id=location_id) location_available_checker = LocationAvailableChecker() if location_available_checker.execute( location_meetings, meeting_started_datetime, meeting_finished_datetime): return self.__create_meeting(*args, **kwargs) else: raise InvalidTimeException() else: raise LocationTimeBoundaryException() else: raise InvalidLocationIdException()
def __create_available_times_blocks(self, location_id, date: datetime.date): if location_id: location_service = LocationFormService() location = location_service.get_model(_id=location_id) if location: location = location.serialize() location_opened_time = datetime.strptime( location['opened_time'], '%H:%M:%S').time() location_closed_time = datetime.strptime( location['closed_time'], '%H:%M:%S').time() meeting_service = self._get_service() location_meetings = meeting_service.get_meetings_on_date( date=date, location_id=location_id) available_block_block = self._create_available_block_getter() occupied_block_getter = self._create_occupied_block_getter() occupied_block = occupied_block_getter.get_time_block( location_meetings=location_meetings) available_block = available_block_block.get_time_block( date=date, location_closed_time=location_closed_time, location_opened_time=location_opened_time, meeting_time_blocks=occupied_block) return available_block else: raise InvalidLocationIdException()
def _validate_time_fields(self, meeting, *args, **kwargs) -> dict: location_id = kwargs.get('location_id', meeting.location_id) meeting_started_datetime = kwargs.get('started_time', meeting.started_time) meeting_finished_datetime = kwargs.get('finished_time', meeting.finished_time) location_service = LocationFormService() location = location_service.get_model(_id=location_id) # CHECK UPDATE TIME location_boundary_checker = LocationBoundaryChecker() if location_boundary_checker.execute(location, meeting_started_datetime, meeting_finished_datetime): meeting_service = MeetingFormService() location_meetings = meeting_service.get_available_meetings( location_id=location_id) location_available_checker = LocationUpdateChecker() if location_available_checker.execute(meeting.id, location_meetings, meeting_started_datetime, meeting_finished_datetime): # the reset logic that reset all attendees states to false return self.__reset_attendees_states(meeting, **kwargs) else: raise InvalidTimeException() else: raise LocationTimeBoundaryException()
def __validate_location_id(meeting, **kwargs) -> dict: if isinstance(meeting, Meeting): location_id = kwargs.get('location_id', meeting.location_id) location_service = LocationFormService() location = location_service.get_model(_id=location_id) if isinstance(location, Location): return kwargs else: raise InvalidLocationIdException()
def _add_periodic_state(self, **kwargs) -> dict: location_service = LocationFormService() location = location_service.get_model(_id=kwargs['location_id']) if location: if not location.need_approval: kwargs['state'] = True kwargs['is_approval'] = True else: kwargs['state'] = False kwargs['is_approval'] = False return kwargs
def __create_xsl(self): meeting_service = self._prepared_service( base_service=MeetingLocationService()) location_service = self._prepared_service( base_service=LocationFormService()) if isinstance(meeting_service, MeetingLocationService): writer = ScheduleWriter() for location_id in self.__location_ids: location = location_service.get_model(_id=location_id) self.__location_names.append(location.name) meetings = meeting_service.get_location_meetings( location_id=location_id, from_date=self.__from_date, to_date=self.__to_date) writer.init_location( **{ 'location_name': location.name, 'from': self.__from_date, 'to': self.__to_date, 'meetings': meetings }) self.__xls.append({ 'path': writer.export(export_name='vMeeting_' + self.__f_date + ':' + self.__t_date) })
def create_new_model(self, *args, **kwargs) -> Model: """ New meeting need to wait for approval from location_manager All meeting create activities that use this service have default state and is_approval input data fields :param args: :param kwargs: :return: New meeting with state and is_approval equal to False """ location_service = LocationFormService() location = location_service.get_model(_id=kwargs['location_id']) if location: if location.need_approval: kwargs['state'] = False kwargs['is_approval'] = False else: kwargs['state'] = True kwargs['is_approval'] = True return super(MeetingApprovalCreateDecorator, self).create_new_model(*args, **kwargs)
def _create_service(self) -> Service: return LocationFormService()
def _create_form_service( self, service=LocationFormService()) -> FormService: return service
def __create_location_name(self, location_id: int) -> str: location = self._prepared_service( base_service=LocationFormService()).get_model(_id=location_id) location = location.serialize() return '{name} - {address}'.format(name=location['name'], address=location['address'])