Commit 794b1457 by Awais Committed by Awais Qureshi

Adding comments template on course-run detail page.

ECOM-6075
parent d7cf29c3
from django.db import migrations
def create_switch(apps, schema_editor):
"""Create the publisher_comment_widget_feature switch if it does not already exist."""
Switch = apps.get_model('waffle', 'Switch')
Switch.objects.get_or_create(name='publisher_comment_widget_feature', defaults={'active': False})
def delete_switch(apps, schema_editor):
"""Delete the publisher_comment_widget_feature switch."""
Switch = apps.get_model('waffle', 'Switch')
Switch.objects.filter(name='publisher_comment_widget_feature').delete()
class Migration(migrations.Migration):
dependencies = [
('publisher', '0031_courserunstate_coursestate_historicalcourserunstate_historicalcoursestate'),
('waffle', '0001_initial'),
]
operations = [
migrations.RunPython(create_switch, delete_switch),
]
...@@ -601,8 +601,7 @@ class SeatsCreateUpdateViewTests(TestCase): ...@@ -601,8 +601,7 @@ class SeatsCreateUpdateViewTests(TestCase):
# add new and check the comment on edit page. # add new and check the comment on edit page.
comment = CommentFactory(content_object=self.seat, user=self.user, site=self.site) comment = CommentFactory(content_object=self.seat, user=self.user, site=self.site)
response = self.client.get(self.seat_edit_url) response = self.client.get(self.seat_edit_url)
self.assertContains(response, 'Total Comments 1') self.assertContains(response, 'Comment:')
self.assertContains(response, 'Add new comment')
self.assertContains(response, comment.comment) self.assertContains(response, comment.comment)
def test_edit_seat_page_with_non_staff(self): def test_edit_seat_page_with_non_staff(self):
...@@ -861,7 +860,6 @@ class CourseRunDetailTests(TestCase): ...@@ -861,7 +860,6 @@ class CourseRunDetailTests(TestCase):
self._assert_cat(response) self._assert_cat(response)
self._assert_drupal(response) self._assert_drupal(response)
self._assert_subjects(response) self._assert_subjects(response)
self.assertContains(response, 'Total Comments 1')
self.assertContains(response, comment.comment) self.assertContains(response, comment.comment)
self._assert_breadcrumbs(response, self.course_run) self._assert_breadcrumbs(response, self.course_run)
...@@ -990,22 +988,38 @@ class CourseRunDetailTests(TestCase): ...@@ -990,22 +988,38 @@ class CourseRunDetailTests(TestCase):
self.assertNotIn(response_string, '<button data-tab="#tab-4">DRUPAL</button>') self.assertNotIn(response_string, '<button data-tab="#tab-4">DRUPAL</button>')
self.assertNotIn(response_string, '<button data-tab="#tab-5">Salesforce</button>') self.assertNotIn(response_string, '<button data-tab="#tab-5">Salesforce</button>')
def test_page_enable_waffle_switch(self): def test_page_enable_waffle_switch_pilot(self):
""" Verify that user will see only studio fields when 'publisher_hide_features_for_pilot' is activated. """ """ Verify that user will see only studio fields when 'publisher_hide_features_for_pilot' is activated. """
toggle_switch('publisher_hide_features_for_pilot', True) toggle_switch('publisher_hide_features_for_pilot', True)
response = self.client.get(self.page_url) response = self.client.get(self.page_url)
self.assertContains(response, '<aside class="layout-col layout-col-a hidden">') self.assertContains(response, '<div id="approval-widget" class="hidden">')
self.assertContains(response, '<div class="non-studio-fields hidden">') self.assertContains(response, '<div class="non-studio-fields hidden">')
def test_page_disable_waffle_switch(self): def test_page_disable_waffle_switch_pilot(self):
""" Verify that user will see whole page when 'publisher_hide_features_for_pilot' is deactivated. """ """ Verify that user will see whole page when 'publisher_hide_features_for_pilot' is deactivated. """
toggle_switch('publisher_hide_features_for_pilot', False) toggle_switch('publisher_hide_features_for_pilot', False)
response = self.client.get(self.page_url) response = self.client.get(self.page_url)
response_string = response.content.decode('UTF-8') self.assertContains(response, '<div id="approval-widget" class="">')
self.assertNotIn(response_string, '<aside class="layout-col layout-col-a hidden">') self.assertContains(response, '<div class="non-studio-fields ">')
self.assertNotIn(response_string, '<div class="non-studio-fields hidden">')
def test_comments_with_enable_switch(self):
""" Verify that user will see the comments widget when
'publisher_comment_widget_feature' is enabled.
"""
toggle_switch('publisher_comment_widget_feature', True)
response = self.client.get(self.page_url)
self.assertContains(response, '<div id="comments-widget" class="comment-container ">')
def test_comments_with_disable_switch(self):
""" Verify that user will not see the comments widget when
'publisher_comment_widget_feature' is disable.
"""
toggle_switch('publisher_comment_widget_feature', False)
response = self.client.get(self.page_url)
self.assertContains(response, '<div id="comments-widget" class="comment-container hidden">')
class ChangeStateViewTests(TestCase): class ChangeStateViewTests(TestCase):
......
...@@ -168,6 +168,7 @@ class CourseRunDetailView(mixins.LoginRequiredMixin, mixins.PublisherPermissionM ...@@ -168,6 +168,7 @@ class CourseRunDetailView(mixins.LoginRequiredMixin, mixins.PublisherPermissionM
context['can_view_all_tabs'] = mixins.check_roles_access(self.request.user) context['can_view_all_tabs'] = mixins.check_roles_access(self.request.user)
context['publisher_hide_features_for_pilot'] = waffle.switch_is_active('publisher_hide_features_for_pilot') context['publisher_hide_features_for_pilot'] = waffle.switch_is_active('publisher_hide_features_for_pilot')
context['publisher_comment_widget_feature'] = waffle.switch_is_active('publisher_comment_widget_feature')
return context return context
......
...@@ -7,14 +7,14 @@ msgid "" ...@@ -7,14 +7,14 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-02-08 23:51-0500\n" "POT-Creation-Date: 2017-02-09 15:57+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: apps/api/filters.py #: apps/api/filters.py
#, python-brace-format #, python-brace-format
...@@ -828,12 +828,11 @@ msgid "modified" ...@@ -828,12 +828,11 @@ msgid "modified"
msgstr "" msgstr ""
#: templates/comments/add_auth_comments.html #: templates/comments/add_auth_comments.html
msgid "Add new comment" msgid "Comment:"
msgstr "" msgstr ""
#: templates/comments/comments_list.html #: templates/comments/comments_list.html
#, python-format msgid "Submitted by"
msgid "Total Comments %(comment_count)s"
msgstr "" msgstr ""
#: templates/comments/edit_comment.html #: templates/comments/edit_comment.html
......
...@@ -7,14 +7,14 @@ msgid "" ...@@ -7,14 +7,14 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-02-08 23:51-0500\n" "POT-Creation-Date: 2017-02-09 15:57+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: static/js/catalogs-change-form.js #: static/js/catalogs-change-form.js
msgid "Preview" msgid "Preview"
......
...@@ -7,14 +7,14 @@ msgid "" ...@@ -7,14 +7,14 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-02-08 23:51-0500\n" "POT-Creation-Date: 2017-02-09 15:57+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: apps/api/filters.py #: apps/api/filters.py
...@@ -982,13 +982,12 @@ msgid "modified" ...@@ -982,13 +982,12 @@ msgid "modified"
msgstr "mödïfïéd Ⱡ'σяєм ιρѕυм ∂#" msgstr "mödïfïéd Ⱡ'σяєм ιρѕυм ∂#"
#: templates/comments/add_auth_comments.html #: templates/comments/add_auth_comments.html
msgid "Add new comment" msgid "Comment:"
msgstr "Àdd néw çömmént Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт α#" msgstr "Çömmént: Ⱡ'σяєм ιρѕυм ∂#"
#: templates/comments/comments_list.html #: templates/comments/comments_list.html
#, python-format msgid "Submitted by"
msgid "Total Comments %(comment_count)s" msgstr "Süßmïttéd ßý Ⱡ'σяєм ιρѕυм ∂σłσя ѕ#"
msgstr "Tötäl Çömménts %(comment_count)s Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт#"
#: templates/comments/edit_comment.html #: templates/comments/edit_comment.html
msgid "Course Run Form" msgid "Course Run Form"
......
...@@ -7,14 +7,14 @@ msgid "" ...@@ -7,14 +7,14 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-02-08 23:51-0500\n" "POT-Creation-Date: 2017-02-09 15:57+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/js/catalogs-change-form.js #: static/js/catalogs-change-form.js
......
...@@ -18,43 +18,48 @@ $(document).on('click', '.comment-edit', function (e) { ...@@ -18,43 +18,48 @@ $(document).on('click', '.comment-edit', function (e) {
editableControlsHtml = '<div class="edit-controls"><button class="btn-brand btn-small comment-save">Save</button>' + editableControlsHtml = '<div class="edit-controls"><button class="btn-brand btn-small comment-save">Save</button>' +
'<button class="btn-brand btn-small comment-cancel">Cancel</button></div>'; '<button class="btn-brand btn-small comment-cancel">Cancel</button></div>';
$(parentDt).next('dd').attr('contenteditable', 'True').addClass('editable-comment'); $(parentDt).prev('dd').attr('contenteditable', 'True').addClass('editable-comment');
$(parentDt).after(editableControlsHtml); $(parentDt).prev('dd').after(editableControlsHtml);
$('.editable-comment').data('oldComment', $('.edit-controls').next().text()); $('.editable-comment').data('oldComment', $('.edit-controls').prev().text());
$(parentDt).hide(); $(parentDt).hide();
}); });
$(document).on('click', '.comment-cancel', function (e) { $(document).on('click', '.comment-cancel', function (e) {
e.preventDefault(); e.preventDefault();
cancelHtmlRender();
var editableControls = $('.edit-controls'),
editableDd = $(editableControls).next();
editableDd.text($('.editable-comment').data('oldComment'));
editableControls.hide();
removeEditable(editableControls, editableDd)
}); });
$(document).on('click', '.comment-save', function (e) { $(document).on('click', '.comment-save', function (e) {
e.preventDefault(); e.preventDefault();
var editableControls = $('.edit-controls'), var editableControls = $('.edit-controls'),
editableDd = $(editableControls).next(), editableDd = $(editableControls).prev(),
updatedComment = $(editableDd).text(); updatedComment = $(editableDd).text(),
oldComment = $('.editable-comment').data('oldComment');
if (updatedComment === ''){
$(editableDd).focus();
return
}
if (updatedComment === oldComment) {
cancelHtmlRender();
return
}
$.ajax({ $.ajax({
type: "PATCH", type: "PATCH",
url: $(editableControls).prev().find('button').data('url'), url: $(editableControls).next().find('button').data('url'),
data: {'comment': updatedComment}, data: {'comment': updatedComment},
success: function (response) { success: function (response) {
var formattedDatetime; var formattedDatetime;
removeEditable(editableControls, editableDd); removeEditable(editableControls, editableDd);
$(editableDd).text(response['comment']); $(editableDd).text(response['comment']);
//format datetime e.g. Dec. 15, 2016, 10:03 a.m. //format datetime e.g. February 08, 2017, 13:36:45 p.m.
formattedDatetime = $.format.date(response['modified'], 'MMM. dd, yyyy, hh:mm p'); formattedDatetime = $.format.date(response['modified'], 'MMMM dd, yyyy, hh:mm p');
$(editableDd).prev().find('span.datetime').text(formattedDatetime); $(editableDd).prev('dt').find('span.datetime').text(formattedDatetime);
}, },
error: function () { error: function () {
alert("Unable to edit comment this time, Please try again later."); alert("Unable to edit comment this time, Please try again later.");
...@@ -65,8 +70,17 @@ $(document).on('click', '.comment-save', function (e) { ...@@ -65,8 +70,17 @@ $(document).on('click', '.comment-save', function (e) {
}); });
function cancelHtmlRender(){
var editableControls = $('.edit-controls'),
editableDd = $(editableControls).prev();
editableDd.text($('.editable-comment').data('oldComment'));
editableControls.hide();
removeEditable(editableControls, editableDd)
}
function removeEditable(editableControls, editableDd) { function removeEditable(editableControls, editableDd) {
$(editableControls).remove(); $(editableControls).remove();
$(editableDd).removeAttr('contenteditable').removeClass('editable-comment'); $(editableDd).removeAttr('contenteditable').removeClass('editable-comment');
$(editableDd).prev().show(); $(editableDd).next('dt').show();
} }
...@@ -18,9 +18,35 @@ ...@@ -18,9 +18,35 @@
margin-bottom: 20px; margin-bottom: 20px;
} }
#comments dt { .comments{
font-weight: bold; @include margin(0px, 0px, 0px, 0px);
color: #757575; margin: 5% auto;
.align-right {
@include text-align(right);
margin: 10px auto;
}
.submitted-by {
overflow: auto;
@include text-align(right);
margin-bottom: 40px;
span {
@include float(left);
margin: 10px auto;
}
}
}
.add-comment {
@include text-align(right);
margin-top: 5px;
}
#id_comment {
width: 100%;
max-width: 100%;
rows: 6;
} }
.editable-comment { .editable-comment {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% if user.is_authenticated and comment_object %} {% if user.is_authenticated and comment_object %}
<div> <div>
<p>{% trans 'Add new comment' %}</p> <p><div class="heading">{% trans 'Comment:' %}</div></p>
<div> <div>
{% get_comment_form for comment_object as form %} {% get_comment_form for comment_object as form %}
<form id="frm_comment" action="{% comment_form_target %}" method="POST"> <form id="frm_comment" action="{% comment_form_target %}" method="POST">
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
{{ form.timestamp }} {{ form.timestamp }}
{{ form.security_hash }} {{ form.security_hash }}
<input type="hidden" name="next" value="{% url 'publisher:publisher_course_run_detail' object.id %}"/> <input type="hidden" name="next" value="{% url 'publisher:publisher_course_run_detail' object.id %}"/>
<div> <div class="add-comment">
<input type="button" value="Add comment" id="id_submit" class="btn-brand btn-base" /> <input type="button" value="Add comment" id="id_submit" class="btn btn-brand btn-small btn-course-add" />
</div> </div>
</form> </form>
</div> </div>
......
...@@ -2,25 +2,21 @@ ...@@ -2,25 +2,21 @@
{% load comments %} {% load comments %}
{% if comment_object %} {% if comment_object %}
<div> <div>
{% get_comment_count for comment_object as comment_count %}
<h4 class="hd-4">
{% blocktrans with comment_count=comment_count trimmed %}
Total Comments {{ comment_count }}
{% endblocktrans %}
</h4>
{% get_comment_list for comment_object as comment_list %} {% get_comment_list for comment_object as comment_list %}
<dl class="comments"> <dl class="comments">
{% for comment in comment_list reversed %} {% for comment in comment_list reversed %}
<dt> <dt class="align-right"><span class="datetime">{{ comment.modified|date:"F d, Y, H:i:s a" }}&nbsp;</span></dt>
<span class="datetime">{{ comment.modified }}</span> - <span>{{ comment.name }}</span> <dd class="edit-comment">
{{ comment.comment }}
</dd>
<dt class="submitted-by">
<span>
<em>{% trans 'Submitted by' %}&nbsp;{{ comment.name }}</em>
</span>
{% ifequal user comment.user %} {% ifequal user comment.user %}
- <button class="btn-brand btn-small btn-comment comment-edit" data-url="{% url 'publisher_comments:api:comments' comment.id %}">Edit</button> <button class="align-right btn-neutral btn-small btn-comment comment-edit" data-url="{% url 'publisher_comments:api:comments' comment.id %}">Edit</button>
{% endifequal %} {% endifequal %}
</dt> </dt>
<dd>
{{ comment.comment }}
</dd>
{% endfor %} {% endfor %}
</dl> </dl>
</div> </div>
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
{% endblock title %} {% endblock title %}
{% block page_content %} {% block page_content %}
<div class="layout-1t2t layout-flush publisher-container course-detail"> <div class="grid-manual">
<main class="layout-col layout-col-b"> <main class="col col-7">
<nav class="administration-nav"> <nav class="administration-nav">
<div class="tab-container"> <div class="tab-container">
{% if can_view_all_tabs %} {% if can_view_all_tabs %}
...@@ -66,8 +66,14 @@ ...@@ -66,8 +66,14 @@
</div> </div>
</main> </main>
<aside class="layout-col layout-col-a {% if publisher_hide_features_for_pilot %}hidden{% endif %}"> <aside id="right-panel" class="col col-5">
<div id="approval-widget" class="{% if publisher_hide_features_for_pilot %}hidden{% endif %}">
{% include 'publisher/course_run_detail/_approval_widget.html' %} {% include 'publisher/course_run_detail/_approval_widget.html' %}
</div>
<div id="comments-widget" class="comment-container {% if not publisher_comment_widget_feature %}hidden{% endif %}">
{% include 'comments/add_auth_comments.html' %}
{% include 'comments/comments_list.html' %}
</div>
</aside> </aside>
</div> </div>
{% endblock %} {% endblock %}
......
...@@ -44,9 +44,4 @@ ...@@ -44,9 +44,4 @@
<button type="submit" value="{{ object.change_state_button.value }}" class="btn-brand btn-small btn-states" name="state">{{ object.change_state_button.text }}</button> <button type="submit" value="{{ object.change_state_button.value }}" class="btn-brand btn-small btn-states" name="state">{{ object.change_state_button.text }}</button>
</form> </form>
</div> </div>
<div class="comment-container">
{% include 'comments/comments_list.html' %}
{% include 'comments/add_auth_comments.html' %}
</div>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment