Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
2925cde8
Commit
2925cde8
authored
Jun 10, 2017
by
Skia
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a MarkdownInput widget, and make use of it
Signed-off-by:
Skia
<
skia@libskia.so
>
parent
4b9fa0cd
Pipeline
#1047
failed with stage
in 4 minutes and 47 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
14 deletions
+38
-14
core/static/core/style.scss
core/static/core/style.scss
+12
-0
core/templates/core/base.jinja
core/templates/core/base.jinja
+1
-3
core/views/forms.py
core/views/forms.py
+8
-1
core/views/page.py
core/views/page.py
+3
-3
forum/templates/forum/reply.jinja
forum/templates/forum/reply.jinja
+3
-5
forum/views.py
forum/views.py
+11
-2
No files found.
core/static/core/style.scss
View file @
2925cde8
...
...
@@ -515,6 +515,12 @@ textarea {
margin
:
1px
;
font-size
:
smaller
;
}
a
{
color
:
$black-color
;
}
a
:hover
{
text-decoration
:
underline
;
}
}
.tools
{
...
...
@@ -551,6 +557,12 @@ textarea {
margin
:
1px
;
font-size
:
smaller
;
}
a
{
color
:
$black-color
;
}
a
:hover
{
text-decoration
:
underline
;
}
}
.category
{
...
...
core/templates/core/base.jinja
View file @
2925cde8
...
...
@@ -248,8 +248,7 @@ function add_syntax(e, choice) {
}
$
(
document
).
ready
(
function
()
{
textarea
=
$
(
'
.markdown_editor textarea
'
);
editor
=
textarea
.
parent
();
editor
=
$
(
'
.markdown_editor
'
);
editor
.
prepend
(
'
<a onclick="javascript:add_syntax(this,
\'
image
\'
)">
{%
trans
%}
Image
{%
endtrans
%}
</a>
'
);
editor
.
prepend
(
'
<a onclick="javascript:add_syntax(this,
\'
link
\'
)">
{%
trans
%}
Link
{%
endtrans
%}
</a>
'
);
editor
.
prepend
(
'
<a onclick="javascript:add_syntax(this,
\'
sup
\'
)"><sup>
{%
trans
%}
sup
{%
endtrans
%}
</sup></a>
'
);
...
...
@@ -258,7 +257,6 @@ $(document).ready(function() {
editor
.
prepend
(
'
<a onclick="javascript:add_syntax(this,
\'
underline
\'
)"><u>
{%
trans
%}
U
{%
endtrans
%}
</u></a>
'
);
editor
.
prepend
(
'
<a onclick="javascript:add_syntax(this,
\'
italic
\'
)"><i>
{%
trans
%}
I
{%
endtrans
%}
</i></a>
'
);
editor
.
prepend
(
'
<a onclick="javascript:add_syntax(this,
\'
bold
\'
)"><b>
{%
trans
%}
B
{%
endtrans
%}
</b></a>
'
);
console
.
log
(
textarea
.
parent
());
});
</script>
{%
endblock
%}
...
...
core/views/forms.py
View file @
2925cde8
...
...
@@ -27,7 +27,7 @@ from django import forms
from
django.db
import
transaction
from
django.core.exceptions
import
ValidationError
from
django.contrib.auth
import
logout
,
login
,
authenticate
from
django.forms
import
CheckboxSelectMultiple
,
Select
,
DateInput
,
TextInput
,
DateTimeInput
from
django.forms
import
CheckboxSelectMultiple
,
Select
,
DateInput
,
TextInput
,
DateTimeInput
,
Textarea
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext
from
phonenumber_field.widgets
import
PhoneNumberInternationalFallbackWidget
...
...
@@ -73,6 +73,13 @@ class SelectDate(DateInput):
attrs
=
{
'class'
:
"select_date"
}
return
super
(
SelectDate
,
self
).
render
(
name
,
value
,
attrs
)
class
MarkdownInput
(
Textarea
):
def
render
(
self
,
name
,
value
,
attrs
=
None
):
output
=
'<div class="markdown_editor">%(content)s</div>'
%
{
'content'
:
super
(
MarkdownInput
,
self
).
render
(
name
,
value
,
attrs
),
}
return
output
class
SelectFile
(
TextInput
):
def
render
(
self
,
name
,
value
,
attrs
=
None
):
if
attrs
:
...
...
core/views/page.py
View file @
2925cde8
...
...
@@ -30,10 +30,10 @@ from django.views.generic.edit import UpdateView, CreateView, DeleteView
from
django.contrib.auth.decorators
import
login_required
,
permission_required
from
django.utils.decorators
import
method_decorator
from
django.forms.models
import
modelform_factory
from
django.forms
import
CheckboxSelectMultiple
from
django.forms
import
CheckboxSelectMultiple
,
modelform_factory
from
core.models
import
Page
,
PageRev
,
LockError
from
core.views.forms
import
PagePropForm
from
core.views.forms
import
PagePropForm
,
MarkdownInput
from
core.views
import
CanViewMixin
,
CanEditMixin
,
CanEditPropMixin
,
CanCreateMixin
class
PageListView
(
CanViewMixin
,
ListView
):
...
...
@@ -147,7 +147,7 @@ class PagePropView(CanEditPropMixin, UpdateView):
class
PageEditView
(
CanEditMixin
,
UpdateView
):
model
=
PageRev
fields
=
[
'title'
,
'content'
,]
form_class
=
modelform_factory
(
model
=
PageRev
,
fields
=
[
'title'
,
'content'
,]
,
widgets
=
{
'content'
:
MarkdownInput
})
template_name
=
'core/pagerev_edit.jinja'
def
get_object
(
self
):
...
...
forum/templates/forum/reply.jinja
View file @
2925cde8
...
...
@@ -22,18 +22,16 @@
<div
id=
"forum"
>
<h3>
{{
topic.title
}}
</h3>
<h4>
{%
trans
%}
Reply
{%
endtrans
%}
</h4>
{%
else
%}
{%
else
%}
<div
id=
"forum"
>
<h4>
{%
trans
%}
New topic
{%
endtrans
%}
</h4>
{%
endif
%}
{%
endif
%}
<form
action=
""
method=
"post"
enctype=
"multipart/form-data"
>
{%
csrf_token
%}
<p>
{{
form.title.errors
}}
<label
for=
"
{{
form.title.name
}}
"
>
{{
form.title.label
}}
</label>
{{
form.title
}}
</p>
<p>
{{
form.message.errors
}}
<label
for=
"
{{
form.message.name
}}
"
>
{{
form.message.label
}}
</label>
</p>
<p><a
href=
"
{{
syntax_help_page.get_absolute_url
()
}}
"
>
{%
trans
%}
Help on the syntax
{%
endtrans
%}
</a>
<div
class=
"markdown_editor"
>
{{
form.message
}}
</div>
</p>
<p><input
type=
"button"
value=
"
{%
trans
%}
Preview
{%
endtrans
%}
"
onclick=
"javascript:make_preview();"
/></p>
<p><input
type=
"submit"
value=
"
{%
trans
%}
Save
{%
endtrans
%}
"
/></p>
</form>
...
...
forum/views.py
View file @
2925cde8
...
...
@@ -38,6 +38,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from
ajax_select
import
make_ajax_form
,
make_ajax_field
from
core.views
import
CanViewMixin
,
CanEditMixin
,
CanEditPropMixin
,
CanCreateMixin
,
TabedViewMixin
from
core.views.forms
import
MarkdownInput
from
core.models
import
Page
from
forum.models
import
Forum
,
ForumMessage
,
ForumTopic
,
ForumMessageMeta
...
...
@@ -142,6 +143,9 @@ class TopicForm(forms.ModelForm):
class
Meta
:
model
=
ForumMessage
fields
=
[
'title'
,
'message'
]
widgets
=
{
'message'
:
MarkdownInput
,
}
title
=
forms
.
CharField
(
required
=
True
,
label
=
_
(
"Title"
))
class
ForumTopicCreateView
(
CanCreateMixin
,
CreateView
):
...
...
@@ -162,6 +166,11 @@ class ForumTopicCreateView(CanCreateMixin, CreateView):
form
.
instance
.
author
=
self
.
request
.
user
return
super
(
ForumTopicCreateView
,
self
).
form_valid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
kwargs
=
super
(
ForumTopicCreateView
,
self
).
get_context_data
(
**
kwargs
)
kwargs
[
'syntax_help_page'
]
=
Page
.
get_page_by_full_name
(
settings
.
SITH_CORE_PAGE_SYNTAX
)
return
kwargs
class
ForumTopicEditView
(
CanEditMixin
,
UpdateView
):
model
=
ForumTopic
fields
=
[
'forum'
]
...
...
@@ -205,7 +214,7 @@ class ForumMessageView(SingleObjectMixin, RedirectView):
class
ForumMessageEditView
(
CanEditMixin
,
UpdateView
):
model
=
ForumMessage
fields
=
[
'title'
,
'message'
]
form_class
=
forms
.
modelform_factory
(
model
=
ForumMessage
,
fields
=
[
'title'
,
'message'
,],
widgets
=
{
'message'
:
MarkdownInput
})
template_name
=
"forum/reply.jinja"
pk_url_kwarg
=
"message_id"
...
...
@@ -243,7 +252,7 @@ class ForumMessageUndeleteView(SingleObjectMixin, RedirectView):
class
ForumMessageCreateView
(
CanCreateMixin
,
CreateView
):
model
=
ForumMessage
fields
=
[
'title'
,
'message'
]
form_class
=
forms
.
modelform_factory
(
model
=
ForumMessage
,
fields
=
[
'title'
,
'message'
,],
widgets
=
{
'message'
:
MarkdownInput
})
template_name
=
"forum/reply.jinja"
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
Skia
@skia
Mentioned in issue
#6 (closed)
·
Jun 10, 2017
Mentioned in issue
#6 (closed)
Mentioned in issue #6
Toggle commit list
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