-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for issue #136 : tags counting #155
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,11 +416,16 @@ def get_non_started_next_projects(self, user): | |
else: | ||
return Project.objects.none() | ||
|
||
@classmethod | ||
def get_projects_excluded_from_listing(cls): | ||
return Project.objects.filter(Q(not_listed=True) | ||
|Q(deleted=True)|Q(archived=True) | ||
|Q(under_development=True)|Q(test=True)).values('id') | ||
|
||
@classmethod | ||
def get_popular_tags(cls, max_count=10): | ||
ct = ContentType.objects.get_for_model(Project) | ||
not_listed = Project.objects.filter( | ||
Q(not_listed=True)|Q(deleted=True)).values('id') | ||
not_listed = Project.get_projects_excluded_from_listing() | ||
return GeneralTaggedItem.objects.filter( | ||
content_type=ct).exclude(object_id__in=not_listed).values( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will become something like return GeneralTaggedItem.objects.filter(content_type=ct, object_id__in=listed).values( if we rather use listed instead of not_listed |
||
'tag__name').annotate(tagged_count=Count('object_id')).order_by( | ||
|
@@ -429,8 +434,7 @@ def get_popular_tags(cls, max_count=10): | |
@classmethod | ||
def get_weighted_tags(cls, min_count=2, min_weight=1.0, max_weight=7.0): | ||
ct = ContentType.objects.get_for_model(Project) | ||
not_listed = Project.objects.filter( | ||
Q(not_listed=True)|Q(deleted=True)).values('id') | ||
not_listed = Project.get_projects_excluded_from_listing() | ||
tags = GeneralTaggedItem.objects.filter( | ||
content_type=ct).exclude(object_id__in=not_listed).values( | ||
'tag__name').annotate(tagged_count=Count('object_id')).filter( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,3 +79,33 @@ def test_challenge_creation(self): | |
challenge = Project.objects.get(slug=slug) | ||
self.assertEqual(challenge.category, Project.CHALLENGE) | ||
self.assertEqual(challenge.duration_hours, 10) | ||
|
||
def test_get_projects_excluded_from_listing(self): | ||
deleted_project = Project(deleted=True, test=False) | ||
deleted_project.save() | ||
|
||
not_listed_project = Project(not_listed=True, test=False) | ||
not_listed_project.save() | ||
|
||
under_dev_project = Project(name="under_dev:default", test=False) | ||
under_dev_project.save() | ||
|
||
archived_project = Project(under_development=False, archived=True) | ||
archived_project.save() | ||
|
||
test_project = Project(under_development=False, test=True) | ||
test_project.save() | ||
|
||
project = Project(name="listed", under_development=False, test=False) | ||
project.save() | ||
|
||
not_listed = Project.get_projects_excluded_from_listing() | ||
not_listed_ids = [] | ||
for project_entry in not_listed: | ||
not_listed_ids.append(project_entry['id']) | ||
|
||
self.assertTrue(deleted_project.id in not_listed_ids) | ||
self.assertTrue(not_listed_project.id in not_listed_ids) | ||
self.assertTrue(under_dev_project.id in not_listed_ids) | ||
self.assertTrue(test_project.id in not_listed_ids) | ||
self.assertFalse(project.id in not_listed_ids) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Big +1 for this test! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://twitter.com/#!/carlosble is the one to be blamed for that. I was pairing with him last night to track this down! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought, but wouldn't it make more sense to return the listed projects? The queries in get_popular_tags and get_weighted_tags can also be changed to use the listed projects instead.
Also, consider returning the QuerySet rather than a list of ids
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heya, it does make sense; actuallay I was stuck for a while till I figured out that it was a dict of ids. It makes the test harder to write, which in itself is a sign that something is wrong. :)
I won't have time to look at this for now, so feel free to apply it and we can revisit later, or to make the changes yourself, or I will make them probably at the weekend.