Esempio n. 1
0
    def _validate_id(employee_id=None, department_id=None, project_id=None):
        if not any([k for k in [employee_id, department_id, project_id]]):
            raise UUnprocessableEntity(
                '''At least one of employee_id, department_id, project_id
                must be existed''')

        if employee_id and not any([k for k in [department_id, project_id]]):
            raise UUnprocessableEntity(
                'department_id or project_id is required')
Esempio n. 2
0
    def _validate_criteria(criterias):
        total_ratio = sum([c['ratio'] for c in criterias])
        if round(total_ratio, 3) != 1:
            raise UUnprocessableEntity('Total ratio must be equal 1')

        for c in criterias:
            c['name'] = c['name'].strip()
Esempio n. 3
0
 def _validate_time(query):
     start_time = query.get('start_time', None)
     end_time = query.get('end_time', None)
     try:
         # 2019-10-02 00:00:00
         if start_time:
             start_time = datetime.datetime.strptime(
                 start_time, '%Y-%m-%d %H:%M:%S').astimezone(pytz.utc)
         if end_time:
             end_time = datetime.datetime.strptime(
                 end_time, '%Y-%m-%d %H:%M:%S').astimezone(pytz.utc)
         return start_time, end_time
     except Exception:
         raise UUnprocessableEntity('Time invalid')
Esempio n. 4
0
    def check_exist(self, **condition):
        record = self.first(**condition)

        if not record:
            return None
        raise UUnprocessableEntity(f'{self.model.__name__} is exist')