Skip to content

Views


Views are used with Centurion ERP to Fetch the data for rendering.

Info

Centurion release v1.3.0 added a feature lock to ALL Views and the current API. From this release, there is a new API at endpoint api/v2. As such we will only be using DRF ViewSets. This is required as the UI is being separated from the Centurion Codebase to its own repository. This means that Centurion will become an API only codebase. Release 2.0.0 will remove the current UI and api from Centurion. See # for details.

Requirements

  • Views are class based

  • Inherits from one of the following base class':

    • Index Viewset api.viewsets.common.CommonViewSet

    • Model Viewset api.viewsets.common.ModelViewSet

    • Model Viewset that are to be Read-Only api.viewsets.common.ReadOnlyModelViewSet

  • ALL views are ViewSets

  • Views are saved within the module the model is from under path viewsets/

  • views are documented at the class level for the swagger UI.

  • Index Viewsets must be tested against tests from api.tests.abstract.viewsets import ViewSetCommon

  • Model VieSets must be tested against the following tests:

    • Unit Test Cases from api.tests.abstract.viewsets import ViewSetModel

    • Functional test cases from api.tests.abstract.api_serializer_viewset import SerializersTestCases

    • Functional test cases from api.tests.abstract.api_permissions_viewset import APIPermission

    • Functional test cases (Only required if model has an API endpoint)_from api.tests.abstract.test_metadata_functional import MetadataAttributesFunctional

    • Functional test cases (Only required if model has nav menu entry)from api.tests.abstract.test_metadata_functional import MetaDataNavigationEntriesFunctional

  • View Added to Navigation

Permissions

If you wish to deviate from the standard CRUD permissions, define a function called get_dynamic_permissions within the view/ViewSet. The function must return a list of permissions. This is useful if you have added additional permissions to a model.

Example of the function get_dynamic_permissions

def get_dynamic_permissions(self):

    if self.action == 'create':

        self.permission_required = [
            'core.random_permission_name',
        ]

    else:

        raise ValueError('unable to determine the action_keyword')

    return super().get_permission_required()

Although Centurion ERP is a Rest API application, there is a UI. The UI uses data from Centurion's API to render the view that the end user sees. One of those items is the navigation structure.

Location of the navigation is in app/api/react_ui_metadata.py under the attribute _nav.

Menu Entry

When adding a view, that is also meant to be seen by the end user, a navigation entry must be added to the correct navgation menu. The entry is a python dictionary and has the following format.

{
    '<app name>.<permission name>': {
        "display_name": "<menu entry name>",
        "name": "<html id>",
        "icon": "<menu entry icon>",
        "link": "<relative url.>"
    }
}
  • app name Optional is the centurion application name the model belongs to. This entry should only be supplied if the application name for the entry does not match the application for the navigation menu.

  • permission name is the centurion permission required for this menu entry to be rendered for the end user.

  • display_name Menu entry name that the end user will see

  • name This is used as part of the html rendering of the page. must be unique across ALL menu entries

  • icon Optional if specified, this is the name of the icon that the UI will place next to the menu entry. If this is not specified, the name key is used as the icon name.

  • link the relative URL for the entry. this will be the relative URL of the API after the API's version number. i.e. /api/v2/assistance/ticket/request would become /assistance/ticket/request

Testing of the navigation is via api.tests.unit.test_navigation_menu.py If the item has a navigation menu entry the setUpTestData will need to be updated, along with test cases for the entry.

The navigation menu is obtained by the UI as part of the metadata. The structure of the menu is a python dictionary in the following format:

 {
        '<app name>': {
            "display_name": "<Menu entry>",
            "name": "<menu id>",
            "pages": {
                '<menu entries>'
            }
        }
 }
  • app name the centurion application name the menu belongs to.

  • display_name Menu name that the end user will see

  • name This is used as part of the html rendering of the page. must be unique across ALL menu entries

  • pages Menu entry dictionaries.

Upon the UI requesting the navigation menu, the users permission are obtained, and if they have the permission for the menu entry within any organization, they will be presented with the menu that has a menu entries.

Pre v1.3 Docs

Warning

These docs are depreciated

Views are used with Centurion ERP to Fetch the data for rendering as html. We have templated our views to aid in quick development. We have done this by adding to our views the required pieces of logic so as to ensure the right information is available. The available API can be found within the API Views docs.

The views that we use are:

  • Index

    Models index page

  • Add

    For adding data to model tables

  • Change

    Changing data within a model

  • Delete

    Delete a model

  • Display

    Display a model

Common test cases are available for views. These test cases can be found within the API docs under model view test cases.

Requirements - Depreciated

All views are to meet the following requirements:

  • is defined as a class

  • View class inherits from one of the above listed views

  • View class has the following attributes definedL

    • form_class for the display of forms.

    • model for which data model to use.

  • Add and change views to use a form class

Tests

The following unit test cases exist for views:

Tip

The AllViews test class is an aggregation of all views. This class is the recommended test class to include if the model uses all available views.

Docs to clean up

Note

The below documentation is still to be developed. As such what is written below may be incorrect.

Templates

The base template includes blocks that are designed to assist in rendering your content. The following blocks are available:

  • title - The page and title

  • content_header_icon - Header icon that is middle aligned with the page title, floating right.

  • body - The html content of the page

template.html.j2
{% extends 'base.html.j2' %}

{% block title %}{% endblock %}
{% block content_header_icon %}<span title="View History" id="content_header_icon">H</span>{% endblock %}

{% block body %}

your content here

{% endblock %}

About:

This page forms part of our Project Centurion ERP.

Page Metadata
Version: ToDo: place files short git commit here
Date Created: 2024-07-12
Date Edited: 2024-12-08

Contribution:

Would You like to contribute to our Centurion ERP project? You can assist in the following ways:

 

ToDo: Add the page list of contributors