Commit ec2af959 by Waheed Ahmed

Create only course object from new course page, removed run and seat related code.

ECOM-7760
parent 5e8c9f42
......@@ -157,6 +157,8 @@ class CustomCourseForm(CourseForm):
validators=[validate_text_count(max_length=2500)]
)
add_new_run = forms.BooleanField(required=False)
class Meta(CourseForm.Meta):
model = Course
widgets = {
......
......@@ -214,19 +214,18 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
""" Create Course View."""
model = Course
course_form = CustomCourseForm
run_form = CustomCourseRunForm
seat_form = CustomSeatForm
template_name = 'publisher/add_course_form.html'
success_url = 'publisher:publisher_course_detail'
def get_success_url(self, course_id): # pylint: disable=arguments-differ
return reverse(self.success_url, kwargs={'pk': course_id})
def get_success_url(self, course_id, add_new_run=None): # pylint: disable=arguments-differ
success_url = reverse(self.success_url, kwargs={'pk': course_id})
if add_new_run:
success_url = reverse('publisher:publisher_course_runs_new', kwargs={'parent_course_id': course_id})
return success_url
def get_context_data(self):
return {
'course_form': self.course_form(user=self.request.user),
'run_form': self.run_form,
'seat_form': self.seat_form,
'publisher_hide_features_for_pilot': waffle.switch_is_active('publisher_hide_features_for_pilot'),
'publisher_add_instructor_feature': waffle.switch_is_active('publisher_add_instructor_feature'),
}
......@@ -236,46 +235,25 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
def post(self, request, *args, **kwargs):
ctx = self.get_context_data()
add_new_run = request.POST.get('add_new_run')
# pass selected organization to CustomCourseForm to populate related
# choices into institution admin field
user = self.request.user
organization = self.request.POST.get('organization')
self.request.POST['start'] = parse_datetime_field(self.request.POST.get('start'))
self.request.POST['end'] = parse_datetime_field(self.request.POST.get('end'))
course_form = self.course_form(
request.POST, request.FILES, user=user, 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():
if course_form.is_valid():
try:
with transaction.atomic():
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 = user
course.save()
# commit false does not save m2m object. Keyword field is m2m.
course_form.save_m2m()
run_course.course = course
run_course.changed_by = user
run_course.save()
# commit false does not save m2m object.
run_form.save_m2m()
if seat:
seat.course_run = run_course
seat.changed_by = user
seat.save()
organization_extension = get_object_or_404(
OrganizationExtension, organization=course_form.data['organization']
)
......@@ -291,9 +269,7 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
# Initialize workflow for Course.
CourseState.objects.create(course=course, owner_role=PublisherUserRole.CourseTeam)
# Initialize workflow for Course-run.
CourseRunState.objects.create(course_run=run_course, owner_role=PublisherUserRole.CourseTeam)
if not add_new_run:
# pylint: disable=no-member
messages.success(
request, _(
......@@ -305,10 +281,7 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
)
)
# sending email for notifying new course is created.
emails.send_email_for_course_creation(course, run_course)
return HttpResponseRedirect(self.get_success_url(course.id))
return HttpResponseRedirect(self.get_success_url(course.id, add_new_run=add_new_run))
except Exception as e: # pylint: disable=broad-except
# pylint: disable=no-member
error_message = _('An error occurred while saving your changes. {error}').format(error=str(e))
......@@ -323,8 +296,6 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
ctx.update(
{
'course_form': course_form,
'run_form': run_form,
'seat_form': seat_form
}
)
return render(request, self.template_name, ctx, status=400)
......@@ -484,12 +455,16 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, CreateView):
def get_last_run(self):
if not self.last_run:
parent_course = self.get_parent_course()
try:
self.last_run = parent_course.course_runs.latest('created')
except CourseRun.DoesNotExist:
self.last_run = None
return self.last_run
def set_last_run_data(self, new_run):
last_run = self.get_last_run()
if last_run:
last_run_data = model_to_dict(last_run)
# Delete all those fields which cannot be copied from previous run
del (last_run_data['id'], last_run_data['start'], last_run_data['end'], last_run_data['pacing_type'],
......@@ -513,7 +488,11 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, CreateView):
new_run.transcript_languages.add(*transcript_languages)
def get_seat_initial_data(self):
initial_seat_data = {}
last_run = self.get_last_run()
if not last_run:
return initial_seat_data
try:
latest_seat = last_run.seats.latest('created')
initial_seat_data = model_to_dict(latest_seat)
......@@ -526,9 +505,13 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, CreateView):
def get_context_data(self, **kwargs):
parent_course = self.get_parent_course()
last_run = self.get_last_run()
run_initial_data = {}
if last_run:
run_initial_data = {'pacing_type': last_run.pacing_type}
context = {
'parent_course': parent_course,
'run_form': self.run_form(initial={'pacing_type': last_run.pacing_type}),
'run_form': self.run_form(initial=run_initial_data),
'seat_form': self.seat_form(initial=self.get_seat_initial_data())
}
return context
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-04 15:16+0500\n"
"POT-Creation-Date: 2017-05-05 13:13+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: apps/api/filters.py
#, python-brace-format
......@@ -1332,70 +1332,6 @@ msgid "Statistics: Probability"
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "COURSE START DATE"
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "Start on a Tuesday, Wednesday, or Thursday."
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "Avoid major U.S. holidays."
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Specify a month, day, and year. If you are unsure of the exact date, specify"
" a day that is close to the estimated start date. For example, if your "
"course will start near the end of March, specify March 31."
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "COURSE END DATE"
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Specify a month, day, and year. If you are unsure of the exact date, specify"
" a day that is close to the estimated end date. For example, if your course "
"will end near the end of March, specify March 31."
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "COURSE PACING"
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Instructor-paced courses include individual assignments that have specific "
"due dates before the course end date."
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Self-paced courses do not have individual assignments that have specific due"
" dates before the course end date. All assignments are due on the course end"
" date."
msgstr ""
#: templates/publisher/add_course_form.html
#: templates/publisher/course_edit_form.html
msgid "COURSE NUMBER"
msgstr ""
......@@ -1436,6 +1372,10 @@ msgid ""
" to Studio and enter content for the course."
msgstr ""
#: templates/publisher/add_course_form.html
msgid "I want to add a run to this course at this time"
msgstr ""
#: templates/publisher/add_courserun_form.html
msgid "New Course Run"
msgstr ""
......@@ -1455,11 +1395,62 @@ msgid ""
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "COURSE START DATE"
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "Start on a Tuesday, Wednesday, or Thursday."
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "Avoid major U.S. holidays."
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Specify a month, day, and year. If you are unsure of the exact date, specify"
" a day that is close to the estimated start date. For example, if your "
"course will start near the end of March, specify March 31."
msgstr ""
#: templates/publisher/add_courserun_form.html
msgid "PACING TYPE"
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Instructor-paced courses include individual assignments that have specific "
"due dates before the course end date."
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Self-paced courses do not have individual assignments that have specific due"
" dates before the course end date. All assignments are due on the course end"
" date."
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "COURSE END DATE"
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid ""
"Specify a month, day, and year. If you are unsure of the exact date, specify"
" a day that is close to the estimated end date. For example, if your course "
"will end near the end of March, specify March 31."
msgstr ""
#: templates/publisher/add_courserun_form.html
#: templates/publisher/course_run/edit_run_form.html
msgid "CERTIFICATE TYPE AND PRICE"
msgstr ""
......@@ -2023,6 +2014,10 @@ msgid ""
msgstr ""
#: templates/publisher/course_run/edit_run_form.html
msgid "COURSE PACING"
msgstr ""
#: templates/publisher/course_run/edit_run_form.html
msgid "The Studio URL for this course run."
msgstr ""
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-04 15:16+0500\n"
"POT-Creation-Date: 2017-05-05 13:13+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: static/js/catalogs-change-form.js
msgid "Preview"
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-04 15:16+0500\n"
"POT-Creation-Date: 2017-05-05 13:13+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/js/catalogs-change-form.js
......
......@@ -87,51 +87,6 @@
</div>
</div>
<div class="field-title">{% trans "COURSE START DATE" %}</div>
<div class="row">
<div class="col col-6 help-text">
<ul>
<li>
{% trans "Start on a Tuesday, Wednesday, or Thursday." %}
</li>
<li>
{% trans "Avoid major U.S. holidays." %}
</li>
<li>
{% trans "Specify a month, day, and year. If you are unsure of the exact date, specify a day that is close to the estimated start date. For example, if your course will start near the end of March, specify March 31." %}
</li>
</ul>
</div>
<div class="col col-6">
<label class="field-label ">{{ run_form.start.label_tag }} <span class="required">*</span></label>
{{ run_form.start }}
</div>
</div>
<div class="field-title">{% trans "COURSE END DATE" %}</div>
<div class="row">
<div class="col col-6 help-text">
{% trans "Specify a month, day, and year. If you are unsure of the exact date, specify a day that is close to the estimated end date. For example, if your course will end near the end of March, specify March 31." %}
</div>
<div class="col col-6">
<label class="field-label ">{{ run_form.end.label_tag }} <span class="required">*</span></label>
{{ run_form.end }}
</div>
</div>
<div class="field-title">{% trans "COURSE PACING" %}</div>
<div class="row">
<div class="col col-6 help-text">
<p>{% trans "Instructor-paced courses include individual assignments that have specific due dates before the course end date." %} </p>
<p>{% trans "Self-paced courses do not have individual assignments that have specific due dates before the course end date. All assignments are due on the course end date." %}</p>
</div>
<div class="col col-6">
<label class="field-label">{{ run_form.pacing_type.label_tag }} <span class="required">*</span></label>
<div class="checkbox-inline">{{ run_form.pacing_type }}</div>
</div>
</div>
<div class="field-title">{% trans "COURSE NUMBER" %}</div>
<div class="row">
<div class="col col-6 help-text">
......@@ -177,11 +132,21 @@
</div>
<div class="course-form">
<div class="course-information action-buttons">
<div class="field">
<label class="field-label label-inline">
{{ course_form.add_new_run }}
<span class="field-input-label">
{% trans "I want to add a run to this course at this time" %}
</span>
</label>
</div>
<div class="action-buttons">
<a href="{% url 'publisher:publisher_courses' %}">{% trans "Cancel" %}</a>
<button class="btn-brand btn-base btn-save" type="submit">
{% trans "Create New Course" %}
</button>
</div>
</div>
</div>
</form>
......@@ -199,7 +164,3 @@
<script src="{% static 'js/publisher/modal-screen.js' %}"></script>
<script src="{% static 'js/publisher/course-image.js' %}"></script>
{% endblock %}
{% block js_without_compress %}
{{ run_form.media }}
{% endblock %}
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