Commits

Anonymous committed b2e62a5

added some template tags

  • Participants
  • Parent commits a94e070

Comments (0)

Files changed (6)

 		# ...,
 	)
 	
-For more information read the docs.
+For more information read the (not yet available) docs.

src/photos/models.py

     timestamp_created = models.DateTimeField(_('Timestamp created'), auto_now_add=True, editable=False)
     timestamp_edited = models.DateTimeField(_('Timestamp edited'), auto_now=True, editable=False)
     
+    def get_albums(self):
+        return self.album_set.filter(display=True)
+    
     def __unicode__(self):
         return self.name
     
     timestamp_created = models.DateTimeField(_('Timestamp created'), auto_now_add=True, editable=False)
     timestamp_edited = models.DateTimeField(_('Timestamp edited'), auto_now=True, editable=False)
     
+    def get_photos(self):
+        return self.photos.filter(display=True)
+    
     def __unicode__(self):
         return self.name
     

src/photos/templates/photos/album_detail.html

 {% block content %}
 <h1>Album from {{ album.user }}</h1>
 
-{% autopaginate object.photos.all 25  %}
+{% autopaginate object.get_photos 25  %}
 
 <ul>
-{% for photo in object.photo.all %}
+{% for photo in object.get_photos %}
 <li><img src="{% thumbnail photo.photo 150x150 crop quality=50 %}" /></li>
 {% endfor %}
 </ul>

src/photos/templates/photos/album_list.html

 <ul>
 {% for album in object_list %}
 <li><a href="{{ album.get_absolute_url }}">{{ album }}</a><br />
-{% for photo in album.photos.all|slice:":3" %}
+{% for photo in album.get_photos|slice:":3" %}
 <a href="{% url photo-album-detail album.id photo.id %}"><img src="{% thumbnail photo.photo 100x100 crop quality=50 %}" description="{{ photo.description }}" /></a> 
 {% endfor %}
 {% empty %}

src/photos/templates/photos/photo_detail.html

 
 
 {% if next %}<a href="{% url photo-album-detail album.id next.id %}">{% endif %}<img src="{% thumbnail object.photo 900x900 quality=75 %}" />{% if next %}</a>{% endif %}
+
+<ul>
+<h3>Album of this photo:</h3>
+{% for album in object.get_albums %}
+<li><a href="{{ album.get_absolute_url }}">{{ album }}</a></li>
+{% endfor %}
+</ul>
 {% endblock %}

src/photos/templatetags/photos_extras.py

 @tag(register, [Variable(), Variable(), Constant('as'), Name()])
 def get_previous(context, album, photo, asvar):
     prev = None
-    for tmp in album.photos.all():
+    for tmp in album.get_photos():
         if tmp == photo:
             context[asvar] = prev
             return ''
 @tag(register, [Variable(), Variable(), Constant('as'), Name()])
 def get_next(context, album, photo, asvar):
     flag = False
-    for tmp in album.photos.all():
+    for tmp in album.get_photos():
         if flag == True:
             context[asvar] = tmp
             return ''
         if tmp == photo:
             flag = True
                 
+    return ''
+
+@tag(register, [Constant('as'), Name()])
+def get_photos(context, asvar):
+    context[asvar] = Photos.objects.filter(display=True)
+    return ''
+
+@tag(register, [Constant('as'), Name()])
+def get_albums(context, asvar):
+    context[asvar] = Albums.objects.filter(display=True)
     return ''