## Django views Most django views that make up the UX for PeeringDB are located in `views.py` Templates for these views can be found in `templates/site` ## Javascript PeeringDB uses the following third party js libraries: - [jQuery](https://jquery.com/) DOM manipulation - [20c-core](https://github.com/20c/js-core) class managment / inheritance / data loading - [20c-edit](https://github.com/20c/js-edit) wiring of forms to REST API, seamless switching between view and editor - [20c-list-util](https://github.com/20c/js-listutil) list filtering and sorting - [autocomplete-light](https://django-autocomplete-light.readthedocs.io/en/master/) autocomplete fields - [dom-purify](https://github.com/cure53/DOMPurify) santize DOM - [showdown](https://github.com/showdownjs/showdown) markdown to html - [js-cookie](https://github.com/js-cookie/js-cookie) cookie utils These libraries are to be found in the `/static` directory PeeringDB specific javascript code can be found in these files: - `/static/peeringdb.js`: main javascript code - REST API client - advanced search - custom 20c-edit input types - custom 20c-edit editor handlers - data loaders - ix-f post mortem, preview and review tools - quick search - api key permissions - user permissions - org user editor - `/static/peeringdb.admin.js`: django-admin aditions - org merge tool ### Entity views In order to render the `org`, `net`, `fac` and `ix` views a single template is used. That template exists at `templates/site/view.html` Properties are passed through to this templates from their respective views in `views.py` - `views.py::view_network` - `views.py::view_facility` - `views.py::view_exchange` - `views.py::view_organization` ### Data is built by using the REST api serializers We use the REST API data serialization to build the data piped into those entity views. ```py data = InternetExchangeSerializer(exchange, context={"user": request.user}).data ``` This allows us to make use of the permissioning of sensitive data according to the user's viewing permissions that already exists within the REST API functionality. Data is passed through to the template in field definitions using a `dict` for each field. These field definitions get turned into UI elements that provide both a normal view rendering of the property as well as an `edit-mode` form field. On the frontend, this UX behavior is handled by the [20c-edit](https://github.com/20c/js-edit) library. ### Entity field definitions Each field definition has the following common properties: - `name` (`str`): the name of the field as it exists in the REST API (*required*) - `label` (`str`): the label of the field as it is shown in the UX (*required, i18n*) - `value` (`mixed`): the value (*required*) - `type` (`str`): field type - defaults to `string` - reference to possible values below - `readonly` (`bool`): if `True` property is not editable - `help_text` (`str`): tooltip text - `admin` (`bool`): only visible to object administrators Some types have specific properties, find those listed below: ### Field types - `string` (default) - `number` - `flags`: renders checkboxes for boolean flags - `value` (`list`): one entry for each checkbox (flag), each item should be a `dict` containing `name` and `value` keys (*required*) - `url` - `list` - `data` (`str`): data loader name (*required*) - reference to data loaders below - `multiple` (`bool`): allow multi select - `email` - `entity_link`: link to another peeringdb object (org for example) - `link` (`str`): relative url path (*required*) - `sub`: starts a new sub section in the UX - `group`: starts a new group of form elements that will target a separate API endpoint. - `target` (`str`): api target for these form elements in the format of "api:{reftag}:{update|create|delete}" (*required*) - `id` (`int`): api target id (object id) (*required* if target is `update` or `delete`) - `payload` (`list`): can specify extra payload to send with the API write call, each item should be a `dict` containing `name` and `value` keys ### Data Loaders for list elements `