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
ac5f3649
Commit
ac5f3649
authored
Dec 28, 2016
by
Tasawer Nawaz
Committed by
GitHub
Dec 28, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #509 from edx/tasawer/ecom-6666-fron-end-of-istitution-admin
ECOM-6666 front end of istitution admin
parents
c9ccb22f
e1623e86
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
15 deletions
+76
-15
course_discovery/apps/publisher/forms.py
+10
-1
course_discovery/apps/publisher/tests/test_views.py
+5
-0
course_discovery/apps/publisher/views.py
+6
-1
course_discovery/static/js/publisher/publisher.js
+32
-0
course_discovery/static/sass/publisher/publisher.scss
+4
-0
course_discovery/templates/publisher/add_course_form.html
+19
-13
No files found.
course_discovery/apps/publisher/forms.py
View file @
ac5f3649
...
...
@@ -53,7 +53,9 @@ class CustomCourseForm(CourseForm):
)
title
=
forms
.
CharField
(
label
=
_
(
'Course Title'
),
required
=
True
)
number
=
forms
.
CharField
(
label
=
_
(
'Course Number'
),
required
=
True
)
team_admin
=
forms
.
ModelChoiceField
(
queryset
=
User
.
objects
.
all
(),
required
=
True
)
# users will be loaded through AJAX call based on organization
team_admin
=
forms
.
ModelChoiceField
(
queryset
=
User
.
objects
.
none
(),
required
=
True
)
class
Meta
(
CourseForm
.
Meta
):
model
=
Course
...
...
@@ -64,6 +66,13 @@ class CustomCourseForm(CourseForm):
'level_type'
,
'organization'
,
'is_seo_review'
,
'keywords'
,
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
queryset
=
kwargs
.
pop
(
'team_admin_queryset'
,
None
)
if
queryset
:
self
.
declared_fields
[
'team_admin'
]
.
queryset
=
queryset
super
(
CustomCourseForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
class
UpdateCourseForm
(
BaseCourseForm
):
""" Course form to update specific fields for already created course. """
...
...
course_discovery/apps/publisher/tests/test_views.py
View file @
ac5f3649
...
...
@@ -242,6 +242,11 @@ class CreateUpdateCourseViewTests(TestCase):
course
=
Course
.
objects
.
get
(
number
=
data
[
'number'
])
self
.
_assert_test_data
(
response
,
course
,
seat_type
,
0
)
def
test_create_form_with_single_organization
(
self
):
"""Verify that if there is only one organization then that organization will be shown as text. """
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
self
.
assertContains
(
response
,
'<input id="id_organization" name="organization" type="hidden"'
)
def
_post_data
(
self
,
data
,
course
,
course_run
,
seat
):
course_dict
=
model_to_dict
(
course
)
course_dict
.
update
(
**
data
)
...
...
course_discovery/apps/publisher/views.py
View file @
ac5f3649
...
...
@@ -16,6 +16,7 @@ from django_fsm import TransitionNotAllowed
from
guardian.shortcuts
import
get_objects_for_user
from
rest_framework.generics
import
UpdateAPIView
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.publisher.choices
import
PublisherUserRole
from
course_discovery.apps.publisher.forms
import
(
CourseForm
,
CourseRunForm
,
SeatForm
,
CustomCourseForm
,
CustomCourseRunForm
,
...
...
@@ -178,9 +179,13 @@ class CreateCourseView(mixins.LoginRequiredMixin, CreateView):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
ctx
=
self
.
get_context_data
()
course_form
=
self
.
course_form
(
request
.
POST
,
request
.
FILES
)
# add selected team admin into choice of ChoiceField
team_admin_queryset
=
User
.
objects
.
filter
(
id
=
self
.
request
.
POST
.
get
(
'team_admin'
))
course_form
=
self
.
course_form
(
request
.
POST
,
request
.
FILES
,
team_admin_queryset
=
team_admin_queryset
)
run_form
=
self
.
run_form
(
request
.
POST
)
seat_form
=
self
.
seat_form
(
request
.
POST
)
if
course_form
.
is_valid
()
and
run_form
.
is_valid
()
and
seat_form
.
is_valid
():
try
:
with
transaction
.
atomic
():
...
...
course_discovery/static/js/publisher/publisher.js
View file @
ac5f3649
...
...
@@ -23,4 +23,36 @@ $(document).ready(function(){
$
(
".field-admin-name"
).
hide
();
$
(
"#field-team-admin"
).
show
();
});
var
org_id
=
$
(
'#organization-name'
).
data
(
'org_id'
);
if
(
org_id
){
loadAdminUsers
(
org_id
);
}
});
$
(
document
).
on
(
'change'
,
'#id_organization'
,
function
(
e
)
{
var
org_id
=
$
(
this
).
value
();
// it will reset the select input
$
(
"#id_team_admin"
).
prop
(
"selectedIndex"
,
0
);
if
(
org_id
)
{
loadAdminUsers
(
org_id
);
}
});
function
loadAdminUsers
(
org_id
)
{
$
.
getJSON
({
url
:
'/publisher/api/admins/organizations/'
+
org_id
+
'/users/'
,
success
:
function
(
data
)
{
var
teamAdminDropDown
=
$
(
'#id_team_admin'
);
teamAdminDropDown
.
empty
();
// it will looks same like other django model choice fields
teamAdminDropDown
.
append
(
'<option selected="selected">---------</option>'
);
$
.
each
(
data
.
results
,
function
(
i
,
user
)
{
teamAdminDropDown
.
append
(
$
(
'<option> </option>'
).
val
(
user
.
id
).
html
(
user
.
full_name
));
});
}
});
}
course_discovery/static/sass/publisher/publisher.scss
View file @
ac5f3649
...
...
@@ -714,3 +714,7 @@ select {
@include
padding
(
20px
,
20px
,
20px
,
20px
);
border
:
2px
solid
#169bd5
;
}
#id_organization
{
width
:
auto
;
}
course_discovery/templates/publisher/add_course_form.html
View file @
ac5f3649
...
...
@@ -35,22 +35,28 @@
<div
class=
"field-title"
>
{% trans "INSTITUTION INFORMATION" %}
</div>
<div
class=
"row"
>
<div
class=
"col col-6 help-text"
>
{% trans "Please choose the school that will be providing the course. Once chosen then you can select an administrator for the studio shell." %}
</div>
<div
class=
"col col-6"
>
<label
class=
"field-label"
>
{{ course_form.organization.label_tag }}
<span
class=
"required"
>
* {% trans "required" %}
</span>
<div
class=
"col col-6 help-text"
>
{% trans "Please choose the school that will be providing the course. Once chosen then you can select an administrator for the studio shell." %}
</div>
<div
class=
"col col-6"
>
{% if course_form.organization.choices|length > 1 %}
<label
class=
"field-label"
>
{{ course_form.organization.label_tag }}
<span
class=
"required"
>
* {% trans "required" %}
</span>
</label>
{{ course_form.organization }}
{% else %}
{% with course_form.organization.field.queryset|first as organization %}
<label
id=
"organization-name"
class=
"field-label"
data-org_id=
"{{ organization.id }}"
>
{{ course_form.organization.label_tag }} {{ organization.name }}
</label>
{{ course_form.organization }}
<input
id=
"id_organization"
name=
"organization"
type=
"hidden"
value=
"{{ organization.id }}"
>
{% endwith %}
{% endif %}
<label
class=
"field-label"
>
{{ course_form.team_admin.label_tag }}
<span
class=
"required"
>
* {% trans "required" %}
</span>
</label>
{{ course_form.team_admin }}
<label
class=
"field-label"
>
{{ course_form.team_admin.label_tag }}
<span
class=
"required"
>
* {% trans "required" %}
</span>
</label>
{{ course_form.team_admin }}
</div>
</div>
</div>
<div
class=
"field-title"
>
{% trans "Course Title" %}
</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