Commit edf1589e by Clinton Blackburn Committed by GitHub

Merge pull request #273 from edx/clintonb/facet-seat-type

Added facet for seat types
parents 52587ad7 561d4d7d
......@@ -33,6 +33,7 @@ COURSE_RUN_FACET_FIELD_OPTIONS = {
'pacing_type': {},
'content_type': {},
'type': {},
'seat_types': {},
}
COURSE_RUN_FACET_FIELD_QUERIES = {
......@@ -50,6 +51,8 @@ COURSE_RUN_SEARCH_FIELDS = (
PROGRAM_FACET_FIELD_OPTIONS = {
'category': {},
'status': {},
'type': {},
'seat_types': {},
}
BASE_PROGRAM_FIELDS = (
......
......@@ -632,11 +632,17 @@ class Program(TimeStampedModel):
return set(subjects)
@property
def price_ranges(self):
def seats(self):
applicable_seat_types = self.type.applicable_seat_types.values_list('slug', flat=True)
seats = Seat.objects.filter(course_run__in=self.course_runs, type__in=applicable_seat_types) \
.values('currency') \
.annotate(models.Min('price'), models.Max('price'))
return Seat.objects.filter(course_run__in=self.course_runs, type__in=applicable_seat_types)
@property
def seat_types(self):
return set(self.seats.values_list('type', flat=True))
@property
def price_ranges(self):
seats = self.seats.values('currency').annotate(models.Min('price'), models.Max('price'))
price_ranges = []
for seat in seats:
......
......@@ -151,6 +151,7 @@ class ProgramIndex(BaseIndex, indexes.Indexable, OrganizationsMixin):
status = indexes.CharField(model_attr='status', faceted=True)
partner = indexes.CharField(model_attr='partner__short_code', null=True, faceted=True)
start = indexes.DateTimeField(model_attr='start', null=True, faceted=True)
seat_types = indexes.MultiValueField(model_attr='seat_types', null=True, faceted=True)
def prepare_organizations(self, obj):
return self.prepare_authoring_organizations(obj) + self.prepare_credit_backing_organizations(obj)
......
......@@ -262,6 +262,19 @@ class ProgramTests(TestCase):
self.excluded_course_run = factories.CourseRunFactory(course=self.courses[0])
self.program = factories.ProgramFactory(courses=self.courses, excluded_course_runs=[self.excluded_course_run])
def create_program_with_seats(self):
currency = Currency.objects.get(code='USD')
course_run = factories.CourseRunFactory()
factories.SeatFactory(type='audit', currency=currency, course_run=course_run, price=0)
factories.SeatFactory(type='credit', currency=currency, course_run=course_run, price=600)
factories.SeatFactory(type='verified', currency=currency, course_run=course_run, price=100)
applicable_seat_types = SeatType.objects.filter(slug__in=['credit', 'verified'])
program_type = factories.ProgramTypeFactory(applicable_seat_types=applicable_seat_types)
return factories.ProgramFactory(type=program_type, courses=[course_run.course])
def test_str(self):
"""Verify that a program is properly converted to a str."""
self.assertEqual(str(self.program), self.program.title)
......@@ -326,14 +339,7 @@ class ProgramTests(TestCase):
self.assertIsNone(self.program.start)
def test_price_ranges(self):
currency = Currency.objects.get(code='USD')
course_run = factories.CourseRunFactory()
factories.SeatFactory(type='audit', currency=currency, course_run=course_run, price=0)
factories.SeatFactory(type='credit', currency=currency, course_run=course_run, price=600)
factories.SeatFactory(type='verified', currency=currency, course_run=course_run, price=100)
applicable_seat_types = SeatType.objects.filter(slug__in=['credit', 'verified'])
program_type = factories.ProgramTypeFactory(applicable_seat_types=applicable_seat_types)
program = factories.ProgramFactory(type=program_type, courses=[course_run.course])
program = self.create_program_with_seats()
expected_price_ranges = [{'currency': 'USD', 'min': Decimal(100), 'max': Decimal(600)}]
self.assertEqual(program.price_ranges, expected_price_ranges)
......@@ -357,6 +363,10 @@ class ProgramTests(TestCase):
self.assertIsNotNone(sized_file)
self.assertIn(image_url_prefix, sized_file.url)
def test_seat_types(self):
program = self.create_program_with_seats()
self.assertEqual(program.seat_types, set(['credit', 'verified']))
class PersonSocialNetworkTests(TestCase):
"""Tests of the PersonSocialNetwork model."""
......
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