Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
2f1e6966
Commit
2f1e6966
authored
Dec 30, 2013
by
zubiar-arbi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add validation for grading types (allow only integers)
STUD-988
parent
3fc461f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
5 deletions
+13
-5
cms/static/coffee/spec/models/settings_course_grader_spec.coffee
+9
-1
cms/static/js/models/settings/course_grader.js
+4
-4
No files found.
cms/static/coffee/spec/models/settings_course_grader_spec.coffee
View file @
2f1e6966
...
@@ -23,5 +23,13 @@ define ["js/models/settings/course_grader"], (CourseGrader) ->
...
@@ -23,5 +23,13 @@ define ["js/models/settings/course_grader"], (CourseGrader) ->
model
=
new
CourseGrader
()
model
=
new
CourseGrader
()
errors
=
model
.
validate
({
min_count
:
0
,
drop_count
:
''
},
{
validate
:
true
})
errors
=
model
.
validate
({
min_count
:
0
,
drop_count
:
''
},
{
validate
:
true
})
expect
(
errors
.
min_count
).
toBe
(
'Please enter an integer greater than 0.'
)
expect
(
errors
.
min_count
).
toBe
(
'Please enter an integer greater than 0.'
)
expect
(
errors
.
drop_count
).
toBe
(
'Please enter an integer.'
)
expect
(
errors
.
drop_count
).
toBe
(
'Please enter non-negative integer.'
)
# don't allow negative integers
errors
=
model
.
validate
({
min_count
:
-
12
,
drop_count
:
-
1
},
{
validate
:
true
})
expect
(
errors
.
min_count
).
toBe
(
'Please enter an integer greater than 0.'
)
expect
(
errors
.
drop_count
).
toBe
(
'Please enter non-negative integer.'
)
# don't allow floats
errors
=
model
.
validate
({
min_count
:
12.2
,
drop_count
:
1.5
},
{
validate
:
true
})
expect
(
errors
.
min_count
).
toBe
(
'Please enter an integer greater than 0.'
)
expect
(
errors
.
drop_count
).
toBe
(
'Please enter non-negative integer.'
)
cms/static/js/models/settings/course_grader.js
View file @
2f1e6966
...
@@ -51,19 +51,19 @@ var CourseGrader = Backbone.Model.extend({
...
@@ -51,19 +51,19 @@ var CourseGrader = Backbone.Model.extend({
}}
}}
if
(
_
.
has
(
attrs
,
'min_count'
))
{
if
(
_
.
has
(
attrs
,
'min_count'
))
{
var
intMinCount
=
parseInt
(
attrs
.
min_count
,
10
);
var
intMinCount
=
parseInt
(
attrs
.
min_count
,
10
);
if
(
!
isFinite
(
intMinCount
)
||
/
\D
+/
.
test
(
intMinC
ount
)
||
intMinCount
<
1
)
{
if
(
!
isFinite
(
intMinCount
)
||
/
\D
+/
.
test
(
attrs
.
min_c
ount
)
||
intMinCount
<
1
)
{
errors
.
min_count
=
gettext
(
"Please enter an integer greater than 0."
);
errors
.
min_count
=
gettext
(
"Please enter an integer greater than 0."
);
}
}
else
attrs
.
min_count
=
intMinCount
;
else
attrs
.
min_count
=
intMinCount
;
}
}
if
(
_
.
has
(
attrs
,
'drop_count'
))
{
if
(
_
.
has
(
attrs
,
'drop_count'
))
{
var
intDropCount
=
parseInt
(
attrs
.
drop_count
,
10
);
var
intDropCount
=
parseInt
(
attrs
.
drop_count
,
10
);
if
(
!
isFinite
(
intDropCount
)
||
/
\D
+/
.
test
(
intDropCount
)
||
isNaN
(
intDropCount
)
)
{
if
(
!
isFinite
(
intDropCount
)
||
/
\D
+/
.
test
(
attrs
.
drop_count
)
||
isNaN
(
intDropCount
)
||
intDropCount
<
0
)
{
errors
.
drop_count
=
gettext
(
"Please enter
an
integer."
);
errors
.
drop_count
=
gettext
(
"Please enter
non-negative
integer."
);
}
}
else
attrs
.
drop_count
=
intDropCount
;
else
attrs
.
drop_count
=
intDropCount
;
}
}
if
(
_
.
has
(
attrs
,
'min_count'
)
&&
_
.
has
(
attrs
,
'drop_count'
)
&&
attrs
.
drop_count
>
attrs
.
min_count
)
{
if
(
_
.
has
(
attrs
,
'min_count'
)
&&
_
.
has
(
attrs
,
'drop_count'
)
&&
!
_
.
has
(
errors
,
'min_count'
)
&&
!
_
.
has
(
errors
,
'drop_count'
)
&&
attrs
.
drop_count
>
attrs
.
min_count
)
{
errors
.
drop_count
=
_
.
template
(
errors
.
drop_count
=
_
.
template
(
gettext
(
"Cannot drop more <% attrs.types %> than will assigned."
),
gettext
(
"Cannot drop more <% attrs.types %> than will assigned."
),
attrs
,
{
variable
:
'attrs'
});
attrs
,
{
variable
:
'attrs'
});
...
...
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