pax_global_header00006660000000000000000000000064124531724620014520gustar00rootroot0000000000000052 comment=acd259d2831132550ab3d8a8cb7e56d17fbdd48f drf-fsm-transitions-0.2.0/000077500000000000000000000000001245317246200154305ustar00rootroot00000000000000drf-fsm-transitions-0.2.0/.gitignore000066400000000000000000000012431245317246200174200ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .cache nosetests.xml coverage.xml # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ drf-fsm-transitions-0.2.0/LICENSE000066400000000000000000000020741245317246200164400ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Jacob Haslehurst Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. drf-fsm-transitions-0.2.0/README.md000066400000000000000000000021401245317246200167040ustar00rootroot00000000000000drf-fsm-transitions =================== Automatically hook your Django-FSM transitions up to Django REST Framework ## Installation ```bash pip install drf-fsm-transitions ``` ## Usage When declaring your viewset, simply mix in the result of `get_viewset_transition_action_mixin` ```python from rest_framework import viewsets from drf_transition_methods.viewset_mixins import get_viewset_transition_action_mixin from .models import Article class ArticleViewSet( get_viewset_transition_action_mixin(Article), viewsets.ModelViewSet ): queryset = Article.objects.all() ``` if `Article` had 2 transitions, `delete` and `publish`, the following API calls would be set up - `POST /api/article/1234/delete/` - `POST /api/article/1234/publish/` ### Saving By default, the model instance will be saved after the transition has been successfully called. This can be disabled with the `save_after_transition` attribute ```python class ArticleViewSet( get_viewset_transition_action_mixin(Article), viewsets.ModelViewSet ): queryset = Article.objects.all() save_after_transition = False ``` drf-fsm-transitions-0.2.0/drf_fsm_transitions/000077500000000000000000000000001245317246200215055ustar00rootroot00000000000000drf-fsm-transitions-0.2.0/drf_fsm_transitions/__init__.py000066400000000000000000000000001245317246200236040ustar00rootroot00000000000000drf-fsm-transitions-0.2.0/drf_fsm_transitions/viewset_mixins.py000066400000000000000000000023511245317246200251350ustar00rootroot00000000000000from rest_framework.decorators import detail_route from rest_framework.response import Response def get_transition_viewset_method(transition_name): ''' Create a viewset method for the provided `transition_name` ''' @detail_route(methods=['post']) def inner_func(self, request, pk=None): object = self.get_object() transition_method = getattr(object, transition_name) transition_method(by=self.request.user) if self.save_after_transition: object.save() serializer = self.get_serializer(object) return Response(serializer.data) return inner_func def get_viewset_transition_action_mixin(model): ''' Find all transitions defined on `model`, then create a corresponding viewset action method for each and apply it to `Mixin`. Finally, return `Mixin` ''' instance = model() class Mixin(object): save_after_transition = True transitions = instance.get_all_status_transitions() transition_names = set(x.name for x in transitions) for transition_name in transition_names: setattr( Mixin, transition_name, get_transition_viewset_method(transition_name) ) return Mixin drf-fsm-transitions-0.2.0/setup.py000066400000000000000000000007011245317246200171400ustar00rootroot00000000000000#!/usr/bin/env python from setuptools import setup, find_packages setup( name='drf-fsm-transitions', version='0.2.0', description='Automatically hook your Django-FSM transitions up to Django REST Framework', author='Jacob Haslehurst', author_email='jacob@haslehurst.net', url='https://github.com/hzy/drf-fsm-transitions', packages=find_packages(), install_requires=['django', 'django_fsm', 'djangorestframework'] )