Re: [Zope3-Users] addview name not form

2005-09-29 Thread Florian Lindner
Hi,
no one any more ideas?  *desperated* I can't really believ that this error has 
not occured to anyone else, since IMO it is very a standard situation...

Would it help if I create a small package which demonstrates the error?

Thx,

Florian

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Oh no, doncha violate the o-v-p

2005-09-29 Thread Christian Lueck
Hi,

I found a relatively easy way to write an addview for multiple objects.
As this violates the object view paradigm (o-v-p) I'd like to have your
expert critiques/comments: Are there any risks regarding the violation?

The task was to have one view V to create two objects A and B. A is a
container, B is contained in A. There must not be an empty A container,
one item at least.

I wrote a viewclass based on formlib, which makes it very easy to
generate fields from multiple schemas. (But this flexibility seems to be
intented for cases different from mine...)

The thing is to customize the createAndAdd method to call create- and
add-methods specified for both A and B (see sourcecode of
formlib.from.AddFormBase).

In my concrete case 'A' is 'Example' and 'B' is 'ExampleResourceSet'.
The major problem was the addExampleResourceSet method (see below last
method of code).


class ExampleAddView(form.AddForm):

snip

def createAndAdd(self, data):

obExample = self.createExample(data)
obExampleResourceSet = self.createExampleResourceSet(data)

notify(ObjectCreatedEvent(obExample))
notify(ObjectCreatedEvent(obExampleResourceSet))

instExample = self.addExample(obExample)
instExampleResourceSet =
self.addExampleResourceSet(obExampleResourceSet, instExample)

return instExample, instExampleResourceSet

def createExample(self, data):
Pass Example related form values to an Example factory.
example_factory = zapi.getUtility(IFactory,
  uexample.ExampleFactory_AddForm)
example = example_factory(
einheitsacht = self.session_data['einheitsacht'],
example_orig_lang = data['example_orig_lang'],
example_x_lang = [])
return example

def createExampleResourceSet(self, data):
example_resource_set_factory = zapi.getUtility(IFactory,
  
uexample.ExampleResourceSetFactory_AddForm)
example_resource_set = example_resource_set_factory(
resource = self.session_data['resource'],
example = data['example'],
quotation = data['quotation'],
page = data['page'])
return example_resource_set

_finished_add = False
_finished_addExample = False
_finished_addExampleResourceSet = False

_example_name = u__stillunkown__

def addExample(self, object):
ob = self.context.add(object)
self._finished_addExample = True
if self._finished_addExample and
self._finished_addExampleResourceSet:
self._finished_add = True
return ob

def addExampleResourceSet(self, content, container):
PROBLEM: no IAdding regarding container.
So code this following the lines of the IAdding implementation
in zope.app.container.browser.adding.Adding .

name = None

# check precondition
checkObject(container, name, content)

if self._finished_addExample:

# choose a name
if IContainerNamesContainer.providedBy(container):
name = INameChooser(container).chooseName('', content)
else:
Exception since we don't want to choose a name by
hand.
err = container %s does not implement
IContainerNamesContainer % container
raise Exception_ExampleAddView, err

# Create the object.
container[name] = content

# set status tings
self._finished_addExampleResourceSet = True
self._finished_add = True

return container[name]

else:
err = Unable to create ExampleResourceSet _before_ Example
raise Exception_ExampleAddView, err

snip

Note: Both content classes implement IContainerNamesContainer.

In the addExample method the codeline
ob = self.context.add(object)
calls the add method defined by IAdding (or rather its implementation,
the magic /+/ ;). But since there is no IAdding context regarding the
new created Example object we have to 'hardcode' the add method for the
ExampleResourceSet object. I did that following and adapting the lines
of the IAdding implementation of zope.app.container.browser.adding.Adding.



Best regards,
Christian


PS. If you wonder about the class name 'Example' -- the application is
supposed to be a database to collect examples and metaphors (rhetorical
figures) and will be part of a project located at the department for
german language and literature at the Ruhr-University Bochum, germany.
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] addview name not form

2005-09-29 Thread Julien Anguenot
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

First have a look at this :

http://www.zope.org/Collectors/Zope3-dev/391

The addMenuItem directive should look this way in order to work :

addMenuItem
title=Link
class=CS.Link.link.Link
view=AddCSLink.html
permission=zope.Public
menu=CSaddMenu
 /

without 'for=CS.ContentFolder.interfaces.IContentFolder' (check the
collector entry)

The addMenuItem doesn't support the layer attribute. I'm going to add
this to the addMenuItem directive interface.

J.

Florian Lindner wrote:
 Ok, here we go. The package is located at http://xgm.de/addform.tar.gz. 
 Simple 
 register it (a cs-configure.zcml is provided) and start Zope (SVN version), 
 you'll see the error.
 
 To check the intended behavior:
 
 0) Start Zope successfully (first important step!)
 1) Create a ContentFolder named cs.
 2) Go to http://horus:8080/++skin++centershock/cs/
 3) The menu on the left should show a entry Link under Items to add
 4) This entry should link to /++skin++centershock/cs/+/%40%40AddCSLink.html, 
 NOT to the URL but withount the /+/ (what the Folder link does at the 
 moment), since this method is broken somehow.
 
 
 Thanks for you help,
 
 Florian
 
 
 
 Am Donnerstag, 29. September 2005 14:45 schrieb Julien Anguenot:
 
Yup please. I could investigate much more easily.

  J.

Florian Lindner wrote


Hi,
no one any more ideas?  *desperated* I can't really believ that this
error has not occured to anyone else, since IMO it is very a standard
situation...

Would it help if I create a small package which demonstrates the error?

Thx,

Florian


- --
Julien Anguenot | Nuxeo RD (Paris, France)
CPS Platform : http://www.cps-project.org
Zope3 / ECM   : http://www.z3lab.org
mail: anguenot at nuxeo.com; tel: +33 (0) 6 72 57 57 66
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFDPDGCGhoG8MxZ/pIRAoNNAJ9LQRdqWOmohbi4uNMZHILIgniFmgCfWtL7
HlHJu21gahHsdu/+HSzjF58=
=Hp9t
-END PGP SIGNATURE-
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] addview name not form

2005-09-29 Thread Florian Lindner
Am Donnerstag, 29. September 2005 20:25 schrieb Julien Anguenot:
 First have a look at this :

 http://www.zope.org/Collectors/Zope3-dev/391

 The addMenuItem directive should look this way in order to work :

 addMenuItem
 title=Link
 class=CS.Link.link.Link
 view=AddCSLink.html
 permission=zope.Public
 menu=CSaddMenu
  /

 without 'for=CS.ContentFolder.interfaces.IContentFolder' (check the
 collector entry)

But then the menu entry does not show up in views on IContentFolder. And I 
need it showing up there.

 The addMenuItem doesn't support the layer attribute. I'm going to add
 this to the addMenuItem directive interface.

When do you think you will be done?

Thx,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users