Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-wiki
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-wiki
Commits
ad7b664e
Commit
ad7b664e
authored
May 19, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respect custom models (NB! current django 1.5.1 breaks wiki.views.accounts) #145
parent
68e34789
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
19 deletions
+21
-19
wiki/forms.py
+4
-2
wiki/models/article.py
+1
-1
wiki/models/pluginbase.py
+4
-7
wiki/plugins/attachments/forms.py
+6
-6
wiki/plugins/attachments/views.py
+1
-1
wiki/tests/__init__.py
+3
-1
wiki/views/accounts.py
+2
-1
No files found.
wiki/forms.py
View file @
ad7b664e
...
@@ -20,10 +20,12 @@ from wiki.editors import getEditor
...
@@ -20,10 +20,12 @@ from wiki.editors import getEditor
from
wiki.core.diff
import
simple_merge
from
wiki.core.diff
import
simple_merge
from
django.forms.widgets
import
HiddenInput
from
django.forms.widgets
import
HiddenInput
from
wiki.core.plugins.base
import
PluginSettingsFormMixin
from
wiki.core.plugins.base
import
PluginSettingsFormMixin
from
django.contrib.auth.models
import
User
from
django.contrib.auth.forms
import
UserCreationForm
from
django.contrib.auth.forms
import
UserCreationForm
from
wiki.core
import
permissions
from
wiki.core
import
permissions
from
wiki.core.compat
import
get_user_model
User
=
get_user_model
()
class
SpamProtectionMixin
():
class
SpamProtectionMixin
():
"""Check a form for spam. Only works if properties 'request' and 'revision_model' are set."""
"""Check a form for spam. Only works if properties 'request' and 'revision_model' are set."""
...
@@ -368,7 +370,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
...
@@ -368,7 +370,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm):
if
username
:
if
username
:
try
:
try
:
user
=
User
.
objects
.
get
(
username
=
username
)
user
=
User
.
objects
.
get
(
username
=
username
)
except
models
.
User
.
DoesNotExist
:
except
User
.
DoesNotExist
:
raise
forms
.
ValidationError
(
_
(
u'No user with that username'
))
raise
forms
.
ValidationError
(
_
(
u'No user with that username'
))
else
:
else
:
user
=
None
user
=
None
...
...
wiki/models/article.py
View file @
ad7b664e
...
@@ -206,7 +206,7 @@ class BaseRevisionMixin(models.Model):
...
@@ -206,7 +206,7 @@ class BaseRevisionMixin(models.Model):
ip_address
=
models
.
IPAddressField
(
_
(
'IP address'
),
blank
=
True
,
null
=
True
,
editable
=
False
)
ip_address
=
models
.
IPAddressField
(
_
(
'IP address'
),
blank
=
True
,
null
=
True
,
editable
=
False
)
user
=
models
.
ForeignKey
(
settings
.
USER_MODEL
,
verbose_name
=
_
(
'user'
),
user
=
models
.
ForeignKey
(
settings
.
USER_MODEL
,
verbose_name
=
_
(
'user'
),
blank
=
True
,
null
=
True
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
SET_NULL
)
on_delete
=
models
.
SET_NULL
)
modified
=
models
.
DateTimeField
(
auto_now
=
True
)
modified
=
models
.
DateTimeField
(
auto_now
=
True
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
...
...
wiki/models/pluginbase.py
View file @
ad7b664e
...
@@ -3,8 +3,6 @@ from django.db import models
...
@@ -3,8 +3,6 @@ from django.db import models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.db.models
import
signals
from
django.db.models
import
signals
from
wiki.models.article
import
BaseRevisionMixin
"""
"""
There are three kinds of plugin base models:
There are three kinds of plugin base models:
...
@@ -26,8 +24,7 @@ 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
from
wiki.conf
import
settings
class
ArticlePlugin
(
models
.
Model
):
class
ArticlePlugin
(
models
.
Model
):
...
@@ -36,7 +33,7 @@ class ArticlePlugin(models.Model):
...
@@ -36,7 +33,7 @@ class ArticlePlugin(models.Model):
clean. Furthermore, it's possible to list all plugins and maintain generic
clean. Furthermore, it's possible to list all plugins and maintain generic
properties in the future..."""
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"
))
verbose_name
=
_
(
u"article"
))
deleted
=
models
.
BooleanField
(
default
=
False
)
deleted
=
models
.
BooleanField
(
default
=
False
)
...
@@ -82,7 +79,7 @@ class ReusablePlugin(ArticlePlugin):
...
@@ -82,7 +79,7 @@ class ReusablePlugin(ArticlePlugin):
ArticlePlugin
.
article
.
null
=
True
ArticlePlugin
.
article
.
null
=
True
ArticlePlugin
.
article
.
blank
=
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
# Since the article relation may be None, we have to check for this
# before handling permissions....
# before handling permissions....
...
@@ -131,7 +128,7 @@ class SimplePlugin(ArticlePlugin):
...
@@ -131,7 +128,7 @@ class SimplePlugin(ArticlePlugin):
YourPlugin.objects.create(article=article_instance, ...)
YourPlugin.objects.create(article=article_instance, ...)
"""
"""
# The article revision that this plugin is attached to
# 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
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
article
=
kwargs
.
pop
(
'article'
,
None
)
article
=
kwargs
.
pop
(
'article'
,
None
)
...
...
wiki/plugins/attachments/forms.py
View file @
ad7b664e
...
@@ -35,7 +35,7 @@ class AttachmentForm(forms.ModelForm):
...
@@ -35,7 +35,7 @@ class AttachmentForm(forms.ModelForm):
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
attachment_revision
=
super
(
AttachmentForm
,
self
)
.
save
(
commit
=
False
)
attachment_revision
=
super
(
AttachmentForm
,
self
)
.
save
(
commit
=
False
)
# Added because of AttachmentArc
ih
veForm removing file from fields
# Added because of AttachmentArc
hi
veForm removing file from fields
# should be more elegant
# should be more elegant
attachment_revision
.
file
=
self
.
cleaned_data
[
'file'
]
attachment_revision
.
file
=
self
.
cleaned_data
[
'file'
]
...
@@ -53,7 +53,7 @@ class AttachmentForm(forms.ModelForm):
...
@@ -53,7 +53,7 @@ class AttachmentForm(forms.ModelForm):
model
=
models
.
AttachmentRevision
model
=
models
.
AttachmentRevision
fields
=
(
'file'
,
'description'
,)
fields
=
(
'file'
,
'description'
,)
class
AttachmentArc
ih
veForm
(
AttachmentForm
):
class
AttachmentArc
hi
veForm
(
AttachmentForm
):
file
=
forms
.
FileField
(
#@ReservedAssignment
file
=
forms
.
FileField
(
#@ReservedAssignment
label
=
_
(
u'File or zip archive'
),
label
=
_
(
u'File or zip archive'
),
...
@@ -67,7 +67,7 @@ class AttachmentArcihveForm(AttachmentForm):
...
@@ -67,7 +67,7 @@ class AttachmentArcihveForm(AttachmentForm):
)
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
AttachmentArc
ih
veForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
AttachmentArc
hi
veForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
ordered_fields
=
[
'unzip_archive'
,
'file'
]
ordered_fields
=
[
'unzip_archive'
,
'file'
]
self
.
fields
.
keyOrder
=
ordered_fields
+
[
k
for
k
in
self
.
fields
.
keys
()
if
k
not
in
ordered_fields
]
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):
...
@@ -84,12 +84,12 @@ class AttachmentArcihveForm(AttachmentForm):
except
zipfile
.
BadZipfile
:
except
zipfile
.
BadZipfile
:
raise
forms
.
ValidationError
(
_
(
u"Not a zip file"
))
raise
forms
.
ValidationError
(
_
(
u"Not a zip file"
))
else
:
else
:
return
super
(
AttachmentArc
ih
veForm
,
self
)
.
clean_file
()
return
super
(
AttachmentArc
hi
veForm
,
self
)
.
clean_file
()
return
uploaded_file
return
uploaded_file
def
clean
(
self
):
def
clean
(
self
):
if
not
can_moderate
(
self
.
article
,
self
.
request
.
user
):
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
return
self
.
cleaned_data
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
...
@@ -125,7 +125,7 @@ class AttachmentArcihveForm(AttachmentForm):
...
@@ -125,7 +125,7 @@ class AttachmentArcihveForm(AttachmentForm):
raise
raise
return
new_attachments
return
new_attachments
else
:
else
:
return
super
(
AttachmentArc
ih
veForm
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
super
(
AttachmentArc
hi
veForm
,
self
)
.
save
(
*
args
,
**
kwargs
)
class
Meta
(
AttachmentForm
.
Meta
):
class
Meta
(
AttachmentForm
.
Meta
):
fields
=
[
'description'
,]
fields
=
[
'description'
,]
...
...
wiki/plugins/attachments/views.py
View file @
ad7b664e
...
@@ -29,7 +29,7 @@ class AttachmentView(ArticleMixin, FormView):
...
@@ -29,7 +29,7 @@ class AttachmentView(ArticleMixin, FormView):
current_revision__file
=
None
current_revision__file
=
None
)
.
order_by
(
'original_filename'
)
)
.
order_by
(
'original_filename'
)
self
.
form_class
=
forms
.
AttachmentArc
ih
veForm
self
.
form_class
=
forms
.
AttachmentArc
hi
veForm
else
:
else
:
self
.
attachments
=
models
.
Attachment
.
objects
.
active
()
.
filter
(
articles
=
article
)
self
.
attachments
=
models
.
Attachment
.
objects
.
active
()
.
filter
(
articles
=
article
)
...
...
wiki/tests/__init__.py
View file @
ad7b664e
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.test.client
import
Client
from
wiki.models
import
Article
,
ArticleRevision
,
URLPath
import
pprint
import
pprint
class
InitialWebClientTest
(
TestCase
):
class
InitialWebClientTest
(
TestCase
):
...
@@ -52,6 +52,7 @@ class WebClientTest(TestCase):
...
@@ -52,6 +52,7 @@ class WebClientTest(TestCase):
def
tearDown
(
self
):
def
tearDown
(
self
):
# clear Article cache before the next test
# clear Article cache before the next test
from
wiki.models
import
Article
Article
.
objects
.
all
()
.
delete
()
Article
.
objects
.
all
()
.
delete
()
def
get_by_path
(
self
,
path
):
def
get_by_path
(
self
,
path
):
...
@@ -63,6 +64,7 @@ class WebClientTest(TestCase):
...
@@ -63,6 +64,7 @@ class WebClientTest(TestCase):
def
dump_db_status
(
self
,
message
=
''
):
def
dump_db_status
(
self
,
message
=
''
):
"""Debug printing of the complete important database content."""
"""Debug printing of the complete important database content."""
print
(
'*** db status *** {}'
.
format
(
message
))
print
(
'*** db status *** {}'
.
format
(
message
))
from
wiki.models
import
Article
,
ArticleRevision
,
URLPath
for
klass
in
(
Article
,
ArticleRevision
,
URLPath
):
for
klass
in
(
Article
,
ArticleRevision
,
URLPath
):
print
(
'* {} *'
.
format
(
klass
.
__name__
))
print
(
'* {} *'
.
format
(
klass
.
__name__
))
pprint
.
pprint
(
list
(
klass
.
objects
.
values
()),
width
=
240
)
pprint
.
pprint
(
list
(
klass
.
objects
.
values
()),
width
=
240
)
...
...
wiki/views/accounts.py
View file @
ad7b664e
...
@@ -14,7 +14,6 @@ from django.conf import settings as django_settings
...
@@ -14,7 +14,6 @@ from django.conf import settings as django_settings
from
django.contrib
import
messages
from
django.contrib
import
messages
from
django.contrib.auth
import
logout
as
auth_logout
,
login
as
auth_login
from
django.contrib.auth
import
logout
as
auth_logout
,
login
as
auth_login
from
django.contrib.auth.forms
import
AuthenticationForm
from
django.contrib.auth.forms
import
AuthenticationForm
from
django.contrib.auth.models
import
User
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
...
@@ -24,6 +23,8 @@ from django.views.generic.edit import CreateView, FormView
...
@@ -24,6 +23,8 @@ from django.views.generic.edit import CreateView, FormView
from
wiki
import
forms
from
wiki
import
forms
from
wiki.conf
import
settings
from
wiki.conf
import
settings
from
wiki.core.compat
import
get_user_model
User
=
get_user_model
()
class
Signup
(
CreateView
):
class
Signup
(
CreateView
):
model
=
User
model
=
User
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment