Commit ad7b664e by benjaoming

Respect custom models (NB! current django 1.5.1 breaks wiki.views.accounts) #145

parent 68e34789
......@@ -20,10 +20,12 @@ from wiki.editors import getEditor
from wiki.core.diff import simple_merge
from django.forms.widgets import HiddenInput
from wiki.core.plugins.base import PluginSettingsFormMixin
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from wiki.core import permissions
from wiki.core.compat import get_user_model
User = get_user_model()
class SpamProtectionMixin():
"""Check a form for spam. Only works if properties 'request' and 'revision_model' are set."""
......@@ -368,7 +370,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
if username:
try:
user = User.objects.get(username=username)
except models.User.DoesNotExist:
except User.DoesNotExist:
raise forms.ValidationError(_(u'No user with that username'))
else:
user = None
......
......@@ -206,7 +206,7 @@ class BaseRevisionMixin(models.Model):
ip_address = models.IPAddressField(_('IP address'), blank=True, null=True, editable=False)
user = models.ForeignKey(settings.USER_MODEL, verbose_name=_('user'),
blank=True, null=True,
on_delete=models.SET_NULL)
on_delete=models.SET_NULL)
modified = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)
......
......@@ -3,8 +3,6 @@ from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.db.models import signals
from wiki.models.article import BaseRevisionMixin
"""
There are three kinds of plugin base models:
......@@ -26,8 +24,7 @@ There are three kinds of plugin base models:
"""
from article import Article, ArticleRevision
from article import ArticleRevision, BaseRevisionMixin
from wiki.conf import settings
class ArticlePlugin(models.Model):
......@@ -36,7 +33,7 @@ class ArticlePlugin(models.Model):
clean. Furthermore, it's possible to list all plugins and maintain generic
properties in the future..."""
article = models.ForeignKey(Article, on_delete=models.CASCADE,
article = models.ForeignKey('wiki.Article', on_delete=models.CASCADE,
verbose_name=_(u"article"))
deleted = models.BooleanField(default=False)
......@@ -82,7 +79,7 @@ class ReusablePlugin(ArticlePlugin):
ArticlePlugin.article.null = True
ArticlePlugin.article.blank = True
articles = models.ManyToManyField(Article, related_name='shared_plugins_set')
articles = models.ManyToManyField('wiki.Article', related_name='shared_plugins_set')
# Since the article relation may be None, we have to check for this
# before handling permissions....
......@@ -131,7 +128,7 @@ class SimplePlugin(ArticlePlugin):
YourPlugin.objects.create(article=article_instance, ...)
"""
# The article revision that this plugin is attached to
article_revision = models.ForeignKey(ArticleRevision, on_delete=models.CASCADE)
article_revision = models.ForeignKey('wiki.ArticleRevision', on_delete=models.CASCADE)
def __init__(self, *args, **kwargs):
article = kwargs.pop('article', None)
......
......@@ -35,7 +35,7 @@ class AttachmentForm(forms.ModelForm):
def save(self, *args, **kwargs):
attachment_revision = super(AttachmentForm, self).save(commit=False)
# Added because of AttachmentArcihveForm removing file from fields
# Added because of AttachmentArchiveForm removing file from fields
# should be more elegant
attachment_revision.file = self.cleaned_data['file']
......@@ -53,7 +53,7 @@ class AttachmentForm(forms.ModelForm):
model = models.AttachmentRevision
fields = ('file', 'description',)
class AttachmentArcihveForm(AttachmentForm):
class AttachmentArchiveForm(AttachmentForm):
file = forms.FileField( #@ReservedAssignment
label=_(u'File or zip archive'),
......@@ -67,7 +67,7 @@ class AttachmentArcihveForm(AttachmentForm):
)
def __init__(self, *args, **kwargs):
super(AttachmentArcihveForm, self).__init__(*args, **kwargs)
super(AttachmentArchiveForm, self).__init__(*args, **kwargs)
ordered_fields = ['unzip_archive', 'file']
self.fields.keyOrder = ordered_fields + [k for k in self.fields.keys() if k not in ordered_fields]
......@@ -84,12 +84,12 @@ class AttachmentArcihveForm(AttachmentForm):
except zipfile.BadZipfile:
raise forms.ValidationError(_(u"Not a zip file"))
else:
return super(AttachmentArcihveForm, self).clean_file()
return super(AttachmentArchiveForm, self).clean_file()
return uploaded_file
def clean(self):
if not can_moderate(self.article, self.request.user):
raise forms.ValidationError("User")
raise forms.ValidationError("User not allowed to moderate this article")
return self.cleaned_data
def save(self, *args, **kwargs):
......@@ -125,7 +125,7 @@ class AttachmentArcihveForm(AttachmentForm):
raise
return new_attachments
else:
return super(AttachmentArcihveForm, self).save(*args, **kwargs)
return super(AttachmentArchiveForm, self).save(*args, **kwargs)
class Meta(AttachmentForm.Meta):
fields = ['description',]
......
......@@ -29,7 +29,7 @@ class AttachmentView(ArticleMixin, FormView):
current_revision__file=None
).order_by('original_filename')
self.form_class = forms.AttachmentArcihveForm
self.form_class = forms.AttachmentArchiveForm
else:
self.attachments = models.Attachment.objects.active().filter(articles=article)
......
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from wiki.models import Article, ArticleRevision, URLPath
import pprint
class InitialWebClientTest(TestCase):
......@@ -52,6 +52,7 @@ class WebClientTest(TestCase):
def tearDown(self):
# clear Article cache before the next test
from wiki.models import Article
Article.objects.all().delete()
def get_by_path(self, path):
......@@ -63,6 +64,7 @@ class WebClientTest(TestCase):
def dump_db_status(self, message=''):
"""Debug printing of the complete important database content."""
print('*** db status *** {}'.format(message))
from wiki.models import Article, ArticleRevision, URLPath
for klass in (Article, ArticleRevision, URLPath):
print('* {} *'.format(klass.__name__))
pprint.pprint(list(klass.objects.values()), width=240)
......
......@@ -14,7 +14,6 @@ from django.conf import settings as django_settings
from django.contrib import messages
from django.contrib.auth import logout as auth_logout, login as auth_login
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.shortcuts import redirect
from django.utils.translation import ugettext as _
......@@ -24,6 +23,8 @@ from django.views.generic.edit import CreateView, FormView
from wiki import forms
from wiki.conf import settings
from wiki.core.compat import get_user_model
User = get_user_model()
class Signup(CreateView):
model = User
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment