Permalink
Browse files

fix bug 839314 - Don't show hidden demos with next/prev

  • Loading branch information...
1 parent 9bf0e28 commit 7e395cb46b2f00b47898ec7d88657ed90bff679c @darkwing darkwing committed Feb 22, 2013
Showing with 30 additions and 4 deletions.
  1. +2 −2 apps/demos/models.py
  2. +28 −2 apps/demos/tests/test_models.py
View
4 apps/demos/models.py
@@ -536,15 +536,15 @@ def clean(self):
def next(self):
"""Find the next submission by created time, return None if not found."""
try:
- obj = self.get_next_by_created()
+ obj = self.get_next_by_created(hidden=False)
return obj
except Submission.DoesNotExist:
return None
def previous(self):
"""Find the previous submission by created time, return None if not found."""
try:
- obj = self.get_previous_by_created()
+ obj = self.get_previous_by_created(hidden=False)
return obj
except Submission.DoesNotExist:
return None
View
30 apps/demos/tests/test_models.py
@@ -12,6 +12,7 @@
from os import unlink
from os.path import basename, dirname, isfile, isdir
from shutil import rmtree
+import datetime
try:
from cStringIO import StringIO
@@ -77,17 +78,35 @@ def setUp(self):
'visitor', 'visitor@visitor.com', 'visitor')
self.other_user.save()
+ hidden_prev_demo = self._build_hidden_submission('hidden-submission-1')
+
self.submission = self._build_submission()
self.old_blacklist = demos.models.DEMO_MIMETYPE_BLACKLIST
+ hidden_next_demo = self._build_hidden_submission('hidden-submission-2')
+
def tearDown(self):
demos.models.DEMO_MIMETYPE_BLACKLIST = self.old_blacklist
self.user.delete()
def _build_submission(self):
- s = Submission(title='Hello world', slug='hello-world',
- description='This is a hello world demo',
+ now = str(datetime.datetime.now())
+
+ s = Submission(title='Hello world' + now, slug='hello-world' + now,
+ description='This is a hello world demo', hidden=False,
creator=self.user)
+ s.save()
+
+ return s
+
+ def _build_hidden_submission(self, slug):
+ now = str(datetime.datetime.now())
+
+ s = Submission(title='Hidden submission 1' + now, slug=slug + now,
+ description='This is a hidden demo', hidden=True,
+ creator=self.other_user)
+ s.save()
+
return s
def test_demo_package_no_files(self):
@@ -425,6 +444,13 @@ def test_demo_file_type_blacklist(self):
except ValidationError, e:
ok_('ZIP file contains an unacceptable file: badfile' in e.messages)
+ def test_hidden_demo_next_prev(self):
+ """Ensure hidden demos do not display when next() or previous() are called"""
+ s = self.submission
+
+ eq_(s.previous(), None)
+ eq_(s.next(), None)
+
def test_hidden_demo_shows_to_creator_and_admin(self):
"""Demo package with at least index.html in root is valid"""
s = self.submission

0 comments on commit 7e395cb

Please sign in to comment.