javrasya / django-river

Django workflow library that supports on the fly changes ⛵
BSD 3-Clause "New" or "Revised" License
742 stars 105 forks source link

Tracking Workflow Created and Updated Time and Date #80

Closed rupin closed 5 years ago

rupin commented 5 years ago

I did go through the API and couldn't find a method that will log every interaction of the workflow and track when the workflow came in a certain stage of the process and when it was updated.

Is there a functionality like that available?

javrasya commented 5 years ago

Hooking Pre-Transition or Hooking Post-Transition are what you are looking for. If you don't specify the source and the destination state, it will trigger your callback functions for every transition.

You have to do the hooking for every object rather than on class level. You can do it every time you save an object then call the hooking you want. I think django-river should support it on the class level as well. I will look into that when I have the time.

rupin commented 5 years ago

So I should go ahead and define my own tables to track the states, and update/create those using the hooks, you mean?

javrasya commented 5 years ago

Nope, django-river will do it. But you should tell django-river to call your callback functions in certain (you define) conditions. If you don't give any condition (source_state, destination_state), it will call the callback function you registered on every transition.

rupin commented 5 years ago

Assuming i create the callback functions for for the Pre and Post transitions, django river will log the date and time when a certain state occurred. How do I get access to this data in my template? Is there a choice to saver the log on a file or in a DB table?

javrasya commented 5 years ago

You can do anything you want in your callback function. It is your spot. django-river will pass the workflow object(an instance of your model class) which is currently transitioning to your callback function. If it is post-transition hook, django-river also passes the TransitionApproval object to your callback function as well. There you can have what the current state and the previous state are.

Apart from that, If you are curious about the logs, TransitionApproval is all the transition logs. Since it is an implicit model which is used by django-river, I didn't document it. But that is where django-river keeps all the transition logs. What you can see in that table is the information of who approved, who rejected and when etc. Take a look at the schema of that table to see what more you can have. So you don't need to keep track of it by yourself. So if what you need is only logs, you don't need to use hooks.

rupin commented 5 years ago

If the logs are saved in Transition Approval, using the state object, can i get access to the data?

Let me look at the model relations and figure out. If i need help, will updated this thread. closing for now.

javrasya commented 5 years ago

TransitionApproval is yet another Django model. You can, of course, access that data. Whenever a workflow object is created django-river creates all the TransitionApprovals initially as PENDING. If it is still pending, which means, that transition hasn't happened yet. That is why it is not exactly like a log although it seems to be. They are all created preliminary.

But it can definitely be used as log objects as long as it fits in the demand