Need to know how to implement the i18n

2011-09-02 Thread Geo
Reading through the i18n chapter of pyramid, I still can't figure out
how can I actually use that feature.  What I want to do is to have a
place to change the locale globally, for now I'm trying to do in
this way, in the page have a url which will be routed to the view like
this:

def change_to_chinese(request):
response = Response()
response.set_cookie('_LOCALE_','zh')
return response

I tried and it worked, but I can't just return a blank page, so I
tried to use HTTPFound to redirect to the home page, but then the
language doesn't change.
I can't find out a way to serve my purpose. Or do we have other way to
do that?

And this paragraph:
Set the _LOCALE_ attribute of the request to a valid locale name
(usually directly within view code). E.g. request._LOCALE_ = 'de'. I
still don't know how to do with that. So if I have a line in the view
code : request._LOCALE_='de', does that change the locale globally? If
it doesn't, what is the scenario to utilize this method? Could
somebody give a real example code to show how do those setting the
locale work in a real world?

-- 
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 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Browse registered views

2011-09-02 Thread Dirk Makowski
Hi all,

with its paster command pviews Pyramid offers a nice way to check the view 
callables that can be reached by a certain URL. Now, I'd like to go the 
other way round, that is list *all* registered views and display their 
attributes like name, permission etc. So I get not lost in details and code 
;)

After having analysed the pviews command and read more about ZCA than I ever 
wanted to ask (but now that I know about Adapters and Utilities and such, I 
ask myself how I could've lived without it), I came up with a little 
scripthttp://3amcode.de/pharaoh/static-pym/cms/pharaoh/viewbrowser.pythat:
- collects all registered views
- lists them grouped by their module
- shows detailed info like pviews

Ok, I borrowed much from the pviews command, and some subjects are still 
unclear for me. The questions are in the code.

One question I'd like to ask here is, given a view adapter queried from the 
registry, and also the corresponding view callable, is it possible to 
determine the context that was defined for the view (e.g. as 
@view_config(context=Foo)). With such context and the traversal functions, 
I could also list the URL path that invokes each view.

Some more notes and the code to download you'll find here:
http://3amcode.de/pharaoh/Cms/pharaoh/learning-pyramid/list-registered-views-zope-component-architecture

Maybe someone finds this useful, too.

Thanks,
Dirk

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pylons-discuss/-/OAU9WoJo9cUJ.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: pylons-discuss and pylons-devel

2011-09-02 Thread Joe Dallago
O cool I've always wanted more details.

On Thu, Sep 1, 2011 at 2:58 PM, Chris McDonough chr...@plope.com wrote:

 My bad, I let this spam through.

 - C

 On Tue, 2011-08-30 at 10:14 -0700, bhuvanesh barani wrote:
  For more details:
 
  http://123maza.com/65/babul739/
 
 
  --
  You received this message because you are subscribed to the Google
  Groups pylons-discuss group.
  To view this discussion on the web visit
  https://groups.google.com/d/msg/pylons-discuss/-/Oe9vilhBaAAJ.
  To post to this group, send email to pylons-discuss@googlegroups.com.
  To unsubscribe from this group, send email to pylons-discuss
  +unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/pylons-discuss?hl=en.


 --
 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
 pylons-discuss+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/pylons-discuss?hl=en.



-- 
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 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Share a variable across modules - How do I replicate this Pylons Kungfu?

2011-09-02 Thread casibbald
Hi All,

I have been playing with the pylons family of web products and love
them, but I am working on a basic commandline toolset and would like
some of the pylons magic without having a running service as the
toolset will not be allowed to run as a webservice.

So here is my problem, I have setup a couple of modules to handle
configuration and logging for example and want this to be available
across all other modules in the toolset.

here is the basic code.

##
# utils.py
##
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import os
import fnmatch
import sys
import subprocess
import stat


def locate(pattern, root=os.curdir):
'''Locate all files matching supplied filename pattern
in and below supplied root directory.'''
for path, dirs, files in os.walk(os.path.abspath(root)):
for filename in fnmatch.filter(files, pattern):
yield os.path.join(path, filename)


def executioner(self, execution_list):
self.execution_list = execution_list
execute = subprocess.Popen(self.execution_list, shell=False,
stdout=subprocess.PIPE)
while 1:
self.logLine = execute.stdout.readline()
self.exitcode = execute.poll()
if (not self.logLine) and (self.exitcode is not None):
break
self.log = self.logLine[:-1]
if not self.log == '':
print self.log

def singleton(cls):
__instances = {}
def getinstance():
if cls not in __instances:
__instances[cls] = cls()
return __instances[cls]
return getinstance


###
#Configuration.py
###
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import ConfigParser
import os

from releasetools.classes.utils import singleton

@singleton
class Config(object):

def __init__(self, config_file=None):
self.config = self.read_config_file(config_file)

def save_default_config(self):
default_config = ConfigParser.RawConfigParser()
config_file = os.path.join(os.path.expanduser('~'),
'.releasetools', self.config_file)

default_config.add_section('Authentication')
default_config.set('Authentication', 'username',
'releasetools')
default_config.set('Authentication', 'password',
'releasetools')

default_config.add_section('Nexus')
default_config.set('Nexus', 'hostname', 'localhost')
default_config.set('Nexus', 'port', '8081')

default_config.add_section('Subversion')
default_config.set('Subversion', 'hostname', 'localhost')
default_config.set('Subversion', 'port', '80')

self.write_config(default_config)

def read_config_file(self, config_file):
config = ConfigParser.ConfigParser()
if config_file == None:
self.config_file = os.path.join(os.path.expanduser('~'),
'.releasetools', 'releasetools.cfg')
if  os.path.exists(self.config_file):
try:
print
print Configuration file found, loading
settings...
config.readfp(open(self.config_file))
except IOError:
pass # TODO CHECK EXCEPTION AND LOG
else:
self.save_default_config()
config.readfp(open(self.config_file))
else:
try:
print Configuration file found, loading settings...
config.readfp(open(config_file))
except IOError:
pass # TODO CHECK EXCEPTION AND LOG
return config


def write_config(self, config):
config_file = os.path.join(os.path.expanduser('~'),
'.releasetools', 'releasetools.cfg')
print Configuration file not found, writing out default
file.
if os.path.exists(os.path.dirname(config_file)):
with open(config_file, 'wb') as configfile:
config.write(configfile)
elif not os.path.exists(os.path.dirname(config_file)):
os.makedirs(os.path.dirname(config_file))
with open(config_file, 'wb') as configfile:
config.write(configfile)
else:
pass

def get_username(self):
return self.config.get('Authentication', 'username')
def set_username(self, username):
self.config.set('Authentication', 'username', username)
self.write_config(C.config)

def get_password(self):
return self.config.get('Authentication', 'password')
def set_password(self, password):
self.config.set('Authentication', 'password', password)
self.write_config(self.config)

def get_nexus_host(self):
return self.config.get('Nexus', 'hostname')
def set_nexus_host(self, hostname):
self.config.set('Nexus', 'hostname', hostname)
self.write_config(self.config)

def get_nexus_port(self):
return self.config.get('Nexus', 'port')
def set_nexus_port(self, port):
self.config.set('Nexus', 'port', port)

Pyramid 1.2a4 released

2011-09-02 Thread Chris McDonough
Pyramid 1.2a4 has been released.  The changes from 1.2a3 are as
follows:

  Features
  

  - Support an ``onerror`` keyword argument to
``pyramid.config.Configurator.scan()``.  This onerror keyword
argument is passed to ``venusian.Scanner.scan()`` to influence
error behavior when an exception is raised during scanning.

  - The ``request_method`` predicate argument to
``pyramid.config.Configurator.add_view`` and
``pyramid.config.Configurator.add_route`` is now permitted to be a
tuple of HTTP method names.  Previously it was restricted to being
a string representing a single HTTP method name.

  - Undeprecated ``pyramid.traversal.find_model``,
``pyramid.traversal.model_path``,
``pyramid.traversal.model_path_tuple``, and
``pyramid.url.model_url``, which were all deprecated in Pyramid
1.0.  There's just not much cost to keeping them around forever as
aliases to their renamed ``resource_*`` prefixed functions.

  - Undeprecated ``pyramid.view.bfg_view``, which was deprecated in
Pyramid 1.0.  This is a low-cost alias to
``pyramid.view.view_config`` which we'll just keep around forever.

  Dependencies
  

  - Pyramid now requires Venusian 1.0a1 or better to support the
``onerror`` keyword argument to
``pyramid.config.Configurator.scan``.

A What's New In Pyramid 1.2 document exists at
http://docs.pylonsproject.org/projects/pyramid/1.2/whatsnew-1.2.html .

You will be able to see the 1.2 release documentation (across all
alphas and betas, as well as when it eventually gets to final release)
at http://docs.pylonsproject.org/projects/pyramid/1.2/ .

You can install it via PyPI:

  easy_install Pyramid==1.2a4

Enjoy, and please report any issues you find to the issue tracker at
https://github.com/Pylons/pyramid/issues

Thanks!

- C


-- 
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 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Virtual Hosting routes using composite application

2011-09-02 Thread Jason
HelIo,

I've got a composite application using urlmap with two applications on 
different url prefixes. The documentation for virtual hosting at 
https://pylonsproject.org/projects/pyramid/dev/narr/vhosting.html doesn't 
say what I need to do to have my routes generate the correct URL.

When I use request.route_path or request.route_url it always gives me a url 
without the prefix /pyramidapp. But if I add /pyramidapp to the route's 
pattern or I use config.include with route_prefix=pyramidapp then no 
incoming routes match because urlmap passes everything after /pyramidapp as 
the path. 

Is there a step I missed to tell the route generation that I am using urlmap 
to do virtual hosting?

As an alternative: is there a way to tell url map to use subdomains for 
virtual hosting (I use route_path for url generation)? 
It looks like the urlmap function can do it 
(http://pythonpaste.org/modules/urlmap.html) but I don't see how to do that 
in the config file.

Thanks for the help,

Jason

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pylons-discuss/-/uAPF9156JCYJ.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Routing requested based on presence of query params

2011-09-02 Thread goya bean
Hello, to avoid 'None' checking and duplicate request returning code,
I'm trying to use (or abuse) route requests in pyramid by using
parameters in query Strings using the 'request_param=' argument as
seen here:
http://pastebin.com/G2shq75s
is there a way to do what I'm trying to do using routing or view
config?

Thanks,
Gavin

-- 
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 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Virtual Hosting routes using composite application

2011-09-02 Thread Jason
I browsed the urlmap source code to find that this can be entered into the 
config file to use a subdomain for url mapping:

[composite:main]
use = egg:Paste#urlmap 
domain app1.localhost = app1pipe 
domain app2.localhost = app2pipe

It's less than ideal because I would like to use a path to specify the 
application, but it will work. Rumour has it I will also have to include the 
ProxyPreserveHost directive in my Apache config (I'm using mod proxy in the 
production deployment).

--Jason

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pylons-discuss/-/4EWc_EONpPIJ.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Routing requested based on presence of query params

2011-09-02 Thread Jason
Could you write a custom route predicate 
(https://docs.pylonsproject.org/projects/pyramid/dev/narr/urldispatch.html#custom-route-predicates)
 
that checks for your requirements?

-- Jason

-- 
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pylons-discuss/-/pOOGuO8cdfQJ.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Routing requested based on presence of query params

2011-09-02 Thread Michael Merickel
``request_method`` is limited to comparison with a single query
parameter. To add more complex behavior you will need to use a custom
predicate.

Note that you are not required to use 2 routes here... After the pattern is
matched for your route, there is view lookup performed based on the *view*
predicates. For example:

config.add_route('readPage', '/SupportMapAdmin/api')

config.add_view(sortView, route_name='readPage', request_param='sort')

config.add_view(startAndLimitView, route_name='readPage',
request_param='start')
config.add_view(startAndLimitView, route_name='readPage',
request_param='limit')

OR, if this is too verbose, a custom predicate:

def custom_param_predicate(*params):
def predicate(context, request):
return any([param in request.params for param in params])
return predicate

config.add_route('readPage', '/SupportMapAdmin/api')

config.add_view(sortView, route_name='readPage', request_param='sort')

config.add_view(startAndLimitView, route_name='readPage',
custom_predicates=(custom_params_predicate('start', 'limit'),))

It is also possible to do this with route predicates instead of view
predicates, but I'm not sure why you would want to necessarily unless the
different groups of views set different traversal paths or root factories.

-- 

Michael

-- 
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 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Routing requested based on presence of query params

2011-09-02 Thread Chris McDonough
On Fri, 2011-09-02 at 16:37 -0500, Michael Merickel wrote:
 ``request_method`` is limited to comparison with a single query
 parameter. To add more complex behavior you will need to use a custom
 predicate.

Actually request_method on the trunk accepts more than one, but
request_param, yeah does not.

- C


-- 
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 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.



Re: Composite application configuration

2011-09-02 Thread jazg
Well I can do this:


def main(global_config, **settings):
settings.update((key, val) for key, val in global_config.items()
if key not in settings)


...which means that this would work:


[DEFAULT]
x = 1

[app:app1]
#inherits x
x = my x #overrides x


But if PasteDeploy already supports this with the set keyword, can't
we access that functionality somehow? Does pyramid bypass it and parse
the file on its own?


On Sep 1, 4:36 pm, Wyatt Baldwin wyatt.lee.bald...@gmail.com wrote:
 It should work the same way in Pyramid or Pylons, since they both use
 PasteDeploy to parse and interpret the config file. My config looks
 something like this:

 [DEFAULT]
 x = 1

 [app:app1]
 use = egg:MyEgg
 # this should inherit x
 # If you want to override the global x, you have to use `set` (which is a
 PasteDeploy thing and is what makes it behave differently from native
 ConfigParser):
 set x = my x

 [app:app2]
 use = egg:AnotherEgg
 # this should also inherit x

-- 
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 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.