[snowy] Only show public notebooks when browsing anonymously or another user's collection



commit 437f26720d647ef1aeb1570cba417425da8a3b0b
Author: Jeff Schroeder <jeffschroeder computer org>
Date:   Fri Aug 6 21:05:09 2010 -0700

    Only show public notebooks when browsing anonymously or another user's collection
    
        Fixes bug#614814

 notes/models.py                                  |   14 ++++++++++++--
 notes/templates/notes/note_detail.html           |    4 +---
 notes/templates/notes/note_index.html            |    9 ++-------
 notes/templates/notes/notebook_list_snippet.html |    7 +++++++
 4 files changed, 22 insertions(+), 12 deletions(-)
---
diff --git a/notes/models.py b/notes/models.py
index a04f9d1..c01ae53 100644
--- a/notes/models.py
+++ b/notes/models.py
@@ -26,7 +26,7 @@ from snowy.notes.managers import NoteManager
 
 class Note(models.Model):
     NOTE_PERMISSIONS = (
-        (0, _(u'Private')), (1, _(u'Public')), 
+        (0, _(u'Private')), (1, _(u'Public')),
     )
 
     guid = models.CharField(max_length=36)
@@ -49,7 +49,7 @@ class Note(models.Model):
 
     open_on_startup = models.BooleanField(default=False)
     pinned = models.BooleanField(default=False)
-    
+
     last_sync_rev = models.IntegerField(default=-1)
 
     objects = NoteManager()
@@ -87,11 +87,21 @@ class NoteTag(models.Model):
     def __unicode__(self):
         return self.name
 
+    def _note_is_public(self):
+        # This will need to be expanded once a more
+        # fine-grained permissions system is in place.
+        if self.note_set.filter(permissions__gt=0).count():
+            return True
+        else:
+            return False
+
     def get_name_for_display(self):
         if self.is_notebook:
             return self.name.split(':', 2)[-1]
         return self.name
 
+    is_public = property(_note_is_public)
+
 def _update_is_notebook(sender, instance, **kwargs):
     """
     Update is_notebook based upon the NoteTag name.
diff --git a/notes/templates/notes/note_detail.html b/notes/templates/notes/note_detail.html
index 22f9f90..b3cadd1 100644
--- a/notes/templates/notes/note_detail.html
+++ b/notes/templates/notes/note_detail.html
@@ -42,9 +42,7 @@
     <h3>{% trans "Notebooks" %}</h3>
     <ul> 
 {% user_notebook_list request author as all_notebooks %}
-{% for n in all_notebooks %}
-        <li class="notebook-item"><a href="#">{{ n.get_name_for_display }}</a></li>
-{% endfor %}
+{% include "notes/notebook_list_snippet.html" %}
         <li class="more-item"><a href="#">{% trans "More Notebooks..." %}</a></li>
     </ul>
 </div>
diff --git a/notes/templates/notes/note_index.html b/notes/templates/notes/note_index.html
index bbe35b6..2f4ce99 100644
--- a/notes/templates/notes/note_index.html
+++ b/notes/templates/notes/note_index.html
@@ -28,14 +28,9 @@
 </div>
 <div id="sidebar-notebook-list">
     <h3>{% trans "Notebooks" %}</h3>
-    <ul> 
+    <ul>
 {% user_notebook_list request author as all_notebooks %}
-{% for n in all_notebooks %}
-        <li class="notebook-item"><a href="#">{{ n.get_name_for_display }}</a></li>
-{% endfor %}
-        <li class="more-item"><a href="#">{% trans "More Notebooks..." %}</a></li>
-    </ul>
-</div>
+{% include "notes/notebook_list_snippet.html" %}
 {% endblock %}
 
 {% block content %}
diff --git a/notes/templates/notes/notebook_list_snippet.html b/notes/templates/notes/notebook_list_snippet.html
new file mode 100644
index 0000000..4cbbbe1
--- /dev/null
+++ b/notes/templates/notes/notebook_list_snippet.html
@@ -0,0 +1,7 @@
+{% comment %}In the spirit of D.R.Y.{% endcomment %}
+{% for n in all_notebooks %}
+  {# This grossness goes away with django 1.2's smarter if tags #}
+  {% if n.is_public %}<li class="notebook-item"><a href="#">{{ n.get_name_for_display }}</a></li>
+  {% else %}{% ifequal request.user n.author %}<li class="notebook-item"><a href="#">{{ n.get_name_for_display }}</a></li>{% endifequal %}
+  {% endif %}
+{% endfor %}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]