1

I am using flask version 0.10.1 and python version 2.7.6

I have a web application that manages some orders. Let's say we have 3 orders:

order 1
order 2
order 3

There is a view

@main.route(/prder/<int:orderid>, methods=['GET'])
edit(orderid):
   pass

The view is accesible only to registered users and I have a user object. Let's say we have to users user A and user B.

When A edits order 1 this order should not be editable by user B.

I need a mechanism that "locks" the order and the order is inaccessible for edits when user A is working on the order.

This "lock" need to be revoked when the user finishes editing*

  • There is the scenario that user A closed the browser or stopped working on the order. Then I do not want the order to be "locked" forever.

Any ideas what is the best way to achieve the above functionality?

gosom
  • 1,299
  • 3
  • 16
  • 35

1 Answers1

0

I've never used flask, but it sounds like you want a mutex (example for multi-threading here). What the behaviour should be when B tries to edit something A is already editing is another matter.

As for not being locked forever, a little more information is required. By "stopped working on the order," do you mean was idle for some time, or closed some window? I'm pretty sure the try...finally construction would unlock the mutex in the event that whatever was inside of the try block was prematurely terminated, but I'm don't have enough experience with it to tell you for certain.

Community
  • 1
  • 1
nchen24
  • 502
  • 2
  • 9
  • stopped working on the order could be many things. Could be idle for some time ( forgetting closing the browser/lose internet connection etc), Also when he closes the browser window or if he clicks a save button on the order. – gosom Nov 05 '14 at 10:35