release lock when article is saved
This commit is contained in:
parent
0026c12e64
commit
16052c9612
@ -42,10 +42,12 @@ class Article(models.Model):
|
||||
else:
|
||||
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
|
||||
lock = cache.get(cache_key)
|
||||
if lock:
|
||||
if release:
|
||||
cache.delete(cache_key)
|
||||
return lock == user.id
|
||||
|
||||
cache.set(cache_key, user.id, WRITE_LOCK_SECONDS)
|
||||
|
@ -105,7 +105,7 @@ def edit_article(request, title):
|
||||
else:
|
||||
if not article.get_write_lock(request.user):
|
||||
# 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)
|
||||
|
||||
# otherwise get latest num
|
||||
@ -118,6 +118,8 @@ def edit_article(request, title):
|
||||
version.number = num
|
||||
version.save()
|
||||
|
||||
article.get_write_lock(request.user, release=True)
|
||||
|
||||
# redirect to view article on save
|
||||
return redirect(article)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user