Unverified Commit a4474385 by John Eskew Committed by GitHub

Merge pull request #16606 from edx/jeskew/remove_default_manager_access

Add a proper get_queryset() method to remove _default_manager access.
parents 3bc05d37 9292741f
...@@ -21,13 +21,13 @@ class SoftDeleteCouponAdmin(admin.ModelAdmin): ...@@ -21,13 +21,13 @@ class SoftDeleteCouponAdmin(admin.ModelAdmin):
readonly_fields = ('created_at',) readonly_fields = ('created_at',)
actions = ['really_delete_selected'] actions = ['really_delete_selected']
def queryset(self, request): def get_queryset(self, request):
""" Returns a QuerySet of all model instances that can be edited by the """
admin site. This is used by changelist_view. """ Returns a QuerySet of all model instances that can be edited by the
# Default: qs = self.model._default_manager.get_active_coupons_query_set() admin site - used by changelist_view.
# Queryset with all the coupons including the soft-deletes: qs = self.model._default_manager.get_queryset() """
query_string = self.model._default_manager.get_active_coupons_queryset() # pylint: disable=protected-access qs = super(SoftDeleteCouponAdmin, self).get_queryset(request)
return query_string return qs.filter(is_active=True)
def get_actions(self, request): def get_actions(self, request):
actions = super(SoftDeleteCouponAdmin, self).get_actions(request) actions = super(SoftDeleteCouponAdmin, self).get_actions(request)
......
...@@ -1309,21 +1309,6 @@ class RegistrationCodeRedemption(models.Model): ...@@ -1309,21 +1309,6 @@ class RegistrationCodeRedemption(models.Model):
return code_redemption return code_redemption
class SoftDeleteCouponManager(models.Manager):
""" Use this manager to get objects that have a is_active=True """
def get_active_coupons_queryset(self):
"""
filter the is_active = True Coupons only
"""
return super(SoftDeleteCouponManager, self).get_queryset().filter(is_active=True)
def get_queryset(self):
"""
get all the coupon objects
"""
return super(SoftDeleteCouponManager, self).get_queryset()
class Coupon(models.Model): class Coupon(models.Model):
""" """
This table contains coupon codes This table contains coupon codes
...@@ -1344,8 +1329,6 @@ class Coupon(models.Model): ...@@ -1344,8 +1329,6 @@ class Coupon(models.Model):
def __unicode__(self): def __unicode__(self):
return "[Coupon] code: {} course: {}".format(self.code, self.course_id) return "[Coupon] code: {} course: {}".format(self.code, self.course_id)
objects = SoftDeleteCouponManager()
@property @property
def display_expiry_date(self): def display_expiry_date(self):
""" """
......
...@@ -572,7 +572,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin): ...@@ -572,7 +572,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
messages = FallbackStorage(request) messages = FallbackStorage(request)
request._messages = messages # pylint: disable=protected-access request._messages = messages # pylint: disable=protected-access
coupon_admin = SoftDeleteCouponAdmin(Coupon, AdminSite()) coupon_admin = SoftDeleteCouponAdmin(Coupon, AdminSite())
test_query_set = coupon_admin.queryset(request) test_query_set = coupon_admin.get_queryset(request)
test_actions = coupon_admin.get_actions(request) test_actions = coupon_admin.get_actions(request)
self.assertIn('really_delete_selected', test_actions['really_delete_selected']) self.assertIn('really_delete_selected', test_actions['really_delete_selected'])
self.assertEqual(get_coupon.is_active, True) self.assertEqual(get_coupon.is_active, True)
...@@ -585,7 +585,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin): ...@@ -585,7 +585,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
coupon = Coupon(code='TestCode123', description='testing123', course_id=self.course_key, coupon = Coupon(code='TestCode123', description='testing123', course_id=self.course_key,
percentage_discount=22, created_by=self.user, is_active=True) percentage_discount=22, created_by=self.user, is_active=True)
coupon.save() coupon.save()
test_query_set = coupon_admin.queryset(request) test_query_set = coupon_admin.get_queryset(request)
coupon_admin.really_delete_selected(request, test_query_set) coupon_admin.really_delete_selected(request, test_query_set)
for coupon in test_query_set: for coupon in test_query_set:
self.assertEqual(coupon.is_active, False) self.assertEqual(coupon.is_active, False)
......
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