Commit 96fff7c8 by Awais Committed by Awais Qureshi

Making Seat optional on course-creation page.

Add waffle switch for hiding featues.

ECOM-6797
parent 6b0d9bd1
......@@ -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')
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),
]
......@@ -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
cannot be created.
""" 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}),
......
......@@ -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():
......
......@@ -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">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment