<html><body bgcolor="#FFFFFF"><div>You are going to have to find 'text' in the request the way you have it setup. &nbsp;See below<br><br>Sent from my iPod</div><div><br>On Jul 27, 2010, at 10:49 AM, "J. Cameron Cooper" &lt;<a href="mailto:jccooper@gmail.com">jccooper@gmail.com</a>&gt; wrote:<br><br></div><div></div><blockquote type="cite"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Date: Tue, 27 Jul 2010 12:15:15 +0200<br>
From: Lumir Jasiok &lt;<a href="mailto:lumir.jasiok@vsb.cz"><a href="mailto:lumir.jasiok@vsb.cz">lumir.jasiok@vsb.cz</a></a>&gt;<br>
Subject: [Grok-dev] Whats wrong wit my update method<br>
To: <a href="mailto:grok-dev@zope.org"><a href="mailto:grok-dev@zope.org">grok-dev@zope.org</a></a><br>
Message-ID: &lt;<a href="mailto:4C4EB1B3.5030203@vsb.cz"><a href="mailto:4C4EB1B3.5030203@vsb.cz">4C4EB1B3.5030203@vsb.cz</a></a>&gt;<br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
 &nbsp;Hi,<br>
<br>
I am pretty new in Grok Development, so sorry for (probably) trivia<br>
question. I have small testing application in app.py<br>
<br>
import grok<br>
<br>
class Awbarcode(grok.Application,grok.Container):<br>
<br>
 &nbsp; &nbsp; def __init__(self):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; super(Awbarcode, self).__init__()<br>
 &nbsp; &nbsp; &nbsp; &nbsp; self.title = 'AWBarcode manager'<br>
 &nbsp; &nbsp; &nbsp; &nbsp; self.text = "basic text"<br>
 &nbsp; &nbsp; &nbsp; &nbsp; self.next_id = 0<br>
<br>
 &nbsp; &nbsp; def addBarcode(self,text):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; id = str(self.next_id)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; self.next_id = self.next_id + 1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; self[id] = Barcode(text)<br>
<br>
 &nbsp; &nbsp; def deleteBarcode(self,barode):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; del self[barcode]<br>
<br>
class Barcode(grok.Model):<br>
<br>
 &nbsp; &nbsp; def __init__(self,text):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; super(Barcode,self).__init__()<br>
 &nbsp; &nbsp; &nbsp; &nbsp; self.text = text<br>
<br>
class AwbarcodeIndex(grok.View):<br>
 &nbsp; &nbsp; grok.context(Awbarcode)<br>
 &nbsp; &nbsp; <a href="http://grok.name" target="_blank"><a href="http://grok.name">grok.name</a></a>('index')<br>
<br>
class AddBarcode(grok.View):<br>
 &nbsp; &nbsp; grok.context(Awbarcode)<br>
 &nbsp; &nbsp; <a href="http://grok.name" target="_blank"><a href="http://grok.name">grok.name</a></a>('addbarcode')<br>
<br>
 &nbsp; &nbsp; def update(self,text):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; </blockquote></div></div></blockquote><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.context.addBarcode(self.request.get('text'))</div><blockquote type="cite"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;#self.context.addBarcode(text)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; self.redirect(self.url('index'))<br>
<br>
Also I have two .pt files, <a href="http://awbarcodeindex.pt" target="_blank"><a href="http://awbarcodeindex.pt">awbarcodeindex.pt</a></a>:<br>
<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title tal:content="context/title"&gt;Barcode manager&lt;/title&gt;<br>
&lt;/head&gt;<br>
&lt;body&gt;<br>
&lt;h1 tal:content="context/title"&gt;Barcode manager&lt;/h1&gt;<br>
&lt;h2&gt;Here you can see barcodes:&lt;/h2&gt;<br>
&lt;tal:block repeat="barcode context/values"&gt;<br>
&lt;ul&gt;<br>
&lt;li tal:content="barcode/text"&gt;Barcode&lt;/li&gt;<br>
&lt;/ul&gt;<br>
&lt;/tal:block&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
<br>
and <a href="http://addbarcode.pt" target="_blank"><a href="http://addbarcode.pt">addbarcode.pt</a></a>:<br>
<br>
&lt;html&gt;<br>
&lt;body&gt;<br>
&lt;h2&gt;Add barcode&lt;/h2&gt;<br>
&lt;form tal:attributes="action view/url" &nbsp;method="POST"&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; New Barcode text: &lt;input type="text" name="text" value=""<br>
/&gt;&lt;br /&gt;<br>
&lt;input type="submit" value="Add Barcode Text" /&gt;<br>
&lt;/form&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
<br>
So, if I manually add some barcode text, I can see it listed on the<br>
index page, but when I try to add new barcode text using url:<br>
<br>
<a href="http://localhost:8080/test/addbarcode" target="_blank"><a href="http://localhost:8080/test/addbarcode">http://localhost:8080/test/addbarcode</a></a><br>
<br>
I can see just "A system error occurred.", not form I have in<br>
<a href="http://addbarcode.pt" target="_blank"><a href="http://addbarcode.pt">addbarcode.pt</a></a> &nbsp;and in log file is "TypeError: Missing argument to<br>
update(): text". I must use this to add new text to the storage:<br>
<br>
<a href="http://localhost:8080/test/addbarcode?text=text1" target="_blank"><a href="http://localhost:8080/test/addbarcode?text=text1">http://localhost:8080/test/addbarcode?text=text1</a></a><br>
<br>
After that I can finally see form and add new barcode text.<br>
<br>
What I am doing wrong? Thanks for any help.<br></blockquote><div><br></div><div>The 'update' method runs before the template is displayed. See&nbsp;<a href="http://grok.zope.org/doc/current/tutorial.html#doing-some-calculation-before-viewing-a-page"><a href="http://grok.zope.org/doc/current/tutorial.html#doing-some-calculation-before-viewing-a-page">http://grok.zope.org/doc/current/tutorial.html#doing-some-calculation-before-viewing-a-page</a></a></div>
<div><br></div><div>When you say "/test/addbarcode" you are going to the 'AddBarcode' view, which uses its 'update' method first, which demands the data it needs. If it fails, it fails, if it succeeds, you see &nbsp;the '<a href="http://addbarcode.pt"><a href="http://addbarcode.pt">addbarcode.pt</a></a>' template.</div>
<div><br></div><div>You could create another view for the form and have it submit to 'addbarcode', which then becomes a "thank you" page. Or, perhaps, you could not require 'text' in the method params (text=None), and look for the submit param value and test for proper data (text is not empty/false) yourself inside the method before changing the model. That would allow the form to load without params and also submit to itself. This is (close to) what happens in <a href="http://grok.zope.org/doc/current/tutorial.html#simple-forms"><a href="http://grok.zope.org/doc/current/tutorial.html#simple-forms">http://grok.zope.org/doc/current/tutorial.html#simple-forms</a></a><br>
</div></div><div><br></div><div>As already mentioned, though, it would probably be a good idea to look into automatic forms.</div><br clear="all">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--jcc<br>-- <br>J Cameron Cooper<br><a href="mailto:jccooper@gmail.com"><a href="mailto:jccooper@gmail.com">jccooper@gmail.com</a></a><br>
<a href="mailto:anything@jcameroncooper.com"><a href="mailto:anything@jcameroncooper.com">anything@jcameroncooper.com</a></a><br>mobile: 713.882.7395<br>Skype: jcameroncooper<br>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Grok-dev mailing list</span><br><span><a href="mailto:Grok-dev@zope.org">Grok-dev@zope.org</a></span><br><span><a href="https://mail.zope.org/mailman/listinfo/grok-dev">https://mail.zope.org/mailman/listinfo/grok-dev</a></span><br></div></blockquote></body></html>