[Checkins] SVN: z3c.reference/branches/flash/src/z3c/reference/
Make progress with view reference implementation
Roger Ineichen
roger at projekt01.ch
Wed Sep 5 09:02:34 EDT 2007
Log message for revision 79478:
Make progress with view reference implementation
Changed:
U z3c.reference/branches/flash/src/z3c/reference/README.txt
U z3c.reference/branches/flash/src/z3c/reference/browser/README.txt
A z3c.reference/branches/flash/src/z3c/reference/browser/editor.pt
D z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt
U z3c.reference/branches/flash/src/z3c/reference/browser/views.py
U z3c.reference/branches/flash/src/z3c/reference/browser/widget.py
U z3c.reference/branches/flash/src/z3c/reference/configure.zcml
U z3c.reference/branches/flash/src/z3c/reference/demo/app.py
U z3c.reference/branches/flash/src/z3c/reference/demo/browser/configure.zcml
U z3c.reference/branches/flash/src/z3c/reference/demo/browser/views.py
U z3c.reference/branches/flash/src/z3c/reference/demo/interfaces.py
U z3c.reference/branches/flash/src/z3c/reference/interfaces.py
A z3c.reference/branches/flash/src/z3c/reference/property.py
U z3c.reference/branches/flash/src/z3c/reference/reference.py
U z3c.reference/branches/flash/src/z3c/reference/schema.py
-=-
Modified: z3c.reference/branches/flash/src/z3c/reference/README.txt
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/README.txt 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/README.txt 2007-09-05 13:02:33 UTC (rev 79478)
@@ -1,6 +1,6 @@
-=========================
- Refererences to Objects
-=========================
+=======================
+Refererences to Objects
+=======================
Referenced objects must be adaptable to IKeyReference.
@@ -30,7 +30,6 @@
True
-
Reference Fields
================
@@ -54,7 +53,8 @@
>>> c.ref = ViewReference(o2)
>>> c.ref.target is o2
True
-
+
+
Image Reference Fields
======================
@@ -94,6 +94,7 @@
>>> c.img.target is img
True
+
Back references
===============
@@ -138,3 +139,24 @@
...
ValueError: ('viewReferences', 'field is readonly')
+
+ViewReferenceSettings
+---------------------
+
+Fields define a settingName, by default this name is a empty string if not
+explicit given. This settingName is used for call a related named adapter
+providing IViewReferenceSettings which provides a dictionary with key, values
+under the attribute ``settings``.
+
+This settings are used for help to setup a reference editor. Let's see how
+this works. By default, we get the DefaultViewReferenceSetting adapter for a
+referenced object:
+
+ >>> import zope.component
+ >>> from z3c.reference.interfaces import IViewReferenceSettings
+ >>> from z3c.reference.reference import DefaultViewReferenceSettings
+ >>> zope.component.provideAdapter(DefaultViewReferenceSettings)
+
+ >>> adapter = IViewReferenceSettings(o)
+ >>> adapter
+ <DefaultViewReferenceSettings None>
Modified: z3c.reference/branches/flash/src/z3c/reference/browser/README.txt
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/browser/README.txt 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/browser/README.txt 2007-09-05 13:02:33 UTC (rev 79478)
@@ -13,7 +13,7 @@
...
... intro = ViewReferenceField(title=u'Intro',
... description=u'A intro text',
- ... viewName=u'')
+ ... settingName=u'')
Let's define the IPage object:
@@ -51,8 +51,8 @@
>>> print widget()
<a class="popupwindow" href="http://127.0.0.1/viewReferenceEditor.html"
id="field.intro.tag" name="field.intro" onclick="" title="Undefined"
- rel="window">Undefined</a><input class="hiddenType" id="field.intro.view"
- name="field.intro.view" type="hidden" value="" rel="window"
+ rel="window">Undefined</a><input class="hiddenType" id="field.intro.setting"
+ name="field.intro.setting" type="hidden" value="" rel="window"
/><input class="hiddenType" id="field.intro.intid"
name="field.intro.intid" type="hidden" value="" rel="window" />
Copied: z3c.reference/branches/flash/src/z3c/reference/browser/editor.pt (from rev 79475, z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt)
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/browser/editor.pt (rev 0)
+++ z3c.reference/branches/flash/src/z3c/reference/browser/editor.pt 2007-09-05 13:02:33 UTC (rev 79478)
@@ -0,0 +1,189 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:i18n="http://namespaces.zope.org/i18n"
+ xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>demo picker</title>
+ <style type="text/css">
+ body {
+ margin: 0px;
+ padding: 0px;
+ height: 100%;
+ font-family: 'Trebuchet MS';
+ font-size: 10pt;
+ }
+
+ a {
+ color: #000;
+ }
+
+ a.ex1, a.ex2 {
+ color: #888;
+ text-decoration: none;
+ }
+
+ div {
+ margin: 0px;
+ }
+
+ div.float {
+ position: absolute;
+ padding: 0px 10px;
+ border: 0px solid #888;
+ border-right-width: 1px;
+ float:left;
+ height: 100%
+ }
+
+ div.picker {
+ width: 150px;
+ }
+
+ div.properties {
+ position: absolute;
+ left: 170px;
+ width: 200px;
+ }
+
+ div.image-tool {
+ position: absolute;
+ left: 390px;
+ width: 500px;
+ }
+
+ div.actions {
+ position: absolute;
+ left: 910px;
+ padding: 0px 10px;
+ }
+
+ h1 {
+ font-size: 12pt;
+ margin: 10px 0px;
+ }
+
+ label {
+ width: 80px;
+ }
+
+ input, textarea {
+ width: 196px;
+ }
+
+ </style>
+ <script src="jquery"
+ type="text/javascript"
+ tal:attributes="src context/++resource++jquery.js">
+ </script>
+ <script type="text/javascript"
+ tal:content="string:
+ function loadFlash() {
+ var url='${context/++resource++imagetool.swf}';
+ var img='${context/++resource++img.jpg}';
+ url = url + '?url=' + img;
+ var so = new SWFObject(url, 'image-tool', '100%', '490px', '8', 0x000000);
+ so.addParam('allowScriptAccess', 'sameDomain');
+ so.addParam('movie', url);
+ so.addParam('quality', 'high');
+ so.addVariable('crop_x', '100');
+ so.addVariable('crop_y', '100');
+ so.addVariable('crop_w', '100');
+ so.addVariable('crop_h', '100');
+ so.addVariable('original_w', '600');
+ so.addVariable('original_h', '400');
+ so.addVariable('zoomfactor', '0.33');
+ so.addVariable('rotation', '90');
+ var ok = so.write('flash-target');
+ }
+ ">
+ </script>
+ <script type="text/javascript">
+ $(document).ready(loadFlash);
+
+ // user selects an item
+ function setIntId(uid) {
+ // reset values
+ $("textarea").val("");
+ $("input[@type=text]").val("");
+ // set iniid of selected item
+ $("input[@name=intid]").val(uid);
+ // highlight selected item
+ $("a").attr("style", "");
+ $("a[@href*=" + uid + "]").attr("style","background-color: #888");
+ // show divs
+ $("div.properties").show();
+ // $("div.actions").show();
+ // $("div.image-tool").show();
+ }
+
+
+ $(document).ready(function(){
+ // pressed submit button
+ // return selected item to parent and close popup
+ $("input[@type=submit]").click(function() {
+ var intid = $("input[@name=intid]").val();
+ window.opener.setIntId(intid);
+ window.close();
+ });
+
+ $("a.target").click(function() {
+ $("div.actions").hide();
+ $("div.image-tool").hide();
+ $("a.ex1").show();
+ $("a.ex2").show();
+ window.resizeTo(171, 550);
+ window.resizeBy(220, 0);
+ });
+
+ $("a.ex1").click(function() {
+ $("a.ex1").hide();
+ $("div.image-tool").show();
+ window.resizeBy(520, 0);
+ });
+
+ $("a.ex2").click(function() {
+ $("a.ex2").hide();
+ $("div.actions").show();
+ window.resizeBy(220, 0);
+ });
+ });
+ </script>
+ </head>
+ <body>
+ <div class="picker float">
+ <input name="intid" type="hidden" value="None" />
+ <h1>Targets</h1>
+ <tal:block repeat="item view/items">
+ <a href="#" class="target"
+ tal:attributes="href string:JavaScript:setIntId(${item/uid})">
+ <span tal:replace="item/name" />
+ </a>
+ <br />
+ </tal:block>
+ </div>
+ <div class="properties float" style="display:none;">
+ <h1>
+ Properties
+ <a href="#" class="ex1">>></a>
+ </h1>
+ <label for="title">Title</label><br />
+ <input id="title" name="title" type="text" /><br />
+ <label for="description">Description</label><br />
+ <textarea id="description" name="description"
+ cols="20" rows="5"
+ >abcd</textarea>
+ </div>
+ <div class="image-tool float" style="display:none;">
+ <h1>
+ Image-Tool
+ <a href="#" class="ex2">>></a>
+ </h1>
+ <div id="flash-target"></div>
+ </div>
+ <div class="actions" style="display:none;">
+ <h1>Save</h1>
+ <input type="submit" value="add reference" />
+ </div>
+ </body>
+</html>
\ No newline at end of file
Deleted: z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/browser/picker.pt 2007-09-05 13:02:33 UTC (rev 79478)
@@ -1,189 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:i18n="http://namespaces.zope.org/i18n"
- xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>demo picker</title>
- <style type="text/css">
- body {
- margin: 0px;
- padding: 0px;
- height: 100%;
- font-family: 'Trebuchet MS';
- font-size: 10pt;
- }
-
- a {
- color: #000;
- }
-
- a.ex1, a.ex2 {
- color: #888;
- text-decoration: none;
- }
-
- div {
- margin: 0px;
- }
-
- div.float {
- position: absolute;
- padding: 0px 10px;
- border: 0px solid #888;
- border-right-width: 1px;
- float:left;
- height: 100%
- }
-
- div.picker {
- width: 150px;
- }
-
- div.properties {
- position: absolute;
- left: 170px;
- width: 200px;
- }
-
- div.image-tool {
- position: absolute;
- left: 390px;
- width: 500px;
- }
-
- div.actions {
- position: absolute;
- left: 910px;
- padding: 0px 10px;
- }
-
- h1 {
- font-size: 12pt;
- margin: 10px 0px;
- }
-
- label {
- width: 80px;
- }
-
- input, textarea {
- width: 196px;
- }
-
- </style>
- <script src="jquery"
- type="text/javascript"
- tal:attributes="src context/++resource++jquery.js">
- </script>
- <script type="text/javascript"
- tal:content="string:
- function loadFlash() {
- var url='${context/++resource++imagetool.swf}';
- var img='${context/++resource++img.jpg}';
- url = url + '?url=' + img;
- var so = new SWFObject(url, 'image-tool', '100%', '490px', '8', 0x000000);
- so.addParam('allowScriptAccess', 'sameDomain');
- so.addParam('movie', url);
- so.addParam('quality', 'high');
- so.addVariable('crop_x', '100');
- so.addVariable('crop_y', '100');
- so.addVariable('crop_w', '100');
- so.addVariable('crop_h', '100');
- so.addVariable('original_w', '600');
- so.addVariable('original_h', '400');
- so.addVariable('zoomfactor', '0.33');
- so.addVariable('rotation', '90');
- var ok = so.write('flash-target');
- }
- ">
- </script>
- <script type="text/javascript">
- $(document).ready(loadFlash);
-
- // user selects an item
- function setIntId(uid) {
- // reset values
- $("textarea").val("");
- $("input[@type=text]").val("");
- // set iniid of selected item
- $("input[@name=intid]").val(uid);
- // highlight selected item
- $("a").attr("style", "");
- $("a[@href*=" + uid + "]").attr("style","background-color: #888");
- // show divs
- $("div.properties").show();
- // $("div.actions").show();
- // $("div.image-tool").show();
- }
-
-
- $(document).ready(function(){
- // pressed submit button
- // return selected item to parent and close popup
- $("input[@type=submit]").click(function() {
- var intid = $("input[@name=intid]").val();
- window.opener.setIntId(intid);
- window.close();
- });
-
- $("a.target").click(function() {
- $("div.actions").hide();
- $("div.image-tool").hide();
- $("a.ex1").show();
- $("a.ex2").show();
- window.resizeTo(171, 550);
- window.resizeBy(220, 0);
- });
-
- $("a.ex1").click(function() {
- $("a.ex1").hide();
- $("div.image-tool").show();
- window.resizeBy(520, 0);
- });
-
- $("a.ex2").click(function() {
- $("a.ex2").hide();
- $("div.actions").show();
- window.resizeBy(220, 0);
- });
- });
- </script>
- </head>
- <body>
- <div class="picker float">
- <input name="intid" type="hidden" value="None" />
- <h1>Targets</h1>
- <tal:block repeat="item view/items">
- <a href="#" class="target"
- tal:attributes="href string:JavaScript:setIntId(${item/uid})">
- <span tal:replace="item/name" />
- </a>
- <br />
- </tal:block>
- </div>
- <div class="properties float" style="display:none;">
- <h1>
- Properties
- <a href="#" class="ex1">>></a>
- </h1>
- <label for="title">Title</label><br />
- <input id="title" name="title" type="text" /><br />
- <label for="description">Description</label><br />
- <textarea id="description" name="description"
- cols="20" rows="5"
- >abcd</textarea>
- </div>
- <div class="image-tool float" style="display:none;">
- <h1>
- Image-Tool
- <a href="#" class="ex2">>></a>
- </h1>
- <div id="flash-target"></div>
- </div>
- <div class="actions" style="display:none;">
- <h1>Save</h1>
- <input type="submit" value="add reference" />
- </div>
- </body>
-</html>
\ No newline at end of file
Modified: z3c.reference/branches/flash/src/z3c/reference/browser/views.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/browser/views.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/browser/views.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -16,14 +16,18 @@
"""
__docformat__ = 'restructuredtext'
-from zope.traversing.browser.absoluteurl import absoluteURL, AbsoluteURL
import urllib
+
+from zope import component
+from zope.traversing.browser import absoluteURL
+from zope.traversing.interfaces import IContainmentRoot
from zope.traversing.browser.interfaces import IAbsoluteURL
-from zope import component
+from zope.traversing.browser.absoluteurl import AbsoluteURL
from zope.app.intid.interfaces import IIntIds
-from zope.traversing.interfaces import IContainmentRoot
+
noImage = '/@@/z3c.reference.resources/noimage.jpg'
+
class ViewReferenceAbsoluteURL(AbsoluteURL):
"""adapts a view reference to IAbsoluteURL
@@ -32,18 +36,18 @@
>>> from zope.publisher.browser import TestRequest
>>> ref = ViewReference(view=u'http://www.zope.org/')
>>> request = TestRequest()
- >>> view = ViewReferenceAbsoluteURL(ref,request)
+ >>> view = ViewReferenceAbsoluteURL(ref, request)
>>> view
<z3c.reference.browser.views.ViewReferenceAbsoluteURL ...>
>>> view()
'http://www.zope.org/'
>>> ref = ViewReference(target=site)
- >>> view = ViewReferenceAbsoluteURL(ref,request)
+ >>> view = ViewReferenceAbsoluteURL(ref, request)
>>> view()
'http://127.0.0.1'
- >>> ref = ViewReference(target=site,view=u'index.html?x=1&y=2')
+ >>> ref = ViewReference(target=site, view=u'index.html?x=1&y=2')
>>> view = ViewReferenceAbsoluteURL(ref,request)
>>> view()
'http://127.0.0.1/index.html?x=1&y=2'
@@ -66,7 +70,7 @@
except TypeError:
return noImage
if self.view is not None:
- url = '%s/%s' % (url,self.view.encode('utf8'))
+ url = '%s/%s' % (url, self.view.encode('utf8'))
return url
else:
# the target ist lost TODO:
@@ -87,8 +91,35 @@
class ViewReferenceEditor(object):
- """View reference editor."""
+ """View reference editor offering search and edit form setup.
+
+ The following objects are used:
+
+ context = view reference
+ target = referenced object
+ """
+
+ searchForm = None
+ editForm = None
+
+ def update(self):
+ super(ViewReferenceEditor, self).update()
+ target = self.request.get('target')
+ searchFormName = self.request.get('search')
+ editFormName = self.request.get('edit')
+
+ # prepare search form
+ if target is not None and searchFormName is not None:
+ self.searchForm = zope.component.getMultiAdapter(
+ (self.context, self.request), name=searchFormName)
+
+ # prepare edit form
+ if target is not None and editFormName is not None:
+ self.editForm = zope.component.getMultiAdapter(
+ (self.context, self.target, self.request), name=editFormName)
+
+
def items(self):
intIds = component.getUtility(IIntIds)
for o in self.context.values():
Modified: z3c.reference/branches/flash/src/z3c/reference/browser/widget.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/browser/widget.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/browser/widget.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -76,63 +76,8 @@
class ViewReferenceWidget(TextWidget):
- """renders an "a" tag with the title and href attributes
-
- if no target
+ """renders an "a" tag with the title and href attributes."""
- >>> from zope.publisher.browser import TestRequest
- >>> from z3c.reference.schema import ViewReferenceField
- >>> from zope.app.folder import Folder
- >>> f = Folder()
- >>> site['folder'] = f
- >>> field = ViewReferenceField(title=(u'Title of Field'),
- ... __name__='ref')
- >>> request = TestRequest()
- >>> w = ViewReferenceWidget(field,request)
- >>> w()
- u'<input class="hiddenType" id="field.ref" .../>...</a>'
- >>> request.form['field.ref']=u'http://127.0.0.1/folder'
- >>> res = w.getInputValue()
- >>> res
- <z3c.reference.reference.ViewReference object at ...>
-
- >>> res.view is None
- True
-
- >>> res.target is f
- True
-
- >>> request.form['field.ref']=u'http://127.0.0.1/folder/index.html'
- >>> res = w.getInputValue()
- >>> res.target is f
- True
- >>> res.view
- u'index.html'
- >>> absoluteURL(res,request)
- 'http://127.0.0.1/folder/index.html'
-
- >>> request.form['field.ref']=u'http://127.0.0.1/folder/index.html?x=1&y=2'
- >>> res = w.getInputValue()
- >>> res.target is f
- True
- >>> res.view
- u'index.html?x=1&y=2'
- >>> absoluteURL(res,request)
- 'http://127.0.0.1/folder/index.html?x=1&y=2'
-
- >>> print w()
- <input class="hiddenType" .../><a href="..." ...</a>
-
- >>> ff = Folder()
- >>> f[u'second'] = ff
- >>> request.form['field.ref']=u'http://127.0.0.1/folder/second/index.html?x=1&y=2'
- >>> res = w.getInputValue()
- >>> res.target is ff
- True
-
-
- """
-
tag = u'input'
type = u'text'
cssClass = u'popupwindow'
@@ -162,7 +107,6 @@
def __call__(self):
resourcelibrary.need('z3c.reference')
- hidden = super(ViewReferenceWidget,self).__call__()
if self._renderedValueSet():
ref = self._data
else:
@@ -181,11 +125,10 @@
#else:
# contents = untitled
#ref = self._emptyReference
- siteUrl = absoluteURL(hooks.getSite(),self.request)
contents = undefined
href = self.getReferenceExplorerURL()
intIdName = self.name + '.intid'
- viewName = self.name + '.view'
+ settingName = self.name + '.setting'
intidInput = renderElement(u'input',
type='hidden',
name=intIdName,
@@ -194,8 +137,8 @@
extra=self.extra)
viewInput = renderElement(u'input',
type='hidden',
- name=viewName,
- id=viewName,
+ name=settingName,
+ id=settingName,
value=self.getViewString(),
extra=self.extra)
linkTag = renderElement(self.refTag,
Modified: z3c.reference/branches/flash/src/z3c/reference/configure.zcml
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/configure.zcml 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/configure.zcml 2007-09-05 13:02:33 UTC (rev 79478)
@@ -10,7 +10,11 @@
<class class="z3c.reference.reference.ImageReference">
<allow interface=".interfaces.IImageReference"/>
</class>
-
+
+ <adapter
+ factory=".reference.DefaultViewReferenceSettings"
+ />
+
<include package=".browser"/>
-
+
</configure>
\ No newline at end of file
Modified: z3c.reference/branches/flash/src/z3c/reference/demo/app.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/demo/app.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/demo/app.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -18,18 +18,22 @@
from zope import interface
from zope.schema.fieldproperty import FieldProperty
+from zope.location.interfaces import ILocation
from zope.app.folder.folder import Folder
from zope.app.file.image import Image
+
+from lovely.relation.property import (FieldRelationManager,
+ RelationPropertyOut,
+ RelationPropertyIn)
+
from z3c.reference.demo.interfaces import (IDemoFolder,
IDemoImage)
from z3c.reference.interfaces import (IViewReference,
IReferenced)
from z3c.reference.reference import viewReferenceRelated
-from lovely.relation.property import (FieldRelationManager,
- RelationPropertyOut,
- RelationPropertyIn)
-from z3c.reference.schema import ViewReferenceProperty
+from z3c.reference.property import ViewReferenceProperty
+
class DemoFolder(Folder):
"""Demo folder implementation."""
@@ -42,8 +46,10 @@
class DemoImage(Image):
- """DEmo image implementation."""
+ """Demo image implementation."""
- interface.implements(IDemoImage, IReferenced)
+ interface.implements(IDemoImage, IReferenced, ILocation)
+ __name__ = __parent__ = None
+
viewReferences = RelationPropertyIn(viewReferenceRelated)
Modified: z3c.reference/branches/flash/src/z3c/reference/demo/browser/configure.zcml
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/demo/browser/configure.zcml 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/demo/browser/configure.zcml 2007-09-05 13:02:33 UTC (rev 79478)
@@ -43,7 +43,7 @@
for="z3c.reference.demo.interfaces.IDemoFolder"
class=".views.ViewReferenceEditor"
permission="zope.ManageContent"
- template="picker.pt"
+ template="editor.pt"
/>
</configure>
Modified: z3c.reference/branches/flash/src/z3c/reference/demo/browser/views.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/demo/browser/views.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/demo/browser/views.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -29,12 +29,18 @@
from zope.app.intid.interfaces import IIntIds
from zc import resourcelibrary
+
class DemoFolderEdit(form.EditForm):
+ """Demo folder edit form."""
+
+ label = u"Edit Demo Folder"
+
form_fields = form.Fields(IDemoFolder)
- label = u"Edit demofolder"
class DemoImageEdit(form.EditForm):
+ """Demo image edit form."""
+
form_fields = form.Fields(IDemoImage)
Modified: z3c.reference/branches/flash/src/z3c/reference/demo/interfaces.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/demo/interfaces.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/demo/interfaces.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -25,13 +25,17 @@
""" demo folder"""
previewImage = ViewReferenceField(
- title=u'previewImage',
+ title=u'Preview Image',
+ description=u'Referenced Preview Image',
required=False,
- viewName=u'')
+ settingName=u'')
assets = schema.List(
title=u'Related',
- value_type=ViewReferenceField(viewName=u''),
+ description=u'Referenced list of objects',
+ value_type=ViewReferenceField(
+ title=u'Related item',
+ settingName=u''),
required=False,
default=[])
@@ -39,7 +43,7 @@
class IDemoImage(interface.Interface):
""" demo image"""
-
+
# view code example
# field.settings
Modified: z3c.reference/branches/flash/src/z3c/reference/interfaces.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/interfaces.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/interfaces.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -16,63 +16,80 @@
"""
__docformat__ = 'restructuredtext'
-from zope import interface,schema
+import zope.interface
+import zope.schema
from zope.location.interfaces import ILocation
from zope.app.file.interfaces import IImage
from zope.interface.interfaces import IInterface
-class IViewReference(interface.Interface):
+
+class IViewReference(zope.interface.Interface):
"""a reference to a view of an object, by storing the name of the
view. If the target is None, the view name is supposed to be an
absolute url to an external target"""
- target = schema.Object(ILocation,required=True,
- title=u'Target Object')
- view = schema.TextLine(required=False,title=u'View')
+ target = zope.schema.Object(
+ schema=ILocation,
+ title=u'Target Object',
+ required=True,)
+ view = zope.schema.TextLine(
+ title=u'View',
+ required=False)
+
class IImageReference(IViewReference):
"""a reference to an image with optional size constraints"""
- target = schema.Object(IImage,required=False,
- title=u'Target Image')
+ target = zope.schema.Object(
+ schema=IImage,
+ title=u'Target Image',
+ required=False)
-class IReferenced(interface.Interface):
+class IReferenced(zope.interface.Interface):
"""backrefs"""
- viewReferences = schema.List(title=u"View references",
- value_type=schema.Object(IViewReference),
- required=False,
- readonly=True,
- default=[])
+ viewReferences = zope.schema.List(
+ title=u"View references",
+ value_type=zope.schema.Object(IViewReference),
+ required=False,
+ readonly=True,
+ default=[])
-class IViewReferenceSettings(interface.Interface):
- settings = schema.List(title=u'Settings',
- required=False,
- default=[])
-
-class IViewReferenceField(schema.interfaces.IObject):
+class IViewReferenceField(zope.schema.interfaces.IObject):
"""a view reference field"""
- viewName = schema.TextLine(title=u"Settings",
- required=False)
+ settingName = zope.schema.TextLine(
+ title=u"Setting Name",
+ required=False,
+ default=u'')
-class IImageReferenceField(schema.interfaces.IObject):
-
+class IViewReferenceSettings(zope.interface.Interface):
+
+ settings = zope.schema.Dict(
+ title=u'Settings',
+ description=u'Settings used for setup the view reference editor.',
+ required=False,
+ default={})
+
+
+class IImageReferenceField(zope.schema.interfaces.IObject):
"""an image reference field"""
- size = schema.Tuple(title=u'Forced Size',
- value_type=schema.Int(),
- required=True,
- min_length=2,max_length=2)
+ size = zope.schema.Tuple(
+ title=u'Forced Size',
+ value_type=zope.schema.Int(),
+ required=True,
+ min_length=2,
+ max_length=2)
class IObjectReferenceField(IViewReferenceField):
-
"""a schema based reference field"""
- refSchema = schema.Object(IInterface,
- title=u'Reference Schema')
+ refSchema = zope.schema.Object(
+ schema=IInterface,
+ title=u'Reference Schema')
Added: z3c.reference/branches/flash/src/z3c/reference/property.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/property.py (rev 0)
+++ z3c.reference/branches/flash/src/z3c/reference/property.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id: schema.py 79462 2007-09-04 16:14:53Z rogerineichen $
+"""
+__docformat__ = 'restructuredtext'
+
+import types
+
+_marker = object()
+
+
+class ViewReferenceProperty(object):
+ """A property that takes care of setting __parent__ for all reference
+ objects when being set on the content object.
+ """
+
+ def __init__(self, field, name=None):
+ if name is None:
+ name = field.__name__
+
+ self.__field = field
+ self.__name = name
+
+ def __get__(self, inst, klass):
+ if inst is None:
+ return self
+
+ value = inst.__dict__.get(self.__name, _marker)
+ if value is _marker:
+ field = self.__field.bind(inst)
+ value = getattr(field, 'default', _marker)
+ if value is _marker:
+ raise AttributeError(self.__name)
+
+ return value
+
+ def __set__(self, inst, value):
+ field = self.__field.bind(inst)
+ field.validate(value)
+ if field.readonly and inst.__dict__.has_key(self.__name):
+ raise ValueError(self.__name, 'field is readonly')
+ if type(value) in (types.ListType, types.TupleType):
+ for ref in value:
+ ref.__parent__ = inst
+ else:
+ value.__parent__ = inst
+ inst.__dict__[self.__name] = value
+
+ def __getattr__(self, name):
+ return getattr(self.__field, name)
Property changes on: z3c.reference/branches/flash/src/z3c/reference/property.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.reference/branches/flash/src/z3c/reference/reference.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/reference.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/reference.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -16,38 +16,39 @@
"""
__docformat__ = 'restructuredtext'
-from interfaces import *
-from persistent import Persistent
+import persistent
+
+import zope.interface
+import zope.component
+from zope.location.interfaces import ILocation
from zope.schema.fieldproperty import FieldProperty
-from zope.cachedescriptors.property import readproperty
-from zope.dublincore.interfaces import IZopeDublinCore
-from zope.app.keyreference.interfaces import IKeyReference
-from zope import interface
-from zope.traversing.browser.absoluteurl import absoluteURL
-import urlparse,cgi
from lovely.relation.property import (FieldRelationManager,
RelationPropertyOut)
+from z3c.reference import interfaces
-viewReferenceRelated = FieldRelationManager(IViewReference['target'],
- IReferenced['viewReferences'])
+viewReferenceRelated = FieldRelationManager(
+ interfaces.IViewReference['target'],
+ interfaces.IReferenced['viewReferences'])
-class ViewReference(Persistent):
- interface.implements(IViewReference)
+class ViewReference(persistent.Persistent):
- view = FieldProperty(IViewReference['view'])
+ zope.interface.implements(interfaces.IViewReference)
+
+ view = FieldProperty(interfaces.IViewReference['view'])
target = RelationPropertyOut(viewReferenceRelated)
def __init__(self,target=None,view=None):
if target is not None:
self.target = target
- self.view = view
+ if view is not None:
+ self.view = view
def __eq__(self,other):
if not other:
return False
- if IViewReference.providedBy(other):
+ if interfaces.IViewReference.providedBy(other):
return (self.view == other.view) and \
(self.target is other.target)
return False
@@ -55,12 +56,28 @@
def __ne__(self,other):
if not other:
return True
- if IViewReference.providedBy(other):
+ if interfaces.IViewReference.providedBy(other):
return (self.view != other.view) or \
(self.target != other.target)
return True
class ImageReference(ViewReference):
- interface.implements(IImageReference)
-
+ zope.interface.implements(interfaces.IImageReference)
+
+
+class DefaultViewReferenceSettings(object):
+ """Default view reference settings adapter."""
+
+ zope.interface.implements(interfaces.IViewReferenceSettings)
+ zope.component.adapts(ILocation)
+
+ def __init__(self, context):
+ self.context = context
+
+ def settings(self):
+ return {'settingName':self.context.settingName}
+
+ def __repr__(self):
+ return '<%s %r>' % (self.__class__.__name__, self.context.__name__)
+
Modified: z3c.reference/branches/flash/src/z3c/reference/schema.py
===================================================================
--- z3c.reference/branches/flash/src/z3c/reference/schema.py 2007-09-05 10:56:28 UTC (rev 79477)
+++ z3c.reference/branches/flash/src/z3c/reference/schema.py 2007-09-05 13:02:33 UTC (rev 79478)
@@ -17,50 +17,33 @@
__docformat__ = 'restructuredtext'
from zope import schema,interface
-from interfaces import *
+from z3c.reference import interfaces
import types
+
class ViewReferenceField(schema.Object):
- interface.implements(IViewReferenceField)
+ interface.implements(interfaces.IViewReferenceField)
def __init__(self, **kw):
- self.viewName = kw.pop('viewName', None)
- super(ViewReferenceField,self).__init__(IViewReference,
+ settingName = kw.pop('settingName', u'')
+ self.settingName = settingName
+ super(ViewReferenceField,self).__init__(interfaces.IViewReference,
**kw)
-class ViewReferenceProperty(property):
- """A property that takes care of setting __parent__ for all reference
- objects when being set on the content object.
- """
-
- def __init__(self, name):
- self.name = "_%s" % name
-
- def __get__(self, obj, default=None):
- return getattr(obj, self.name, default)
-
- def __set__(self, obj, value):
- if type(value) in (types.ListType, types.TupleType):
- for ref in value:
- ref.__parent__ = obj
- else:
- value.__parent__ = obj
- setattr(obj, self.name, value)
-
-
class ImageReferenceField(schema.Object):
- interface.implements(IImageReferenceField)
- size = schema.fieldproperty.FieldProperty(IImageReferenceField['size'])
+ interface.implements(interfaces.IImageReferenceField)
+ size = schema.fieldproperty.FieldProperty(
+ interfaces.IImageReferenceField['size'])
def __init__(self,**kw):
self.size = kw.pop('size',None)
- super(ImageReferenceField,self).__init__(IImageReference,
+ super(ImageReferenceField,self).__init__(interfaces.IImageReference,
**kw)
class ObjectReferenceField(ViewReferenceField):
- interface.implements(IObjectReferenceField)
+ interface.implements(interfaces.IObjectReferenceField)
def __init__(self,refSchema,**kw):
self.refSchema = refSchema
More information about the Checkins
mailing list