Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 7e395cb46b2f00b47898ec7d88657ed90bff679c 1 parent 9bf0e28
David Walsh authored February 22, 2013
4  apps/demos/models.py
@@ -536,7 +536,7 @@ def clean(self):
536 536
     def next(self):
537 537
         """Find the next submission by created time, return None if not found."""
538 538
         try:
539  
-            obj = self.get_next_by_created()
  539
+            obj = self.get_next_by_created(hidden=False)
540 540
             return obj
541 541
         except Submission.DoesNotExist:
542 542
             return None
@@ -544,7 +544,7 @@ def next(self):
544 544
     def previous(self):
545 545
         """Find the previous submission by created time, return None if not found."""
546 546
         try:
547  
-            obj = self.get_previous_by_created()
  547
+            obj = self.get_previous_by_created(hidden=False)
548 548
             return obj
549 549
         except Submission.DoesNotExist:
550 550
             return None
30  apps/demos/tests/test_models.py
@@ -12,6 +12,7 @@
12 12
 from os import unlink
13 13
 from os.path import basename, dirname, isfile, isdir
14 14
 from shutil import rmtree
  15
+import datetime
15 16
 
16 17
 try:
17 18
     from cStringIO import StringIO
@@ -77,17 +78,35 @@ def setUp(self):
77 78
             'visitor', 'visitor@visitor.com', 'visitor')
78 79
         self.other_user.save()
79 80
 
  81
+        hidden_prev_demo = self._build_hidden_submission('hidden-submission-1')
  82
+
80 83
         self.submission = self._build_submission()
81 84
         self.old_blacklist = demos.models.DEMO_MIMETYPE_BLACKLIST
82 85
 
  86
+        hidden_next_demo = self._build_hidden_submission('hidden-submission-2')
  87
+
83 88
     def tearDown(self):
84 89
         demos.models.DEMO_MIMETYPE_BLACKLIST = self.old_blacklist
85 90
         self.user.delete()
86 91
 
87 92
     def _build_submission(self):
88  
-        s = Submission(title='Hello world', slug='hello-world',
89  
-            description='This is a hello world demo',
  93
+        now = str(datetime.datetime.now())
  94
+
  95
+        s = Submission(title='Hello world' + now, slug='hello-world' + now,
  96
+            description='This is a hello world demo', hidden=False,
90 97
             creator=self.user)
  98
+        s.save()
  99
+
  100
+        return s
  101
+
  102
+    def _build_hidden_submission(self, slug):
  103
+        now = str(datetime.datetime.now())
  104
+
  105
+        s = Submission(title='Hidden submission 1' + now, slug=slug + now,
  106
+            description='This is a hidden demo', hidden=True,
  107
+            creator=self.other_user)
  108
+        s.save()
  109
+
91 110
         return s
92 111
 
93 112
     def test_demo_package_no_files(self):
@@ -425,6 +444,13 @@ def test_demo_file_type_blacklist(self):
425 444
             except ValidationError, e:
426 445
                 ok_('ZIP file contains an unacceptable file: badfile' in e.messages)
427 446
 
  447
+    def test_hidden_demo_next_prev(self):
  448
+        """Ensure hidden demos do not display when next() or previous() are called"""
  449
+        s = self.submission
  450
+
  451
+        eq_(s.previous(), None)
  452
+        eq_(s.next(), None)
  453
+
428 454
     def test_hidden_demo_shows_to_creator_and_admin(self):
429 455
         """Demo package with at least index.html in root is valid"""
430 456
         s = self.submission

0 notes on commit 7e395cb

Please sign in to comment.
Something went wrong with that request. Please try again.