Beispiel #1
0
 def validate(self, attrs):
     file = self.initial_data.get('file', None)
     if file is None:
         raise exception.RequireValue(detail="videoCourse is require!")
     attrs['video'] = file
     attrs['title'] = file.name
     return attrs
Beispiel #2
0
 def validate(self, attrs):
     if self.initial_data.get('old_password', None) is None:
         raise exception.RequireValue(detail=f"old_password is require!!!")
     is_correct_password = self.instance.check_password(
         self.initial_data.get('old_password'))
     if is_correct_password is False:
         raise exception.APIException(detail="password is wrong!!!")
     if self.initial_data.get('old_password', None) is not None:
         attrs['new_password'] = self.initial_data.get('new_password')
     return attrs
Beispiel #3
0
 def validate(self, attrs):
     required_fields = ['email', 'username']
     for field in required_fields:
         if self.initial_data.get(field, None) is None:
             raise exception.RequireValue(detail=f"{field} is require!")
     is_teacher = self.initial_data.get('isTeacher', None)
     if is_teacher is True:
         attrs['temporary_user'] = True
         attrs['position'] = 1
     return attrs
Beispiel #4
0
 def validate(self, attrs):
     required_fields = ['photo', 'old_price',
                        'title', 'type', 'description']
     for field in required_fields:
         if self.initial_data.get(field, None) is None:
             raise exception.RequireValue(detail=f"{field} is require!")
     check_math = CourseModel.objects.filter(
         title=self.initial_data['title'].strip())
     if check_math.count() > 0:
         raise exception.ExistedValue
     return attrs
Beispiel #5
0
    def validate(self, attrs):
        required_fields = ['username', 'phone', 'name', 'email', 'photo']
        for field in required_fields:
            if self.initial_data.get(field, None) is None:
                raise exception.RequireValue(detail=f"{field} is require")
        description = self.initial_data.get('description', None)
        slogan = self.initial_data.get('slogan', None)
        if description is None:
            attrs['description'] = ""

        if slogan is None:
            attrs['description'] = ""
        return attrs
Beispiel #6
0
 def validate(self, attrs):
     code_discount = self.initial_data.get('discount', None)
     if code_discount is None:
         raise exception.RequireValue(detail="discount là bắt buộc!")
     attrs['discount'] = code_discount
     return attrs
Beispiel #7
0
 def validate(self, attrs):
     email = self.initial_data.get('email', None)
     if email is None:
         raise exception.RequireValue(detail="Trường email là bắt buộc!")
     attrs['email'] = email
     return attrs
Beispiel #8
0
 def validate(self, attrs):
     images_user = self.initial_data.get('imagesUser', None)
     if images_user is None:
         raise exception.RequireValue(detail="imagesUser is require!")
     attrs['photo'] = images_user
     return attrs