Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

raise NotImplementedError for non auth.User objects

  • Loading branch information...
commit 52b8bf18253d55563bc1b39c3856aebe9d6005f7 1 parent dc6fa56
@paltman paltman authored
Showing with 21 additions and 19 deletions.
  1. +5 −12 agon/templatetags/agon_tags.py
  2. +16 −7 agon/tests.py
View
17 agon/templatetags/agon_tags.py
@@ -3,7 +3,6 @@
from django import template
from django.db.models import Sum
from django.db.models.loading import cache as app_cache
-from django.utils.datastructures import SortedDict
from django.contrib.auth.models import User
@@ -96,13 +95,11 @@ def render(self, context):
if self.time_limit is None:
if issubclass(model, User):
- queryset = queryset.annotate(num_points=Sum("targetstat_targets__points"))
- else:
- queryset = queryset.extra(
- select = SortedDict([
- ("num_points", "SELECT NULL")
- ])
+ queryset = queryset.annotate(
+ num_points=Sum("targetstat_targets__points")
)
+ else:
+ raise NotImplementedError("Only auth.User is supported at this time.")
else:
since = datetime.datetime.now() - self.time_limit
if issubclass(model, User):
@@ -112,11 +109,7 @@ def render(self, context):
num_points=Sum("awardedpointvalue_targets__points")
)
else:
- queryset = queryset.extra(
- select = SortedDict([
- ("num_points", "SELECT NULL")
- ])
- )
+ raise NotImplementedError("Only auth.User is supported at this time.")
queryset = queryset.order_by("-num_points")
if self.limit is not None:
View
23 agon/tests.py
@@ -361,9 +361,12 @@ def test_should_return_annotated_queryset(self):
def test_should_return_annotated_queryset_non_user_model(self):
t = Template("""{% load agon_tags %}{% top_objects "auth.Group" as top_users %}""")
c = Context({})
- t.render(c)
- self.assertEquals(c["top_users"].model, Group.objects.all().model)
-
+ try:
+ t.render(c)
+ self.fail("Should have raised a NotImplementedError!")
+ except NotImplementedError:
+ pass
+
def test_should_return_annotated_queryset_has_points(self):
t = Template("""{% load agon_tags %}{% top_objects "auth.User" as top_users %}""")
c = Context({})
@@ -373,8 +376,11 @@ def test_should_return_annotated_queryset_has_points(self):
def test_should_return_annotated_queryset_non_user_model_has_points(self):
t = Template("""{% load agon_tags %}{% top_objects "auth.Group" as top_users %}""")
c = Context({})
- t.render(c)
- self.assertEquals(c["top_users"][0].num_points, 20)
+ try:
+ t.render(c)
+ self.fail("Should have raised a NotImplementedError!")
+ except NotImplementedError:
+ pass
def test_should_return_annotated_queryset_with_timeframe_has_points(self):
t = Template("""{% load agon_tags %}{% top_objects "auth.User" as top_users timeframe 7 days %}""")
@@ -385,8 +391,11 @@ def test_should_return_annotated_queryset_with_timeframe_has_points(self):
def test_should_return_annotated_queryset_with_timeframe_non_user_model_has_points(self):
t = Template("""{% load agon_tags %}{% top_objects "auth.Group" as top_users limit 10 timeframe 7 days %}""")
c = Context({})
- t.render(c)
- self.assertEquals(c["top_users"][0].num_points, 10)
+ try:
+ t.render(c)
+ self.fail("Should have raised a NotImplementedError!")
+ except NotImplementedError:
+ pass
class PointsForObjectTagTestCase(BasePointsTestCase, TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.