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
66cf870c
Commit
66cf870c
authored
Nov 02, 2017
by
Asad Azam
Committed by
AsadAzam
Nov 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate organization key field
parent
a6dc243f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
1 deletions
+51
-1
course_discovery/apps/course_metadata/models.py
+6
-1
course_discovery/apps/course_metadata/tests/test_models.py
+25
-0
course_discovery/conf/locale/en/LC_MESSAGES/django.po
+8
-0
course_discovery/conf/locale/eo/LC_MESSAGES/django.po
+12
-0
No files found.
course_discovery/apps/course_metadata/models.py
View file @
66cf870c
import
datetime
import
itertools
import
logging
import
re
from
collections
import
defaultdict
from
urllib.parse
import
urljoin
from
uuid
import
uuid4
...
...
@@ -175,7 +176,7 @@ class Organization(TimeStampedModel):
""" Organization model. """
partner
=
models
.
ForeignKey
(
Partner
,
null
=
True
,
blank
=
False
)
uuid
=
models
.
UUIDField
(
blank
=
False
,
null
=
False
,
default
=
uuid4
,
editable
=
False
,
verbose_name
=
_
(
'UUID'
))
key
=
models
.
CharField
(
max_length
=
255
)
key
=
models
.
CharField
(
max_length
=
255
,
help_text
=
_
(
'Only ascii characters allowed (a-zA-Z0-9)'
)
)
name
=
models
.
CharField
(
max_length
=
255
)
marketing_url_path
=
models
.
CharField
(
max_length
=
255
,
null
=
True
,
blank
=
True
)
description
=
models
.
TextField
(
null
=
True
,
blank
=
True
)
...
...
@@ -192,6 +193,10 @@ class Organization(TimeStampedModel):
help_text
=
_
(
'Pick a tag from the suggestions. To make a new tag, add a comma after the tag name.'
),
)
def
clean
(
self
):
if
not
re
.
match
(
"^[a-zA-Z0-9_-]*$"
,
self
.
key
):
raise
ValidationError
(
_
(
'Please do not use any spaces or special characters in the key field'
))
class
Meta
:
unique_together
=
(
(
'partner'
,
'key'
),
...
...
course_discovery/apps/course_metadata/tests/test_models.py
View file @
66cf870c
...
...
@@ -331,6 +331,7 @@ class CourseRunTests(TestCase):
assert
self
.
course_run
.
image_url
==
self
.
course_run
.
course
.
image_url
@ddt.ddt
class
OrganizationTests
(
TestCase
):
""" Tests for the `Organization` model. """
...
...
@@ -338,6 +339,30 @@ class OrganizationTests(TestCase):
super
(
OrganizationTests
,
self
)
.
setUp
()
self
.
organization
=
factories
.
OrganizationFactory
()
@ddt.data
(
"key with space"
,
"key[with,special"
,
"keyó"
)
def
test_clean_error
(
self
,
key
):
"""
Verify that the clean method raises validation error if key consists of special characters
"""
self
.
organization
.
key
=
key
self
.
assertRaises
(
ValidationError
,
self
.
organization
.
clean
)
@ddt.data
(
"keywithoutspace"
,
"correctkey"
,
"correct_key"
)
def
test_clean_success
(
self
,
key
):
"""
Verify that the clean method returns None if key is valid
"""
self
.
organization
.
key
=
key
self
.
assertEqual
(
self
.
organization
.
clean
(),
None
)
def
test_str
(
self
):
""" Verify casting an instance to a string returns a string containing the key and name. """
self
.
assertEqual
(
str
(
self
.
organization
),
'{key}: {name}'
.
format
(
key
=
self
.
organization
.
key
,
...
...
course_discovery/conf/locale/en/LC_MESSAGES/django.po
View file @
66cf870c
...
...
@@ -294,6 +294,10 @@ msgid "Subject model translations"
msgstr ""
#: apps/course_metadata/models.py
msgid "Only ascii characters allowed (a-zA-Z0-9)"
msgstr ""
#: apps/course_metadata/models.py
msgid ""
"Logo to be displayed on certificates. If this logo is the same as "
"logo_image_url, copy and paste the same value to both fields."
...
...
@@ -306,6 +310,10 @@ msgid ""
msgstr ""
#: apps/course_metadata/models.py
msgid "Please do not use any spaces or special characters in the key field"
msgstr ""
#: apps/course_metadata/models.py
msgid "People"
msgstr ""
...
...
course_discovery/conf/locale/eo/LC_MESSAGES/django.po
View file @
66cf870c
...
...
@@ -347,6 +347,12 @@ msgid "Subject model translations"
msgstr "Süßjéçt mödél tränslätïöns Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕ#"
#: apps/course_metadata/models.py
msgid "Only ascii characters allowed (a-zA-Z0-9)"
msgstr ""
"Önlý äsçïï çhäräçtérs ällöwéd (ä-zÀ-Z0-9) Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя #"
#: apps/course_metadata/models.py
msgid ""
"Logo to be displayed on certificates. If this logo is the same as "
"logo_image_url, copy and paste the same value to both fields."
...
...
@@ -363,6 +369,12 @@ msgstr ""
"täg nämé. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢т#"
#: apps/course_metadata/models.py
msgid "Please do not use any spaces or special characters in the key field"
msgstr ""
"Pléäsé dö nöt üsé äný späçés ör spéçïäl çhäräçtérs ïn thé kéý fïéld Ⱡ'σяєм "
"ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя #"
#: apps/course_metadata/models.py
msgid "People"
msgstr "Péöplé Ⱡ'σяєм ιρѕυ#"
...
...
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