Skip to content

Commit

Permalink
Added error message on saving course-key.
Browse files Browse the repository at this point in the history
ECOM-6748
  • Loading branch information
waheedahmed committed Jan 18, 2017
1 parent db25b93 commit 73e2a23
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 10 deletions.
7 changes: 6 additions & 1 deletion course_discovery/apps/publisher/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Publisher API Serializers"""
import waffle

from django.utils.translation import ugettext_lazy as _
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from rest_framework import serializers
Expand Down Expand Up @@ -51,7 +53,10 @@ def validate(self, data):
try:
CourseKey.from_string(lms_course_id)
except InvalidKeyError:
raise serializers.ValidationError('Invalid course key [{}]'.format(lms_course_id))
# pylint: disable=no-member
raise serializers.ValidationError(
{'lms_course_id': _('Invalid course key "{lms_course_id}"').format(lms_course_id=lms_course_id)}
)

request = self.context.get('request')
if request:
Expand Down
37 changes: 36 additions & 1 deletion course_discovery/apps/publisher/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,42 @@ def test_update_course_key_with_errors(self):

self.assertEqual(response.status_code, 400)
self.assertEqual(
response.data.get('non_field_errors'), ['Invalid course key [{}]'.format(invalid_course_id)]
response.data.get('lms_course_id'),
['Invalid course key "{lms_course_id}"'.format(lms_course_id=invalid_course_id)]
)

def test_update_course_key_without_permission(self):
"""
Test that api returns error without permission.
"""
self.user.groups.remove(Group.objects.get(name=INTERNAL_USER_GROUP_NAME))
response = self.client.patch(
self.update_course_key_url,
data=json.dumps({'lms_course_id': 'course-v1:edxTest+TC12+2050Q1'}),
content_type=JSON_CONTENT_TYPE
)

self.assertEqual(response.status_code, 403)
self.assertEqual(
response.data.get('detail'), 'You do not have permission to perform this action.'
)

def test_update_course_key_with_duplicate(self):
"""
Test that api returns error if course key already exist.
"""
lms_course_id = 'course-v1:edxTest+TC12+2050Q1'
factories.CourseRunFactory(lms_course_id=lms_course_id)

response = self.client.patch(
self.update_course_key_url,
data=json.dumps({'lms_course_id': lms_course_id}),
content_type=JSON_CONTENT_TYPE
)

self.assertEqual(response.status_code, 400)
self.assertEqual(
response.data.get('lms_course_id'), ['CourseRun with this lms course id already exists.']
)

def test_update_course_key(self):
Expand Down
Binary file modified course_discovery/conf/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
9 changes: 7 additions & 2 deletions course_discovery/conf/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"

#: apps/api/filters.py
#, python-brace-format
Expand Down Expand Up @@ -411,6 +411,11 @@ msgstr ""
msgid "JSON string containing an elasticsearch function score config."
msgstr ""

#: apps/publisher/api/serializers.py
#, python-brace-format
msgid "Invalid course key \"{lms_course_id}\""
msgstr ""

#: apps/publisher/choices.py templates/publisher/courses.html
msgid "Partner Coordinator"
msgstr ""
Expand Down
Binary file modified course_discovery/conf/locale/en/LC_MESSAGES/djangojs.mo
Binary file not shown.
8 changes: 6 additions & 2 deletions course_discovery/conf/locale/en/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"

#: static/js/catalogs-change-form.js
msgid "Preview"
Expand All @@ -26,6 +26,10 @@ msgid ""
"{courseRunDetail} with a start date of {startDate}"
msgstr ""

#: static/js/publisher/views/dashboard.js
msgid "There was an error in saving your data."
msgstr ""

#: static/js/publisher/views/navbar.js
msgid "OFF"
msgstr ""
Expand Down
Binary file modified course_discovery/conf/locale/eo/LC_MESSAGES/django.mo
Binary file not shown.
9 changes: 7 additions & 2 deletions course_discovery/conf/locale/eo/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: apps/api/filters.py
Expand Down Expand Up @@ -517,6 +517,11 @@ msgstr ""
"JSÖN strïng çöntäïnïng än élästïçséärçh fünçtïön sçöré çönfïg. Ⱡ'σяєм ιρѕυм "
"∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"

#: apps/publisher/api/serializers.py
#, python-brace-format
msgid "Invalid course key \"{lms_course_id}\""
msgstr "Ìnvälïd çöürsé kéý \"{lms_course_id}\" Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢ση#"

#: apps/publisher/choices.py templates/publisher/courses.html
msgid "Partner Coordinator"
msgstr "Pärtnér Çöördïnätör Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт,#"
Expand Down
Binary file modified course_discovery/conf/locale/eo/LC_MESSAGES/djangojs.mo
Binary file not shown.
10 changes: 8 additions & 2 deletions course_discovery/conf/locale/eo/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-16 14:06+0500\n"
"POT-Creation-Date: 2017-01-18 12:59+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: static/js/catalogs-change-form.js
Expand All @@ -30,6 +30,12 @@ msgstr ""
"{courseRunDetail} wïth ä stärt däté öf {startDate} Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт "
"αмєт, ¢σηѕє¢#"

#: static/js/publisher/views/dashboard.js
msgid "There was an error in saving your data."
msgstr ""
"Théré wäs än érrör ïn sävïng ýöür dätä. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя#"

#: static/js/publisher/views/navbar.js
msgid "OFF"
msgstr "ÖFF Ⱡ'σяєм#"
Expand Down
11 changes: 11 additions & 0 deletions course_discovery/static/js/publisher/views/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(document).ready(function() {
courseTitleTag = $courseRunParentTag.find("#course-title").html().trim(),
startDateTag = $courseRunParentTag.find("#course-start").html().trim(),
$studioInstanceSuccess = $(".studio-instance-success"),
$studioInstanceError = $(".studio-instance-error"),
successMessage = interpolateString(
gettext("You have successfully created a studio instance ({studioLinkTag}) for {courseRunDetail} with a start date of {startDate}"),
{
Expand All @@ -38,6 +39,16 @@ $(document).ready(function() {
$("#studio-count").html(data_table_studio.rows().count());
$studioInstanceSuccess.find(".copy-meta").html(successMessage);
$studioInstanceSuccess.css("display", "block");
},
error: function (response) {
if(response.responseJSON.lms_course_id) {
$studioInstanceError.find(".copy").html(response.responseJSON.lms_course_id[0]);
} else if(response.responseJSON.detail) {
$studioInstanceError.find(".copy").html(response.responseJSON.detail);
} else {
$studioInstanceError.find(".copy").html(gettext("There was an error in saving your data."));
}
$studioInstanceError.removeClass("hidden");
}
});
});
Expand Down
4 changes: 4 additions & 0 deletions course_discovery/static/sass/publisher/dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
}
}

.studio-instance-error {
margin-bottom: 20px;
}

.tabs {
@include padding(0, 0, 0, 0);
@include margin(0, 0, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<div class="studio-instance-success depth depth-0">
<p class="copy-meta"></p>
</div>
<div class="alert alert-error alert-slim studio-instance-error hidden">
<div class="alert-message">
<p class="copy"></p>
</div>
</div>
<div class="table-view">
<table class="data-table-studio display" cellspacing="0" width="100%">
<thead>
Expand Down

0 comments on commit 73e2a23

Please sign in to comment.