示例#1
0
def get(request):
    """
        Get an account request

        Parameters:
            request (HttpRequest): request

        Returns:
            Response object
    """
    try:
        # Get parameters
        account_request_id = request.DATA['request_id']
        try:
            requests = account_request_api.get(account_request_id)
            serializer = AccountRequestSerializer(requests)

            if serializer.is_valid():
                return Response(serializer.data, status=status.HTTP_200_OK)
            else:
                content = {'message': 'Serialization failed'}
                return Response(content, status=status.HTTP_400_BAD_REQUEST)

        except Exception as api_exception:
            content = {'message': api_exception.message}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

    except Exception as e:
        content = {'message': 'Expected parameters not provided.'}
        logger.exception(e.message)
        return Response(content, status=status.HTTP_400_BAD_REQUEST)
示例#2
0
def accept(request):
    """
        Accept an account request

        Parameters:
            request (HttpRequest): request

        Returns:
            Response object
    """
    try:
        # Get parameters
        request_id = request.DATA['requestid']
        account_request_from_api = account_request_api.get(request_id)
        try:
            user_request = account_request_api.accept(account_request_from_api,
                                                      send_mail=False)
        except Exception as api_exception:
            content = {'message': api_exception.message}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

        # Serialize the request
        serializer = AccountRequestSerializer(user_request)

        if serializer.is_valid():
            return Response(serializer.data, status=status.HTTP_200_OK)
        else:
            content = {'message': 'Serialization failed'}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

    except Exception as e:
        content = {'message': 'Expected parameters not provided.'}
        logger.exception(e.message)
        return Response(content, status=status.HTTP_400_BAD_REQUEST)
示例#3
0
def post(request):
    """ Create a new account request

    Parameters:

        {
            "username": "******",
            "firstname": "firstname",
            "lastname": "lastname",
            "password": "******",
            "email": "email"
        }

    Args:

        request: HTTP request

    Returns:

        - code: 200
          content: Requested Account
        - code: 400
          content: Validation error / missing parameters
    """
    try:
        # Get parameters
        username = request.DATA['username']
        first_name = request.DATA['firstname']
        last_name = request.DATA['lastname']
        password = request.DATA['password']
        email = request.DATA['email']

        account_request_from_request = AccountRequest(username, first_name,
                                                      last_name, password,
                                                      email)
        try:
            # Create the request
            request_content = account_request_api.insert(
                account_request_from_request)
            # Serialize the request
            serializer = AccountRequestSerializer(request_content)
            if serializer.is_valid():
                return Response(serializer.data, status=status.HTTP_200_OK)
            else:
                content = {'message': 'Serialization failed'}
                return Response(content, status=status.HTTP_400_BAD_REQUEST)

        except Exception as api_exception:
            content = {'message': api_exception.message}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

    except Exception as e:
        content = {'message': 'Expected parameters not provided.'}
        logger.exception(e.message)
        return Response(content, status=status.HTTP_400_BAD_REQUEST)
示例#4
0
def get_all(request):
    """
        List all account requests

        Parameters:
            request (HttpRequest): request

        Returns:
            Response object
    """
    requests = account_request_api.get_all()
    serializer = AccountRequestSerializer(requests)

    if serializer.is_valid():
        return Response(serializer.data, status=status.HTTP_200_OK)
    else:
        content = {'message': 'Serialization failed'}
        return Response(content, status=status.HTTP_400_BAD_REQUEST)
示例#5
0
def post(request):
    """
        Post a new account request

        Parameters:
            request (HttpRequest): request

        Returns:
            Response object
    """
    try:
        # Get parameters
        username = request.DATA['username']
        first_name = request.DATA['firstname']
        last_name = request.DATA['lastname']
        password = request.DATA['password']
        email = request.DATA['email']

        account_request_from_request = AccountRequest(username, first_name,
                                                      last_name, password,
                                                      email)
        try:
            # Create the request
            request_content = account_request_api.insert(
                account_request_from_request)
            # Serialize the request
            serializer = AccountRequestSerializer(request_content)
            if serializer.is_valid():
                return Response(serializer.data, status=status.HTTP_200_OK)
            else:
                content = {'message': 'Serialization failed'}
                return Response(content, status=status.HTTP_400_BAD_REQUEST)

        except Exception as api_exception:
            content = {'message': api_exception.message}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

    except Exception as e:
        content = {'message': 'Expected parameters not provided.'}
        logger.exception(e.message)
        return Response(content, status=status.HTTP_400_BAD_REQUEST)
示例#6
0
def get(request):
    """ Get an account request

    Parameters:

        {
            "request_id": "request_id"
        }

    Args:

        request: HTTP request

    Returns:

        - code: 200
          content: List of account requests
        - code: 400
          content: Validation error / api exceptions / missing parameters
    """
    try:
        # Get parameters
        account_request_id = request.DATA['request_id']
        try:
            requests = account_request_api.get(account_request_id)
            serializer = AccountRequestSerializer(requests)

            if serializer.is_valid():
                return Response(serializer.data, status=status.HTTP_200_OK)
            else:
                content = {'message': 'Serialization failed'}
                return Response(content, status=status.HTTP_400_BAD_REQUEST)

        except Exception as api_exception:
            content = {'message': api_exception.message}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

    except Exception as e:
        content = {'message': 'Expected parameters not provided.'}
        logger.exception(e.message)
        return Response(content, status=status.HTTP_400_BAD_REQUEST)
示例#7
0
def get_all(request):
    """ Get all account requests

    Args:

        request: HTTP request

    Returns:

        - code: 200
          content: List of account requests
        - code: 400
          content: Validation error
    """
    requests = account_request_api.get_all()
    serializer = AccountRequestSerializer(requests)

    if serializer.is_valid():
        return Response(serializer.data, status=status.HTTP_200_OK)
    else:
        content = {'message': 'Serialization failed'}
        return Response(content, status=status.HTTP_400_BAD_REQUEST)