Skip to content

Commit

Permalink
Flattening
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Gorlin committed Dec 1, 2009
1 parent a12af35 commit 11905d3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 11 deletions.
17 changes: 17 additions & 0 deletions djzen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ class Group(GroupElement):
**setByZen)
# better separation this way anyways ;)

"""If this Group object only contains a single PhotoSet with the same title
(and contains no child groups), the UI will try to flatten the tree
structure by replacing this group with the photoset where (i.e., the
photoset will be listed in the parent's children instead of this group. If
these conditions are met this value is autoset to True during calls to
self.update(), and setting back to False will prevent such behavior."""
FlattenMe = models.BooleanField(default=False, editable=True,
help_text="If True, the child PhotoSet will"+\
" be extracted")

"""
Group : GroupElement
{
Expand Down Expand Up @@ -335,6 +345,13 @@ def update(self, groupResponse=None, updateChildren=False,
self.TitlePhoto = ps[0]


if self.GroupElements.count() == 0 \
and self.PhotoSetElements.count()==1 \
and self.PhotoSetElements.all()[0].Title == self.Title:
self.FlattenMe = True
else:
self.FlattenMe = False

self.save()

class PhotoSet(GroupElement):
Expand Down
4 changes: 2 additions & 2 deletions djzen/templates/djzen/group_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

{% block djcontent %}
<div align="center">
{% for group in object.GroupElements.all %}
{% for group in groupChildren %}
<div style="float:left; width:250px; height:280px; display:block; padding:10px;"><a href="{{ group.get_absolute_url }}" title="{{ group.Title }}"><table border=0px style="width:220px; padding:0px; margins:0px; height:220px; text-align:center; vertical-align:middle;"><tr><td align="center" ><img border=0px src="{{ group.TitlePhoto.thumb_xl}}"/></td></tr></table><h2>{{ group.Title }}</h2></a></div>
{% endfor %}
{% for ps in object.PhotoSetElements.all %}
{% for ps in photosetChildren %}
<div style="float:left; display:block; padding:10px;"><a href="{{ ps.PageUrl }}" title="{{ ps.Title }}"><table border=0px style="position:relative; left:0px; top:0px; width:220px; height:220px; vertical-align:middle;"><tr><td align="center" ><img border=0px src="{{ ps.TitlePhoto.thumb_xl}}"/></td></tr></table><h2>{{ ps.Title }}</h2></a></div>
{% endfor %}
<div style="clear:both;"><br/></div>
Expand Down
2 changes: 1 addition & 1 deletion djzen/templates/djzen/root.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}{{ object.Title }}{% endblock %}

{% block content %}
<h2><a href="{% url djzen-galleryRoot %}">Photos</a> &rsaquo; {% for parent in object.ancestry %}<a title="{{ parent.Title }}" href="{{ parent.get_absolute_url }}">{{ parent.Title }}</a> &rsaquo; {% endfor %} {{ object.Title }}</h2>
<h2>{% comment %}<a href="{% url djzen-galleryRoot %}">Photos</a> &rsaquo; {% endcomment %}{% for parent in object.ancestry %}<a title="{{ parent.Title }}" href="{{ parent.get_absolute_url }}">{{ parent.Title }}</a> &rsaquo; {% endfor %} {{ object.Title }}</h2>

{% block djcontent %}
{% endblock %}
Expand Down
29 changes: 21 additions & 8 deletions djzen/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@
from models import *


urlpatterns = patterns('django.views.generic.list_detail',
url(r'^$', 'object_detail',
{'queryset': Group.objects.all(),
'object_id': User.objects.all()[0].RootGroup.Id},
urlpatterns = patterns('djzen.views', #'django.views.generic.list_detail',

url(r'^$',
'renderGroup',
{'object_id':User.objects.all()[0].RootGroup.Id},
name='djzen-galleryRoot'),
url(r'^f(?P<object_id>\d+)/$', 'object_detail',
{'queryset': Group.objects.all()},

#url(r'^$', 'object_detail',
#{'queryset': Group.objects.all(),
#'object_id': User.objects.all()[0].RootGroup.Id},
#name='djzen-galleryRoot'),

url(r'^f(?P<object_id>\d+)/$',
'renderGroup',
{},
name='djzen-group'),
url(r'^p(?P<object_id>\d+)/$', 'object_detail',

#url(r'^f(?P<object_id>\d+)/$', 'object_detail',
#{'queryset': Group.objects.all()},
#name='djzen-group'),

url(r'^p(?P<object_id>\d+)/$', 'renderPhotoSet',
{'queryset': PhotoSet.objects.all()},
name='djzen-photoset'),
url(r'^photo(?P<object_id>\d+)/$', 'object_detail',
url(r'^photo(?P<object_id>\d+)/$', 'renderPhoto',
{'queryset': Photo.objects.all()},
name='djzen-photo'),
)
Expand Down
41 changes: 41 additions & 0 deletions djzen/views.py
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# Create your views here.
from django.shortcuts import render_to_response, get_object_or_404
import operator
from models import *

def renderGroup(request, object_id=None):
"""Prepares a group for display
In addition to sending the group object directly to the template, this view:
Flattens any child group with FlattenMe=True by pulling out the photosets
for display here. This is very useful for groups with a single contained
photoset of the same name as the group
"""

group = get_object_or_404(Group, Id=object_id)

groupChildren = group.GroupElements.exclude(FlattenMe=True)

newPSChildren = [g.PhotoSetElements.all() for g in \
group.GroupElements.filter(FlattenMe=True)]

photosetChildren = reduce(operator.or_, newPSChildren,
group.PhotoSetElements.all())

return render_to_response('djzen/group_detail.html',
{'object':group,
'groupChildren':groupChildren,
'photosetChildren':photosetChildren,
'request':request})

def renderPhoto(request, object_id=None):
photo = get_object_or_404(Photo, Id=object_id)
return render_to_response('djzen/photo_detail.html',
{'object':photo,
'request':request})

def renderPhotoSet(request, object_id=None):
ps = get_object_or_404(Group, Id=object_id)
return render_to_response('djzen/photoset_detail.html',
{'object':ps,
'request':request})

0 comments on commit 11905d3

Please sign in to comment.