Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
edx
course-discovery
Commits
5e334a7b
Commit
5e334a7b
authored
May 09, 2017
by
Awais
Committed by
Awais Qureshi
May 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding revision comparison with current course version and loading changes into
tinymce's. ECOM-7790
parent
6d1b800b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
9 deletions
+95
-9
course_discovery/apps/publisher/tests/test_views.py
+25
-0
course_discovery/apps/publisher/views.py
+11
-2
course_discovery/static/js/publisher/course-edit-history-compare.js
+15
-0
course_discovery/static/js/publisher/revision-history.js
+10
-3
course_discovery/static/js/publisher/tinymce-init.js
+7
-1
course_discovery/templates/publisher/_history_widget.html
+8
-1
course_discovery/templates/publisher/course_detail/_widgets.html
+4
-1
course_discovery/templates/publisher/course_edit_form.html
+15
-1
No files found.
course_discovery/apps/publisher/tests/test_views.py
View file @
5e334a7b
...
...
@@ -2243,6 +2243,31 @@ class CourseEditViewTests(TestCase):
course
=
Course
.
objects
.
get
(
id
=
self
.
course
.
id
)
self
.
assertEqual
(
post_data
[
field
]
.
strip
(),
getattr
(
course
,
field
)
.
strip
())
def
test_edit_page_with_revision_changes
(
self
):
"""
Verify that page contains the history object.
"""
self
.
user
.
groups
.
add
(
Group
.
objects
.
get
(
name
=
INTERNAL_USER_GROUP_NAME
))
self
.
course
.
title
=
"updated title"
self
.
course
.
save
()
history_obj
=
self
.
course
.
history
.
first
()
response
=
self
.
client
.
get
(
self
.
edit_page_url
+
'?history_id={}'
.
format
(
history_obj
.
history_id
))
self
.
assertEqual
(
history_obj
.
history_id
,
response
.
context
[
'history_object'
]
.
history_id
)
def
test_edit_page_with_invalid_revision_id
(
self
):
"""
Verify that if history id is invalid then history object will be none.
"""
self
.
user
.
groups
.
add
(
Group
.
objects
.
get
(
name
=
INTERNAL_USER_GROUP_NAME
))
self
.
course
.
title
=
"updated title"
self
.
course
.
save
()
response
=
self
.
client
.
get
(
self
.
edit_page_url
+
'?history_id={}'
.
format
(
100
))
self
.
assertIsNone
(
response
.
context
[
'history_object'
])
@ddt.ddt
class
CourseRunEditViewTests
(
TestCase
):
...
...
course_discovery/apps/publisher/views.py
View file @
5e334a7b
...
...
@@ -339,10 +339,19 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
CourseEditView
,
self
)
.
get_context_data
(
**
kwargs
)
history_id
=
self
.
request
.
GET
.
get
(
'history_id'
,
None
)
try
:
history_object
=
self
.
object
.
history
.
get
(
history_id
=
history_id
)
if
history_id
else
None
except
:
# pylint: disable=bare-except
history_object
=
None
context
.
update
(
{
'is_internal_user'
:
is_internal_user
(
self
.
request
.
user
)}
{
'is_internal_user'
:
is_internal_user
(
self
.
request
.
user
),
'history_object'
:
history_object
}
)
return
context
def
form_valid
(
self
,
form
):
...
...
course_discovery/static/js/publisher/course-edit-history-compare.js
0 → 100644
View file @
5e334a7b
$
(
document
).
ready
(
function
(){
$
(
'.history'
).
each
(
function
()
{
var
dmp
=
new
diff_match_patch
();
var
element_id
=
this
.
id
.
split
(
'_revision'
)[
0
];
var
current_course_object
=
$
(
'#'
+
element_id
).
val
();
var
history_object_value
=
$
(
this
).
val
().
trim
();
if
(
history_object_value
!=
''
)
{
var
d
=
dmp
.
diff_main
(
current_course_object
,
history_object_value
);
dmp
.
diff_cleanupEfficiency
(
d
)
tinymce
.
get
(
element_id
).
setContent
(
dmp
.
diff_prettyHtml
(
d
))
}
});
});
course_discovery/static/js/publisher/revision-history.js
View file @
5e334a7b
$
(
document
).
on
(
'change'
,
'#id_select_revisions'
,
function
(
e
)
{
var
revisionUrl
=
$
(
this
.
selectedOptions
).
data
(
'revisionUrl'
);
// on changing the revision from dropdown set the href of button.
// on changing the revision from drop
-
down set the href of button.
$
(
'#id_open_revision'
).
prop
(
"href"
,
this
.
value
);
var
btn_edit
=
$
(
'#btn_course_edit'
);
var
current_btn_edit_url
=
btn_edit
.
attr
(
'href'
);
if
(
revisionUrl
)
{
loadRevisionHistory
(
revisionUrl
);
}
else
{
...
...
@@ -11,10 +14,14 @@ $(document).on('change', '#id_select_revisions', function (e) {
}
//show revert button for any revision except current version.
if
(
this
.
selectedIndex
>
0
)
if
(
this
.
selectedIndex
>
0
)
{
$
(
'#span_revert_revision'
).
show
();
else
btn_edit
.
prop
(
"href"
,
$
(
this
.
selectedOptions
).
data
(
'revisionId'
));
}
else
{
$
(
'#span_revert_revision'
).
hide
();
btn_edit
.
prop
(
"href"
,
current_btn_edit_url
.
split
(
'?history'
)[
0
]);
}
});
...
...
course_discovery/static/js/publisher/tinymce-init.js
View file @
5e334a7b
...
...
@@ -10,9 +10,15 @@ $(document).ready(function(){
paste_remove_styles
:
true
,
paste_as_text
:
true
,
paste_auto_cleanup_on_paste
:
true
,
skin
:
false
skin
:
false
,
forced_root_block
:
false
};
tinymceConfig
[
"selector"
]
=
"textarea"
;
tinymce
.
init
(
tinymceConfig
);
tinymceConfig
[
"selector"
]
=
"#id_title"
;
tinymceConfig
[
"toolbar"
]
=
false
;
tinymce
.
init
(
tinymceConfig
);
});
course_discovery/templates/publisher/_history_widget.html
View file @
5e334a7b
...
...
@@ -11,7 +11,14 @@
{% endblocktrans %}
</option>
{% else %}
<option
data-revision-url=
"{% url 'publisher:api:course_revisions' history.history_id %}"
value=
"{% url 'publisher:publisher_course_revision' course.id history.history_id %}"
data-revert-url=
"{% url 'publisher:api:course_revision_revert' history.history_id %}"
>
{% url 'publisher:api:course_revisions' history.history_id as revision_url %}
{% url 'publisher:publisher_course_revision' course.id history.history_id as course_revision_url %}
{% url 'publisher:api:course_revision_revert' history.history_id as revision_revert_url %}
{% url 'publisher:publisher_courses_edit' pk=object.id as revision_id_url %}
<option
data-revision-url=
"{{ revision_url }}"
value=
"{{ course_revision_url }}"
data-revert-url=
"{{ revision_revert_url }}"
data-revision-id=
"{{ revision_id_url }}?history_id={{ history.history_id }}"
>
{% blocktrans with history.history_date|date:'d-m-Y' as history_date and history.changed_by as changed_by trimmed %}
{{ history_date }}
by
{{ changed_by}}
{% endblocktrans %}
...
...
course_discovery/templates/publisher/course_detail/_widgets.html
View file @
5e334a7b
...
...
@@ -3,11 +3,14 @@
<div
class=
"course-widgets"
>
{% if can_edit %}
{% url 'publisher:publisher_courses_edit' pk=object.id as edit_page_url %}
<a
href=
"{% if add_warning_popup %}#{% else %}{{ edit_page_url }}{% endif %}"
class=
"btn btn-neutral btn-course-edit"
>
<a
id=
"btn_course_edit"
href=
"{% if add_warning_popup %}#{% else %}{{ edit_page_url }}{% endif %}"
class=
"btn btn-neutral btn-course-edit"
>
{% trans "EDIT" %}
</a>
<div
class=
"clearfix"
></div>
{% endif %}
<div
class=
"clearfix"
></div>
<div
class=
"margin-top20"
>
<h5
class=
"hd-5 emphasized course-runs-heading"
>
{% trans "COURSE RUNS" %}
</h5>
<a
href=
"{% url 'publisher:publisher_course_runs_new' parent_course_id=object.id %}"
class=
"btn btn-brand btn-small btn-courserun-add"
>
...
...
course_discovery/templates/publisher/course_edit_form.html
View file @
5e334a7b
...
...
@@ -93,7 +93,9 @@
</label>
{{ form.team_admin }}
<label
class=
"field-label "
>
{{ form.title.label }}
</label>
{{ form.title }}
<label
class=
"field-label "
>
{{ form.title.label }}
</label>
<input
id=
"id_title_revision"
type=
"text"
value=
"{{ history_object.title }}"
class=
"history"
>
{{ form.title }}
</div>
</div>
<div
class=
"field-title"
>
{% trans "COURSE NUMBER" %}
</div>
...
...
@@ -161,6 +163,7 @@
</div>
</div>
<div
class=
"col col-6"
>
<input
id=
"id_short_description_revision"
type=
"hidden"
value=
"{{ history_object.short_description }}"
class=
"history"
>
<label
class=
"field-label "
>
{{ form.short_description.label_tag }}
</label>
{{ form.short_description }}
<p>
{% trans "255 character limit, including spaces." %}
</p>
...
...
@@ -209,6 +212,7 @@
</div>
<div
class=
"col col-6"
>
<label
class=
"field-label "
>
{{ form.full_description.label_tag }}
</label>
<input
id=
"id_full_description_revision"
type=
"hidden"
value=
"{{ history_object.full_description }}"
class=
"history"
>
{{ form.full_description }}
<p>
{% trans "2500 character limit, including spaces." %}
</p>
{% if form.full_description.errors %}
...
...
@@ -252,6 +256,7 @@
</div>
<div
class=
"col col-6"
>
<label
class=
"field-label "
>
{{ form.expected_learnings.label_tag }}
</label>
<input
id=
"id_expected_learnings_revision"
type=
"hidden"
value=
"{{ history_object.expected_learnings }}"
class=
"history"
>
{{ form.expected_learnings }}
<p>
{% trans "2500 character limit, including spaces." %}
</p>
{% if form.expected_learnings.errors %}
...
...
@@ -351,6 +356,7 @@
</div>
<div
class=
"col col-6"
>
<label
class=
"field-label "
>
{{ form.prerequisites.label_tag }}
</label>
<input
id=
"id_prerequisites_revision"
type=
"hidden"
value=
"{{ history_object.prerequisites }}"
class=
"history"
>
{{ form.prerequisites }}
<p>
{% trans "200 character limit, including spaces." %}
</p>
{% if form.prerequisites.errors %}
...
...
@@ -397,6 +403,7 @@
</div>
<div
class=
"col col-6"
>
<label
class=
"field-label "
>
{{ form.syllabus.label_tag }}
</label>
<input
id=
"id_syllabus_revision"
type=
"hidden"
value=
"{{ history_object.syllabus }}"
class=
"history"
>
{{ form.syllabus }}
<p>
{% trans "2500 character limit, including spaces." %}
</p>
{% if form.syllabus.errors %}
...
...
@@ -431,6 +438,7 @@
</div>
<div
class=
"col col-6 help-text"
>
<label
class=
"field-label "
>
{{ form.faq.label }}
</label>
<input
id=
"id_faq_revision"
type=
"hidden"
value=
"{{ history_object.faq }}"
class=
"history"
>
{{ form.faq }}
<p>
{% trans "2500 character limit, including spaces." %}
</p>
{% if form.faq.errors %}
...
...
@@ -528,6 +536,7 @@
</div>
<div
class=
"col col-6 help-text"
>
<label
class=
"field-label "
>
{{ form.learner_testimonial.label }}
</label>
<input
id=
"id_learner_testimonial_revision"
type=
"hidden"
value=
"{{ history_object.learner_testimonial }}"
class=
"history"
>
{{ form.learner_testimonial }}
<p>
{% trans "500 character limit, including spaces." %}
</p>
{% if form.learner_testimonial.errors %}
...
...
@@ -557,9 +566,12 @@
</form>
</div>
</div>
<input
type=
"button"
id=
"show"
value=
"showdif"
>
{% endblock %}
{{% block extra_js %}
<script
src=
"{% static 'js/publisher/course-tabs.js' %}"
></script>
<script
src=
"{% static 'js/publisher/organizations.js' %}"
></script>
<script
src=
"{% static 'js/publisher/image-validation.js' %}"
></script>
...
...
@@ -573,6 +585,8 @@
<script
src=
"{% static 'bower_components/tinymce/plugins/link/plugin.min.js' %}"
></script>
<script
src=
"{% static 'bower_components/tinymce/plugins/anchor/plugin.min.js' %}"
></script>
<script
src=
"{% static 'bower_components/tinymce/plugins/paste/plugin.min.js' %}"
></script>
<script
src=
"{% static 'bower_components/google-diff-match-patch/diff_match_patch.js' %}"
></script>
<script
src=
"{% static 'js/publisher/course-edit-history-compare.js' %}"
></script>
{% endblock %}
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