Skip to main content

No project description provided

Project description

DJ Actions

PyPI version

A pattern + tooling to enable a standardized way to interact with and mutate data on a Django model

Getting started

Installation

pip install dj-actions

Add to INSTALLED_APPS

Prepare your app for action!

python manage.py start_actions

Add your first action

python manage.py create_action

Add actions to your Django app

1. Create an actions module in your app:

DJActions convention is to isolate each action into it's own module. A typical file layout might look something like this:

[app]
  |_ [actions]
        |_ action_registry.py
        |_ [some_action]
        |_ [some_other_action]

2. Create your action registry

The action registry is how we tell DJActions how to route to our actions. The action registry will also be responsible for generating your documentation endpoints

Here is an example registry:

from actions.util import (
    STATUS,
    ACTION_TYPE,
    # get_action_docs,
    enrich_actions
)

action_list = []
## -- START ACTION REGISTRY -- ##
action_list.append(('mark_done', ACTION_TYPE.INSTANCE.value, STATUS.ALPHA.value))
## -- END ACTION REGISTRY -- ##

# this is the abolsute path to the base of your app:
# dj-actions uses this to locate your action directory
base = '/code/example_app/'

# convention over configuration
# this will load your actions configurations from
initial_registry = { "resource": "todo", "basepath": "/todos/", "actions": {} }
ACTIONS = enrich_actions(
    base,
    initial_registry,
    action_list
)

Now you need to mixin actions.ActionViews into your ViewSet:

from rest_framework import routers, serializers, viewsets

from actions.mixins import ActionMixin
from actions.actions.action_registry import ACTIONS
from actions.models import EventAction


class EventActionViewSet(ActionMixin, viewsets.ModelViewSet):
    queryset = EventAction.objects.all()
    serializer_class = TodoSerializer
    action_registry = ACTIONS


router = routers.DefaultRouter()
router.register(r'todos', TodoViewSet)

Configuration

  • DJACTION_TRACK_ACTIONS if True will store action info in the db (default: True)
  • DJACTION_TTL_MINUTES actions older than this will be archived (default 1 day (60*24))

Features

  • Reliable, simple pattern to execute complex logic
  • Self documenting

Tooling

This library provides you with some tools and tasks which might be useful:

Stream,io (WIP)

Push action information into stream.io

Airflow (WIP)

Push downstream work to an airflow task

Concepts

Task Registry

The Task Registry provides a means of defining tasks in a self documenting way. Based on the meta-data provided in the task registry, tasks will be exposed in various different ways

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj-actions-0.0.7.tar.gz (15.9 kB view details)

Uploaded Source

File details

Details for the file dj-actions-0.0.7.tar.gz.

File metadata

  • Download URL: dj-actions-0.0.7.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for dj-actions-0.0.7.tar.gz
Algorithm Hash digest
SHA256 98a428cef867f954a2885875b40daf60531c4f16736d1227cdc70d9ea8cff51c
MD5 34092af951ca7efa5d2067c6950d8346
BLAKE2b-256 df44af8d2d1a4e08cea8ab45ba7735b574300d072525e4d33360a001a43747f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page