diff --git a/lernanta/apps/projects/models.py b/lernanta/apps/projects/models.py index e6fb7640..e3d0db52 100644 --- a/lernanta/apps/projects/models.py +++ b/lernanta/apps/projects/models.py @@ -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 @@ -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( archived=False, deleted=False, diff --git a/lernanta/apps/projects/tests.py b/lernanta/apps/projects/tests.py index 81317a4e..5be53748 100644 --- a/lernanta/apps/projects/tests.py +++ b/lernanta/apps/projects/tests.py @@ -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() @@ -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 = 'test@mozillafoundation.org' + 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)) diff --git a/lernanta/apps/projects/views.py b/lernanta/apps/projects/views.py index 6c4619f1..dca56fca 100644 --- a/lernanta/apps/projects/views.py +++ b/lernanta/apps/projects/views.py @@ -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() @@ -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