def validate_date(cls, date_string, message, message2): date_string = datetime.datetime.strptime( date_string, "%Y-%m-%dT%H:%M:%S.%fZ").date() if date_string is not None: if datetime.datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%S.%fZ"): return raise CustomException(message, status.HTTP_400_BAD_REQUEST) raise CustomException(message2, status.HTTP_400_BAD_REQUEST)
def validate_mom(cls, time, date, message): date = datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ").date() today = datetime.date.today() ctime = datetime.datetime.now() if (((ctime < time) and (date == today))) or (date > today): raise CustomException(message, status.HTTP_400_BAD_REQUEST) return
def validate_mom(cls, time, date, message): today = datetime.date.today() now = datetime.datetime.now() current_time = now.strftime("%H:%M") ctime = datetime.datetime.strptime(current_time, '%H:%M').time() if (((ctime < time) and (date == today))) or (date > today): raise CustomException(message, status.HTTP_400_BAD_REQUEST) return
def validate_meet(cls, open_time, close_time, meetings, message): otime = datetime.datetime.strptime(open_time, '%H:%M').time() ctime = datetime.datetime.strptime(close_time, '%H:%M').time() for e in meetings: if ((otime >= e.open_time) and (otime < e.close_time)) or ((ctime > e.open_time) and (ctime <= e.close_time)): raise CustomException(message, status.HTTP_400_BAD_REQUEST) return
def validate_updated_meet(cls, meet_id, open_time, close_time, meetings, message): otime = datetime.datetime.strptime(open_time, "%Y-%m-%dT%H:%M:%S.%fZ").time() ctime = datetime.datetime.strptime(close_time, "%Y-%m-%dT%H:%M:%S.%fZ").time() for e in meetings: if e.meet_id == meet_id: continue if ((otime >= e.open_time) and (otime < e.close_time)) or ((ctime > e.open_time) and (ctime <= e.close_time)): raise CustomException(message, status.HTTP_400_BAD_REQUEST) return
def validate_date_today(cls, meeting_date, message): date_object = datetime.datetime.strptime(meeting_date, '%Y-%m-%d').date() if date_object >= datetime.datetime.today().date(): return raise CustomException(message, status.HTTP_400_BAD_REQUEST)
def validate_meeting_type(cls, meeting_type, message): if meeting_type is not None: return raise CustomException(message, status.HTTP_400_BAD_REQUEST)
def validate_contact(cls, contact_id, message): if contact_id is not None: return raise CustomException(message, status.HTTP_400_BAD_REQUEST)
def validate_time(cls, time, message): if time is not None: return raise CustomException(message, status.HTTP_400_BAD_REQUEST)
def validate_date(cls, date_string, message, message2): if date_string is not None: if datetime.datetime.strptime(date_string, '%Y-%m-%d'): return raise CustomException(message, status.HTTP_400_BAD_REQUEST) raise CustomException(message2, status.HTTP_400_BAD_REQUEST)
def validate_zone(cls, zone, msg): if zone is not None: return else: raise CustomException(msg, status.HTTP_400_BAD_REQUEST)
def validate_date_today(cls, meeting_date, message): date = datetime.datetime.strptime(meeting_date, "%Y-%m-%dT%H:%M:%S.%fZ").date() if date >= datetime.datetime.today().date(): return raise CustomException(message, status.HTTP_400_BAD_REQUEST)
def validate_superuser(cls, user, msg): if user.is_superuser: return else: raise CustomException(msg, status.HTTP_401_UNAUTHORIZED)
def validate_company(cls, self, company_name, msg): if Company_Details.objects.exclude(comp_id=self.comp_id).filter( company_name__iexact=company_name): raise CustomException(msg, status.HTTP_400_BAD_REQUEST)
def validate_username(cls, self, username, msg): if user_details.objects.exclude(id=self.id).filter( username__iexact=username): raise CustomException(msg, status.HTTP_400_BAD_REQUEST)
def validate_string(cls, input, message): if input is not None: return raise CustomException(message, status.HTTP_400_BAD_REQUEST)
def validate_email(cls, self, email, msg): if user_details.objects.exclude(id=self.id).filter( email__iexact=email): raise CustomException(msg, status.HTTP_400_BAD_REQUEST)