Skip to content
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

Tags count in view #158

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lernanta/apps/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def get_listed_projects(cls):
deleted=False,
archived=False,
under_development=False,
test=False)
test=False).order_by('-created_on')
return listed

@classmethod
Expand Down Expand Up @@ -490,10 +490,12 @@ def filter_learning_activities(activities):
register_filter('learning', Project.filter_learning_activities)


def get_active_projects():
def get_active_projects(projects=None):
""" get all projects that are not deleted, archived, tests
or under development
"""
if not projects:
active_projects = Projects.objects.all()
active_projects = Project.objects.filter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be

active_projects = projects.filter(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops! what was I thinking? :)
will have some time over the weekend to amend this. thanks for the review!

archived=False,
deleted=False,
Expand Down
62 changes: 60 additions & 2 deletions lernanta/apps/projects/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def test_challenge_creation(self):
def test_get_listed_projects(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()

Expand All @@ -106,3 +106,61 @@ def test_get_listed_projects(self):
self.assertFalse(under_dev_project in listed_projects)
self.assertFalse(test_project in listed_projects)
self.assertTrue(project in listed_projects)


class ProjectViewTests(TestCase):

test_username = 'testuser'
test_email = '[email protected]'
test_password = 'testpass'

def setUp(self):
self.client = Client()
self.locale = 'en'
django_user = User(
username=self.test_username,
email=self.test_email,
)
self.user = create_profile(django_user)
self.user.set_password(self.test_password)
self.user.save()

def test_all_kinds_of_projects_appear_in_listing(self):

#Should appear in listing
challenge = Project(under_development=False, test=False,
category=Project.CHALLENGE)
challenge.save()

course = Project(under_development=False, test=False,
category=Project.COURSE)
course.save()
from signups.models import Signup
sign_up = Signup(project=course, author=self.user,
status=Signup.MODERATED)
sign_up.save()

study_group = Project(under_development=False, test=False,
category=Project.STUDY_GROUP)
study_group.save()
sign_up = Signup(project=study_group, author=self.user,
status=Signup.NON_MODERATED)
sign_up.save()

#Should not appear in listing
test_challenge = Project(under_development=False, test=True,
category=Project.CHALLENGE)
test_challenge.save()

closed_study_group = Project(under_development=False, test=False,
category=Project.STUDY_GROUP)
closed_study_group.save()
sign_up = Signup(project=closed_study_group, author=self.user,
status=Signup.CLOSED)
sign_up.save()

response = self.client.get('/%s/groups/?all_languages=on' %
(self.locale))
print response.context['pagination_current_page'].object_list
self.assertEqual(3,
len(response.context['pagination_current_page'].object_list))
19 changes: 4 additions & 15 deletions lernanta/apps/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@


def learn(request, max_count=24):
projects = Project.objects.filter(not_listed=False,
deleted=False).order_by('-created_on')
projects = Project.get_listed_projects()
get_params = request.GET.copy()
if not 'language' in get_params:
get_params['language'] = get_language()
Expand All @@ -60,19 +59,9 @@ def learn(request, max_count=24):
'infinite_scroll': request.GET.get('infinite_scroll', False),
}
if form.is_valid():
archived = form.cleaned_data['archived']
under_development = form.cleaned_data['under_development']
projects = projects.filter(archived=archived,
under_development=under_development)
closed_signup = form.cleaned_data['closed_signup']
if closed_signup:
projects = projects.exclude(
category=Project.CHALLENGE).filter(
sign_up__status=Signup.CLOSED)
else:
projects = projects.filter(Q(category=Project.CHALLENGE)
| Q(sign_up__status=Signup.MODERATED)
| Q(sign_up__status=Signup.NON_MODERATED))
projects = projects.filter(Q(category=Project.CHALLENGE)
| Q(sign_up__status=Signup.MODERATED)
| Q(sign_up__status=Signup.NON_MODERATED))
featured = form.cleaned_data['featured']
if featured == project_forms.ProjectsFilterForm.SHOWCASE:
context['learn_showcase'] = True
Expand Down