release lock when article is saved
This commit is contained in:
parent
0026c12e64
commit
16052c9612
@ -42,10 +42,12 @@ class Article(models.Model):
|
|||||||
else:
|
else:
|
||||||
return user.is_authenticated()
|
return user.is_authenticated()
|
||||||
|
|
||||||
def get_write_lock(self, user):
|
def get_write_lock(self, user, release=False):
|
||||||
cache_key = 'markupwiki_articlelock_%s' % self.id
|
cache_key = 'markupwiki_articlelock_%s' % self.id
|
||||||
lock = cache.get(cache_key)
|
lock = cache.get(cache_key)
|
||||||
if lock:
|
if lock:
|
||||||
|
if release:
|
||||||
|
cache.delete(cache_key)
|
||||||
return lock == user.id
|
return lock == user.id
|
||||||
|
|
||||||
cache.set(cache_key, user.id, WRITE_LOCK_SECONDS)
|
cache.set(cache_key, user.id, WRITE_LOCK_SECONDS)
|
||||||
|
@ -105,7 +105,7 @@ def edit_article(request, title):
|
|||||||
else:
|
else:
|
||||||
if not article.get_write_lock(request.user):
|
if not article.get_write_lock(request.user):
|
||||||
# set message and redirect
|
# set message and redirect
|
||||||
messages.error(request, 'You took too long to edit and someone else is now editing this page.')
|
messages.error(request, 'Your session timed out and someone else is now editing this page.')
|
||||||
return redirect(article)
|
return redirect(article)
|
||||||
|
|
||||||
# otherwise get latest num
|
# otherwise get latest num
|
||||||
@ -118,6 +118,8 @@ def edit_article(request, title):
|
|||||||
version.number = num
|
version.number = num
|
||||||
version.save()
|
version.save()
|
||||||
|
|
||||||
|
article.get_write_lock(request.user, release=True)
|
||||||
|
|
||||||
# redirect to view article on save
|
# redirect to view article on save
|
||||||
return redirect(article)
|
return redirect(article)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user