Interfaces¶
Tools for automating interactions.
Version: 0.1.0-x
AJAX¶
Conveniently and consistently register AJAX views across a project.
Component Reference: AJAX
CLI¶
Utilities for working with command line interfaces.
Component Reference: CLI
constants¶
-
superdjango.interfaces.cli.constants.
DEFAULT_OUTPUT_FORMAT
= 'plain'¶ The default output format.
-
class
superdjango.interfaces.cli.constants.
EXIT
[source]¶ Bases:
object
Constants for standardizing shell exit codes.
-
superdjango.interfaces.cli.constants.
EXIT_FAILURE
= 1¶ A shortcut for a shell exit code of “failure”.
-
superdjango.interfaces.cli.constants.
EXIT_SUCCESS
= 0¶ A shortcut for a shell exit code of “success”.
-
superdjango.interfaces.cli.constants.
EXIT_UNKNOWN
= 99¶ An unknown shell exit code.
-
class
superdjango.interfaces.cli.constants.
OUTPUT_FORMAT
[source]¶ Bases:
object
The output formats supported by python-tabulate.
The
MARKDOWN
format is the same aspipe
.
-
superdjango.interfaces.cli.constants.
OUTPUT_FORMAT_CHOICES
= ['fancy_grid', 'github', 'grid', 'html', 'jira', 'latex', 'latex_booktabs', 'latex_raw', 'markdown', 'mediawiki', 'moinmoin', 'orgtbl', 'pipe', 'plain', 'presto', 'psql', 'rst', 'simple', 'textile', 'youtrack']¶ Command line choices for all supported output formats.
-
superdjango.interfaces.cli.constants.
OUTPUT_FORMAT_COMMON_CHOICES
= ['html', 'markdown', 'plain', 'rst', 'simple']¶ Command line choices for the most common output formats.
library¶
-
class
superdjango.interfaces.cli.library.
Row
(number=None, values=None)[source]¶ Bases:
object
A row in tabular (command line) output.
-
class
superdjango.interfaces.cli.library.
Table
(headings=None, formatting='plain', title=None)[source]¶ Bases:
object
A table for tabular (command line) output.
-
__init__
(headings=None, formatting='plain', title=None)[source]¶ Initialize a table.
- Parameters
headings (list[str]) – A list of headings.
formatting (str) – The output format of the table.
title (str) – The title of the table.
Note
Output is generated by python-tabulate. See https://bitbucket.org/astanin/python-tabulate/
-
Hooks¶
A simple alternative to Django’s signal handling system.
Component Reference: Hooks
library¶
-
class
superdjango.interfaces.hooks.library.
HookManager
(module_name='hooks')[source]¶ Bases:
object
Serves as registry and interface for hooks.
-
__init__
(module_name='hooks')[source]¶ Initialize the hook manager.
- Parameters
module_name – The name of the module to look for hooks.
-
REST¶
A lightweight interface for easily registering Django REST Framework resources.
Component Reference: REST
interfaces¶
-
class
superdjango.interfaces.rest.interfaces.
API
[source]¶ Bases:
object
Capture REST API resources.
# settings.py INSTALLED_APPS = [ "superdjango.interfaces.reset.apps.AutoConfig", ] # urls.py from rest_framework import routers from superdjango.interfaces.reset import api router = routers.DefaultRouter() urlpatterns = [ # ... path('api/v1/', include(api.get_urls(router))), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), ]
library¶
-
class
superdjango.interfaces.rest.library.
REST
[source]¶ Bases:
object
A utility class for collecting REST API information.
# <app_name>/api/serializers.py from rest_framework import serializers from ..models import Category, Objective class CategorySerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Category fields = ( "label", "value", ) class ObjectiveSerializer(serializers.HyperlinkedModelSerializer): categories = serializers.HyperlinkedIdentityField(view_name="objectives-api-category-detail") client = serializers.HyperlinkedIdentityField(view_name="clients-api-client-detail") class Meta: model = Objective fields = ( "annual_resolved_value", "cached_percentage_complete", "categories", "client", "description", "end_date", "percentage_complete_override", "priority", "stage", "start_date", "title", ) # <app_name>/api/views.py from rest_framework import viewsets from ..models import Category, Objective from .serializers import CategorySerializer, ObjectiveSerializer class CategoryViewSet(viewsets.ModelViewSet): queryset = Category.objects.all() serializer_class = CategorySerializer class ObjectiveViewSet(viewsets.ModelViewSet): queryset = Objective.objects.all() serializer_class = ObjectiveSerializer
# <app_name>/api/__init__.py from superdjango.interfaces.reset import api, REST from .views import CategoryViewSet, ObjectiveViewSet class ObjectiveREST(REST): # basename = "objectives-api" # prefix = "objectives" viewsets = [ CategoryViewSet, ObjectiveViewSet, ] api.register("objectives", ObjectiveREST)
basename
andprefix
are optional and default to<app_name>-api
and<app_name>
respectively. In the example above, category detail is available atobjectives-api-category-detail
and objective detail atobjectives-api-objective-detail
.