Ejemplo n.º 1
0
 def post(self, request, format=None):
     form = self.form_class(data=request.data)
     if not form.is_valid():
         raise ValueError("Invalid")
     serializer = CustomUserSerializer(data=request.data)
     if serializer.is_valid():
         user = CustomUser(**serializer.data)
         CustomUser.objects.save_data(users=[user])
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 2
0
class EnrollSerializer(serializers.ModelSerializer):
    userId = CustomUserSerializer(read_only=True)
    subjectId = SubjectSerializer(read_only=True)

    class Meta:
        model = Enroll
        fields = '__all__'
Ejemplo n.º 3
0
class CommentSerializer(serializers.ModelSerializer):
    commentPostId = PostSerializer(read_only=True, required=False)
    commentDetail = serializers.CharField()
    commentUserId = CustomUserSerializer(read_only=True, required=False)
    commentUpdateDate = serializers.DateTimeField(required=False)

    class Meta:
        model = Comment
        fields = '__all__'
Ejemplo n.º 4
0
class SubmitSerializer(serializers.ModelSerializer):
    assignmentId = AssignmentSerializer(required=False, read_only = True)
    submitUpdateDate = serializers.DateTimeField(required=False)
    submitDetail = serializers.CharField(allow_null=True, allow_blank=True)
    submitFile = serializers.FileField(required=False, allow_null=True)
    submitFileName = serializers.CharField(required=False, max_length=64, allow_null=True, allow_blank=True)
    submitUserId = CustomUserSerializer(required=False, read_only=True)

    class Meta:
        model = Submit
        fields = '__all__'
Ejemplo n.º 5
0
class PostSerializer(serializers.ModelSerializer):
    isNotice = serializers.BooleanField(default=True)
    postUpdateDate = serializers.DateTimeField(required=False)
    postUserId = CustomUserSerializer(read_only=True, required=False)
    postDetail = serializers.CharField()
    postName = serializers.CharField(max_length=255)
    postSubjectId = SubjectSerializer(read_only=True, required=False)

    class Meta:
        model = Post
        fields = '__all__'
Ejemplo n.º 6
0
def user(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    print("요청 들어옴")
    # 해당하는 user 1명의 정보 반환, 개인페이지에서 사용가능
    if request.method == 'GET':
        serializer = CustomUserSerializer(user)
        return Response(serializer.data)

    elif request.method == 'PUT':
        # 유저 정보 변경
        user.username = request.data['username']
        user.isAdmin = request.data['isAdmin']
        user.save()
        serializer = CustomUserSerializer(user, many=False)
        return Response(serializer.data)

    elif request.method == 'DELETE':
        # 유저 정보 삭제
        serializer = CustomUserSerializer(user, many=False)
        user.delete()
        return Response(serializer.data)
Ejemplo n.º 7
0
def genre_detail(request, user_id):
    user = get_object_or_404(User, pk=user_id)

    if request.method == 'PUT':
        serializer = CustomUserSerializer(user,
                                          data=request.data,
                                          partial=True)

        if serializer.is_valid(raise_exception=True):
            serializer.save(like_genre=request.data['like_genre'])

            return Response({'message': '변경 완료'})
    else:
        like_genres = user.like_genre.all()

        content = {}

        for genre in like_genres:
            content[genre.name] = genre.id

        return Response(content)
Ejemplo n.º 8
0
class SubjectSerializer(serializers.ModelSerializer):
    subjectName = serializers.CharField(max_length=255)
    subjectTimeList = serializers.CharField()
    subjectInstructorId = CustomUserSerializer(read_only=True)
    subjectClass = serializers.IntegerField()
    subjectGrade = serializers.IntegerField()
    invitationCode = serializers.CharField(max_length=16,
                                           required=False,
                                           allow_null=True)

    class Meta:
        model = Subject
        fields = '__all__'
Ejemplo n.º 9
0
 def post(self, request, *args, **kwargs):
     """
     Method for logging the user in.  Returns the logged in user,
     their newly-created token, and its expiry date.
     """
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = serializer.validated_data
     instance, token = AuthToken.objects.create(user)
     return Response({
         'user': CustomUserSerializer(user, context=self.get_serializer_context()).data,
         'token': token,
         'expiry_date': instance.expiry
     })
Ejemplo n.º 10
0
 def changepass(self, request, *args, **kwargs):
     user_data = request.data
     tokenString = self.request.headers.get('Authorization').split(' ')[1]
     token = Token.objects.get(key=tokenString)
     user = CustomUser.objects.get(id=token.user.id)
     oldPassword = user_data['password_old']
     newPassword = user_data['password']
     if user.check_password(oldPassword):
         user.set_password(newPassword)
         serializer = CustomUserSerializer(
             user, many=False, context={'request': request})
         return Response(serializer.data, status=status.HTTP_202_ACCEPTED)
     else:
         return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)
Ejemplo n.º 11
0
 def create(self, request, *args, **kwargs):
     user_data = request.data
     try:
         user = CustomUser.objects.create_user(
             email=user_data['email'], password=user_data['password'])
     except MultiValueDictKeyError as e:
         content = {'Value is required': str(e)}
         return Response(content, status=status.HTTP_400_BAD_REQUEST)
     except IntegrityError as e:
         content = {'Value error': 'email exists in system'}
         return Response(content, status=status.HTTP_400_BAD_REQUEST)
     user.save()
     serializer = CustomUserSerializer(
         user, many=False, context={'request': request})
     return Response(serializer.data, status=status.HTTP_201_CREATED)
Ejemplo n.º 12
0
    def post(self, request, *args, **kwargs):
        """
        Method for registering a user with the given data. Uses the 
        RegisterSerializer to create the user and also creates a 
        token with the Django REST Knox library. Includes the expiry date
        for the frontend to use.
        """

        # Create the user
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.save()

        # Create a token for teh user
        instance, token = AuthToken.objects.create(user)

        return Response({
            'user': CustomUserSerializer(user, context=self.get_serializer_context()).data,
            'token': token,
            'expiry_date': instance.expiry
        })
Ejemplo n.º 13
0
def users(request):
    users = User.objects.all()
    serializer = CustomUserSerializer(users, many=True)
    return Response(serializer.data)
Ejemplo n.º 14
0
class ProjectMembershipDetailSerializer(serializers.ModelSerializer):
    user = CustomUserSerializer(read_only=True)

    class Meta:
        model = ProjectMembership
        fields = ["id", "role", "category", "user"]
Ejemplo n.º 15
0
class ScheduleSerializer(serializers.ModelSerializer):
    userId = CustomUserSerializer(required=False, read_only=True)
Ejemplo n.º 16
0
 def get(self, request, format=None):
     filter_params = self.request.query_params
     users = CustomUser.objects.filter(**filter_params.dict())
     serializer = CustomUserSerializer(users, many=True)
     return Response(serializer.data)
Ejemplo n.º 17
0
class UserProfileSerializer(serializers.ModelSerializer):
  user = CustomUserSerializer(read_only=True)
  class Meta:
    model = UserProfile
    fields = '__all__'