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
fb40d08f
Commit
fb40d08f
authored
Jan 09, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid losing user data when a sidebar form is called and article contents have been modified #33
parent
b9e95efa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
20 deletions
+59
-20
wiki/core/plugins/base.py
+8
-2
wiki/plugins/images/forms.py
+1
-1
wiki/plugins/images/templates/wiki/plugins/images/sidebar.html
+31
-16
wiki/templates/wiki/includes/editor_sidebar.html
+1
-1
wiki/views/article.py
+18
-0
No files found.
wiki/core/plugins/base.py
View file @
fb40d08f
...
@@ -9,6 +9,7 @@ from django.utils.translation import ugettext as _
...
@@ -9,6 +9,7 @@ from django.utils.translation import ugettext as _
Please have a look in wiki.models.pluginbase to see where to inherit your
Please have a look in wiki.models.pluginbase to see where to inherit your
plugin's models.
plugin's models.
"""
"""
from
django
import
forms
class
BasePlugin
(
object
):
class
BasePlugin
(
object
):
"""Plugins should inherit from this"""
"""Plugins should inherit from this"""
...
@@ -35,8 +36,13 @@ class BasePlugin(object):
...
@@ -35,8 +36,13 @@ class BasePlugin(object):
js
=
[]
js
=
[]
css
=
{}
css
=
{}
class
PluginSidebarFormMixin
(
object
):
class
PluginSidebarFormMixin
(
forms
.
ModelForm
):
unsaved_article_title
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
(),
required
=
True
)
unsaved_article_content
=
forms
.
CharField
(
widget
=
forms
.
HiddenInput
(),
required
=
False
)
def
get_usermessage
(
self
):
def
get_usermessage
(
self
):
pass
pass
...
...
wiki/plugins/images/forms.py
View file @
fb40d08f
...
@@ -5,7 +5,7 @@ from wiki.core.plugins.base import PluginSidebarFormMixin
...
@@ -5,7 +5,7 @@ from wiki.core.plugins.base import PluginSidebarFormMixin
from
wiki.plugins.images
import
models
from
wiki.plugins.images
import
models
class
SidebarForm
(
forms
.
ModelForm
,
PluginSidebarFormMixin
):
class
SidebarForm
(
PluginSidebarFormMixin
):
def
__init__
(
self
,
article
,
request
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
article
,
request
,
*
args
,
**
kwargs
):
self
.
article
=
article
self
.
article
=
article
...
...
wiki/plugins/images/templates/wiki/plugins/images/sidebar.html
View file @
fb40d08f
...
@@ -13,6 +13,16 @@ function insert_image(image_id) {
...
@@ -13,6 +13,16 @@ function insert_image(image_id) {
$
(
'#id_content'
).
insertAtCaret
(
imagetag
+
'
\
n
\
n'
);
$
(
'#id_content'
).
insertAtCaret
(
imagetag
+
'
\
n
\
n'
);
}
}
}
}
$
(
document
).
ready
(
function
()
{
$
(
'.sidebar-form'
).
each
(
function
()
{
$
(
this
).
submit
(
function
()
{
this
.
unsaved_article_title
.
value
=
$
(
'#id_title'
).
val
();
this
.
unsaved_article_content
.
value
=
$
(
'#id_content'
).
val
();
});
});
});
</script>
</script>
{% endaddtoblock %}
{% endaddtoblock %}
...
@@ -72,22 +82,27 @@ function insert_image(image_id) {
...
@@ -72,22 +82,27 @@ function insert_image(image_id) {
{% endfor %}
{% endfor %}
{% endif %}
{% endif %}
{% for field in form %}
{# Include the hidden fields #}
<fieldset
id=
"div_{{ field.auto_id }}"
class=
"control-group fields {% if field.errors %} error{% endif %}"
>
{% for hidden in form.hidden_fields %}
{% if field.label %}
{{ hidden }}
<!--<label for="{{ field.id_for_label }}" class="{% if field.field.required %}requiredField{% endif %}">
{% endfor %}
{{ field.label|safe }}
</label>-->
{% for field in form.visible_fields %}
{% endif %}
<fieldset
id=
"div_{{ field.auto_id }}"
class=
"control-group fields {% if field.errors %} error{% endif %}"
>
{{ field }}
{% if field.label %}
{% if field.errors %}
<!--<label for="{{ field.id_for_label }}" class="{% if field.field.required %}requiredField{% endif %}">
<div
id=
"error_{{ forloop.counter }}_{{ field.auto_id }}"
class=
"help-block"
>
{{ field.label|safe }}
{% for error in field.errors %}
</label>-->
<div>
{{ error }}
</div>
{% endif %}
{% endfor %}
{{ field }}
</div>
{% if field.errors %}
{% endif %}
<div
id=
"error_{{ forloop.counter }}_{{ field.auto_id }}"
class=
"help-block"
>
</fieldset>
{% for error in field.errors %}
<div>
{{ error }}
</div>
{% endfor %}
</div>
{% endif %}
</fieldset>
{% if field.help_text %}
{% if field.help_text %}
<p
id=
"hint_{{ field.auto_id }}"
class=
"help-block"
>
{{ field.help_text|safe }}
</p>
<p
id=
"hint_{{ field.auto_id }}"
class=
"help-block"
>
{{ field.help_text|safe }}
</p>
{% endif %}
{% endif %}
...
...
wiki/templates/wiki/includes/editor_sidebar.html
View file @
fb40d08f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
<div
class=
"accordion-inner form-vertical"
>
<div
class=
"accordion-inner form-vertical"
>
{% if plugin.sidebar.template %}
{% if plugin.sidebar.template %}
{% with plugin_form as form and plugin as plugin %}
{% with plugin_form as form and plugin as plugin %}
<form
method=
"POST"
class=
"form-horizontal"
action=
"?f={{ plugin_form.form_id }}"
enctype=
"multipart/form-data"
>
<form
method=
"POST"
class=
"form-horizontal
sidebar-form
"
action=
"?f={{ plugin_form.form_id }}"
enctype=
"multipart/form-data"
>
{% csrf_token %}
{% csrf_token %}
{% include plugin.sidebar.template %}
{% include plugin.sidebar.template %}
</form>
</form>
...
...
wiki/views/article.py
View file @
fb40d08f
...
@@ -219,6 +219,17 @@ class Edit(FormView, ArticleMixin):
...
@@ -219,6 +219,17 @@ class Edit(FormView, ArticleMixin):
self
.
sidebar
=
[]
self
.
sidebar
=
[]
return
super
(
Edit
,
self
)
.
dispatch
(
request
,
article
,
*
args
,
**
kwargs
)
return
super
(
Edit
,
self
)
.
dispatch
(
request
,
article
,
*
args
,
**
kwargs
)
def
get_initial
(
self
):
initial
=
FormView
.
get_initial
(
self
)
for
field_name
in
[
'title'
,
'content'
]:
session_key
=
'unsaved_article_
%
s_
%
d'
%
(
field_name
,
self
.
article
.
id
)
if
session_key
in
self
.
request
.
session
.
keys
():
content
=
self
.
request
.
session
[
session_key
]
initial
[
field_name
]
=
content
del
self
.
request
.
session
[
session_key
]
return
initial
def
get_form
(
self
,
form_class
):
def
get_form
(
self
,
form_class
):
"""
"""
Checks from querystring data that the edit form is actually being saved,
Checks from querystring data that the edit form is actually being saved,
...
@@ -266,9 +277,16 @@ class Edit(FormView, ArticleMixin):
...
@@ -266,9 +277,16 @@ class Edit(FormView, ArticleMixin):
messages
.
success
(
self
.
request
,
usermessage
)
messages
.
success
(
self
.
request
,
usermessage
)
else
:
else
:
messages
.
success
(
self
.
request
,
_
(
u'Your changes were saved.'
))
messages
.
success
(
self
.
request
,
_
(
u'Your changes were saved.'
))
request
.
session
[
'unsaved_article_title_
%
d'
%
self
.
article
.
id
]
=
form
.
cleaned_data
[
'unsaved_article_title'
]
request
.
session
[
'unsaved_article_content_
%
d'
%
self
.
article
.
id
]
=
form
.
cleaned_data
[
'unsaved_article_content'
]
messages
.
warning
(
request
,
_
(
'Please note that your article text has not yet been saved!'
))
if
self
.
urlpath
:
if
self
.
urlpath
:
return
redirect
(
'wiki:edit'
,
path
=
self
.
urlpath
.
path
)
return
redirect
(
'wiki:edit'
,
path
=
self
.
urlpath
.
path
)
return
redirect
(
'wiki:edit'
,
article_id
=
self
.
article
.
id
)
return
redirect
(
'wiki:edit'
,
article_id
=
self
.
article
.
id
)
else
:
else
:
form
=
Form
(
self
.
article
,
self
.
request
)
form
=
Form
(
self
.
article
,
self
.
request
)
setattr
(
form
,
'form_id'
,
form_id
)
setattr
(
form
,
'form_id'
,
form_id
)
...
...
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