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
9edefee2
Commit
9edefee2
authored
Dec 22, 2016
by
tasawernawaz
Committed by
Tasawer Nawaz
Dec 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove team admin from course model ecom-6665
parent
c686e99f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
21 deletions
+67
-21
course_discovery/apps/publisher/forms.py
+6
-3
course_discovery/apps/publisher/migrations/0023_auto_20161228_1350.py
+23
-0
course_discovery/apps/publisher/models.py
+0
-1
course_discovery/apps/publisher/tests/factories.py
+0
-2
course_discovery/apps/publisher/tests/test_views.py
+24
-6
course_discovery/apps/publisher/views.py
+12
-7
course_discovery/static/js/publisher/publisher.js
+1
-1
course_discovery/templates/publisher/add_course_form.html
+1
-1
No files found.
course_discovery/apps/publisher/forms.py
View file @
9edefee2
...
...
@@ -67,9 +67,12 @@ class CustomCourseForm(CourseForm):
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
queryset
=
kwargs
.
pop
(
'team_admin_queryset'
,
None
)
if
queryset
:
self
.
declared_fields
[
'team_admin'
]
.
queryset
=
queryset
team_admin_id
=
kwargs
.
pop
(
'team_admin_id'
,
None
)
if
team_admin_id
:
try
:
self
.
declared_fields
[
'team_admin'
]
.
queryset
=
User
.
objects
.
filter
(
id
=
team_admin_id
)
except
Exception
:
# pylint: disable=broad-except
pass
super
(
CustomCourseForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
...
course_discovery/apps/publisher/migrations/0023_auto_20161228_1350.py
0 → 100644
View file @
9edefee2
# -*- coding: utf-8 -*-
# Generated by Django 1.9.11 on 2016-12-28 13:50
from
__future__
import
unicode_literals
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'publisher'
,
'0022_auto_20161222_2135'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'course'
,
name
=
'team_admin'
,
),
migrations
.
RemoveField
(
model_name
=
'historicalcourse'
,
name
=
'team_admin'
,
),
]
course_discovery/apps/publisher/models.py
View file @
9edefee2
...
...
@@ -118,7 +118,6 @@ class Course(TimeStampedModel, ChangedByMixin):
Subject
,
default
=
None
,
null
=
True
,
blank
=
True
,
related_name
=
'publisher_courses_tertiary'
)
team_admin
=
models
.
ForeignKey
(
User
,
null
=
True
,
blank
=
True
,
related_name
=
'team_admin_user'
)
image
=
StdImageField
(
upload_to
=
UploadToFieldNamePath
(
populate_from
=
'number'
,
...
...
course_discovery/apps/publisher/tests/factories.py
View file @
9edefee2
...
...
@@ -38,8 +38,6 @@ class CourseFactory(factory.DjangoModelFactory):
secondary_subject
=
factory
.
SubFactory
(
factories
.
SubjectFactory
)
tertiary_subject
=
factory
.
SubFactory
(
factories
.
SubjectFactory
)
team_admin
=
factory
.
SubFactory
(
UserFactory
)
class
Meta
:
model
=
Course
...
...
course_discovery/apps/publisher/tests/test_views.py
View file @
9edefee2
...
...
@@ -47,7 +47,7 @@ class CreateUpdateCourseViewTests(TestCase):
self
.
organization_extension
=
factories
.
OrganizationExtensionFactory
()
self
.
group
=
self
.
organization_extension
.
group
self
.
course
=
factories
.
CourseFactory
(
team_admin
=
self
.
user
)
self
.
course
=
factories
.
CourseFactory
()
self
.
course_run
=
factories
.
CourseRunFactory
(
course
=
self
.
course
)
self
.
seat
=
factories
.
SeatFactory
(
course_run
=
self
.
course_run
,
type
=
Seat
.
VERIFIED
,
price
=
2
)
...
...
@@ -129,7 +129,6 @@ class CreateUpdateCourseViewTests(TestCase):
course_dict
=
model_to_dict
(
self
.
course
)
course_dict
.
pop
(
'verification_deadline'
)
course_dict
.
pop
(
'image'
)
course_dict
.
pop
(
'team_admin'
)
updated_course_title
=
'Updated {}'
.
format
(
self
.
course
.
title
)
course_dict
[
'title'
]
=
updated_course_title
...
...
@@ -184,7 +183,6 @@ class CreateUpdateCourseViewTests(TestCase):
course_dict
=
model_to_dict
(
self
.
course
)
course_dict
.
pop
(
'verification_deadline'
)
course_dict
.
pop
(
'image'
)
course_dict
.
pop
(
'team_admin'
)
updated_course_title
=
'Updated {}'
.
format
(
self
.
course
.
title
)
course_dict
[
'title'
]
=
updated_course_title
...
...
@@ -255,9 +253,28 @@ class CreateUpdateCourseViewTests(TestCase):
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
self
.
assertContains
(
response
,
'<input id="id_organization" name="organization" type="hidden"'
)
def
test_create_form_with_multiple_organization
(
self
):
"""Verify that if there are more than one organization then there will be
a drop down of organization choices.
"""
factories
.
OrganizationExtensionFactory
()
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
self
.
assertContains
(
response
,
'<select class="field-input input-select" id="id_organization" name="organization">'
)
def
test_create_with_invalid_team_admin
(
self
):
""" Verify that view returns status_code=400 with invalid team admin. """
data
=
{
'number'
:
'course_1'
,
'image'
:
''
}
course_dict
=
self
.
_post_data
(
data
,
self
.
course
,
self
.
course_run
,
self
.
seat
)
course_dict
[
'team_admin'
]
=
"-------"
response
=
self
.
client
.
post
(
reverse
(
'publisher:publisher_courses_new'
),
course_dict
,
files
=
data
[
'image'
])
self
.
assertEqual
(
response
.
status_code
,
400
)
def
_post_data
(
self
,
data
,
course
,
course_run
,
seat
):
course_dict
=
model_to_dict
(
course
)
course_dict
.
update
(
**
data
)
course_dict
[
'team_admin'
]
=
self
.
user
.
id
course_dict
[
'keywords'
]
=
'abc def xyz'
if
course_run
:
course_dict
.
update
(
**
model_to_dict
(
course_run
))
...
...
@@ -299,7 +316,7 @@ class CreateUpdateCourseViewTests(TestCase):
target_status_code
=
200
)
self
.
assertEqual
(
course
.
organizations
.
first
(),
self
.
organization_extension
.
organization
)
self
.
assertEqual
(
course
.
team_admin
,
self
.
user
)
self
.
assertEqual
(
course
.
course_user_roles
.
filter
(
role
=
PublisherUserRole
.
CourseTeam
)
.
count
(),
1
)
course_run
=
course
.
publisher_course_runs
.
all
()[
0
]
self
.
assertEqual
(
self
.
course_run
.
language
,
course_run
.
language
)
self
.
assertEqual
(
course_run
.
start
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
self
.
start_date_time
)
...
...
@@ -323,13 +340,14 @@ class CreateUpdateCourseRunViewTests(TestCase):
def
setUp
(
self
):
super
(
CreateUpdateCourseRunViewTests
,
self
)
.
setUp
()
self
.
user
=
UserFactory
()
self
.
course
=
factories
.
CourseFactory
(
team_admin
=
self
.
user
)
self
.
course
=
factories
.
CourseFactory
()
factories
.
CourseUserRoleFactory
.
create
(
course
=
self
.
course
,
role
=
PublisherUserRole
.
CourseTeam
,
user
=
self
.
user
)
self
.
course_run
=
factories
.
CourseRunFactory
()
self
.
organization_extension
=
factories
.
OrganizationExtensionFactory
()
self
.
course
.
organizations
.
add
(
self
.
organization_extension
.
organization
)
self
.
course_run_dict
=
model_to_dict
(
self
.
course_run
)
self
.
course_run_dict
.
update
(
{
'number'
:
self
.
course
.
number
,
'team_admin'
:
self
.
course
.
team_admin
.
id
,
'is_self_paced'
:
True
}
{
'number'
:
self
.
course
.
number
,
'team_admin'
:
self
.
user
.
id
,
'is_self_paced'
:
True
}
)
self
.
_pop_valuse_from_dict
(
self
.
course_run_dict
,
...
...
course_discovery/apps/publisher/views.py
View file @
9edefee2
...
...
@@ -15,8 +15,8 @@ from django.views.generic import View, CreateView, UpdateView, DetailView, ListV
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
,
...
...
@@ -25,8 +25,7 @@ from course_discovery.apps.publisher.forms import (
from
course_discovery.apps.publisher
import
mixins
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseRun
,
Seat
,
State
,
UserAttributes
,
OrganizationExtension
)
OrganizationExtension
,
CourseUserRole
)
from
course_discovery.apps.publisher.serializers
import
UpdateCourseKeySerializer
from
course_discovery.apps.publisher.utils
import
(
is_internal_user
,
get_internal_users
,
is_publisher_admin
,
...
...
@@ -181,8 +180,8 @@ class CreateCourseView(mixins.LoginRequiredMixin, CreateView):
ctx
=
self
.
get_context_data
()
# 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
)
team_admin_
id
=
self
.
request
.
POST
.
get
(
'team_admin'
)
course_form
=
self
.
course_form
(
request
.
POST
,
request
.
FILES
,
team_admin_
id
=
team_admin_id
)
run_form
=
self
.
run_form
(
request
.
POST
)
seat_form
=
self
.
seat_form
(
request
.
POST
)
...
...
@@ -215,6 +214,10 @@ class CreateCourseView(mixins.LoginRequiredMixin, CreateView):
# add default organization roles into course-user-roles
course
.
assign_organization_role
(
organization_extension
.
organization
)
# add team admin as CourseTeam role again course
CourseUserRole
.
add_course_roles
(
course
=
course
,
role
=
PublisherUserRole
.
CourseTeam
,
user
=
User
.
objects
.
get
(
id
=
course_form
.
data
[
'team_admin'
]))
messages
.
success
(
request
,
_
(
'Course created successfully.'
)
)
...
...
@@ -285,12 +288,13 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, CreateView):
def
get_context_data
(
self
,
**
kwargs
):
parent_course
=
self
.
get_parent_course
()
course_form
=
self
.
course_form
(
instance
=
parent_course
)
user_role
=
CourseUserRole
.
objects
.
get
(
course
=
parent_course
,
role
=
PublisherUserRole
.
CourseTeam
)
context
=
{
'parent_course'
:
parent_course
,
'course_form'
:
course_form
,
'run_form'
:
self
.
run_form
,
'seat_form'
:
self
.
seat_form
,
'is_team_admin_hidden'
:
parent_course
.
team_admin
and
'team_admin'
not
in
course_form
.
errors
'is_team_admin_hidden'
:
user_role
.
user
and
'team_admin'
not
in
course_form
.
errors
}
return
context
...
...
@@ -323,12 +327,13 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, CreateView):
messages
.
error
(
request
,
_
(
'Please fill all required fields.'
))
context
=
self
.
get_context_data
()
user_role
=
CourseUserRole
.
objects
.
get
(
course
=
parent_course
,
role
=
PublisherUserRole
.
CourseTeam
)
context
.
update
(
{
'course_form'
:
course_form
,
'run_form'
:
run_form
,
'seat_form'
:
seat_form
,
'is_team_admin_hidden'
:
parent_course
.
team_admin
and
'team_admin'
not
in
course_form
.
errors
'is_team_admin_hidden'
:
user_role
.
user
and
'team_admin'
not
in
course_form
.
errors
}
)
...
...
course_discovery/static/js/publisher/publisher.js
View file @
9edefee2
...
...
@@ -31,7 +31,7 @@ $(document).ready(function(){
});
$
(
document
).
on
(
'change'
,
'#id_organization'
,
function
(
e
)
{
var
org_id
=
$
(
this
).
value
()
;
var
org_id
=
this
.
value
;
// it will reset the select input
$
(
"#id_team_admin"
).
prop
(
"selectedIndex"
,
0
);
...
...
course_discovery/templates/publisher/add_course_form.html
View file @
9edefee2
...
...
@@ -35,7 +35,7 @@
{% 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 %}
{% if course_form.organization.
field.queryset.all.count
> 1 %}
<label
class=
"field-label"
>
{{ course_form.organization.label_tag }}
<span
class=
"required"
>
* {% trans "required" %}
</span>
</label>
{{ course_form.organization }}
...
...
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