Exemplo n.º 1
0
 def post(self, request):
     email = request.data.get('email')
     password = request.data.get('password')
     if email is None or password is None:
         raise CommonException(detail=gettext(messages.NO_CREDENTIALS),
                               code=codes.NO_CREDENTIALS)
     try:
         user = MainUser.objects.get(email=email)
         if not user.check_password(password):
             raise CommonException(detail=gettext(
                 messages.WRONG_EMAIL_OR_PASSWORD),
                                   code=codes.WRONG_EMAIL_OR_PASSWORD)
     except MainUser.DoesNotExist:
         raise CommonException(
             detail={gettext(messages.EMAIL_DOESNT_EXIST)},
             code=codes.EMAIL_DOESNT_EXIST)
     token = get_token(user)
     user.last_login = datetime.now()
     user.save()
     url = "http://dev.cheesenology.kz:8080/camunda/app/admin/default/#/login"
     serializer = MainUserSerializer(user)
     return Response({
         'token': token,
         'user': serializer.data
     },
                     status=status.HTTP_200_OK)
Exemplo n.º 2
0
 def login(self, request):
     serializer = self.get_serializer(data=request.query_params)
     serializer.is_valid(raise_exception=True)
     user, token = serializer.login()
     return Response({
         'user': MainUserSerializer(user).data,
         'token': token
     })
Exemplo n.º 3
0
class FavoriteArticleSerializer(serializers.ModelSerializer):
    article = ArticleSerializer()
    user = MainUserSerializer()

    class Meta:
        model = FavoriteArticle
        fields = '__all__'
        read_only_fields = ('user', )
Exemplo n.º 4
0
 def get(self, request):
     serializer = LoginSerializer(data=request.query_params)
     serializer.is_valid(raise_exception=True)
     token, user = serializer.login()
     return Response({
         'token': token,
         'user': MainUserSerializer(user).data
     })
Exemplo n.º 5
0
 def put(self, request):
     serializer = ChangeDetailsSerializer(data=request.data,
                                          context={'request': self.request})
     serializer.is_valid(raise_exception=True)
     serializer.change_details()
     user = MainUserSerializer(self.request.user)
     return Response((gettext(USER_DETAILS_CHANGED), user.data),
                     status=status.HTTP_200_OK)
Exemplo n.º 6
0
 def login(self, request):
     serializer = LoginSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = serializer.validated_data['user']
     token = get_token(user)
     return Response({
         'user': MainUserSerializer(user).data,
         'token': token
     })
Exemplo n.º 7
0
class TaskSerializer(TaskShortSerializer):
    creator = MainUserSerializer(read_only=True)

    class Meta(TaskShortSerializer.Meta):
        fields = TaskShortSerializer.Meta.fields + ('description', 'creator',
                                                    'executor', 'priority')

    def validate_priority(self, value):
        if value not in PRIORITY:
            raise serializers.ValidationError('there is no such priority')
        return value
Exemplo n.º 8
0
class TaskSerializer(serializers.ModelSerializer):
    owner = MainUserSerializer(read_only=True)

    class Meta:
        model = Task
        fields = '__all__'

    def create(self, validated_data):
        validated_data['owner'] = self.context['request'].user
        task = Task.objects.create(**validated_data)
        task.save()
        return task
Exemplo n.º 9
0
class ProjectSerializer(ProjectShortSerializer):
    creator = MainUserSerializer(read_only=True)

    class Meta(ProjectShortSerializer.Meta):
        fields = ProjectShortSerializer.Meta.fields + ('description',
                                                       'creator')

    def create(self, validated_data):
        logger.info('start creation of project')
        project = Project.objects.create(**validated_data)
        logger.info('end of project creation ')
        return project
Exemplo n.º 10
0
class TaskSerializer(serializers.ModelSerializer):
    # common task serializer
    owner = MainUserSerializer(read_only=True)

    class Meta:
        model = Task
        fields = ('id', 'name', 'created', 'due', 'owner', 'completed')

    def create(self, validated_data):
        validated_data['owner'] = self.context['request'].user
        task = Task.objects.create(**validated_data)
        task.save()
        return task
Exemplo n.º 11
0
class TaskDocumentShortSerializer(serializers.ModelSerializer):
    creator = MainUserSerializer(read_only=True)
    # document = serializers.FileField(write_only=True)
    # document_url = serializers.SerializerMethodField(read_only=True)
    read_only_fields = ('task', )

    class Meta:
        model = TaskDocument
        fields = ('id', 'document', 'creator', 'task')

    def get_document_url(self, obj):
        if obj.document:
            return self.context['request'].build_absolute_uri(obj.document.url)
        return None
Exemplo n.º 12
0
def activate(request, uuid):
    try:
        activation = Activation.objects.get(uuid=uuid)
    except Activation.DoesNotExist:
        raise ValidationError(messages.LINK_INVALID)
    activation.is_valid(raise_exception=True)
    serializer = RegistrationSerializer(
        data={
            'email': activation.email,
            'password': activation.password,
            'full_name': activation.full_name
        })
    serializer.is_valid(raise_exception=True)
    user = serializer.complete(activation)
    return Response({'user': MainUserSerializer(user).data})
Exemplo n.º 13
0
 def profile(self, request):
     user = self.get_object()
     return Response(MainUserSerializer(user).data)
Exemplo n.º 14
0
class TaskCommentSerializer(TaskCommentShortSerializer):
    creator = MainUserSerializer(read_only=True)

    class Meta(TaskCommentShortSerializer.Meta):
        fields = TaskCommentShortSerializer.Meta.fields + ('creator',
                                                           'created_at')
Exemplo n.º 15
0
class CommentGetSerializer(CommentSerializer):
    task = TaskSerializer()
    creator = MainUserSerializer()

    class Meta(CommentSerializer.Meta):
        fields = CommentSerializer.Meta.fields
Exemplo n.º 16
0
 def get(self, request):
     user = self.request.user
     serializer = MainUserSerializer(user)
     return Response(serializer.data)
Exemplo n.º 17
0
 def post(self, request):
     serializer = RegisterSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = serializer.complete()
     return Response(MainUserSerializer(user).data)
Exemplo n.º 18
0
 def signup(self, request):
     serializer = MainUserSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data)
Exemplo n.º 19
0
 def change_password(self, request):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = serializer.change()
     return Response({'user': MainUserSerializer(user).data})