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
96fff7c8
Commit
96fff7c8
authored
Jan 11, 2017
by
Awais
Committed by
Awais Qureshi
Jan 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Making Seat optional on course-creation page.
Add waffle switch for hiding featues. ECOM-6797
parent
6b0d9bd1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
19 deletions
+72
-19
course_discovery/apps/publisher/forms.py
+2
-1
course_discovery/apps/publisher/migrations/0026_create_switch_hide_features_for_pilot.py
+24
-0
course_discovery/apps/publisher/tests/test_views.py
+33
-9
course_discovery/apps/publisher/views.py
+12
-8
course_discovery/templates/publisher/add_course_form.html
+1
-1
No files found.
course_discovery/apps/publisher/forms.py
View file @
96fff7c8
...
...
@@ -250,7 +250,8 @@ class CustomSeatForm(SeatForm):
(
Seat
.
PROFESSIONAL
,
_
(
'Professional Education'
)),
]
type
=
forms
.
ChoiceField
(
choices
=
TYPE_CHOICES
,
required
=
True
,
label
=
_
(
'Seat Type'
))
type
=
forms
.
ChoiceField
(
choices
=
TYPE_CHOICES
,
required
=
False
,
label
=
_
(
'Seat Type'
))
price
=
forms
.
DecimalField
(
max_digits
=
6
,
decimal_places
=
2
,
required
=
False
,
initial
=
0.00
)
class
Meta
(
SeatForm
.
Meta
):
fields
=
(
'price'
,
'type'
)
course_discovery/apps/publisher/migrations/0026_create_switch_hide_features_for_pilot.py
0 → 100644
View file @
96fff7c8
from
django.db
import
migrations
def
create_switch
(
apps
,
schema_editor
):
"""Create the publisher_hide_features_for_pilot switch if it does not already exist."""
Switch
=
apps
.
get_model
(
'waffle'
,
'Switch'
)
Switch
.
objects
.
get_or_create
(
name
=
'publisher_hide_features_for_pilot'
,
defaults
=
{
'active'
:
False
})
def
delete_switch
(
apps
,
schema_editor
):
"""Delete the publisher_hide_features_for_pilot switch."""
Switch
=
apps
.
get_model
(
'waffle'
,
'Switch'
)
Switch
.
objects
.
filter
(
name
=
'publisher_hide_features_for_pilot'
)
.
delete
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'publisher'
,
'0025_auto_20170106_1830'
),
(
'waffle'
,
'0001_initial'
),
]
operations
=
[
migrations
.
RunPython
(
create_switch
,
delete_switch
),
]
course_discovery/apps/publisher/tests/test_views.py
View file @
96fff7c8
...
...
@@ -109,6 +109,20 @@ class CreateUpdateCourseViewTests(TestCase):
response
=
self
.
client
.
post
(
reverse
(
'publisher:publisher_courses_new'
),
course_dict
)
self
.
assertEqual
(
response
.
status_code
,
400
)
def
test_create_course_and_course_run_without_seat
(
self
):
""" Verify that course and course run objects create successfully if seat type
is not provided.
"""
data
=
{
'number'
:
'course_without_seat'
,
'image'
:
''
}
course_dict
=
self
.
_post_data
(
data
,
self
.
course
,
self
.
course_run
,
None
)
course_dict
[
'image'
]
=
''
self
.
client
.
post
(
reverse
(
'publisher:publisher_courses_new'
),
course_dict
)
course
=
Course
.
objects
.
get
(
number
=
course_dict
[
'number'
])
course_run
=
course
.
publisher_course_runs
.
first
()
# verify no seat object created with course run.
self
.
assertFalse
(
course_run
.
seats
.
all
())
@ddt.data
(
{
'number'
:
'course_1'
,
'image'
:
''
},
{
'number'
:
'course_2'
,
'image'
:
make_image_file
(
'test_banner.jpg'
)},
...
...
@@ -295,6 +309,22 @@ class CreateUpdateCourseViewTests(TestCase):
response
=
self
.
client
.
post
(
reverse
(
'publisher:publisher_courses_new'
),
course_dict
)
self
.
assertEqual
(
response
.
status_code
,
400
)
def
test_page_with_pilot_switch_enable
(
self
):
""" Verify that if pilot switch is enable then about page information
panel is not visible.
"""
toggle_switch
(
'publisher_hide_features_for_pilot'
,
True
)
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
self
.
assertContains
(
response
,
'<div class="layout-full publisher-layout layout hidden"'
)
def
test_page_with_pilot_switch_disable
(
self
):
""" Verify that if pilot switch is disable then about page information
panel is visible.
"""
toggle_switch
(
'publisher_hide_features_for_pilot'
,
False
)
response
=
self
.
client
.
get
(
reverse
(
'publisher:publisher_courses_new'
))
self
.
assertContains
(
response
,
'<div class="layout-full publisher-layout layout"'
)
def
_post_data
(
self
,
data
,
course
,
course_run
,
seat
):
course_dict
=
model_to_dict
(
course
)
course_dict
.
update
(
**
data
)
...
...
@@ -419,19 +449,13 @@ class CreateUpdateCourseRunViewTests(TestCase):
)
def
test_create_course_run_and_seat_with_errors
(
self
):
""" Verify that without providing required data course run
and seat
c
annot be c
reated.
""" Verify that without providing required data course run
cannot be
created.
"""
response
=
self
.
client
.
post
(
reverse
(
'publisher:publisher_course_runs_new'
,
kwargs
=
{
'parent_course_id'
:
self
.
course
.
id
}),
self
.
course_run_dict
)
self
.
assertEqual
(
response
.
status_code
,
400
)
post_data
=
model_to_dict
(
self
.
course
)
post_data
.
update
(
self
.
course_run_dict
)
post_data
.
update
(
factory
.
build
(
dict
,
FACTORY_CLASS
=
factories
.
SeatFactory
))
self
.
_pop_valuse_from_dict
(
post_data
,
[
'id'
,
'upgrade_deadline'
,
'image'
,
'team_admin'
])
self
.
_pop_valuse_from_dict
(
post_data
,
[
'id'
,
'upgrade_deadline'
,
'image'
,
'team_admin'
,
'start'
])
response
=
self
.
client
.
post
(
reverse
(
'publisher:publisher_course_runs_new'
,
kwargs
=
{
'parent_course_id'
:
self
.
course
.
id
}),
...
...
course_discovery/apps/publisher/views.py
View file @
96fff7c8
...
...
@@ -4,6 +4,7 @@ Course publisher views.
import
json
import
logging
from
datetime
import
datetime
,
timedelta
import
waffle
from
django.contrib
import
messages
from
django.core.urlresolvers
import
reverse
...
...
@@ -14,7 +15,6 @@ from django.utils.translation import ugettext_lazy as _
from
django.views.generic
import
View
,
CreateView
,
UpdateView
,
DetailView
,
ListView
from
django_fsm
import
TransitionNotAllowed
from
guardian.shortcuts
import
get_objects_for_user
import
waffle
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.publisher.choices
import
PublisherUserRole
...
...
@@ -185,7 +185,8 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
return
{
'course_form'
:
self
.
course_form
,
'run_form'
:
self
.
run_form
,
'seat_form'
:
self
.
seat_form
'seat_form'
:
self
.
seat_form
,
'publisher_hide_features_for_pilot'
:
waffle
.
switch_is_active
(
'publisher_hide_features_for_pilot'
)
}
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -200,11 +201,13 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
course_form
=
self
.
course_form
(
request
.
POST
,
request
.
FILES
,
organization
=
organization
)
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
():
seat
=
seat_form
.
save
(
commit
=
False
)
seat
=
None
if
request
.
POST
.
get
(
'type'
):
seat
=
seat_form
.
save
(
commit
=
False
)
run_course
=
run_form
.
save
(
commit
=
False
)
course
=
course_form
.
save
(
commit
=
False
)
course
.
changed_by
=
self
.
request
.
user
...
...
@@ -218,9 +221,11 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
# commit false does not save m2m object.
run_form
.
save_m2m
()
seat
.
course_run
=
run_course
seat
.
changed_by
=
self
.
request
.
user
seat
.
save
()
if
seat
:
seat
.
course_run
=
run_course
seat
.
changed_by
=
self
.
request
.
user
seat
.
save
()
organization_extension
=
get_object_or_404
(
OrganizationExtension
,
organization
=
course_form
.
data
[
'organization'
]
...
...
@@ -340,7 +345,6 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, CreateView):
course_form
=
self
.
course_form
(
request
.
POST
,
instance
=
self
.
get_parent_course
())
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/templates/publisher/add_course_form.html
View file @
96fff7c8
...
...
@@ -164,7 +164,7 @@
</div>
<div
class=
"layout-full publisher-layout layout"
>
<div
class=
"layout-full publisher-layout layout
{% if publisher_hide_features_for_pilot %}hidden{% endif %}
"
>
<h2
class=
"layout-title"
>
{% trans "About page information" %}
</h2>
<div
class=
"card course-form"
>
<div
class=
"course-information"
>
...
...
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