Пример #1
0
def registered_tutor(sender, instance, created, **kwargs):
    try:
        if created:
            schedule = Schedule(tutor=instance)
            schedule.save()
    except:
        raise ValidationError('No se registro horario al tutor')
Пример #2
0
 def validate_user(self, data):
     """Validated user isnt student."""
     email = data['email']
     student = Student.objects.filter(user__email=email)
     if student.exists() and self.context.get('create', True):
         raise ValidationError('Ya existe estudiante')
     return data
Пример #3
0
 def validate_user(self, data):
     """Validated user isnt tutor."""
     email = data['email']
     tutor = Tutor.objects.filter(user__email=email)
     if tutor.exists() and self.context.get('create', True):
         raise ValidationError('Ya existe tutor')
     return data
Пример #4
0
 def validate_token(self, data):
     """Validate token Google"""
     token = data
     CLIENT_ID = "581408483289-vlrheiceitim0evek4mrjnakqm5v07m7.apps.googleusercontent.com"
     try:
         idinfo = id_token.verify_oauth2_token(token, requests.Request(), CLIENT_ID)
         user = self.get_information_google(dict(), idinfo)
         student = Student.objects.filter(user__email=user['email'])
         if student.exists():
             raise ValidationError('Ya existe estudiante')
         return data
         self.context['user'] = get_or_create_user(user)
     except ValueError:
         raise ValidationError('Error auth GoogleAPI')
     except User.DoesNotExist:
         raise ValidationError('Credenciales incorrectas')
     return data
Пример #5
0
 def create(self, request, *args, **kwargs):
     # request.body.decode('utf-8')
     # print(request.data)
     # request.data._mutable = True
     try:
         request.data['tutor'] = Tutor.objects.get(user=request.user.pk).pk
     except Tutor.DoesNotExist:
         raise ValidationError('Tutor no existe')
     # print(request.data['certificate'])
     # serializer = CertificateSerializer(data=request.data['certificate'])
     # serializer.is_valid(raise_exception=True)
     # instance = serializer.save()
     # request.data._mutable = False
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     instance = serializer.save()
     data = KnowledgeArea_TutorViewSerializer(instance).data
     return Response(data, status=status.HTTP_201_CREATED)
Пример #6
0
 def get_object(self):
     try:
         return Student.objects.get(user=self.request.user.pk)
     except:
         raise ValidationError('Estudiante no existe')
Пример #7
0
 def get_object(self):
     try:
         return Student.objects.get(user=self.kwargs['pk'])
     except:
         raise ValidationError('Estudiante no existe')
Пример #8
0
 def get_object(self):
     try:
         return Tutor.objects.get(user=self.request.user.pk)
     except:
         raise ValidationError('Tutor no existe')