tangentlabs/django-oscar — pull request #964 by izidormatusov (2013-11-25 10:29:22+00:00)
Title: ConditionalOffer Priority ignored?

As i wrote here (https://groups.google.com/forum/#!msg/django-oscar/TdQAW_3QAjk/oAlRKQ-F5zMJ) the priority of the conditional offer seems to be ignored.
It has to be considered in this function

```python
def get_site_offers(self):
"""
Return site offers that are available to all users
"""
# Using select_related with the condition/benefit ranges doesn't seem
# to work. I think this is because both the related objects have the
# FK to range with the same name.
date_based_offers = ConditionalOffer.active.select_related(
'condition', 'condition__range', 'benefit').filter(
offer_type=ConditionalOffer.SITE,
status=ConditionalOffer.OPEN)
nondate_based_offers = ConditionalOffer.objects.select_related(
'condition', 'condition__range', 'benefit').filter(
offer_type=ConditionalOffer.SITE,
status=ConditionalOffer.OPEN,
start_datetime=None, end_datetime=None)
return list(chain(date_based_offers, nondate_based_offers))
```

so i replaced it with:

```python
def get_site_offers(self):
"""
Return site offers ordered form priority that are available to all users
"""
# Using select_related with the condition/benefit ranges doesn't seem
# to work. I think this is because both the related objects have the
# FK to range with the same name.
date_based_offers = ConditionalOffer.active.select_related(
'condition', 'condition__range', 'benefit').filter(
offer_type=ConditionalOffer.SITE,
status=ConditionalOffer.OPEN)
date_based_offers_ids =list( date_based_offers.values_list('id',flat=True))
nondate_based_offers = ConditionalOffer.objects.select_related(
'condition', 'condition__range', 'benefit').filter(
offer_type=ConditionalOffer.SITE,
status=ConditionalOffer.OPEN,
start_datetime=None, end_datetime=None)
nondate_based_offers_ids = list(nondate_based_offers.values_list('id',flat=True))
ordered_offers = ConditionalOffer.active.filter(id__in=date_based_offers_ids+nondate_based_offers_ids).order_by('-priority')
return ordered_offers
```

The problem is that the `list(chain())` call in the method `get_offers` will shuffle the queryset if there will be more offers' type .