python - Django - access class attributes of a class-based view in middleware -


i have couple of views , each of them must accesed no more 1 user @ time. therefore use locking service this. idea follows:

- declare each view this

class dummyview(view):     lock = lock()     def dispatch(self, request, *args, **kwargs):         ... 

- in middleware, this

class middleware:     ...     def __call__(self, request):         # lock = view.get_lock_if_it_has_one (this need with)         lock.acquire()          response = self.get_response(request)          lock.release()         return response 

how can access lock attribute of view described?

unsure if can access view inside middleware, suggesting more simple , easy implement / understand.

simply create model lock have fields view_name (char field), user (foreign key) & is_acquired (bool). then, when want lock view given request.user (check anonymous users), instantiate lock model user & view_name, .acquire() changes is_acquired true (and saves).

and when want check if lock has been acquired, check if given entry .exists().

if want, can run periodic task expires old locks.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -