diff --git a/markupwiki/models.py b/markupwiki/models.py index 3400d35..2a5d2dd 100644 --- a/markupwiki/models.py +++ b/markupwiki/models.py @@ -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) diff --git a/markupwiki/views.py b/markupwiki/views.py index 0ee4cb1..948dcb6 100644 --- a/markupwiki/views.py +++ b/markupwiki/views.py @@ -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)