Exemple #1
0
 def delete(self, request, pk, format=None):
     schoolClass = utils.getObject(Class, pk)
     if not schoolClass:
         return Response('Class does not exist',
                         status=status.HTTP_400_BAD_REQUEST)
     schoolClass.delete()
     return Response('Class deleted', status=status.HTTP_204_NO_CONTENT)
Exemple #2
0
 def get(self, request, pk, format=None):
     schoolClass = utils.getObject(Class, pk)
     if not schoolClass:
         return Response('Class does not exist',
                         status=status.HTTP_204_NO_CONTENT)
     serializer = ClassSerializer(schoolClass, many=False)
     return Response(serializer.data, status=status.HTTP_200_OK)
Exemple #3
0
 def delete(self, request, pk, format=None):
     student = utils.getObject(Student, pk)
     if not student:
         return Response('Student does not exist',
                         status=status.HTTP_400_BAD_REQUEST)
     student.delete()
     return Response('Student deleted', status=status.HTTP_204_NO_CONTENT)
Exemple #4
0
 def get(self, request, pk, format=None):
     student = utils.getObject(Student, pk)
     if not student:
         return Response('Student does not exist',
                         status=status.HTTP_204_NO_CONTENT)
     serializer = StudentSerializer(student, many=False)
     return Response(serializer.data, status=status.HTTP_200_OK)
Exemple #5
0
 def patch(self, request, pk, format=None):
     schoolClass = utils.getObject(Class, pk)
     if not schoolClass:
         return Response('Class does not exist',
                         status=status.HTTP_204_NO_CONTENT)
     try:
         data = StudentForm(request.data, False).form
         objSaved = utils.updateObject(Class, schoolClass, data)
         serializer = ClassSerializer(objSaved, many=False)
         return Response(serializer.data, status=status.HTTP_200_OK)
     except ValidationError as error:
         return Response(error, status=status.HTTP_400_BAD_REQUEST)
Exemple #6
0
 def __init__(self, data, allowAllData):
     self.form = {}
     all_fields = [f.name for f in Student._meta.get_fields()]
     forbidden_update_fields = ['pk', 'registration']
     for field in data:
         field = field if field != 'id' else 'pk'
         if field == 'school_class':
             if not getObject(Class, data[field]):
                 raise ValidationError("Class does not exist")
         if field in all_fields:
             if allowAllData or (not allowAllData
                                 and field not in forbidden_update_fields):
                 if field == 'date_birth':
                     self.form[field] = dt.strptime(data[field],
                                                    "%d/%m/%Y").date()
                 else:
                     self.form[field] = data[field]