[web2py] Adding custom attributes to fields and tables

2018-04-22 Thread xelomac
I want to add a custom attribute so that I can decide which customwidget 
has to be used for a form field connected to that field.
Example:

db.define_table('person',
Field('salutation', mycustomwidget='select2', label = T('Salutation'), 
requires=IS_IN_SET(GENDER), represent=lambda v, r: GENDER[v]),
Field('first_name', label = T('First Name')),
format = '%(last_name)s')


I had no luck defining that custom attribute the way it is described in the 
book. How and and where would I define such a custom attribute 
'mycustomwidget' for the table 'person' or even better for all tables?

Adding attributes to fields and tables

If you need to add custom attributes to fields, you can simply do this:

1

db.table.field.extra = {}

"extra" is not a keyword ; it's a custom attributes now attached to the 
field object. You can do it with tables too but they must be preceded by an 
underscore to avoid naming conflicts with fields:

1

db.table._extra = {} 


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: SQLFORM.grid: represent a field with IS_IN_SET validator by its label instead of its value

2018-04-21 Thread xelomac
I've found a solution:

rows = db(db[table].id == id).select()
rendered_row = rows.render(0, fields=[db[table][column]])
value = rendered_row[column]

On Saturday, April 21, 2018 at 12:31:49 PM UTC+2, xelomac wrote:
>
> Thank you Anthony. Works perfectly in a SQLFORM.grid. The values get 
> displayed as expected. 
>
> But outside of the grid for something like this
>
> persons = db(db[table].id == 1).select()
> person=persons[0][column]
>
> the stored values get displayed not its representation. How can I get the 
> representation of the stored value here?
>
> On Monday, April 16, 2018 at 1:55:18 AM UTC+2, Anthony wrote:
>>
>> The validator controls the widget used in forms but not the format in the 
>> grid -- for the latter, use the "represent" attribute:
>>
>> represent=lambda v, r: GENDER[v]
>>
>> Anthony
>>
>> On Sunday, April 15, 2018 at 4:47:27 AM UTC-4, xelomac wrote:
>>>
>>> Consider the following example.
>>>
>>> Model:
>>>
>>> GENDER = {"male": T("Mr.", lazy=False),
>>> "female": T("Ms.", lazy=False)}
>>>
>>> db.define_table('person',
>>> Field('gender', label = T('Salutation'), requires=IS_IN_SET(GENDER)),
>>> Field('first_name', label = T('First Name'),
>>> Field('last_name', label = T('Last Name')),
>>> format = '%(last_name)s')
>>>
>>> In a SQLFORM.grid I want to represent the field gender by its translated 
>>> label not by its value. How can I achieve this?
>>>
>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: SQLFORM.grid: represent a field with IS_IN_SET validator by its label instead of its value

2018-04-21 Thread xelomac
Thank you Anthony. Works perfectly in a SQLFORM.grid. The values get 
displayed as expected. 

But outside of the grid for something like this

persons = db(db[table].id == 1).select()
person=persons[0][column]

the stored values get displayed not its representation. How can I get the 
representation of the stored value here?

On Monday, April 16, 2018 at 1:55:18 AM UTC+2, Anthony wrote:
>
> The validator controls the widget used in forms but not the format in the 
> grid -- for the latter, use the "represent" attribute:
>
> represent=lambda v, r: GENDER[v]
>
> Anthony
>
> On Sunday, April 15, 2018 at 4:47:27 AM UTC-4, xelomac wrote:
>>
>> Consider the following example.
>>
>> Model:
>>
>> GENDER = {"male": T("Mr.", lazy=False),
>> "female": T("Ms.", lazy=False)}
>>
>> db.define_table('person',
>> Field('gender', label = T('Salutation'), requires=IS_IN_SET(GENDER)),
>> Field('first_name', label = T('First Name'),
>> Field('last_name', label = T('Last Name')),
>> format = '%(last_name)s')
>>
>> In a SQLFORM.grid I want to represent the field gender by its translated 
>> label not by its value. How can I achieve this?
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] SQLFORM.grid: represent a field with IS_IN_SET validator by its label instead of its value

2018-04-15 Thread xelomac
Consider the following example.

Model:

GENDER = {"male": T("Mr.", lazy=False),
"female": T("Ms.", lazy=False)}

db.define_table('person',
Field('gender', label = T('Salutation'), requires=IS_IN_SET(GENDER)),
Field('first_name', label = T('First Name'),
Field('last_name', label = T('Last Name')),
format = '%(last_name)s')

In a SQLFORM.grid I want to represent the field gender by its translated 
label not by its value. How can I achieve this?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Using variables in db.table.field expressions

2018-04-08 Thread xelomac
Sorry - I cannot comprehend what I have done wrong before. 
"if db[table][column].writable == False:" works now as expected.

On Sunday, April 8, 2018 at 5:44:55 PM UTC+2, Anthony wrote:
>
> On Sunday, April 8, 2018 at 4:27:59 AM UTC-4, xelomac wrote:
>>
>> Hi all,
>>
>> in a controller function I want to check if a field is set as writable in 
>> the model before updating it. "if db[table][column].writable == False" did 
>> not work.
>>
>
> What do you mean by "did not work"? That is the correct way to check the 
> writable attribute. We need more info.
>
> Anthony
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Using variables in db.table.field expressions

2018-04-08 Thread xelomac
Hi all,

in a controller function I want to check if a field is set as writable in 
the model before updating it. "if db[table][column].writable == False" did 
not work. I have the following:

def upd_field_value():
id,table,column = request.post_vars.id.split('.')
value = request.post_vars.value
my_field = db().db[table][column]
if LOOKING_FOR_THE_CORRECT_SYNTAX_HERE_USING_THE 
VARS_table_AND_column.writable == False:
do something
db(db[table].id == id).update(**{column:value})
return value

Thanks for any help

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Speaking URLs possible?

2013-09-02 Thread xelomac
Hi everybody,

after playing around with routes.py for a while I wonder if what I want to 
do is possible at all. I want to rewrite the URLs shown to the visitor 
after clicking a menu link in the following way:

Lets say I built a site that deals with colors. My menu shows base color 
links like red, green, blue on the top level and variations of the the base 
colors on the next menu level. My app would be named color_book my 
controller colors and the the function showing the pages 
show_color_page.

After clicking the submenu item light-blue under the parent menu-item 
blue I would normally see an URL in the browser like:
http://my.domain.com/color_book/colors/show_color_page/light-blue

But I want to rewrite the URL to: http://my.domain.com/blue/light-blue

Accordingly a page with the menu location red  dark-red should be 
presented with: http://my.domain.com/red/light-red

I thought that a pattern-based routes.py could be configured to do things 
like that. But I've only had success with rewriting URLs manually entered 
in the browser's address field so far- but not with internal links.

Is there an example for my use case somewhere?

Thanks for any help!
 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Speaking URLs possible?

2013-09-02 Thread xelomac
Meanwhile I gave the parameter-based rewrite system a try again. I have:

routers = dict(
  BASE  = dict(
  default_application='color_book',
  default_controller = 'colors',
  default_function = 'show_color_page',),
  color_book = dict(languages=['en', 'it', 'fr', 'de'], 
default_language='en'),
)

In contrast to my initial idea it should be possible to pass my color and 
color variation categories as args to the URL function to build my desired 
URL structure and let the parameter-based routes.py just cut off the 
application, controller and function names instead of replacing them using 
a pattern-based routes.py file.

This works half way: Above defined application and controller names are 
left out as soon as the routes.py is loaded. And I can access my pages 
without app and controller name in the URL. But leaving out the function 
name only works for the index page:

http://127.0.0.1:8000/ (index page loads correctly)

The original URL 
(http://127.0.0.1:8000/color_book/colors/show_color_page/title-of-the-page 
of other pages cannot be replaced by entering
http://127.0.0.1:8000/title-of-the-page (invalid request)
I have to enter: http://127.0.0.1:8000/show_color_page/title-of-the-page to 
access that page.

Any idea why?



On Monday, September 2, 2013 3:20:05 PM UTC+2, Anthony wrote:

 What does your routes.py file look like now?

 On Monday, September 2, 2013 2:22:38 AM UTC-7, xelomac wrote:

 Hi everybody,

 after playing around with routes.py for a while I wonder if what I want 
 to do is possible at all. I want to rewrite the URLs shown to the visitor 
 after clicking a menu link in the following way:

 Lets say I built a site that deals with colors. My menu shows base color 
 links like red, green, blue on the top level and variations of the the base 
 colors on the next menu level. My app would be named color_book my 
 controller colors and the the function showing the pages 
 show_color_page.

 After clicking the submenu item light-blue under the parent menu-item 
 blue I would normally see an URL in the browser like:
 http://my.domain.com/color_book/colors/show_color_page/light-blue

 But I want to rewrite the URL to: http://my.domain.com/blue/light-blue

 Accordingly a page with the menu location red  dark-red should be 
 presented with: http://my.domain.com/red/light-red

 I thought that a pattern-based routes.py could be configured to do things 
 like that. But I've only had success with rewriting URLs manually entered 
 in the browser's address field so far- but not with internal links.

 Is there an example for my use case somewhere?

 Thanks for any help!
  



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Multilingual Content Management System with language switcher (Internationalization)

2013-08-27 Thread xelomac


Hi folks,

I'm working on a multilingual CMS. Therefore I need to give the site 
visitor the option to change the content language using a language switcher 
menu link. My question is about changing content language not about 
changing surface language (please no T function answers here :-)

So far I did the following: I created a routes.py file inside the web2py 
directory with the following content:

routers = dict(
  BASE  = dict(default_application='myapp'),
  myapp = dict(languages=['en', 'it', 'fr', 'de'], default_language='en'),
)

I found an older post dealing with this topic 
(https://groups.google.com/forum/#!msg/web2py/q2B9mekNCwk/Kn-uxao1aIMJ) and 
followed this advice:

URL() by default produces absolute scheme-less URLs, like this /a/c/f. 
 so to link from http://site.com/en/a/c/f to http://site.com/fr/a/c/f, 
 you prepend URL() call with '/fr', like this: 
 a href=/fr{{=URL(a=request.application, c=request.controller, 
 f=request.function, ...)}}French/a 



This works - but only once. The first time I click the link the 'fr' is 
prepended and the request.uri_language is changed accordingly. But on the 
second click on a language link another language token is prepended to the 
URI which breaks the app. (URL after second click reads like this: 
domain.com/app/en/fr/controller/function)

By the way: It only works on the first click because initially there is no 
language token in the URI. But this means there would be pages that can be 
reached with and without language token which will lead to Google duplicate 
content problems. So I will have to find a solution that addresses this 
issue too.

Any help appreciated!



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Multilingual Content Management System with language switcher (Internationalization)

2013-08-27 Thread xelomac
Thanks - good idea - but how do I force the URL to show the language token 
like domain.com/mayapp/en/mycontroller/myfunction?

On Tuesday, August 27, 2013 1:40:00 PM UTC+2, Massimo Di Pierro wrote:

 Look how admin does it:


 https://github.com/web2py/web2py/blob/master/applications/admin/views/layout.html#L62

 https://github.com/web2py/web2py/blob/master/applications/admin/models/0.py#L79


 On Tuesday, 27 August 2013 06:00:57 UTC-5, xelomac wrote:



 Hi folks,

 I'm working on a multilingual CMS. Therefore I need to give the site 
 visitor the option to change the content language using a language switcher 
 menu link. My question is about changing content language not about 
 changing surface language (please no T function answers here :-)

 So far I did the following: I created a routes.py file inside the web2py 
 directory with the following content:

 routers = dict(
   BASE  = dict(default_application='myapp'),
   myapp = dict(languages=['en', 'it', 'fr', 'de'], default_language='en'
 ),
 )

 I found an older post dealing with this topic (
 https://groups.google.com/forum/#!msg/web2py/q2B9mekNCwk/Kn-uxao1aIMJ) 
 and followed this advice:

 URL() by default produces absolute scheme-less URLs, like this /a/c/f. 
 so to link from http://site.com/en/a/c/f to http://site.com/fr/a/c/f, 
 you prepend URL() call with '/fr', like this: 
 a href=/fr{{=URL(a=request.application, c=request.controller, 
 f=request.function, ...)}}French/a 



 This works - but only once. The first time I click the link the 'fr' is 
 prepended and the request.uri_language is changed accordingly. But on the 
 second click on a language link another language token is prepended to the 
 URI which breaks the app. (URL after second click reads like this: 
 domain.com/app/en/fr/controller/function)

 By the way: It only works on the first click because initially there is 
 no language token in the URI. But this means there would be pages that can 
 be reached with and without language token which will lead to Google 
 duplicate content problems. So I will have to find a solution that 
 addresses this issue too.

 Any help appreciated!





-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [web2py] Re: Multilingual Content Management System with language switcher (Internationalization)

2013-08-27 Thread xelomac
As you can see in my first post I used the example from the book. If I 
understand it right this solution allows to access a page in the preferred 
language by calling it with the URL containing the language token, set 
the request.uri_language and keep the language token for further navigation 
through the site. But I need the opposite direction. I need to change/add 
the language token to the URI after changing the language with the solution 
suggested by Massimo (language selector). 

If I get it right the routes example from the book gives a second option to 
retrieve the same document (as long as in default language) by using the 
URL with or without the language token (bad idea because of duplicate 
content punishment by Google).

What I am looking for is more a kind of a language specific permanent 
redirect (301) after changing the language using the language selector.

@Massimo: your solutions works half way for me but the select box shows 
only 17 of the 21 languages the same code offers when used in admin. For 
example German is missing. Any idea what's going wrong at this point?

On Tuesday, August 27, 2013 6:52:33 PM UTC+2, viniciusban wrote:

 There are examples in the book [1]. 

 [1] http://web2py.com/books/default/chapter/29/04/the-core#URL-rewrite 

 On Tue, Aug 27, 2013 at 1:08 PM, xelomac kai...@kaisermacht.dejavascript: 
 wrote: 
  Thanks - good idea - but how do I force the URL to show the language 
 token 
  like domain.com/mayapp/en/mycontroller/myfunction? 
  
  On Tuesday, August 27, 2013 1:40:00 PM UTC+2, Massimo Di Pierro wrote: 
  
  Look how admin does it: 
  
  
  
 https://github.com/web2py/web2py/blob/master/applications/admin/views/layout.html#L62
  
  
  
 https://github.com/web2py/web2py/blob/master/applications/admin/models/0.py#L79
  
  
  
  On Tuesday, 27 August 2013 06:00:57 UTC-5, xelomac wrote: 
  
  
  
  Hi folks, 
  
  I'm working on a multilingual CMS. Therefore I need to give the site 
  visitor the option to change the content language using a language 
 switcher 
  menu link. My question is about changing content language not about 
 changing 
  surface language (please no T function answers here :-) 
  
  So far I did the following: I created a routes.py file inside the 
 web2py 
  directory with the following content: 
  
  routers = dict( 
BASE  = dict(default_application='myapp'), 
myapp = dict(languages=['en', 'it', 'fr', 'de'], 
  default_language='en'), 
  ) 
  
  I found an older post dealing with this topic 
  (https://groups.google.com/forum/#!msg/web2py/q2B9mekNCwk/Kn-uxao1aIMJ) 
 and 
  followed this advice: 
  
  URL() by default produces absolute scheme-less URLs, like this 
 /a/c/f. 
  so to link from http://site.com/en/a/c/f to http://site.com/fr/a/c/f, 

  you prepend URL() call with '/fr', like this: 
  a href=/fr{{=URL(a=request.application, c=request.controller, 
  f=request.function, ...)}}French/a 
  
  
  
  This works - but only once. The first time I click the link the 'fr' 
 is 
  prepended and the request.uri_language is changed accordingly. But on 
 the 
  second click on a language link another language token is prepended to 
 the 
  URI which breaks the app. (URL after second click reads like this: 
  domain.com/app/en/fr/controller/function) 
  
  By the way: It only works on the first click because initially there 
 is 
  no language token in the URI. But this means there would be pages that 
 can 
  be reached with and without language token which will lead to Google 
  duplicate content problems. So I will have to find a solution that 
 addresses 
  this issue too. 
  
  Any help appreciated! 
  
  
  
  -- 
  
  --- 
  You received this message because you are subscribed to the Google 
 Groups 
  web2py-users group. 
  To unsubscribe from this group and stop receiving emails from it, send 
 an 
  email to web2py+un...@googlegroups.com javascript:. 
  For more options, visit https://groups.google.com/groups/opt_out. 


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] Re: Web2Py on OpenShift

2013-08-19 Thread xelomac
Hi Andrew,

thank you for sharing. I just tried your template and successfully 
installed the master (latest development snapshot of web2py). But since I 
want to use the latest stable version I deleted everything (local and 
remote installation) again and started again:

rhc app create -a web2py -t python-2.6
cd web2py
git remote add upstream -m 2.5.1 
git://github.com/prelegalwonder/openshift_web2py.git
git pull -s recursive -X theirs upstream 2.5.1
git push

After having no success with version 2.5.1 I again deleted everything and 
tried the version you name in your example:

rhc app create -a web2py -t python-2.6
cd web2py
git remote add upstream -m 2.3.2 
git://github.com/prelegalwonder/openshift_web2py.git
git pull -s recursive -X theirs upstream 2.3.2
git push

Again no success. I receive the following error message:
To ssh://rhcloud.com/~/git/web2py.git/
 ! [remote rejected] master - master (pre-receive hook declined)
error: failed to push some refs to 'ssh://rhcloud.com/~/git/web2py.git/'

Any idea what's going wrong?

Best,

xelomac


On Friday, June 8, 2012 5:07:39 PM UTC+2, Andrew Replogle wrote:

 Just FYI to anyone interested, I've put together a web2py template for 
 OpenShift https://openshift.redhat.com/app/ (Red Hat's Opensource 
 PaaS). 

 You can find it here: - https://github.com/prelegalwonder/openshift_web2py

 I've also put together a basic openshift deployer from the admin page, and 
 you can grab the changes from my fork of web2py - 
 https://github.com/prelegalwonder/web2py
 It's just 3 files in the admin app:
  controllers/openshift.py
  views/openshift/deploy.html
 and a modification to views/default/site.html

 It's only requirement to work beyond having a local working openshift 
 project is GitPython installed and accessible from the runtime that web2py 
 is running in.

 So you can either run the admin app in the cloud and access it directly or 
 run a local web2py instance and execute the deployer when you want to test 
 out your changes. 

 I'm working on a detailed blog that I intent to submit to the OpenShift 
 team so they can put it on their site for getting started. 

 Enjoy


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.