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
db07ac22
Commit
db07ac22
authored
Feb 14, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
invalidate article cache when plugins are updated
parent
1dd47881
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
6 deletions
+35
-6
wiki/models/article.py
+16
-1
wiki/models/pluginbase.py
+18
-2
wiki/templates/wiki/includes/render.html
+1
-3
No files found.
wiki/models/article.py
View file @
db07ac22
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes
import
generic
from
django.contrib.contenttypes
import
generic
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
User
,
Group
from
django.core.cache
import
cache
from
django.db
import
models
from
django.db
import
models
from
django.utils.safestring
import
mark_safe
from
django.utils.safestring
import
mark_safe
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
...
@@ -185,7 +186,21 @@ class Article(models.Model):
...
@@ -185,7 +186,21 @@ class Article(models.Model):
else
:
else
:
content
=
self
.
current_revision
.
content
content
=
self
.
current_revision
.
content
return
mark_safe
(
article_markdown
(
content
,
self
))
return
mark_safe
(
article_markdown
(
content
,
self
))
def
get_cache_key
(
self
):
return
"wiki:article:
%
d"
%
self
.
id
def
get_cached_content
(
self
):
"""Returns cached """
cache_key
=
self
.
get_cache_key
()
cached_content
=
cache
.
get
(
cache_key
)
if
cached_content
is
None
:
cached_content
=
self
.
render
()
cache
.
set
(
cache_key
,
cached_content
,
settings
.
CACHE_TIMEOUT
)
return
cached_content
def
clear_cache
(
self
):
cache
.
delete
(
self
.
get_cache_key
())
class
ArticleForObject
(
models
.
Model
):
class
ArticleForObject
(
models
.
Model
):
...
...
wiki/models/pluginbase.py
View file @
db07ac22
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
from
django.db
import
models
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
django.core.cache
import
cache
from
wiki.models.article
import
BaseRevisionMixin
from
wiki.models.article
import
BaseRevisionMixin
"""
"""
...
@@ -248,4 +250,19 @@ def update_simple_plugins(**kwargs):
...
@@ -248,4 +250,19 @@ def update_simple_plugins(**kwargs):
# TODO: This was breaking things. SimplePlugin doesn't have a revision?
# TODO: This was breaking things. SimplePlugin doesn't have a revision?
p_revisions
.
update
(
article_revision
=
instance
)
p_revisions
.
update
(
article_revision
=
instance
)
signals
.
post_save
.
connect
(
update_simple_plugins
,
ArticleRevision
)
def
on_article_plugin_post_save
(
**
kwargs
):
\ No newline at end of file
articleplugin
=
kwargs
[
'instance'
]
articleplugin
.
article
.
clear_cache
()
def
on_reusable_plugin_post_save
(
**
kwargs
):
reusableplugin
=
kwargs
[
'instance'
]
for
article
in
reusableplugin
.
articles
.
all
():
article
.
clear_cache
()
def
on_revision_plugin_revision_post_save
(
**
kwargs
):
revision
=
kwargs
[
'instance'
]
revision
.
plugin
.
article
.
clear_cache
()
signals
.
post_save
.
connect
(
update_simple_plugins
,
ArticleRevision
)
signals
.
post_save
.
connect
(
on_article_plugin_post_save
,
ArticlePlugin
)
signals
.
post_save
.
connect
(
on_reusable_plugin_post_save
,
ReusablePlugin
)
wiki/templates/wiki/includes/render.html
View file @
db07ac22
...
@@ -8,9 +8,7 @@
...
@@ -8,9 +8,7 @@
{% if not preview %}
{% if not preview %}
{% if article.current_revision %}
{% if article.current_revision %}
{% cache CACHE_TIMEOUT article article.current_revision.id %}
{{ article.get_cached_content }}
{{ article.render }}
{% endcache %}
{% endif %}
{% endif %}
{% else %}
{% else %}
...
...
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