Пример #1
0
def contact_messages(request):
    """List messages from the contact page

    Args:
        request:

    Returns:
    """

    # Call the API
    messages_contact = contact_message_api.get_all()

    assets = {
        "js": [
            {
                "path": "core_website_app/admin/js/messages.js",
                "is_raw": False
            },
        ],
        "css": ["core_website_app/admin/css/messages.css"],
    }

    modals = [
        "core_website_app/admin/contact_messages/modals/delete_message.html",
    ]

    return render(
        request,
        "core_website_app/admin/contact_messages.html",
        assets=assets,
        modals=modals,
        context={"contacts": messages_contact},
    )
Пример #2
0
    def get(self, request):
        """Get all Contact Message

        Args:

            request: HTTP request

        Returns:

            - code: 200
              content: List of contact messages
            - code: 500
              content: Internal server error
        """
        try:
            contact_message_list = contact_message_api.get_all()

            # Serialize object
            serializer = ContactMessageSerializer(contact_message_list,
                                                  many=True)

            # Return response
            return Response(serializer.data, status=status.HTTP_200_OK)
        except Exception as api_exception:
            content = {"message": str(api_exception)}
            return Response(content,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #3
0
    def test_contact_message_get_all_contains_contact_message_only(self, mock_get_all):
        # Arrange
        mock_message_1 = _create_mock_contact_message()
        mock_message_2 = _create_mock_contact_message(mock_pk=2, mock_name="message name 2", mock_email="*****@*****.**",
                                                      mock_content="content message 2")

        mock_get_all.return_value = [mock_message_1, mock_message_2]

        # Act
        result = contact_message_api.get_all()

        # Assert
        self.assertTrue(all(isinstance(item, ContactMessage) for item in result))
Пример #4
0
def get_all(request):
    """
    List all messages
    :param request:
    :return:
    """
    messages = contact_message_api.get_all()
    serializer = ContactMessageSerializer(messages)

    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 get_all(request):
    """ Get all messages

    Args:

        request: HTTP request

    Returns:

        - code: 200
          content: List of contact messages
        - code: 400
          content: Validation error
    """
    messages = contact_message_api.get_all()
    serializer = ContactMessageSerializer(messages)

    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)