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
83fe3d46
Commit
83fe3d46
authored
Jul 25, 2012
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More on models. Not done yet.
parent
30fb1eca
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
100 additions
and
17 deletions
+100
-17
testproject/db/prepopulated.db
+0
-0
testproject/testproject/settings.py
+1
-0
wiki/conf/settings.py
+4
-2
wiki/migrations/0001_initial.py
+0
-0
wiki/models/__init__.py
+11
-6
wiki/models/article.py
+81
-7
wiki/models/urlpath.py
+3
-2
No files found.
testproject/db/prepopulated.db
View file @
83fe3d46
No preview for this file type
testproject/testproject/settings.py
View file @
83fe3d46
...
...
@@ -85,6 +85,7 @@ INSTALLED_APPS = (
'django.contrib.admindocs'
,
'south'
,
'wiki'
,
'mptt'
,
)
# A sample logging configuration. The only tangible logging
...
...
wiki/conf/settings.py
View file @
83fe3d46
...
...
@@ -2,4 +2,6 @@
from
django.conf
import
settings
as
django_settings
# Should urls be case sensitive?
URL_CASE_SENSITIVE
=
getattr
(
django_settings
,
"WIKI_URL_CASE_SENSITIVE"
,
False
)
\ No newline at end of file
URL_CASE_SENSITIVE
=
getattr
(
django_settings
,
"WIKI_URL_CASE_SENSITIVE"
,
False
)
APP_LABEL
=
'wiki'
\ No newline at end of file
wiki/migrations/0001_initial.py
View file @
83fe3d46
This diff is collapsed.
Click to expand it.
wiki/models/__init__.py
View file @
83fe3d46
# -*- coding: utf-8 -*-
from
django.conf
import
settings
from
django.conf
import
settings
as
django_settings
from
django.core.exceptions
import
ImproperlyConfigured
import
warnings
from
article
import
Article
,
ArticleRevision
,
ObjectForArticle
from
urlpath
import
URLPath
from
article
import
Article
,
ArticleRevision
######################
# Configuration stuff
######################
if
not
'mptt'
in
settings
.
INSTALLED_APPS
:
if
not
'mptt'
in
django_
settings
.
INSTALLED_APPS
:
raise
ImproperlyConfigured
(
'django-wiki: needs mptt in INSTALLED_APPS'
)
if
not
'django.contrib.contenttypes'
in
django_settings
.
INSTALLED_APPS
:
raise
ImproperlyConfigured
(
'django-wiki: needs django.contrib.contenttypes in INSTALLED_APPS'
)
######################
# Warnings
######################
if
not
'south'
in
settings
.
INSTALLED_APPS
:
warnings
.
warn
(
"django-wiki: No south in your INSTALLED_APPS. This is highly discouraged."
)
\ No newline at end of file
if
not
'south'
in
django_settings
.
INSTALLED_APPS
:
warnings
.
warn
(
"django-wiki: No south in your INSTALLED_APPS. This is highly discouraged."
)
\ No newline at end of file
wiki/models/article.py
View file @
83fe3d46
# -*- coding: utf-8 -*-
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes
import
generic
from
django.contrib.auth.models
import
User
,
Group
from
wiki.conf
import
settings
class
Article
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
512
,
verbose_name
=
_
(
u'title'
))
current_revision
=
models
.
ForeignKey
(
'ArticleRevision'
)
title
=
models
.
CharField
(
max_length
=
512
,
verbose_name
=
_
(
u'title'
),
null
=
False
,
blank
=
False
)
current_revision
=
models
.
ForeignKey
(
'ArticleRevision'
,
verbose_name
=
_
(
u'current revision'
),
blank
=
True
,
null
=
True
,
related_name
=
'current_set'
)
# Permissions. If nothing is set, the article will inherit from
# some other parent, whatever the semantics dictate. For instance, using
# URLPaths means that the article inherits from its URLPath parent.
# Inheriting permissions requires a "get_parent_articles" method to exist on
# one of the objects related to the article.
# TIP: The related object with a get_parent_articles method should be an
# MPTTModel inheritor for efficiency. See the URLPath model.
owner
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'owner'
),
blank
=
True
,
null
=
True
)
group
=
models
.
ForeignKey
(
Group
,
verbose_name
=
_
(
'group'
),
blank
=
True
,
null
=
True
)
group_read
=
models
.
BooleanField
(
default
=
True
)
group_write
=
models
.
BooleanField
(
default
=
True
)
other_read
=
models
.
BooleanField
(
default
=
True
)
other_write
=
models
.
BooleanField
(
default
=
True
)
def
can_read
(
self
,
user
=
None
,
group
=
None
):
return
True
def
can_write
(
self
,
user
=
None
,
group
=
None
):
return
True
def
add_revision
(
self
,
new_revision
,
save
=
True
):
"""
Sets the properties of a revision and ensures its the current
revision.
"""
assert
self
.
id
or
save
,
(
'Article.add_revision: Sorry, you cannot add a'
'revision to an article that has not been saved '
'without using save=True'
)
revisions
=
self
.
articlerevision_set
.
all
()
try
:
new_revision
.
revision_number
=
revisions
.
latest
()
.
revision_number
+
1
except
ArticleRevision
.
DoesNotExist
:
new_revision
.
revision_number
=
0
new_revision
.
article
=
self
new_revision
.
save
()
if
save
:
new_revision
.
save
()
self
.
current_revision
=
new_revision
self
.
save
()
if
save
:
self
.
save
()
def
add_object_relation
(
self
,
obj
):
content_type
=
ContentType
.
objects
.
get_for_model
(
obj
)
rel
=
ObjectForArticle
.
objects
.
get_or_create
(
article
=
self
,
content_type
=
content_type
,
object_pk
=
obj
.
pk
,)
return
rel
class
Meta
:
app_label
=
settings
.
APP_LABEL
class
ObjectForArticle
(
models
.
Model
):
article
=
models
.
ForeignKey
(
'Article'
)
# Same as django.contrib.comments
content_type
=
models
.
ForeignKey
(
ContentType
,
verbose_name
=
_
(
'content type'
),
related_name
=
"content_type_set_for_
%(class)
s"
)
object_pk
=
models
.
TextField
(
_
(
'object ID'
))
content_object
=
generic
.
GenericForeignKey
(
ct_field
=
"content_type"
,
fk_field
=
"object_pk"
)
class
Meta
:
app_label
=
settings
.
APP_LABEL
class
ArticleRevision
(
models
.
Model
):
article
=
models
.
ForeignKey
(
'Article'
,
on_delete
=
models
.
CASCADE
,)
...
...
@@ -37,4 +96,19 @@ class ArticleRevision(models.Model):
# way, we can redirects and still maintain old content.
redirect
=
models
.
ForeignKey
(
'Article'
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
u'redirect'
),
help_text
=
_
(
u'If set, the article will redirect to the contents of another article.'
))
\ No newline at end of file
help_text
=
_
(
u'If set, the article will redirect to the contents of another article.'
),
related_name
=
'redirect_set'
)
# User details
ip_address
=
models
.
IPAddressField
(
_
(
'IP address'
),
blank
=
True
,
null
=
True
)
user
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'user'
),
blank
=
True
,
null
=
True
)
# Various stuff
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
modified
=
models
.
DateTimeField
(
auto_now
=
True
)
class
Meta
:
app_label
=
settings
.
APP_LABEL
get_latest_by
=
(
'id'
,)
\ No newline at end of file
wiki/models/urlpath.py
View file @
83fe3d46
...
...
@@ -13,8 +13,8 @@ class URLPath(MPTTModel):
Strategy: Very few fields go here, as most has to be managed through an
article's revision. As a side-effect, the URL resolution remains slim and swift.
"""
article
=
models
.
ForeignKey
(
'Article'
,
verbose
n
_name
=
_
(
u'article'
),
article
=
models
.
ForeignKey
(
'
wiki.
Article'
,
verbose_name
=
_
(
u'article'
),
help_text
=
_
(
u'Article to be displayed for this path'
))
slug
=
models
.
SlugField
(
verbose_name
=
_
(
u'slug'
))
site
=
models
.
ForeignKey
(
Site
)
...
...
@@ -36,6 +36,7 @@ class URLPath(MPTTModel):
verbose_name
=
_
(
u'URL path'
)
verbose_name_plural
=
_
(
u'URL paths'
)
unique_together
=
(
'site'
,
'parent'
,
'slug'
)
app_label
=
settings
.
APP_LABEL
@classmethod
def
get_by_path
(
cls
,
path
):
...
...
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