Skip to content

Commit b106018

Browse files
author
Richard Jones
committed
generic item editing
1 parent f123526 commit b106018

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

roundup/cgi/templating.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,16 @@ def __init__(self, client):
193193
# we want config to be exposed
194194
self.config = client.db.config
195195

196+
def __getitem__(self, item):
197+
self._client.db.getclass(item)
198+
return HTMLClass(self._client, item)
199+
196200
def __getattr__(self, attr):
197201
try:
198-
self._client.db.getclass(attr)
202+
return self[attr]
199203
except KeyError:
200204
raise AttributeError, attr
201-
return HTMLClass(self._client, attr)
205+
202206
def classes(self):
203207
l = self._client.db.classes.keys()
204208
l.sort()
@@ -857,27 +861,27 @@ def plain(self, escape=0):
857861
value = cgi.escape(value)
858862
return value
859863

860-
def field(self):
864+
def field(self, showid=0, size=None):
861865
''' Render a form edit field for the property
862866
'''
863867
linkcl = self._db.getclass(self._prop.classname)
864868
if linkcl.getprops().has_key('order'):
865869
sort_on = 'order'
866870
else:
867871
sort_on = linkcl.labelprop()
868-
options = linkcl.filter(None, {}, [sort_on], [])
872+
options = linkcl.filter(None, {}, ('+', sort_on), (None, None))
869873
# TODO: make this a field display, not a menu one!
870-
l = ['<select name="%s">'%property]
874+
l = ['<select name="%s">'%self._name]
871875
k = linkcl.labelprop(1)
872-
if value is None:
876+
if self._value is None:
873877
s = 'selected '
874878
else:
875879
s = ''
876880
l.append(_('<option %svalue="-1">- no selection -</option>')%s)
877881
for optionid in options:
878882
option = linkcl.get(optionid, k)
879883
s = ''
880-
if optionid == value:
884+
if optionid == self._value:
881885
s = 'selected '
882886
if showid:
883887
lab = '%s%s: %s'%(self._prop.classname, optionid, option)
@@ -999,6 +1003,8 @@ def field(self, size=30, showid=0):
9991003
if value:
10001004
value.sort(sortfunc)
10011005
# map the id to the label property
1006+
if not linkcl.getkey():
1007+
showid=1
10021008
if not showid:
10031009
k = linkcl.labelprop(1)
10041010
value = [linkcl.get(v, k) for v in value]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<form method="POST" onSubmit="return submit_once()"
2+
enctype="multipart/form-data">
3+
4+
<input type="hidden" name=":template" value="item">
5+
<input type="hidden" name=":required" value="title">
6+
7+
<table class="form">
8+
9+
<tr tal:repeat="prop python:db[context._classname].properties()">
10+
<tal:block tal:condition="python:prop._name not in ('id', 'creator', 'created', 'activity')">
11+
<th tal:content="prop/_name"></th>
12+
<td tal:content="structure python:context[prop._name].field()"></td>
13+
</tal:block>
14+
</tr>
15+
<tr>
16+
<td>&nbsp;</td>
17+
<td colspan=3 tal:content="structure context/submit">
18+
submit button will go here
19+
</td>
20+
</tr>
21+
</table>
22+
23+
24+
<tal:block tal:condition="context/id">
25+
<tal:block tal:replace="structure context/history" />
26+
</tal:block>
27+
28+
</form>

0 commit comments

Comments
 (0)