This problem really drive me crazy, anybody could help me. how could the kid receive variable and data from control.py~~?
On Wed, Apr 8, 2009 at 10:43 PM, 跑步鱼 <[email protected]> wrote: > Hi: > > I am a fresh in Turbogear. > > After finish the 20-min wiki, I try to add a upload function to the > wiki. well, I don't understand how the data could be sent to kid. I > have search previous discuss about this issu.get the solution as > following, But I don't know how can I get the data in kid template. > what should I add in kid. > > I tried to add like this:<p py:content="upload_form()">upload</p>, <p>$ > {upload_form}</p>,but it seems not work. > > Could you explain the machanism of the data transform between kid and > control.py > > In this case, what should I write in the template. > Thank you > > > ----------------------------the code in control.py > ------------------------------------ > from turbogears import controllers, expose, widgets, validators, > validate > from file_fields.widgets.file_field import FileField, FileValidator > > # ---- Constants ---- > > BUFFER_SIZE = 8192 > > # ---- Widgets / Forms ---- > > class MediaUploadFields(widgets.WidgetsList): > title = widgets.TextField( > label=_(u"File Title"), > ) > mediafile = FileField( > label=_(u"Video File"), > ) > > # ---- Form Validators ---- > > class MediaUploadSchema(validators.Schema): > title = validators.UnicodeString(max=256, strip=True), > mediafile = FileValidator(not_empty=True) > > # ---- Forms ---- > > upload_form = widgets.TableForm( fields=MediaUploadFields(), > validator=MediaUploadSchema() ) > > # ---- Controllers ---- > > class Root(controllers.RootController): > @expose(template=".templates.welcome") > def index(self): > return dict( > upload_action = './upload', > upload_form = upload_form, > upload_submit_text = 'Upload Media', > upload_value = dict(), > ) > > @expose('.templates.upload', format='xml', content_type="text/ > xml") > @validate(form=upload_form) > def upload(self, title=None, mediafile=None): > > # Copy the file somewhere useful > fp = open('/tmp/uploaded_file', 'wb') > buf = mediafile.file.read(BUFFER_SIZE) > while buf: > fp.write(buf) > buf = mediafile.file.read(BUFFER_SIZE) > fp.close() > > return dict( > filename = mediafile.name, > filesize = mediafile.size, > md5 = mediafile.md5, > mimetype = mediafile.type, > ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

