Source code for mg.orga.tree.views
# -*- coding:utf-8 -*-
# MG_GPL_HEADER_BEGIN
#
# This file is part of Media Gallery, GNU GPLv2.
#
# Media Gallery is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# Media Gallery is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Media Gallery; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# MG_GPL_HEADER_END
__author__ = "Media Gallery contributors <mg@lists.ssji.net>"
__copyright__ = "(c) 2010"
__credits__ = ["Dimitri Refauvelet", "Nicolas Pouillon"]
from django.views.generic.list_detail import object_detail, object_list
from mg.orga.roll.models import Roll
from mg.core.element.models import Element
def _root(request):
[docs] return object_list(
request,
queryset = Element.objects.filter(parents__isnull = True),
template_name = "tree/root.html",
)
def path(request, pk_list, root = None, **extra_context):
[docs] if not root and not pk_list:
return _root(request)
elif not pk_list:
parent_ids = [root.pk]
object_id = root.pk
else:
pk_list = map(int, pk_list[:-1].split("/"))
if root:
parent_ids = [root.pk] + pk_list[:-1]
else:
parent_ids = pk_list[:-1]
object_id = pk_list[-1]
return object_detail(
request,
template_name = "tree/in_path.html",
queryset = Element.objects.all(),
object_id = object_id,
extra_context = dict(
root = root,
parents = map(
lambda x:Element.objects.get(pk = x),
parent_ids),
**extra_context
),
)