[web2py] Re: how to use strftime in view with rows

2016-11-05 Thread Alex Glaros
you're right Anthony

{{if r.auth_membership.through_date != 
None:}}{{=r.auth_membership.through_date.strftime(("%A, %d %B %Y %I:%M 
%p"))}}{{pass}}

thanks both to Anthony and Stifan

-- 
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: how to use strftime in view with rows

2016-11-05 Thread Anthony
On Saturday, November 5, 2016 at 3:56:01 AM UTC-4, Alex Glaros wrote:
>
> I want to display something like this format:  *Saturday, 05 November 
> 2016, 11:30 AM*
>
> the field through_date is datetime type
>
> This: {{=r.auth_membership.through_date}} produces: 2016-11-23 21:14:25
>
> When I apply strftime like this: {{= 
> r.auth_membership.from_date.strftime("%A, %d %B %Y")}}
>
> error arises:
>
>  'NoneType' object has no attribute 'strftime'
>
> what is correct syntax?
>

The problem is obviously that r.auth_membership.from_date is None for some 
record -- so you have to check for that before treating it as a date object.

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.


Re: [web2py] Re: switch to python 3

2016-11-05 Thread António Ramos
what is the gain moving to python 3?

2016-11-05 17:59 GMT+00:00 Leonel Câmara :

> web2py is almost completely python 3 compatible. You can follow the issue
> here: https://github.com/web2py/web2py/issues/1353
>
> --
> 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.
>

-- 
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: how to use strftime in view with rows

2016-11-05 Thread Alex Glaros
It needed a render in the controller select statement to make your 
suggestion work.  .select().render()

represent = lambda value, field: SPAN('%s' % (value.strftime("%A, %d %B %Y 
%I:%M %p"))) if value else ''

Does the render pose a performance problem? 

Thanks for the help Stifan

Alex


-- 
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: switch to python 3

2016-11-05 Thread Leonel Câmara
web2py is almost completely python 3 compatible. You can follow the issue 
here: https://github.com/web2py/web2py/issues/1353

-- 
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: How to translate dynamic data with web2py

2016-11-05 Thread Leonel Câmara
https://groups.google.com/forum/#!topic/web2py/y1QYmM4HfeM

-- 
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: Python Social Auth - example site working with downlevel version of PSA

2016-11-05 Thread mweissen
It is a very interesting project. Are there any news?

Am Freitag, 24. Juni 2016 00:45:51 UTC+2 schrieb Donald McClymont:
>
> Just a further note that following some further updating I can login via 
> Facebook, Twitter, Google (using Mozilla Persona) and Microsoft accounts. 
>  There is a test site at https://www.netdecisionmaking.com/w2ppsatest if 
> anyone wants to take a look without setting up themselves.  I am not really 
> planning to do much more with this unless there are issues or suggestions 
> on what needs done next.
>
> Regards
> Donald
>
> On Friday, June 10, 2016 at 9:49:05 PM UTC+1, Donald McClymont wrote:
>>
>> I have now forked and pruned w2p-social-auth at the following:  
>> https://github.com/DonaldMcC/w2p-social-auth  basically only two changes 
>> of substance:
>>
>> 1 It now uses appconfig to store the keys in so you will need to be on a 
>> fairly recent web2py if you want to use this approach - alternatively just 
>> put the keys directly into db.py but this obviously isn't a best practice 
>> with github for sharing code.
>> 2 I have removed the version of python social auth - I think 0.1.24 which 
>> was included in previous file which means a lot less code - as far as I can 
>> tell this was unmodified however it was not best if the plugin was 
>> importing from their and internal imports within PSA were from the 
>> installed version of that I had installed as a python package.
>>
>> Having done the above - I have successfully completed a basic login with 
>> the revised plugin and PSA 0.2.19 which is the latest version use Mozilla 
>> Persona as the provider - I will need to move it onto an actual site rather 
>> than localhost to test a few other providers but that will be next week at 
>> the earliest and I still have a very limited knowledge of Auth, PSA or the 
>> actual code in the plug-in - so it would be good if people that do could 
>> perhaps chip-in with suggestions on where this should be heading and how it 
>> should be properly tested that would be appreciated.
>>
>> Donald
>>
>> On Monday, June 6, 2016 at 10:43:18 PM UTC+1, Donald McClymont wrote:
>>>
>>> Sounds good - possibly worth trying to contact someone on the psa team 
>>> as well.  I think we need to decide whether an updated plug-in is the best 
>>> way to go or whether this should be a core part of either PSA or web2py. 
>>>  The plug-in may be the quickest way forward but it might well be better to 
>>> go another route as it reduces the risk of being back in the same situation 
>>> we have now where changes in PSA mean the plug-in doesn't work with latest 
>>> versions.
>>>
>>> There was some previous dialogue on wihether python social auth or 
>>> authomatic was the better approach and that did seem to come down in favour 
>>> of PSA because authomatic was no longer being maintained. 
>>>
>>> Donald
>>>
>>> On Monday, June 6, 2016 at 12:30:29 AM UTC+1, Joe Barnhart wrote:

 Well I don't know about OAuth or auth-social, but I know web2py auth 
 and I know python pretty well.  I'll do a little reading on the whole 
 concept of social-auth and see if I can dig up more resources, like maybe 
 the author of w2p-social-auth.  If worse comes to worst, I can get some 
 help from Massimo.  I think a social auth plug-in that works really well 
 would be not only useful, but essential to web2py at this point.

 -- Joe


 On Sunday, June 5, 2016 at 3:08:23 PM UTC-7, Donald McClymont wrote:
>
> I would really like some progress on this - however I have extremely 
> limited knowledge of both auth and Python Social Auth so was rather 
> hoping 
> someone that did might develop this in a better manner than I am likely 
> to 
> do..  I did briefly attempt to update what I have but quickly came to the 
> conclusion it was not straightforward.  However I may have some time to 
> look at in a bit more detail in the next few weeks.
>
> Regards
> Donald
>
> On Sunday, June 5, 2016 at 1:20:38 AM UTC+1, Joe Barnhart wrote:
>>
>> Hi Donald --
>>
>> I find I need this too. The more recent version of social auth should 
>> handle Google authentication in addition to Facebook and Twitter.  I 
>> need 
>> these three in addition to web2py logon for my application. Have you 
>> seen 
>> any progress on this front?  We may have to collaborate and do it 
>> ourselves.
>>
>> -- Joe
>>
>> On Monday, March 7, 2016 at 3:26:34 PM UTC-8, Donald McClymont wrote:
>>>
>>> I am sharing  an example site http://www.netdecisionmaking.com that 
>>> uses Python Social Auth for authentication, based on the following code 
>>> and 
>>>
>>> https://github.com/omab/python-social-auth and the web2py 
>>> integration developed at https://github.com/bnmnetp/w2p-social-auth 
>>> 
>>>
>>> This works basically 

[web2py] Making two queries into one

2016-11-05 Thread Gualter Portella
Dear all,

I hope this e-mail finds you all well.

I have written two queries to retrieve data from my database (model). I did 
them initially through plain SQL, then I followed the DAL syntax. They all 
return the same output regardless the syntax chosen. Please, see the code 
below:

Two different controllers:

def sql():
sql = "SELECT indiban.valor, meses.abrev, anos.numero, empresas.nome "
sql = sql + "FROM indiban INNER JOIN meses ON indiban.meses_id = 
meses.id "
sql = sql + "INNER JOIN anos ON indiban.anos_id = anos.id "
sql = sql + "INNER JOIN indicadores ON indiban.indicadores_id = 
indicadores.id "
sql = sql + "INNER JOIN empresas ON indiban.empresas_id = empresas.id "
sql = sql + "WHERE indicadores.id = 3 "
sql = sql + "AND meses.id = 5 AND anos.id = 22 Limit 10;"
ratios = db.executesql(sql)

sql = "SELECT eleban.valor, meses.abrev, anos.numero, empresas.nome "
sql = sql + "FROM eleban INNER JOIN meses ON eleban.meses_id = meses.id 
"
sql = sql + "INNER JOIN anos ON eleban.anos_id = anos.id "
sql = sql + "INNER JOIN elementos ON eleban.elementos_id = elementos.id  
"
sql = sql + "INNER JOIN empresas ON eleban.empresas_id = empresas.id "
sql = sql + "WHERE elementos.id = 5 "
sql = sql + "AND meses.id = 5 AND anos.id = 22 Limit 10;"
accounts = db.executesql(sql)

return locals()

def sfn():

   ratios = db((Indiban.meses_id==mes_id)&(Indiban.anos_id==ano_id)&

(Indiban.indicadores_id==rspla_id)).select(Indiban.empresas_id, 
Indiban.valor,
   
Indiban.meses_id, Indiban.anos_id, limitby=(0, 10))

   accounts = db((Eleban.meses_id==mes_id)&(Eleban.anos_id==ano_id)&
(Eleban.elementos_id==ativo_id)).select(Eleban.empresas_id, 
Eleban.valor,
   Eleban.meses_id, 
Eleban.anos_id, limitby=(0, 10))


return locals()

DAL output:

indiban.empresas_idindiban.
valorindiban.meses_idindiban.anos_idSISTEMA FINANCEIRO 
NACIONAL0.1300052016BANCO DO BRASIL0.1100052016BRB - BANCO DE 
BRASILIA0.0200052016POTTENCIAL-0.0100052016CAIXA ECONOMICA 
FEDERAL0.0300052016BANCO INTERMEDIUM0.0400052016RIBEIRAO 
PRETO0.1200052016BGN 
CETELEM-0.1200052016SEMEAR-0.0100052016BM 
--

eleban.empresas_ideleban.valoreleban.meses_ideleban.anos_idSISTEMA 
FINANCEIRO NACIONAL7404931306106.43052016BANCO DO 
BRASIL1070715292094.95052016BRB - BANCO DE 
BRASILIA13013438306.52052016POTTENCIAL167724699.00052016CAIXA ECONOMICA 
FEDERAL1096578802720.18052016BANCO INTERMEDIUM2745032207.17052016RIBEIRAO 
PRETO486037290.78052016BGN 
CETELEM8371996257.63052016SEMEAR717457527.11052016BM 

SQL Output: 

((Decimal('0.1300'), u'mai', u'2016', u'SISTEMA FINANCEIRO NACIONAL'), 
(Decimal('0.1100'), u'mai', u'2016', u'BANCO DO BRASIL'), 
(Decimal('0.0200'), u'mai', u'2016', u'BRB - BANCO DE BRASILIA'), 
(Decimal('-0.0100'), u'mai', u'2016', u'POTTENCIAL'), (Decimal('0.0300'), 
u'mai', u'2016', u'CAIXA ECONOMICA FEDERAL'), (Decimal('0.0400'), u'mai', 
u'2016', u'BANCO INTERMEDIUM'), (Decimal('0.1200'), u'mai', u'2016', 
u'RIBEIRAO PRETO'), (Decimal('-0.1200'), u'mai', u'2016', u'BGN CETELEM'), 
(Decimal('-0.0100'), u'mai', u'2016', u'SEMEAR'), (Decimal('0.1500'), 
u'mai', u'2016', u'BM')) 
--
((Decimal('7404931306106.43'), u'mai', u'2016', u'SISTEMA FINANCEIRO 
NACIONAL'), (Decimal('1070715292094.95'), u'mai', u'2016', u'BANCO DO 
BRASIL'), (Decimal('13013438306.52'), u'mai', u'2016', u'BRB - BANCO DE 
BRASILIA'), (Decimal('167724699.00'), u'mai', u'2016', u'POTTENCIAL'), 
(Decimal('1096578802720.18'), u'mai', u'2016', u'CAIXA ECONOMICA FEDERAL'), 
(Decimal('2745032207.17'), u'mai', u'2016', u'BANCO INTERMEDIUM'), 
(Decimal('486037290.78'), u'mai', u'2016', u'RIBEIRAO PRETO'), 
(Decimal('8371996257.63'), u'mai', u'2016', u'BGN CETELEM'), 
(Decimal('717457527.11'), u'mai', u'2016', u'SEMEAR'), 
(Decimal('234811696.13'), u'mai', u'2016', u'BM')) 

The data  in the output are identical as expected. What I want to do is  to 
combine  the two queries into one, preferably in DAL, so that I do not need 
to use two loops in order to insert the indiban.valor and eleban.valor 
values side by side in a view table. So far, I've failed miserably.

The tables indiban and eleban are linked to the meses, anos and empresas 
tables as depicted in the relational schema below. If you can help me, I'd 
appreciate much. Otherwise, I will stick to the two loops.

Best regards,[image: Imagem inline 2]

Gualter

-- 
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] Re: how to use strftime in view with rows

2016-11-05 Thread 黄祥
i think you can achieve it using represent in dal
e.g.
db.auth_membership.from_date.represent = lambda value, field: SPAN('%s' % 
(value.strftime("%A, %d %B %Y") ) )

best regards,
stifan

-- 
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] How to translate dynamic data with web2py

2016-11-05 Thread Marko Seppälä


Let's say we have a table

db.define_table('thing',
Field('name'),
Field('description', 'text'),Field('age', 
'integer'))


and we need to translate this to X amount of different languages and there 
could be potentially huge amount of these objects in database. How I should 
handle internalization/translations of these objects? Not all fields need 
to be translated, for example in that case age is language neutral 
information.

I know I could mark these with T and do something like {{=T(thing.name)}} in 
views for example. But it means that translation files are growing huge and 
managing translations isn't so easy. Also I'm not able to search objects 
from database based on translated information, for example if I want to 
find all things which have keywords x, y and z in their description and I 
want to use Germany as a search language. At least I've understood this so.


Other approach would be to take care of internalization in database level, 
either with "multiple column approach" or "multiple table approach" 
described very well in here: 
https://www.sofokus.com/en/localizing-dynamic-content-in-web-apps/
Multiple column approach is not really an option for X amount of languages 
but multiple table approach would work. The problem is that number of 
models get multiplied almost by two if content is in separate model and 
also controllers gets more complex, especially because I need fallback to 
default language in case of there is no translation. And inserting new data 
to database is more complex too since we need to add data to more than one 
table at time.

I'm wondering, is there any ready-made standard solution for this problem 
which would make this all easy to implement and manage in web2py? This is 
very standard need so for sure I'm not the first one to implement something 
like this. In Django, they have Parler 
(https://pypi.python.org/pypi/django-parler) for example which solves this 
problem very well and it's easy to use.

I think ideal solution is something where I wouldn't need care about 
internalization in views. So I could iterate over all things in views 
normally as I would do just in case of single language and names and 
descriptions would be in language user wants, or with fallback language if 
translation is not found. For example:

{{for thing in things:}}
{{=thing.name}}
{{=thing.description}}
{{=thing.age}}
{{pass}}


Also managing translations should be easy. Interface presented in picture below 
would work very well (from 
https://www.sofokus.com/en/localizing-dynamic-content-in-web-apps/)



Any help is appreciated! I'm sure many of you have done this before so I'm 
willing to hear how you solve this. Also, is there any plans to implement 
something similar like Django Parler for web2py?

-- 
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] how to use strftime in view with rows

2016-11-05 Thread Alex Glaros
I want to display something like this format:  *Saturday, 05 November 2016, 
11:30 AM*

the field through_date is datetime type

This: {{=r.auth_membership.through_date}} produces: 2016-11-23 21:14:25

When I apply strftime like this: {{= 
r.auth_membership.from_date.strftime("%A, %d %B %Y")}}

error arises:

 'NoneType' object has no attribute 'strftime'

what is correct syntax?

Have tried every example in the discussion group.

Also, would like an another example using local time if possible.

thanks

Alex Glaros

-- 
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.