From 63a13d6854a67f7bf1e26a666eb4c4c55bea644f Mon Sep 17 00:00:00 2001 From: helmutm Date: Sat, 23 Sep 2006 10:54:32 +0000 Subject: [PATCH] First working version: add resource (note) via dojo.Dialog git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1358 fd906abe-77d9-0310-91a1-e0d9ade77398 --- README.txt | 65 +++++++++++++++++++++++++++++++++------- browser/configure.zcml | 2 ++ browser/form.py | 67 ++++++++++++++++++++++++++++++++++-------- browser/form_macros.pt | 6 ++-- query.py | 5 ++-- search/README.txt | 13 ++++---- util.py | 14 +++++++++ 7 files changed, 137 insertions(+), 35 deletions(-) diff --git a/README.txt b/README.txt index c90827b..30f518a 100755 --- a/README.txt +++ b/README.txt @@ -346,20 +346,15 @@ We first need a view manager: >>> nodeChecker = NamesChecker(('body',)) >>> defineChecker(Node, nodeChecker) - >>> loopsRoot['views'] = ViewManager() - >>> views = loopsRoot['views'] + >>> views = loopsRoot['views'] = ViewManager() The view space is typically built up with nodes; a node may be a top-level menu that may contain other nodes as menu or content items: - >>> m1 = Node(u'Menu') - >>> views['m1'] = m1 - >>> m11 = Node(u'Zope') - >>> m1['m11'] = m11 - >>> m111 = Node(u'Zope in General') - >>> m11['m111'] = m111 - >>> m112 = Node(u'Zope 3') - >>> m11['m112'] = m112 + >>> m1 = views['m1'] = Node(u'Menu') + >>> m11 = m1['m11'] = Node(u'Zope') + >>> m111 = m11['m111'] = Node(u'Zope in General') + >>> m112 = m11['m112'] = Node(u'Zope 3') >>> m112.title u'Zope 3' >>> m112.description @@ -616,8 +611,56 @@ to the bottom, and to the top. >>> m11.keys() ['m111', 'm114', 'm112', 'm113'] + +End-user Forms +============== + +The browser.form and related modules provide additional support for forms +that are shown in the end-user interface. + + >>> from loops.browser.form import CreateObjectForm, CreateObject, ResourceNameChooser + >>> form = CreateObjectForm(m112, TestRequest) + + >>> from loops.interfaces import INote, ITypeConcept + >>> from loops.type import TypeConcept + >>> from loops.resource import NoteAdapter + >>> component.provideAdapter(TypeConcept) + >>> component.provideAdapter(NoteAdapter) + >>> note_tc = concepts['note'] = Concept('Note') + >>> note_tc.conceptType = typeObject + >>> ITypeConcept(note_tc).typeInterface = INote + + >>> component.provideAdapter(ResourceNameChooser) + >>> request = TestRequest(form={'form.title': 'Test Note'}) + >>> view = NodeView(m112, request) + >>> cont = CreateObject(view, request) + >>> cont.update() + True + >>> sorted(resources.keys()) + [...u'test_note'...] + >>> resources['test_note'].title + 'Test Note' + +If there is a concept selected in the combo box we assign this to the newly +created object: + + >>> from loops import util + >>> topicUid = util.getUidForObject(topic) + >>> request = TestRequest(form={'form.title': 'Test Note', + ... 'form.concept.search.text_selected': topicUid}) + >>> view = NodeView(m112, request) + >>> cont = CreateObject(view, request) + >>> cont.update() + True + >>> sorted(resources.keys()) + [...u'test_note-2'...] + >>> note = resources['test_note-2'] + >>> sorted(t.__name__ for t in note.getConcepts()) + [u'note', u'topic'] + + Import/Export -------------- +============= Nodes may be exported to and loaded from external sources, typically file representations that allow the transfer of nodes from one Zope diff --git a/browser/configure.zcml b/browser/configure.zcml index 709df79..3feae2f 100644 --- a/browser/configure.zcml +++ b/browser/configure.zcml @@ -574,6 +574,8 @@ permission="zope.ManageContent" /> + + -
-
+
+ @@ -10,6 +10,7 @@ i18n:translate="">Create Information Object + + diff --git a/query.py b/query.py index 4697c5a..f363810 100644 --- a/query.py +++ b/query.py @@ -26,12 +26,12 @@ from zope import schema, component from zope.interface import Interface, Attribute, implements from zope.app import traversing from zope.app.catalog.interfaces import ICatalog -from zope.app.intid.interfaces import IIntIds from zope.cachedescriptors.property import Lazy from loops.interfaces import IConcept from loops.common import AdapterBase from loops.type import TypeInterfaceSourceList +from loops import util from loops.util import _ @@ -82,8 +82,7 @@ class BaseQuery(object): if not uid: queue = list(self.queryConcepts(title=title, type=type)) else: - intIds = component.getUtility(IIntIds) - queue = [intIds.getObject(int(uid))] + queue = [util.getObjectForUid(uid)] concepts = [] while queue: c = queue.pop(0) diff --git a/search/README.txt b/search/README.txt index 87e13f2..d56f642 100755 --- a/search/README.txt +++ b/search/README.txt @@ -119,6 +119,7 @@ purposes fairly primitive) catalog and a resource we can search for: ... implements(ICatalog) ... def searchResults(self, **criteria): ... name = criteria.get('loops_title') + ... if name.endswith('*'): name = name[:-1] ... type = criteria.get('loops_type', ('resource',)) ... if name: ... if 'concept' in type[0]: @@ -156,10 +157,10 @@ Search via related concepts We first have to prepare some test concepts (topics); we also assign our test resource (rplone) from above to one of the topics: - >>> czope = concepts['zope'] = Concept('Zope') - >>> czope2 = concepts['zope2'] = Concept('Zope 2') - >>> czope3 = concepts['zope3'] = Concept('Zope 3') - >>> cplone = concepts['plone'] = Concept('Plone') + >>> czope = concepts['zope'] = Concept(u'Zope') + >>> czope2 = concepts['zope2'] = Concept(u'Zope 2') + >>> czope3 = concepts['zope3'] = Concept(u'Zope 3') + >>> cplone = concepts['plone'] = Concept(u'Plone') >>> for c in (czope, czope2, czope3, cplone): ... c.conceptType = topic >>> czope.assignChild(czope2) @@ -193,11 +194,11 @@ To support easy entry of concepts to search for we can preselect the available concepts (optionally restricted to a certain type) by entering text parts of the concepts' titles: - >>> form = {'searchType': 'loops:concept:topic', 'searchString': u'zo'} + >>> form = {'searchType': 'loops:concept:topic', 'searchString': u'zope'} >>> request = TestRequest(form=form) >>> view = Search(page, request) >>> view.listConcepts() - '[]' + "[['Zope', '23']]" TODO - more to come... diff --git a/util.py b/util.py index ea24d11..8b9dcfe 100644 --- a/util.py +++ b/util.py @@ -22,6 +22,8 @@ Utility functions. $Id$ """ +from zope import component +from zope.app.intid.interfaces import IIntIds from zope.interface import directlyProvides, directlyProvidedBy from zope.i18nmessageid import MessageFactory from zope.schema import vocabulary @@ -53,3 +55,15 @@ def nl2br(text): return '
\n'.join(x.replace('\r', '') for x in text.split('\n')) else: # gracefully handle Mac line endings return '
\n'.join(text.split('\r')) + +def getObjectForUid(uid): + if uid == '*': # wild card + return '*' + intIds = component.getUtility(IIntIds) + return intIds.getObject(int(uid)) + +def getUidForObject(obj): + if obj == '*': # wild card + return '*' + intIds = component.getUtility(IIntIds) + return intIds.queryId(obj)
@@ -30,6 +31,7 @@
Assign Concept(s)