I18n doesn't work outside Pylons Controller

2008-03-31 Thread Olli Wang

Hi, I have a i18n string defined outside the Pylons Controller, it
could be collected by python setup.py extract_messages, I can
translate the string and compile it. But in the output page, don't
know why it always displays non-translated string. For example:

# myapp/controller/hello.py

global_string = _(Global String)  # Display non-translated string
always, why?

class HelloController(BaseController):
def index(self):
c.global_string = global_string
c.local_string = _('Local String')  # Display translated
string correctly
return render('/index.mako')

Any idea? Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: I18n doesn't work outside Pylons Controller

2008-03-31 Thread Dalius Dobravolskas

Olli Wang wrote:
 Hi, I have a i18n string defined outside the Pylons Controller, it
 could be collected by python setup.py extract_messages, I can
 translate the string and compile it. But in the output page, don't
 know why it always displays non-translated string. For example:
 
 # myapp/controller/hello.py
 
 global_string = _(Global String)  # Display non-translated string
 always, why?
 
 class HelloController(BaseController):
 def index(self):
 c.global_string = global_string
 c.local_string = _('Local String')  # Display translated
 string correctly
 return render('/index.mako')
 
 Any idea? Thanks.
Use lazy_gettext as defined in 
http://wiki.pylonshq.com/display/pylonsdocs/Internationalization+and+Localization#lazy-translations.
 
There is explanation of your problem BTW.


Regards,
Dalius

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: I18n doesn't work outside Pylons Controller

2008-03-31 Thread Olli Wang

Hi, Dalius. I had tried lazy_gettext, but don't know why the
lazy_gettext strings won't be collected after I run python setup.py
extract_messages, therefore, I couldn't translate the string. :(

On Mar 31, 2:46 pm, Dalius Dobravolskas
[EMAIL PROTECTED] wrote:
 Use lazy_gettext as defined 
 inhttp://wiki.pylonshq.com/display/pylonsdocs/Internationalization+and+
 There is explanation of your problem BTW.

 Regards,
 Dalius
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: I18n doesn't work outside Pylons Controller

2008-03-31 Thread Dalius Dobravolskas

Olli Wang wrote:
 Hi, Dalius. I had tried lazy_gettext, but don't know why the
 lazy_gettext strings won't be collected after I run python setup.py
 extract_messages, therefore, I couldn't translate the string. :(
If you are lazier than lazy_gettext do following:
lazy_gettext(_('your string'))

I have not checked that but I guess extract_messages should collect your 
string now and it will not hit your performance.

Regards,
Dalius

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: I18n doesn't work outside Pylons Controller

2008-03-31 Thread Olli Wang

Thanks, Dalius. It works. But I happened into another encoding issue:

global_test = lazy_gettext(_('Global Test'))

class HelloController(BaseController):
def test(self):
return str(global_test)   # Works fine, returns the translated
string

def test2(self):
return unicode(global_test)  # It renders the following
traceback

Module ollix.controllers.accounts:26 in signin
  g = str(global_test)
print type(g), g
return unicode(global_test)
c.global_test = 'g'
return render('/accounts/signin.mako')  return
unicode(global_test)
Module pylons.i18n.translation:37 in __unicode__

def __unicode__(self):
return unicode(self.eval())

def __str__(self):  return unicode(self.eval())
type 'exceptions.UnicodeDecodeError': 'ascii' codec can't decode
byte 0xe5 in position 0: ordinal not in range(128)


I've tried many ways to encode the string to unicode but failed. This
also causes my mako template down. Any suggestion? Thanks.

On Mar 31, 3:02 pm, Dalius Dobravolskas
[EMAIL PROTECTED] wrote:
 Olli Wang wrote:
  Hi, Dalius. I had tried lazy_gettext, but don't know why the
  lazy_gettext strings won't be collected after I run python setup.py
  extract_messages, therefore, I couldn't translate the string. :(

 If you are lazier than lazy_gettext do following:
 lazy_gettext(_('your string'))

 I have not checked that but I guess extract_messages should collect your
 string now and it will not hit your performance.

 Regards,
 Dalius
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: I18n doesn't work outside Pylons Controller

2008-03-31 Thread Dalius Dobravolskas

Olli Wang wrote:
 Thanks, Dalius. It works. But I happened into another encoding issue:
 
 global_test = lazy_gettext(_('Global Test'))
 
 class HelloController(BaseController):
 def test(self):
 return str(global_test)   # Works fine, returns the translated
 string
 
 def test2(self):
 return unicode(global_test)  # It renders the following
Try following:

return unicode(global_test.decode('utf-8'))

Again, plain guess. I guess there are more possibilities but I'm not 
aware about them. You should consult pylons code here.

Regards,
Dalius


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Auth and Auth

2008-03-31 Thread Dalius Dobravolskas

Mike Orr wrote:
 OpenID is a new and different kind of authentication system, so I
 don't know if we've figured out the best way to integrate it yet.
 Feedback from those who use OpenID would be helpful.
You should use it to figure out. I accept any way where you can login 
and are not asked to create internal account. I login therefore I'm your 
user already. If I'm not then bye.

E.g. you can login using google account to youtube.com but you must 
create youtube account after that anyway. A little big ugly but that's 
not even the worst case.

AuthKit has more serious problem than figuring out how to use OpenID. 
AuthKit's OpenID implementation is correct and it even works but it is 
very painful to configure it and I miss some options. But I have 
expressed my dissatisfaction about that already :-) That's why I offer 
splitting AuthKit - while I believe I have already split it by showing 
that it is possible to do.

Regards,
Dalius

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: I18n doesn't work outside Pylons Controller

2008-03-31 Thread Olli Wang

Oh, thanks a lot. Everything works fine now. :)

On Mar 31, 4:51 pm, Dalius Dobravolskas
[EMAIL PROTECTED] wrote:
 Olli Wang wrote:
  Thanks, Dalius. It works. But I happened into another encoding issue:

  global_test = lazy_gettext(_('Global Test'))

  class HelloController(BaseController):
  def test(self):
  return str(global_test)   # Works fine, returns the translated
  string

  def test2(self):
  return unicode(global_test)  # It renders the following

 Try following:

 return unicode(global_test.decode('utf-8'))

 Again, plain guess. I guess there are more possibilities but I'm not
 aware about them. You should consult pylons code here.

 Regards,
 Dalius
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



logging POST data

2008-03-31 Thread Dunk Fordyce

Hello,

Has anyone ever written some middleware to log POST requests

Secondly, if Im doing it myself, is it safe to read wsgi.input and
then seek it back to 0?

Thanks
Dunk

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Auth and Auth

2008-03-31 Thread Chris Shenton

Mike Orr [EMAIL PROTECTED] writes:

 We need somebody who has used AuthKit to write the simple HOWTOs that
 people are asking for.

I did and did, but it was a while back and I suspect AuthKit's changed
since I wrote it:

http://pylonshq.com/project/pylonshq/wiki/PylonsWithAuthKitForward

I'm using it in a production app for a .gov and a .com client.

What bothered me most was that AuthKit wasn't something I could just
drop in and start using, with anything beyond the appname.conf file
supplying the username/password/groups.

I would hope that any sufficiently well-loved auth middleware would ship
with some working example apps that (say) stored to an
SQLite/MySQL/Postgresql DB, and LDAP/AD, and had user/group/role
management forms -- at least for Pylons.  It bothered me to have to
write these myself, and know that everyone else did too; wasted effort
for lazy/efficient programmers.

Having said that, I did do an SQLite backend and management forms for
the .gov customer, then retrofitted it to get authentication info form a
RADIUS server since we use SecurID tokens and that's the easiest
protocol with which to communicate with the RSA server.

 Regarding auth, that has never been seen as a core Pylons
 responsibility.  If you want a framework with a built-in auth library,
 see TurboGears.

I think this approach may scare a lot of people away from Pylons -- I
know I would have benefitted from a few more common tools being bundled.


 To answer another question in this thread, repoze is a set of
 WSGI-compatible libraries spun off from Zope.  It's the most
 exciting contribution from Zope since ZODB, because it allows Zope
 products like Plone and other WSGI apps to be mixed in the same site.
 However, it's all brand new so it hasn't been fully evaluated which
 parts are most useful in Pylons apps.  Again, we need feedback from
 people who try repoze.who.

At PyCon, I wrote a RADIUS authentication module for repoze.who (with
guidance from Chris McDonough).  I don't understand the whole stack yet
but the approach seems rather good: the plugin was pretty easy to write
even tho I had never seen the repoze code before.  It would be nice if I
could use repoze.who with Pylons, Zope, Grok, and Plone instead of
separate auth mechanisms for each.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tiny error in index.html (generate when create a new project)

2008-03-31 Thread 张沈鹏(电子科大 毕/就业倒计时...)
but with pylons 0.97beta3 and webhelpers0.6

if I use ${h.url_for()}
it apper error as below 
⇝  AttributeError: 'module' object has no attribute 'url_for'


On Mon, Mar 31, 2008 at 1:26 AM, Alec [EMAIL PROTECTED] wrote:

  张沈鹏(电子科大 毕/就业倒计时...) 写道:

  in develop version
  
   when you create a project
  
   the default index.html says
  
   p
   The URL you called: ${h.url_for()}
   /p
  
  
   but it's should be
  
   ${h.rails.url_for()}
  
  Actually, url_for() exposed in 'h' namespace. see webhelpers package
  manual :)

  but,I has no privilege to change the source code
  
   so wish any body do for a favor
  
  


  




-- 
博客:http://zsp.javaeye.com/
个人网站:http://zsp007.com.cn/
电子科大,7月就要毕业了,何去何从...
双学位:生物医学工程+计算机科学与技术
 -- 张教主

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tiny error in index.html (generate when create a new project)

2008-03-31 Thread Mike Orr
2008/3/31 张沈鹏(电子科大 毕/就业倒计时...) [EMAIL PROTECTED]:
 but with pylons 0.97beta3 and webhelpers0.6

  if I use ${h.url_for()}
  it apper error as below 
  ⇝  AttributeError: 'module' object has no attribute 'url_for'

There is some rearrangement happening in WebHelpers right now; that is
why Pylons 0.9.7 has not been released yet.In the meantime, you
can hack your copy of WebHelpers to restore the missing import:

in webhelpers/__init__.py:

from routes import url_for, redirect_to

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Auth and Auth

2008-03-31 Thread Mike Orr

Opened ticket #403 for the outstanding AuthKit issues.

http://pylonshq.com/project/pylonshq/ticket/403

If I failed to list any issues, please add a comment to the ticket so
it doesn't get forgotten.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: I18n doesn't work outside Pylons Controller

2008-03-31 Thread Philip Jenvey


On Mar 31, 2008, at 12:48 AM, Olli Wang wrote:


 Thanks, Dalius. It works. But I happened into another encoding issue:

 global_test = lazy_gettext(_('Global Test'))

 class HelloController(BaseController):
 def test(self):
 return str(global_test)   # Works fine, returns the translated
 string

 def test2(self):
 return unicode(global_test)  # It renders the following
 traceback

 I've tried many ways to encode the string to unicode but failed. This
 also causes my mako template down. Any suggestion? Thanks.


You want lazy_ugettext

--
Philip Jenvey



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tiny error in index.html (generate when create a new project)

2008-03-31 Thread Ben Bangert
On Mar 31, 2008, at 1:37 AM, 张沈鹏(电子科大 毕/就业倒计 
时...) wrote:



but with pylons 0.97beta3 and webhelpers0.6

if I use ${h.url_for()}
it apper error as below 
⇝  AttributeError: 'module' object has no attribute 'url_for'


Changing your apps lib/helpers.py, so that instead of:
from webhelpers import *

It does:
from webhelpers.rails import *

Should remedy your error.

Cheers,
Ben

smime.p7s
Description: S/MIME cryptographic signature


Re: Setting content type of Response() in 0.9.6

2008-03-31 Thread Dalius Dobravolskas

johnnyice wrote:
 James Gardner already posted how to set the content type when using
 the render object in the forum.
 
 response.headers['Content-type'] = application/atom+xml
 return render(template_file, atom-feed)
 
 src:
 http://groups.google.com/group/pylons-discuss/browse_thread/thread/2e0a6cb533ddd0a6/e2ce72d10277fe99?lnk=gstq=content+type+xml#e2ce72d10277fe99http://groups.google.com/group/pylons-discuss/browse_thread/thread/2e0a6cb533ddd0a6/e2ce72d10277fe99?lnk=gstq=content+type+xml#e2ce72d10277fe99
 
 
 BUT, how would you go about setting the content type for a Response
 object?
 
 This worked in 0.9.5, but does not work in 0.9.6.1
 
 xml = 'resultSomething/result'
 response = Response(xml)
 response.headers['content-type'] = 'text/xml; charset=utf-8'
 return response
 
 
 Any ideas?
Don't use Response object. Use response as James Garner offers. Your 
code should be written in this way:

xml = 'resultSomething/result'
response.headers['Content-type'] = 'text/xml; charset=utf-8'
return xml

Usually you should return string from controller (I think the only 
exception is @jsonify - you can return dict there). BTW, if you want to 
serve images this way it will be very slow. There are better ways to do 
that.

Regards,
Dalius

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---