Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_transition #56

Open
lehins opened this issue May 8, 2014 · 0 comments
Open

test_transition #56

lehins opened this issue May 8, 2014 · 0 comments

Comments

@lehins
Copy link

lehins commented May 8, 2014

Great app, I was looking for something like it for a while. Thanks a whole bunch!
One small suggestion:
instead of returning True on
object.get_state_info().test_transition('transition_name', user)
it would probably better to return state_info instance, so the call can be chained:

try:
    object.get_state_info().test_transition('transition_name', user).make_transition('transition_name', user)
except States2Exception as e: 
    raise ValidationError("Cannot changes state because %s" % e) 

instead of:

try:
    if object.get_state_info().test_transition('transition_name', user):
        object.get_state_info().make_transition('transition_name', user)
except States2Exception as e: 
    raise ValidationError("Cannot changes state because %s" % e) 

This way it is type consistent (test_transition never returns False anyhow), it is more DRY and by chaining calls like that we could also eliminate failed transition logs in a more concise way.

I would submit a pull request myself, but it is literally a one line change:
from True to si_self in model_methods.
More over this change wouldn't break any existing code, since si_self would still evaluate to True.

What do you guys think?

lehins added a commit to lehins/django-states2 that referenced this issue May 18, 2014
gvangool added a commit to gvangool/django-states2 that referenced this issue Oct 2, 2015
gvangool added a commit to gvangool/django-states2 that referenced this issue May 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant