[Grok-dev] Whats wrong wit my update method

Souheil CHELFOUH trollfot at gmail.com
Tue Jul 27 06:23:08 EDT 2010


Update is done each time you display the page, before rendering it.
What you want here is a form. I recommand you read the tutorial about
forms, using grokcore.formlib.

cheers.

2010/7/27 Lumir Jasiok <lumir.jasiok at vsb.cz>:
> Hi,
>
> I am pretty new in Grok Development, so sorry for (probably) trivia
> question. I have small testing application in app.py
>
> import grok
>
> class Awbarcode(grok.Application,grok.Container):
>
>     def __init__(self):
>         super(Awbarcode, self).__init__()
>         self.title = 'AWBarcode manager'
>         self.text = "basic text"
>         self.next_id = 0
>
>     def addBarcode(self,text):
>         id = str(self.next_id)
>         self.next_id = self.next_id + 1
>         self[id] = Barcode(text)
>
>     def deleteBarcode(self,barode):
>         del self[barcode]
>
> class Barcode(grok.Model):
>
>     def __init__(self,text):
>         super(Barcode,self).__init__()
>         self.text = text
>
> class AwbarcodeIndex(grok.View):
>     grok.context(Awbarcode)
>     grok.name('index')
>
> class AddBarcode(grok.View):
>     grok.context(Awbarcode)
>     grok.name('addbarcode')
>
>     def update(self,text):
>         self.context.addBarcode(text)
>         self.redirect(self.url('index'))
>
> Also I have two .pt files, awbarcodeindex.pt:
>
> <html>
> <head>
>     <title tal:content="context/title">Barcode manager</title>
> </head>
> <body>
>     <h1 tal:content="context/title">Barcode manager</h1>
>     <h2>Here you can see barcodes:</h2>
>     <tal:block repeat="barcode context/values">
>         <ul>
>             <li tal:content="barcode/text">Barcode</li>
>         </ul>
>     </tal:block>
> </body>
> </html>
>
> and addbarcode.pt:
>
> <html>
>     <body>
>         <h2>Add barcode</h2>
>         <form tal:attributes="action view/url"  method="POST">
>             New Barcode text: <input type="text" name="text" value="" /><br
> />
>             <input type="submit" value="Add Barcode Text" />
>         </form>
>     </body>
> </html>
>
> So, if I manually add some barcode text, I can see it listed on the index
> page, but when I try to add new barcode text using url:
>
> http://localhost:8080/test/addbarcode
>
> I can see just "A system error occurred.", not form I have in addbarcode.pt
> and in log file is "TypeError: Missing argument to update(): text". I must
> use this to add new text to the storage:
>
> http://localhost:8080/test/addbarcode?text=text1
>
> After that I can finally see form and add new barcode text.
>
> What I am doing wrong? Thanks for any help.
>
> Best Regards
>
> Lumir Jasiok
>
> --
>  Lumír Jasiok
>  VSB-TU Ostrava - Computer centre
>  Tel: +420 59 732 3189
>  E-mail: lumir.jasiok at vsb.cz
>  http://www.vsb.cz
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
>
>


More information about the Grok-dev mailing list