[web2py] Re: Web2py Update records only if user is signed in with a different session from previous

2016-10-05 Thread Meinolf
Ok, i was first storing the current session id from some insert statement, 
thanks now i can just access it directly from response.session_id.

I guess my logic is wrong since i am running all these queries in the same 
function, i end up inserting the current session_id and testing it against 
itself (expecting it to be different sometimes), which will not happen for 
any user session. Any idea of how i could set it up such that the next time 
a user logs in with a different session, then i can trigger some operation??

On Tuesday, October 4, 2016 at 6:13:24 PM UTC+2, Anthony wrote:
>
> On Tuesday, October 4, 2016 at 3:16:06 AM UTC-4, Meinolf wrote:
>>
>> Hi there,
>>
>> I need to update my table record only if the user is logged in with a 
>> different session from the previous, but with the code i have, it keeps 
>> updating when i thought the user still logged in with the same session. 
>> problem is i can't view the session id which seem to be encrypted, i can't 
>> tell when its the same and when its not. Did i miss something? below is my 
>> code:
>>
>> prev_ses_id = db((db.rates.user_id==auth.user.id) & 
>> (db.rates.item_id==request.args(0))).select(db.rates.ses_id)
>>
>
> How and where are you setting the value of db.rates.ses_id? Do you expect 
> the above to return only a single record? Note, prev_ses_id is a Rows 
> object, not a Row object, and not an individual session id value. If you 
> want the value of the ses_id field, you need to do prev_ses_id[0].ses_id.
>
> Note, if you need the session id of the current session, it is in 
> response.session_id.
>
> 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] Re: Proposal to add 'extend' to DIV

2016-10-05 Thread Joe Barnhart
Yep.  That is essentially what "extend" does.  It's a standard method in 
the Python list class.  Since DIV has a lot of "list" behavior I think it 
would be nice to "extend" it to have extend() as well!

-- Joe


On Wednesday, October 5, 2016 at 3:19:52 PM UTC-7, Dave S wrote:
>
>
>
> On Wednesday, October 5, 2016 at 12:51:59 PM UTC-7, Joe Barnhart wrote:
>>
>> One Python helper I find enormously useful is "extend()" as applied to 
>> list objects.  Extend differs from append in that it adds the items of the 
>> list provided at the same level as the current list items, thereby 
>> "extending" the list. 
>>
>
>
> I'll try paraphrasing to see if I understand you and the examples:  given 
> 2 lists, [a0, a1, .., an] and [b0, b1, ..., bn], you want the elements of b 
> to be concantenated to the a list, rather than putting a single item 
> consistenting of the b list at the end of the a list.
>
> Roughly
>
> for item in b:
>   a.append(item)
>
> Did I get it?
>  
>
>>
>> An example:
>>
>> body = DIV("this","is","the","body")
>>
>> Result: a DIV with four elements in it.
>>
>> body.append(["and","additional","elements"])
>>
>> Result:  Not what you wanted!  It appends a list to the original DIV 
>> making a mess.
>>
>> body.extend(["and","additional","elements"])
>>
>> This is what you wanted:
>>
>> DIV("this","is","the","body","and","additional","elements")
>>
>> I've been monkey-patching "extend" into DIV quite awhile now and thought 
>> you may want to consider adding it to the DIV helper.  Here is my 
>> monkey-patch:
>>
>> def extend(self,coll):
>> self._setnode(coll)
>> ret = self.components.extend(coll)
>> self._fixup()
>> return ret
>> DIV.extend = extend
>>
>>
>
> /dps
>  
>

-- 
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: Translate on table content ?

2016-10-05 Thread António Ramos
Thank you Leonel.

2016-10-04 11:19 GMT+01:00 Leonel Câmara :

> I have solved this problem in 2 different ways. Depending on your need,
> you pick one.
>
> Option 1 "have an extra translation table" can look something like this
>
> LANG = T.accepted_language if T.accepted_language in SUPPORTED_LANGUAGES
> else 'en'
>
>
> db.define_table('tag',
> format=lambda r: db(
> (db.tag_translation.tag == r.id) &
> (db.tag_translation.lang == LANG)
> ).select().first().name
> )
>
>
> db.define_table('tag_translation',
> Field('tag', 'reference tag'),
> Field('lang', requires=IS_IN_SET(SUPPORTED_LANGUAGES)),
> Field('name', label=T('Name')),
> )
>
>
>
>
> Option 2 which I kind of favor right now if I'm using postgresql, is to
> "use a JSON field" and store all the translations there:
>
>
> def pick_lang():
> twoletter = session.lang or T.accepted_language[:2]
> if twoletter in SUPPORTED_LANGUAGES:
> T.force(twoletter)
> return twoletter
> else:
> T.force('en')
> return 'en'
> LANG = pick_lang()
>
> def represent_lang(v):
> if v is None:
> return v
> if LANG in v:
> return v[LANG]
> else:
> return v['en']
>
>
> db.define_table('tag',
> Field('name', 'json', widget=TranslateWidget().widget,
> requires=IS_JSON(), represent=represent_lang)
> )
>
> You may notice this second option has a TranslateWidget, I have included a
> file with it in this post, just put it in modules and import it in your
> models.
>
> If you go with this option another useful function if you wanted to e.g.
> search tags by name, is:
>
> from gluon.dal import Expression
>
> def JSON_KEY_EXPRESSION(field, key, value_type='string'):
> db = field._db
> def op(first, second):
> return "%s->>'%s'" % (db._adapter.expand(first), db._adapter.
> expand(second))
> return Expression(db, op, field, key, value_type)
>
> And then in a controller you could do something like
>
> tags = db(JSON_KEY_EXPRESSION(db.tag.name, LANG).like('%' + 
> request.vars.search
> + '%', case_sensitive=False)).select()
>
>
>
> --
> 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: Proposal to add 'extend' to DIV

2016-10-05 Thread Dave S


On Wednesday, October 5, 2016 at 12:51:59 PM UTC-7, Joe Barnhart wrote:
>
> One Python helper I find enormously useful is "extend()" as applied to 
> list objects.  Extend differs from append in that it adds the items of the 
> list provided at the same level as the current list items, thereby 
> "extending" the list. 
>


I'll try paraphrasing to see if I understand you and the examples:  given 2 
lists, [a0, a1, .., an] and [b0, b1, ..., bn], you want the elements of b 
to be concantenated to the a list, rather than putting a single item 
consistenting of the b list at the end of the a list.

Roughly

for item in b:
  a.append(item)

Did I get it?
 

>
> An example:
>
> body = DIV("this","is","the","body")
>
> Result: a DIV with four elements in it.
>
> body.append(["and","additional","elements"])
>
> Result:  Not what you wanted!  It appends a list to the original DIV 
> making a mess.
>
> body.extend(["and","additional","elements"])
>
> This is what you wanted:
>
> DIV("this","is","the","body","and","additional","elements")
>
> I've been monkey-patching "extend" into DIV quite awhile now and thought 
> you may want to consider adding it to the DIV helper.  Here is my 
> monkey-patch:
>
> def extend(self,coll):
> self._setnode(coll)
> ret = self.components.extend(coll)
> self._fixup()
> return ret
> DIV.extend = extend
>
>

/dps
 

-- 
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] Pydal ids customs

2016-10-05 Thread argenio . bosanto
I'm doing a migrate data of 2 databases with diferents tables.

My only problems is with ids! 

table 1
id: 5, name: Diana
id: 8, name: Carlos


when i migrate this data to databases 2
id: 1, name: Diana
id: 2, name: Carlos

Look the id's not the same.

what is the method to save the same id?
I read about primarekey parameters but dont work.

The process of migrate if a script with 2 Pydal, one for the old database 
and other for new databases.
I execute one select() of everithing (not much data), later convert to the 
new structure and all work perfectly. the only problem is with ID .

Please help me, thanks.

-- 
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] capturing primary key during insert

2016-10-05 Thread Alex Glaros
yes return of primery key works.  First time it didn't work but changed 
code and it does work.  Sorry guys, tried to delete my post after it tested 
correctly but too late.  Lack of sleep made me miss the solution.

-- 
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] Proposal to add 'extend' to DIV

2016-10-05 Thread Joe Barnhart
One Python helper I find enormously useful is "extend()" as applied to list 
objects.  Extend differs from append in that it adds the items of the list 
provided at the same level as the current list items, thereby "extending" 
the list. 

An example:

body = DIV("this","is","the","body")

Result: a DIV with four elements in it.

body.append(["and","additional","elements"])

Result:  Not what you wanted!  It appends a list to the original DIV making 
a mess.

body.extend(["and","additional","elements"])

This is what you wanted:

DIV("this","is","the","body","and","additional","elements")

I've been monkey-patching "extend" into DIV quite awhile now and thought 
you may want to consider adding it to the DIV helper.  Here is my 
monkey-patch:

def extend(self,coll):
self._setnode(coll)
ret = self.components.extend(coll)
self._fixup()
return ret
DIV.extend = extend

-- 
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] Setup web2py in Vagrant provision phase

2016-10-05 Thread Marko Seppälä
Hi Richard,

Thanks for your reply. Unfortunately your answer is not detailed enough to 
make it sure that I did everything correctly.

I managed to make it work by just adding -batch option to "openssl reg -new 
..." command. Also everything seems to work when I ssh to server and try 
wget to 127.0.0.1. But i'm not sure if the certificate 
is done properly this way.

Could you verify if this method is okay for development?

tiistai 4. lokakuuta 2016 21.17.57 UTC+3 Richard kirjoitti:
>
> prompt and read, then 
> http://stackoverflow.com/questions/15476479/sign-certificate-without-prompt-in-shell-script
>
> Richard
>
> On Tue, Oct 4, 2016 at 2:04 PM, Marko Seppälä  > wrote:
>
>> Hi,
>>
>> I'm using Vagrant to create Ubuntu 14.04 virtual server. I use 
>> setup-web2py-ubuntu.sh 
>> script in provision phase but it doesn't work out of the box with Vagrant. 
>> If 
>> I ssh to virtual server and run the script, everything works. But in 
>> "creating 
>> a self signed certificate" phase script asks some information about 
>> country, email etc. If I run the script through vagrant provision, then 
>> those are not asked but left empty instead. I guess that is the reason why 
>> script fails and gives me an error:
>>
>> ==> default: You are about to be asked to enter information that will be 
>> incorporated
>> ==> default: into your certificate request.
>> ==> default: What you are about to enter is what is called a 
>> Distinguished Name or a DN.
>> ==> default: There are quite a few fields but you can leave some blank
>> ==> default: For some fields there will be a default value,
>> ==> default: If you enter '.', the field will be left blank.
>> ==> default: -
>> ==> default: Country Name (2 letter code) [AU]:
>> ==> default: problems making Certificate Request
>> ==> default: unable to load certificate
>> ==> default: 139944983766688:error:0906D06C:PEM routines:PEM_read_bio:no 
>> start line:pem_lib.c:703:Expecting: TRUSTED CERTIFICATE
>> ==> default: rewriting your apache config file to use mod_wsgi
>> ==> default: =
>> ==> default: Enabling site default.
>> ==> default: To activate the new configuration, you need to run:
>> ==> default:   service apache2 reload
>> ==> default: restarting apache
>> ==> default: 
>> ==> default:  * Restarting web server apache2
>> ==> default:...fail!
>> ==> default:  * The apache2 configtest failed.
>> ==> default: Output of config test was:
>> ==> default: AH00526: Syntax error on line 27 of 
>> /etc/apache2/sites-enabled/default.conf:
>> ==> default: SSLCertificateFile: file '/etc/apache2/ssl/self_signed.cert' 
>> does not exist or is empty
>> ==> default: Action 'configtest' failed.
>> ==> default: The Apache error log may have more information.
>> ==> default: admin password:
>> ==> default: Traceback (most recent call last):
>> ==> default:   File "", line 1, in 
>> ==> default: EOFError
>> ==> default: :
>> ==> default: EOF when reading a line
>> ==> default: done!
>>
>> How I could fix that problem? I'm not too familiar with bash scripting 
>> and just started to learn Vagrant so I'm having problems to figure out how 
>> to proceed.
>>
>> -- 
>> 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+un...@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.


Re: [web2py] capturing primary key during insert

2016-10-05 Thread Richard Vézina
id = db.SuperObject.insert(**db.SuperObject._filter_fields(form.vars))

Should work, does it?

Richard

On Tue, Oct 4, 2016 at 5:42 PM, Alex Glaros  wrote:

> In doing a direct programatic insert without a form such as
> db.SuperObject.insert(person_name = "Alex")
>
> is there a way to capture the primary key during the insert as can be done
> in a form: super_object_fk = db.SuperObject.insert(**db.Sup
> erObject._filter_fields(form.vars)) ?
>
> or do I have to do a select to get the record after created?
>
> thanks
>
> --
> 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: set individual action's transaction mode

2016-10-05 Thread Niphlod


On Tuesday, October 4, 2016 at 8:18:57 PM UTC+2, Pierre wrote:
>
> oh great i see
> so the two apis speak the same language but they don't communicate ?
>

they do perfectly integrate: the only way it's possible and the way it's 
more natural.
 

> never mindbut better be prudent
>
> thanks Niphlod
>
>
> hopefully  everything is under control :)  Have you seen the movie 
> melancholia by lars von trier ?
>

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