allow null editors
This commit is contained in:
parent
e41f77fa72
commit
0864edd921
@ -34,7 +34,7 @@ ARTICLE_STATUSES = (
|
||||
|
||||
class Article(models.Model):
|
||||
title = models.CharField(max_length=200)
|
||||
creator = models.ForeignKey(User, related_name='wiki_articles')
|
||||
creator = models.ForeignKey(User, related_name='wiki_articles', blank=True, null=True)
|
||||
status = models.IntegerField(choices=ARTICLE_STATUSES, default=PUBLIC)
|
||||
redirect_to = models.ForeignKey('self', null=True)
|
||||
|
||||
@ -50,6 +50,11 @@ class Article(models.Model):
|
||||
if '/' in self.title:
|
||||
return self.title.rsplit('/',1)[0]
|
||||
|
||||
# def save(self, **kwargs):
|
||||
# if self.creator is not None and self.creator.is_anonymous():
|
||||
# self.creator = None
|
||||
# super(Article, self).save(**kwargs)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('view_article', args=[self.title])
|
||||
|
||||
@ -68,21 +73,25 @@ class Article(models.Model):
|
||||
else:
|
||||
return EDITOR_TEST_FUNC(user)
|
||||
|
||||
def get_write_lock(self, user, release=False):
|
||||
def get_write_lock(self, user_or_request, release=False):
|
||||
if hasattr(user_or_request, 'session'):
|
||||
lock_id = user_or_request.session.session_key
|
||||
else:
|
||||
lock_id = user_or_request.id
|
||||
cache_key = 'markupwiki_articlelock_%s' % self.id
|
||||
lock = cache.get(cache_key)
|
||||
if lock:
|
||||
if release:
|
||||
cache.delete(cache_key)
|
||||
return lock == user.id
|
||||
return lock == lock_id
|
||||
|
||||
if not release:
|
||||
cache.set(cache_key, user.id, WRITE_LOCK_SECONDS)
|
||||
cache.set(cache_key, lock_id, WRITE_LOCK_SECONDS)
|
||||
return True
|
||||
|
||||
class ArticleVersion(models.Model):
|
||||
article = models.ForeignKey(Article, related_name='versions')
|
||||
author = models.ForeignKey(User, related_name='article_versions')
|
||||
author = models.ForeignKey(User, related_name='article_versions', blank=True, null=True)
|
||||
number = models.PositiveIntegerField()
|
||||
body = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE,
|
||||
markup_choices=WIKI_MARKUP_TYPES,
|
||||
@ -98,6 +107,11 @@ class ArticleVersion(models.Model):
|
||||
|
||||
def __unicode__(self):
|
||||
return '%s rev #%s' % (self.article, self.number)
|
||||
|
||||
# def save(self, **kwargs):
|
||||
# if self.author is not None and self.author.is_anonymous():
|
||||
# self.author = None
|
||||
# super(ArticleVersion, self).save(**kwargs)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('article_version', args=[self.article.title, self.number])
|
||||
|
@ -115,11 +115,13 @@ def edit_article(request, title):
|
||||
form = ArticleForm()
|
||||
elif request.method == 'POST':
|
||||
form = ArticleForm(request.POST)
|
||||
user = None if request.user.is_anonymous() else request.user
|
||||
|
||||
if form.is_valid():
|
||||
if not article:
|
||||
# if article doesn't exist create it and start num at 0
|
||||
article = Article.objects.create(title=title,
|
||||
creator=request.user)
|
||||
creator=user)
|
||||
num = 0
|
||||
else:
|
||||
if not article.get_write_lock(request.user):
|
||||
@ -133,11 +135,11 @@ def edit_article(request, title):
|
||||
# create a new version attached to article specified in name
|
||||
version = form.save(False)
|
||||
version.article = article
|
||||
version.author = request.user
|
||||
version.author = user
|
||||
version.number = num
|
||||
version.save()
|
||||
|
||||
article.get_write_lock(request.user, release=True)
|
||||
article.get_write_lock(user or request, release=True)
|
||||
|
||||
# redirect to view article on save
|
||||
return redirect(article)
|
||||
|
Loading…
Reference in New Issue
Block a user