Re: [google-appengine] Re: How to use the same variable in two handlers?

2011-01-23 Thread djidjadji
With what you want to do there IS NO difference in doing it in Django
templates then in Mako templates.
That will result in a hatred awards Mako too.

2011/1/23 Zeynel azeyn...@gmail.com:
 Unfortunately, I have an irrational hatred for Django templates so I
 am trying to do this with Mako templates.

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Re: How to use the same variable in two handlers?

2011-01-22 Thread djidjadji
input type=hidden name=dir_type value=###

instead of ### print the value of the variable merchandise_type

2011/1/22 Zeynel azeyn...@gmail.com:
 On Jan 22, 12:07 pm, djidjadji djidja...@gmail.com wrote:

 Make merchandise_type a hidden input field of the form generated by
 Directory() and get the value in the DirectorySubmitHandler().


 Ok. I have the hidden field in the form in Directory like this:

 input type=hidden name=dir_type value=merchandise_type

 but how do I get that

 the value of the merchandise_type in the DirectorySubmitHandler?

 self.request.get(dir_type) is merchandise_type not the url
 parameter?

 Thanks!

 --
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appengine@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Re: How to use the same variable in two handlers?

2011-01-22 Thread Robert Kluin
Hi Zeynel,
  You'll have to show us how you are rendering the form.  If you're
using template, just pass the value you get for type to your template
and print the value, like djidjadji said.



Robert









On Sat, Jan 22, 2011 at 10:01, Zeynel azeyn...@gmail.com wrote:
 On Jan 22, 12:53 pm, djidjadji djidja...@gmail.com wrote:
 input type=hidden name=dir_type value=###

 instead of ### print the value of the variable merchandise_type

 Thanks, but I don't understand. The value of the url parameter is
 given by

 self.request.get(type, )

 I cannot put this value in the value=### field. Then what is in the
 value field?

 --
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appengine@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Re: How to use the same variable in two handlers?

2011-01-22 Thread djidjadji
urllib.urlencode() should be used to quote the parameter

If Directory() is processed after DirectorySubmitHandler() you can
NEVER get the merchandise_type variable.
And it is possibly handled in another app instance.

dir_type = merchandise_type # remove this line

dir_type is never used in DirectorySubmitHandler()


import urllib

self.redirect(/dir?%s % urllib.urlencode({ 'type' :
self.request.get(dir_type) } )

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Re: How to use the same variable in two handlers?

2011-01-22 Thread djidjadji
'type' is between quotes == a string.
Has nothing to do with a variable or a function object.

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Re: How to use the same variable in two handlers?

2011-01-22 Thread Robert Kluin
So, if you are getting 'type=' twice, did you think about trying:
  self.redirect(/dir?%s % urllib.urlencode({ type :
self.request.get(dir_type) } ))






On Sat, Jan 22, 2011 at 20:33, Zeynel azeyn...@gmail.com wrote:
 On Jan 22, 8:02 pm, djidjadji djidja...@gmail.com wrote:

 'type' is between quotes == a string.
 Has nothing to do with a variable or a function object.

 I understand this. If I use this solution the url is always

 /dir?type=type=

 type is not replaced with the merchandise_type. Maybe I am not using
 it correctly?

 --
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appengine@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Re: How to use the same variable in two handlers?

2011-01-22 Thread Robert Kluin
If you're trying to do this using Mako templates, here is a fully
functional 'demo' that you should be able to easily adapt to do
exactly what you're asking about.


app.yaml

handlers:
- url: /makodemo.*
  script: makodemo.py
  login: admin


makodemo.py
---
#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from mako.lookup import TemplateLookup
from mako import exceptions

class DemoMakoTemplateHandler(webapp.RequestHandler):
Simple demo using mako templates.
def __init__(self, **kwargs):
webapp.RequestHandler.__init__(self, **kwargs)
self.template_values = {'message': ''}

def render(self, template_name, values=None):
Setup search paths, and render the template.

Any values passed in will be combined with
self.template_values, and passed to the template.

directories = ['templates']
lookup = TemplateLookup(directories=directories)
template = lookup.get_template(template_name)
if values:
self.template_values.update(values)
try:
self.response.out.write(template.render(**self.template_values))
except:
self.response.out.write(exceptions.html_error_template().render())

def get(self):
Render the template.
self.render(demo.mako)

def post(self):
Get the user's message then render the template again.
message = self.request.get('message')
self.render(demo.mako, {'message': message})

def main():
  application = webapp.WSGIApplication([('/makodemo', DemoMakoTemplateHandler)],
   debug=True)
  run_wsgi_app(application)

if __name__ == '__main__':
main()


demo.mako
-
html
head
titleMako Demo/title
/head
body
divLast message was: ${ message }/div
form action=/makodemo method=post
input type=text name=message value=${ message }/input
input type=submit name=doit value=update/input
/form
/body
/html





Make sure you've went through the app engine getting started and
really looked at how things work carefully.  No matter which template
language you chose, be sure to review their docs too.
  http://code.google.com/appengine/docs/python/gettingstarted/introduction.html
  http://www.makotemplates.org/docs/


Robert




On Sat, Jan 22, 2011 at 23:06, Zeynel azeyn...@gmail.com wrote:
 On Jan 22, 10:35 pm, Robert Kluin robert.kl...@gmail.com wrote:
 So, if you are getting 'type=' twice, did you think about trying:
   self.redirect(/dir?%s % urllib.urlencode({ type :
 self.request.get(dir_type) } ))

 Yes, actually I thought about that but I did not try it because I did
 not get

 /dir?type=type=tshirt

 but just /dir?type=type=

 without the url parameter. But I may be wrong so I will try. But now I
 am working on trying to make this work with templates as explained
 here: 
 http://stackoverflow.com/questions/4769063/how-do-i-pass-url-parameter-to-form-value

 Unfortunately, I have an irrational hatred for Django templates so I
 am trying to do this with Mako templates. Researching this I found an
 old answer of yours: 
 http://stackoverflow.com/questions/3938963/mako-templates-with-google-app-engine/3939208#3939208.
 Thanks again for that answer. At this point my template page is
 printing as text like this

 �html �body �pRender template�/p ${greeting} �/body �/html

 so I am going to try to fix that first and then try the urllib option.

 --
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appengine@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.