Coder Social home page Coder Social logo

django-fsm-admin's People

Contributors

bashu avatar brandonkane avatar cleder avatar coalpaw avatar cptlemming avatar decentral1se avatar edwardbetts avatar fabfuel avatar fdemmer avatar fetzig avatar gableroux avatar jonasvp avatar jrief avatar knaperek avatar kwinsch avatar marz619 avatar mord4z avatar mrbox avatar mtmvu avatar nagyman avatar pauloxnet avatar peterdemin avatar rafikdraoui avatar sheepex avatar ticosax avatar titusz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-fsm-admin's Issues

Multiple Objects

It would be great if there was a mixin to allow for transitions to multiple objects. I wrote up simple extension to the mixin that allows for this, but it's not very generic for generation of buttons. This is useful for creating ListViews where a user can transition multiple objects.

Q: How to not show transition button in admin?

Is there a possibility to decorate a method as transition, which when a state transition is allowed, does not show up in the admin page?

I'm asking this, because some of my potential transitions shall only be triggered by external events (through the API), and it thus shall not be possible to trigger them using the buttons added automatically by django-fsm-admin.

Add Travis testing

I'd be happy to submit a pull request with the initial .travis.yml file.

This would potentially close #3, #23 and #55 when we create a travis run that tests across multiple python/django versions. It's not much work and the gains are big.

Could you set up travis for this repository?

Django 1.10: AttributeError: 'Foo' object has no attribute '_deferred'

The Model._deferred attribute is removed as dynamic model classes when using QuerySet.defer() and only() is removed.

https://docs.djangoproject.com/en/1.10/releases/1.10/

The fix is:

diff --git a/fsm_admin/templatetags/fsm_admin.py b/fsm_admin/templatetags/fsm_admin.py
index 3b7e1fb..086c989 100644
--- a/fsm_admin/templatetags/fsm_admin.py
+++ b/fsm_admin/templatetags/fsm_admin.py
@@ -3,6 +3,7 @@ import logging
 from django import template
 from django.contrib.admin.templatetags.admin_modify import submit_row
 from django.conf import settings
+from django.db import models

 register = template.Library()

@@ -47,7 +48,7 @@ def fsm_submit_row(context):
     original = context.get('original', None)
     model_name = ''
     if original is not None:
-        if original._deferred:
+        if original is models.DEFERRED:
             model_name = type(original).__base__._meta.verbose_name
         else:
             model_name = original.__class__._meta.verbose_name

try-the-example fails on Python 3.5.1 but succeeds on Python 2.7.11 + wrong path for setup.py

https://github.com/gadventures/django-fsm-admin#try-the-example

$ git clone [email protected]:gadventures/django-fsm-admin.git
$ cd django-fsm-admin
$ mkvirtualenv fsm_admin
$ pip install -r requirements.txt
$ python fsm_admin/setup.py develop
$ cd example
$ ./manage.py syncdb
$ ./manage.py runserver

Here's what I did:

 gableroux@zbookarch  ~/repos/test 
 git clone [email protected]:gadventures/django-fsm-admin.git
Cloning into 'django-fsm-admin'...
remote: Counting objects: 401, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 401 (delta 0), reused 0 (delta 0), pack-reused 393
Receiving objects: 100% (401/401), 74.72 KiB | 0 bytes/s, done.
Resolving deltas: 100% (188/188), done.
Checking connectivity... done.
 gableroux@zbookarch  ~/repos/test 
 cd django-fsm-admin
 gableroux@zbookarch  ~/repos/test/django-fsm-admin   master 
 mkvirtualenv fsm_admin
Using base prefix '/usr'
New python executable in /home/gableroux/.virtualenvs/fsm_admin/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/gableroux/.virtualenvs/fsm_admin/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/gableroux/.virtualenvs/fsm_admin/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/gableroux/.virtualenvs/fsm_admin/bin/preactivate
virtualenvwrapper.user_scripts creating /home/gableroux/.virtualenvs/fsm_admin/bin/postactivate
virtualenvwrapper.user_scripts creating /home/gableroux/.virtualenvs/fsm_admin/bin/get_env_details
 (fsm_admin)  gableroux@zbookarch  ~/repos/test/django-fsm-admin   master 
 pip install -r requirements.txt
Collecting Django<1.7,>=1.6 (from -r requirements.txt (line 1))
  Using cached Django-1.6.11-py2.py3-none-any.whl
Collecting django-fsm==2.0.1 (from -r requirements.txt (line 2))
Installing collected packages: Django, django-fsm
Successfully installed Django-1.6.11 django-fsm-2.0.1
 (fsm_admin)  gableroux@zbookarch  ~/repos/test/django-fsm-admin   master 
 python fsm_admin/setup.py develop
python: can't open file 'fsm_admin/setup.py': [Errno 2] No such file or directory
 ✘  (fsm_admin)  gableroux@zbookarch  ~/repos/test/django-fsm-admin   master 
 python setup.py develop  
running develop
running egg_info
creating django_fsm_admin.egg-info
writing dependency_links to django_fsm_admin.egg-info/dependency_links.txt
writing requirements to django_fsm_admin.egg-info/requires.txt
writing django_fsm_admin.egg-info/PKG-INFO
writing top-level names to django_fsm_admin.egg-info/top_level.txt
writing manifest file 'django_fsm_admin.egg-info/SOURCES.txt'
reading manifest file 'django_fsm_admin.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'README.md'
writing manifest file 'django_fsm_admin.egg-info/SOURCES.txt'
running build_ext
Creating /home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django-fsm-admin.egg-link (link to .)
Adding django-fsm-admin 1.2.3 to easy-install.pth file

Installed /home/gableroux/repos/test/django-fsm-admin
Processing dependencies for django-fsm-admin==1.2.3
Searching for django-fsm>=2.1.0
Reading https://pypi.python.org/simple/django-fsm/
Best match: django-fsm 2.3.0
Downloading https://pypi.python.org/packages/source/d/django-fsm/django-fsm-2.3.0.tar.gz#md5=fa5d93ba1ce93cb27543acbcfa24e267
Processing django-fsm-2.3.0.tar.gz
Writing /tmp/easy_install-yvhrawb3/django-fsm-2.3.0/setup.cfg
Running django-fsm-2.3.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-yvhrawb3/django-fsm-2.3.0/egg-dist-tmp-fu5u6224
creating /home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django_fsm-2.3.0-py3.5.egg
Extracting django_fsm-2.3.0-py3.5.egg to /home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages
Adding django-fsm 2.3.0 to easy-install.pth file

Installed /home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django_fsm-2.3.0-py3.5.egg
Searching for Django==1.6.11
Best match: Django 1.6.11
Adding Django 1.6.11 to easy-install.pth file

Using /home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages
Finished processing dependencies for django-fsm-admin==1.2.3
 (fsm_admin)  gableroux@zbookarch  ~/repos/test/django-fsm-admin   master 
 cd example
 (fsm_admin)  gableroux@zbookarch  ~/repos/test/django-fsm-admin/example   master 
 python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    commands = get_commands()
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/core/management/__init__.py", line 107, in get_commands
    apps = settings.INSTALLED_APPS
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/conf/__init__.py", line 50, in _setup
    self._configure_logging()
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/conf/__init__.py", line 72, in _configure_logging
    from django.utils.log import DEFAULT_LOGGING
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/utils/log.py", line 7, in <module>
    from django.views.debug import ExceptionReporter, get_exception_reporter_filter
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/views/debug.py", line 12, in <module>
    from django.template import Template, Context, TemplateDoesNotExist
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/template/__init__.py", line 53, in <module>
    from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END,
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/template/base.py", line 19, in <module>
    from django.utils.html import escape
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/utils/html.py", line 14, in <module>
    from .html_parser import HTMLParser, HTMLParseError
  File "/home/gableroux/.virtualenvs/fsm_admin/lib/python3.5/site-packages/django/utils/html_parser.py", line 12, in <module>
    HTMLParseError = _html_parser.HTMLParseError
AttributeError: module 'html.parser' has no attribute 'HTMLParseError'
 ✘  (fsm_admin)  gableroux@zbookarch  ~/repos/test/django-fsm-admin/example   master 

Tried with Python 3.5.1

Note that it works with Python 2.7.11 ;)

mkvirtualenv -p $(which python2.7)

As you can see, path to setup.py is wrong in the listed commands ;)

Add FSM actions to ModelAdmin changelist actions

It would be useful to have an admin action with changelists to perform transition changes (e.g. soft-deletion) on a list of selected objects (e.g. locks), similar to the submit buttons on the detail view.

This could be handled via ModelAdmin's actions.

The list would contain any possible target transition, or just the valid ones according to the existing/listed objects (from the queryset).
(It might be even possible to only provide valid choices in the dropdown, by using JS and looking at the selected objects, but that's not that trivial then anymore)

I see that this might result in trying to apply invalid transitions, but in this case these could just get skipped (with a message/notification).

`trans_func` mixin does not handle `AttributeError` when passing in `request`

When using Django FSM Admin with Django FSM Log on Python 3.4, the call to trans_func(request=request, by=request.user) fails with an AttributeError on the the kwarg request and the try/except is only looking for TypeError. The error reads as follows where my_transition is the name of the transition method:

my_transition() got an unexpected keyword argument 'request'

It appears that if we remove the @fsm_log_by decorator then everything works. This is strange because we have several other transitions that have logging that works.

From https://github.com/gadventures/django-fsm-admin/blob/master/fsm_admin/mixins.py#L162-L172

            try:
                # Attempt to pass in the request and by argument if using django-fsm-log
                trans_func(request=request, by=request.user)
            except TypeError:
                try:
                    # Attempt to pass in the by argument if using django-fsm-log
                    trans_func(by=request.user)
                except TypeError:
                    # If the function does not have a by attribute, just call with no arguments
                    trans_func()
            new_state = self.display_fsm_field(obj, fsm_field_name)

screen shot 2016-07-11 at 11 52 27 am

Django 1.10 warning get_field_by_name

Hi,
With lots of pleasure I'm using fsm-admin, great stuff! I notice that there is a minor warning when moving to 1.10. Any plans to adjust the code?

fsm_admin/mixins.py:78: RemovedInDjango110Warning: 'get_field_by_name is an unofficial API that has been deprecated. You may be able to replace it with 'get_field()' with: return self.model._meta.get_field_by_name(fsm_field_name)[0]

version bump

Is it possible to get a version bump for the Django 1.10 fixes please?

Add some docs

Hi!

I've been using this lib, and it has been extremely helpful for state management within the admin.
I wanted to name the admin buttons with custom names, and could not find any doc / example here.

When I found the right property in the source code, I thought I would add a quicker example in the repo, for the next person who looks for the same feature

#85

add django.core.context_processors.request to example project

This should be added to the example project's settings.py, otherwise it doesn't work:

from django.conf import global_settings

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
    'django.core.context_processors.request',
)

Show/hide transition buttons accordin to permission

I need a way to access the transition's permission param to show/hide the button in template, any clue on how to do?
I believe that instead of displaying all buttons and treat permissions in model or view, it would be more elegant to hide those who do not have the necessary permissions on the template

Demo

QuickCast demo is offline. Could you please upload the demo video somewhere else?

Many thanks,

Please, add tranition.custom['verbose']

in tempaltetags/fsm-admin.py:
This will make it possible to use custom=dict('verbose') in @transition

By example:
58 line code

if 'verbose' in transition.custom::
    return '{0} {1}'.format(transition.custom['verbose'], model_name).title()
else:
    return '{0} {1}'.format(transition.name.replace('_', ' '), model_name).title()

PyPi Package incomplete

pip install django-fsm-admin does not work. The actuall package on PyPi does not contain templates nor templatetags. Actually it only contains mixins.py ...

pip install -e git://github.com/gadventures/django-fsm-admin.git#egg=django-fsm-admin doesn´t work either as it does not install the templates dir.

New pypi release?

Hi there, could you guys think about providing a new release to make the support for Django v4 available on pypi?

State translation in the admin

Hi,

I defined the states as a choice list to be able to translate the labels.
However this does not reflect in the admin panel, the state is still displayed as "new" (the key) where I was expecting "New" (the value)

Am I missing something?

    #States are listed as choices to be translatable
    NEW = 'new'
    ACCEPTED = 'accepted'
    AWAITING_REVIEW = 'awaiting_review'
    REVIEWED = 'reviewed'
    COMPLETED = 'completed'
    CANCELLED = 'cancelled'
    REJECTED = 'rejected'

    STATES = (
        (NEW, _('New')),
        (ACCEPTED, _('Accepted')),
        (AWAITING_REVIEW, _('Awaiting Review')),
        (REVIEWED, _('Reviewed')),
        (COMPLETED, _('Completed')),
        (CANCELLED, _('Cancelled')),
        (REJECTED, _('Rejected')),
    )

    state = FSMField(_('state'), default=NEW, protected=True)

Inline save order

In the FSM Mixin for save_model, the transition is executed before the saving of the model, which causes the inlines to be saved after the transition has occurred.

Is this on purpose? Is there any reason this order was chosen?

If there are post signals attached to the transition which involve the related models, they won't take into account the modifications through the inlines in the current setup.

Python 3 support

I'm using django-fsm-admin with Python 3.4.0. So far, I've found two cases where I've had to change iteritems() to items(). I'm guessing that there will be other changes that need to be made as well.

I have a branch at https://github.com/greg-barnett/django-fsm-admin/tree/python3

This branch hasn't been tested with python 2, which is why I'm opening an issue rather than a pull request. I have no experience with making code compatible with both python 2 & 3.

This project needs a maintainer

Hi,

This repository seems to lack maintenance, I propose myself as a new maintainer.

Could you give me the right to push in your repository or just transfer it on my account in github?

Thank you!

Compatible with other django 3rd party apps

It seems the current version is not compatible with other django apps, such as Django-guardian. Only the first mixin will show up in the admin page. If I put the django-fsm-admin in front of django-guardian mixin, then only django-fsm-admin buttons will show. How can I use both packages on the admin page?

For example, this code will show django-fsm-admin buttons only.

class PIAFormAdmin(FSMTransitionMixin, GuardedModelAdmin)

This will show django-guardian buttons only

class PIAFormAdmin(GuardedModelAdmin, FSMTransitionMixin)

So the order matters. But I want to show buttons from both packages on the admin page.

clarify integration with readonly fields

I suggest the documentation is adjusted so that it clarifies that in order to show the status as read only, you also need to add the field in the ModelAdmin's readonly_fields. This took me a while to work out (I assumed it would do it automatically).

Thanks for the package though!

buttons in get_list_display

For my project, it is important that it is possible to add button buttons to get_list_display.
In your example, I saw how this can be done in the form of editing.
I looked at the source code templatetags and did not see anything that I need.
Tell me, do you have a ready-made version of how to do this, or do I need to implement it from scratch?

Support other Django versions

Specifically I'm hoping for 1.5.5 support. Is there some reason why you want to pin django-fsm-admin to one particular version of Django, and would you be amenable to a pull request that supports 1.5?

I'm also curious about requiring django-fsm 1.5.1 versus 2.0, but that's the version I'm using, so I'm less concerned in the short term :)

Transition condition can't access User obejct

In order to allow certain transitions only to a set of staff users, I'd like to access the User object inside my customized condition functions.

This unfortunately is not possible, because that function never "sees" the request object. By patching the templatetag function fsm_transition_hints and the method FSMTransitionMixin.get_transition_hints() is would easily by possible to pass to request object to my condition function.

If you have concerns about backward compatibility with existing condition functions, I could add a boolean named, say pass_request to the custom dict. Then the request object is passed in only when this is True.

What do you think about this and shall I create a pull request for this feature?

Intermediate pages

Is it possible to add intermediate pages triggered by the state-changes?

Example case: changing state sends email, but allows you to add email content before sending in a new form.

object has no attribute 'get_available_user_state_transitions'

Hello,

I'm trying to use Django FSM and Django FSM Admin but I get the error:
'Employee' object has no attribute 'get_available_user_state_transitions'
In template C:\Python27\lib\site-packages\fsm_admin\templates\fsm_admin\change_form.html, error at line 4: {% fsm_submit_row %}

The last traceback is:
transitions = getattr(obj, transitions_func)(user) if obj else []
with transitions_func = u'get_available_user_state_transitions'
(in Python27\lib\site-packages\fsm_admin\mixins.py in _fsm_get_transitions)

I don't understand...

in models.py:
class Employee(models.Model):
step = FSMField(default=STEP_1, choices=CHOICES, protected=True)
...
@transition(field=step, source=STEP_1, target=STEP_2)
def step1to2(self):
pass

in admin.py:
@admin.register(Employee)
class EmployeeAdmin(FSMTransitionMixin, reversion.VersionAdmin, admin.ModelAdmin):
...

in settings.py:
INSTALLED_APPS = (
'suit',
'django.contrib.admin',
'django_fsm',
'fsm_admin',
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.