From e74d21bb7a6ee4d937a0b5b1bd4a8eab6644b983 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 11 Jun 2011 18:30:54 +0200 Subject: [PATCH] Re-ordering of children and resources. - Implement/activate re-ordering in standard children and resources listings - Parent and (for resources) concept default order: ignore 'order' field --- browser/concept.py | 22 ++++++++++++++++++++-- browser/concept_macros.pt | 33 ++++++++++++++++++++++++++------- concept.py | 3 ++- resource.py | 3 ++- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/browser/concept.py b/browser/concept.py index 1b933f1..68578ad 100644 --- a/browser/concept.py +++ b/browser/concept.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2009 Helmut Merz helmutm@cy55.de +# Copyright (c) 2011 Helmut Merz helmutm@cy55.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -280,7 +280,8 @@ class ConceptView(BaseView): def getChildren(self, topLevelOnly=True, sort=True, noDuplicates=True): form = self.request.form - if form.get('loops.viewName') == 'index.html' and self.editable: + #if form.get('loops.viewName') == 'index.html' and self.editable: + if self.editable: self.registerDojoDnd() if 'children_change_order' in form: tokens = form.get('child_tokens') @@ -370,7 +371,24 @@ class ConceptView(BaseView): for r in rels: yield self.childViewFactory(r, self.request) + def reorderResources(self, tokens): + for r in self.context.getResourceRelations(sort=None): + token = ':'.join((util.getUidForObject(r.second), + util.getUidForObject(r.predicate))) + if token in tokens: + pos = tokens.index(token) + 1 + if r.order != pos: + r.order = pos + def resources(self): + form = self.request.form + #if form.get('loops.viewName') == 'index.html' and self.editable: + if self.editable: + self.registerDojoDnd() + if 'resources_change_order' in form: + tokens = form.get('resources_tokens') + if tokens: + self.reorderResources(tokens) from loops.browser.resource import ResourceRelationView from loops.organize.personal.browser.filter import FilterView fv = FilterView(self.context, self.request) diff --git a/browser/concept_macros.pt b/browser/concept_macros.pt index aec459f..b6de342 100644 --- a/browser/concept_macros.pt +++ b/browser/concept_macros.pt @@ -174,11 +174,13 @@ -
-

Resources

+
+

Resources

+
Info + - + +
@@ -242,12 +247,26 @@ style nothing" tal:condition="view/showObjectActions">
+
-
+ + + + +
diff --git a/concept.py b/concept.py index caaa172..efd9528 100644 --- a/concept.py +++ b/concept.py @@ -198,7 +198,8 @@ class Concept(Contained, Persistent): predicates = predicates is None and ['*'] or predicates relationships = [ConceptRelation(None, self, p) for p in predicates] if sort == 'default': - sort = lambda x: (x.order, x.first.title.lower()) + #sort = lambda x: (x.order, x.first.title.lower()) + sort = lambda x: (x.first.title.lower()) rels = (r for r in getRelations(parent, self, relationships=relationships) if canListObject(r.first, noSecurityCheck)) return sorted(rels, key=sort) diff --git a/resource.py b/resource.py index 41e9b48..bd90bbc 100644 --- a/resource.py +++ b/resource.py @@ -203,7 +203,8 @@ class Resource(Image, Contained): obj = getMaster(self) relationships = [ResourceRelation(None, obj, p) for p in predicates] if sort == 'default': - sort = lambda x: (x.order, x.first.title.lower()) + #sort = lambda x: (x.order, x.first.title.lower()) + sort = lambda x: (x.first.title.lower()) rels = (r for r in getRelations(first=concept, second=obj, relationships=relationships) if canListObject(r.first, noSecurityCheck))