Merge pull request #16074 from edx/tasawer/learner-2296/single-support-form-dynamic-elements
Make username and courses dropdown dynamic on single support form
This commit is contained in:
@@ -374,3 +374,46 @@ class SupportViewEnrollmentsTests(SharedModuleStoreTestCase, SupportViewTestCase
|
||||
)
|
||||
verified_mode.expiration_datetime = datetime(year=1970, month=1, day=9, tzinfo=UTC)
|
||||
verified_mode.save()
|
||||
|
||||
|
||||
class ContactUsViewTests(ModuleStoreTestCase):
|
||||
|
||||
url = reverse('support:contact_us')
|
||||
|
||||
def setUp(self):
|
||||
super(ContactUsViewTests, self).setUp()
|
||||
self.user = UserFactory()
|
||||
self.client.login(username=self.user.username, password='test')
|
||||
self.user_enrollment = CourseEnrollmentFactory.create(
|
||||
user=self.user,
|
||||
)
|
||||
|
||||
def test_get_with_logged_in_user(self):
|
||||
""" Verify that logged in users will see courses dropdown."""
|
||||
response = self.client.get(self.url)
|
||||
expected = '<option value="{course_id}">'.format(course_id=self.user_enrollment.course.id)
|
||||
self.assertContains(response, expected)
|
||||
|
||||
def test_get_without_course_enrollment(self):
|
||||
""" Verify that logged in users will see not courses dropdown,
|
||||
if they are not enrolled in any course.
|
||||
"""
|
||||
self.client.logout()
|
||||
new_user = UserFactory()
|
||||
self.client.login(username=new_user.username, password='test')
|
||||
response = self.client.get(self.url)
|
||||
self._assert_without_course_enrollment(response)
|
||||
|
||||
def test_get_with_anonymous_user(self):
|
||||
""" Verify that logged out users will see not courses dropdown.
|
||||
They will see sign in button.
|
||||
"""
|
||||
self.client.logout()
|
||||
response = self.client.get(self.url)
|
||||
self.assertContains(response, 'class="btn btn-primary btn-signin">Sign in</a>')
|
||||
self._assert_without_course_enrollment(response)
|
||||
|
||||
def _assert_without_course_enrollment(self, response):
|
||||
""" Assert that users will not see simple course text input."""
|
||||
expected = '<input type="text" class="form-control" id="course">'
|
||||
self.assertContains(response, expected)
|
||||
|
||||
@@ -5,12 +5,17 @@ from django.views.generic import View
|
||||
|
||||
from edxmako.shortcuts import render_to_response
|
||||
|
||||
from student.models import CourseEnrollment
|
||||
|
||||
|
||||
#TODO https://openedx.atlassian.net/browse/LEARNER-2296
|
||||
class ContactUsView(View):
|
||||
"""
|
||||
View for viewing and submitting contact us form.
|
||||
"""
|
||||
|
||||
def get(self, request):
|
||||
return render_to_response("support/contact_us.html")
|
||||
context = {}
|
||||
if request.user.is_authenticated():
|
||||
context['user_enrollments'] = CourseEnrollment.enrollments_for_user(request.user)
|
||||
|
||||
return render_to_response("support/contact_us.html", context)
|
||||
|
||||
@@ -228,7 +228,14 @@
|
||||
|
||||
.btn-signin {
|
||||
width: $baseline * 8;
|
||||
color: $white;
|
||||
margin-bottom: ($baseline * 2) + 10;
|
||||
|
||||
&:hover,
|
||||
&:focus
|
||||
{
|
||||
color: $white;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 768px) {
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
<%!
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.html import escape
|
||||
%>
|
||||
|
||||
<%inherit file="../main.html"/>
|
||||
<%namespace file='../main.html' import="login_query"/>
|
||||
|
||||
<%block name="title">
|
||||
<title>
|
||||
Contact US
|
||||
${_("Contact US")}
|
||||
</title>
|
||||
</%block>
|
||||
|
||||
@@ -35,7 +35,7 @@ from django.utils.html import escape
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<a class="btn btn-secondary help-button">${_("Visit edX Help")}</a>
|
||||
<a href="${marketing_link('FAQ')}" class="btn btn-secondary help-button">${_("Visit edX Help")}</a>
|
||||
</div>
|
||||
</div>
|
||||
<!--logged out users-->
|
||||
@@ -50,7 +50,7 @@ from django.utils.html import escape
|
||||
<!-- Sign-in button brings user to sign-in page. After signing in, user is brough to logged in state of contact form.-->
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<button class="btn btn-primary btn-signin">${_("Sign in")}</button>
|
||||
<a href="/login${login_query()}" class="btn btn-primary btn-signin">${_("Sign in")}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -64,8 +64,6 @@ from django.utils.html import escape
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Course is an optional text field in logged out state because we don't know what courses
|
||||
the user is enrolled in and the question may not be course-specific-->
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
@@ -81,7 +79,7 @@ from django.utils.html import escape
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<p>${_("What can we help you with, iananderson21?")}</p>
|
||||
<p>${_("What can we help you with, {username}?").format(username=user.username)}</p>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
@@ -89,12 +87,17 @@ from django.utils.html import escape
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="label-course" for="course">${_("Course Name")}</label>
|
||||
<select class="form-control select-course" id="course">
|
||||
<option>The Science of Happiness</option>
|
||||
<option>Video Game Design: Teamwork and Collaboration</option>
|
||||
<option>Not course-specific</option>
|
||||
</select>
|
||||
% if user_enrollments:
|
||||
<label class="label-course" for="course">${_("Course Name")}</label>
|
||||
<select class="form-control select-course" id="course">
|
||||
% for enrollment in user_enrollments:
|
||||
<option value="${enrollment.course.id}">${enrollment.course.display_name}</option>
|
||||
% endfor
|
||||
</select>
|
||||
% else:
|
||||
<label for="course">${_("Course Name")}<span> ${_("(Optional)")}</span></label>
|
||||
<input type="text" class="form-control" id="course">
|
||||
% endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user