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
1144ef6a
Commit
1144ef6a
authored
May 09, 2017
by
Asad Azam
Committed by
AsadAzam
May 10, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation checks on calendar start and end dates
parent
41ec68db
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
1 deletions
+63
-1
course_discovery/apps/publisher/forms.py
+8
-1
course_discovery/apps/publisher/tests/test_forms.py
+23
-0
course_discovery/conf/locale/en/LC_MESSAGES/django.po
+12
-0
course_discovery/conf/locale/eo/LC_MESSAGES/django.po
+17
-0
course_discovery/templates/publisher/course_run/edit_run_form.html
+3
-0
No files found.
course_discovery/apps/publisher/forms.py
View file @
1144ef6a
...
...
@@ -6,6 +6,7 @@ from django import forms
from
django.core.exceptions
import
ValidationError
from
django.db.models.functions
import
Lower
from
django.template.loader
import
render_to_string
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
opaque_keys
import
InvalidKeyError
from
opaque_keys.edx.keys
import
CourseKey
...
...
@@ -321,8 +322,14 @@ class CustomCourseRunForm(CourseRunForm):
cleaned_data
=
self
.
cleaned_data
min_effort
=
cleaned_data
.
get
(
"min_effort"
)
max_effort
=
cleaned_data
.
get
(
"max_effort"
)
start
=
cleaned_data
.
get
(
"start"
)
end
=
cleaned_data
.
get
(
"end"
)
if
start
and
start
<
timezone
.
now
():
raise
ValidationError
({
'start'
:
_
(
'Start date cannot be in the Past'
)})
if
start
and
end
and
start
>
end
:
raise
ValidationError
({
'start'
:
_
(
'Start date cannot be after the End date'
)})
if
min_effort
and
max_effort
and
min_effort
>
max_effort
:
raise
ValidationError
({
'min_effort'
:
"Minimum effort cannot be greater than Maximum effort"
})
raise
ValidationError
({
'min_effort'
:
_
(
'Minimum effort cannot be greater than Maximum effort'
)
})
return
cleaned_data
...
...
course_discovery/apps/publisher/tests/test_forms.py
View file @
1144ef6a
from
datetime
import
datetime
,
timedelta
from
django.core.exceptions
import
ValidationError
from
django.test
import
TestCase
from
pytz
import
timezone
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.core.tests.factories
import
UserFactory
...
...
@@ -96,3 +98,24 @@ class PublisherCourseRunEditFormTests(TestCase):
run_form
.
cleaned_data
[
'min_effort'
]
=
1
self
.
assertEqual
(
run_form
.
clean
(),
run_form
.
cleaned_data
)
def
test_course_run_dates
(
self
):
"""
Verify that 'clean' raises 'ValidationError' if the Start date is in the past
Or if the Start date is after the End date
"""
run_form
=
CustomCourseRunForm
()
current_datetime
=
datetime
.
now
(
timezone
(
'US/Central'
))
run_form
.
cleaned_data
=
{
'start'
:
current_datetime
+
timedelta
(
days
=
3
),
'end'
:
current_datetime
+
timedelta
(
days
=
1
)}
with
self
.
assertRaises
(
ValidationError
):
run_form
.
clean
()
run_form
.
cleaned_data
=
{
'start'
:
current_datetime
-
timedelta
(
days
=
3
),
'end'
:
current_datetime
+
timedelta
(
days
=
3
)}
with
self
.
assertRaises
(
ValidationError
):
run_form
.
clean
()
run_form
.
cleaned_data
[
'start'
]
=
current_datetime
+
timedelta
(
days
=
1
)
run_form
.
cleaned_data
[
'end'
]
=
current_datetime
+
timedelta
(
days
=
3
)
self
.
assertEqual
(
run_form
.
clean
(),
run_form
.
cleaned_data
)
course_discovery/conf/locale/en/LC_MESSAGES/django.po
View file @
1144ef6a
...
...
@@ -664,6 +664,18 @@ msgid "Video Language"
msgstr ""
#: apps/publisher/forms.py
msgid "Start date cannot be in the Past"
msgstr ""
#: apps/publisher/forms.py
msgid "Start date cannot be after the End date"
msgstr ""
#: apps/publisher/forms.py
msgid "Minimum effort cannot be greater than Maximum effort"
msgstr ""
#: apps/publisher/forms.py
msgid "Only audit seat can be without price."
msgstr ""
...
...
course_discovery/conf/locale/eo/LC_MESSAGES/django.po
View file @
1144ef6a
...
...
@@ -790,6 +790,23 @@ msgid "Video Language"
msgstr "Vïdéö Längüägé Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт#"
#: apps/publisher/forms.py
msgid "Start date cannot be in the Past"
msgstr ""
"Stärt däté çännöt ßé ïn thé Päst Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тє#"
#: apps/publisher/forms.py
msgid "Start date cannot be after the End date"
msgstr ""
"Stärt däté çännöt ßé äftér thé Énd däté Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя#"
#: apps/publisher/forms.py
msgid "Minimum effort cannot be greater than Maximum effort"
msgstr ""
"Mïnïmüm éffört çännöt ßé gréätér thän Mäxïmüm éffört Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт "
"αмєт, ¢σηѕє¢тєтυя α#"
#: apps/publisher/forms.py
msgid "Only audit seat can be without price."
msgstr ""
"Önlý äüdït séät çän ßé wïthöüt prïçé. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
...
...
course_discovery/templates/publisher/course_run/edit_run_form.html
View file @
1144ef6a
...
...
@@ -54,6 +54,9 @@
<div
class=
"col col-6"
>
<label
class=
"field-label "
>
{{ run_form.start.label_tag }}
<span
class=
"required"
>
*
</span></label>
{{ run_form.start }}
{% if run_form.start.errors %}
{{ run_form.start.errors|escape }}
{% endif %}
</div>
</div>
...
...
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