Re: [web2py] Digest for web2py@googlegroups.com - 6 updates in 5 topics

2018-05-11 Thread Nico de Groot
Minimal example using web2py DAL as a script. I'm not using firebird but
your example with the string shows that the storage in a blob is working in
firebird (Note that a python string is saved as binary data in a blob). In
a webapp, move code to model file and to a controller, or use a form to
upload an image, see
https://stackoverflow.com/questions/34999878/upload-image-in-web2py-to-database-from-default-controller-following-image-blog


from gluon import DAL,Field
>
> def testdb():
> uri = 'sqlite://storage.sqlite'  # start of model code
>
> try:
> db_xml = DAL(uri,
>  folder='test',
>  check_reserved=['all'],
>  migrate=True,
>  fake_migrate=False,
>  migrate_enabled=True,
>  fake_migrate_all=False)
>
> except Exception as e:
> print "database {} could not be opened. {}".format(uri, e)
>
> db_xml.define_table('bin_files',
> Field('DATAblob', 'blob'),
> migrate=True
>)
> # controller code
> imgstream = open(u'/users/ncdegroot/pictures/pasfotos/photo.jpg', 'rb')
> bin_data = imgstream.read()
> stored_img = db_xml.bin_files.insert(DATAblob=bin_data)
> db_xml.commit() # needed in a script
> retrieved_img = db_xml(db_xml.bin_files.id==stored_img).select().first()
>
> assert retrieved_img.DATAblob == bin_data # the storage and retrieval 
> worked
>
>
> if __name__ == "__main__":
> testdb()
>
>
2018-05-11 22:50 GMT+02:00 :

> web2py@googlegroups.com
> 
>  Google
> Groups
> 
> 
> Topic digest
> View all topics
> 
>
>- authentiction questions <#m_3708576762426783513_group_thread_0> - 1
>Update
>- link to a grid <#m_3708576762426783513_group_thread_1> - 2 Updates
>- Database question: 60 boolean fields + string:list or all
>string:list? <#m_3708576762426783513_group_thread_2> - 1 Update
>- Unexpected behaviour executing a query with DAL and record
>versioning enabled <#m_3708576762426783513_group_thread_3> - 1 Update
>- Insert data in firebird database
><#m_3708576762426783513_group_thread_4> - 1 Update
>
> authentiction questions
> 
> Dave S : May 11 01:20PM -0700
>
> On Wednesday, May 9, 2018 at 10:20:24 PM UTC-7, Dave S wrote:
> >> out-of-the-box one via default/user.) Sometimes, it works on the first
> >> try.
>
> >> Q1: Why does the login often fail?
>
> No ideas out there?
>
>
> Back to top <#m_3708576762426783513_digest_top>
> link to a grid
> 
> Anthony : May 10 05:06PM -0700
>
> The signature of the URL function is URL(a, c, f). If you pass only two
> arguments, it assumes they are c and f, and if you pass only one, it
> assumes it is f. You passed only 'static/Etichette', so it assumes that is
> the function and therefore uses the current application and controller. It
> should instead be:
>
> URL('static', 'Etichette', args=[row.etichetta])
>
> 'static' is a special value for the controller.
>
> Anthony
>
> On Thursday, May 10, 2018 at 6:59:45 AM UTC-4, Andrea Fae' wrote:
> Andrea Fae' : May 11 10:12AM -0700
>
> ...I'm sorry...it was written in the book!! Sorry...I need to read again
> some parts of the book! Thank you
>
> Il giorno venerdì 11 maggio 2018 02:06:26 UTC+2, Anthony ha scritto:
> Back to top <#m_3708576762426783513_digest_top>
> Database question: 60 boolean fields + string:list or all string:list?
> 
> "Leonel Câmara" : May 11 07:49AM -0700
>
> > On top of that the user will be able to add features not there, in a tag
> cloud format using string:list (I assume that's the best method for
> freeform data of this sort). So for example, you can add tags that say
> 420-friendly or piano
>
> There's your answer. Forget the 60 boolean fields and just have tags.
> Back to top <#m_3708576762426783513_digest_top>
> Unexpected behaviour executing a query with DAL and record versioning
> enabled
> 
> Awe : May 11 07:24AM -0700
>
> Hello Leonel,
> opened this Issue on Mar 14,
> still no one assigned?
> Regards,
> Andreas
>
> Am Freitag, 9. März 2018 16:55:12 UTC+1 schrieb Leonel Câmara:
> Back to top <#m_3708576762426783513_digest_top>
> 

[web2py] Re: authentiction questions

2018-05-11 Thread Dave S


On Wednesday, May 9, 2018 at 10:20:24 PM UTC-7, Dave S wrote:
>
>
> Ooops -- missed the instructions ...
>
> On Wednesday, May 9, 2018 at 4:53:04 PM UTC-7, Dave S wrote:
>>
>> Trying to set up a new user via script, and as usual it isn't going 
>> smoothly.  web2py 2.15.4, fronted by nginx
>>
>> Using adduser script, which I think I got from this group (or maybe from 
>> a pointer Massimo provided):
>>
>>  
>  """
>   Use of this script is like
>
> >>> from gluon.shell import exec_environment
> >>> auth=Auth(db)
> >>> session.db = db
> >>> session.auth = auth
> >>> other=exec_environment('applications/uploafer/scripts/adduser.py', 
> session=session)
>
> """
>
> [ and that should be done in the usual -M -S (interactive) shell]
>
>
>> import gluon.tools
>>
>> auth = session.auth
>> db   = session.db
>> new_user = auth.register_bare(email='easym...@example.com', 
>> password='4mark2easy')
>> print (new_user)
>> if new_user:
>>   new_user.update_record(registration_key='') # This approves the 
>> registration - can be done later
>> db.commit()
>> print (other_stuff_from_auth)
>>
>>
>> This successfully adds a new user, but when  the new user tries to login, 
>> more times than not the result is "invalid login".  (The login form is the 
>> out-of-the-box one via default/user.)  Sometimes, it works on the first 
>> try.
>>
>> Q1:  Why does the login often fail?
>>
>
No ideas out there?  
 

>
>> The script doesn't update an existing user; register_bare() and its 
>> underwiring check for newness (as in !IS_IN_DB()), so it doesn't work as 
>> a reset password tool.  The reset-password-email technique doesn't work 
>> here, because not all of these users have valid email addresses.  I can use 
>> port forwarding to use appadmin, but the server command line is easier 
>> in this setup.
>>
>> Q2:  Is there an easy way to script resetting a user's password?  
>>
>> Some of these accounts should only be used on a short-term basis.  I can 
>> manually reset the password, or delete the user, but I'd like a failsafe 
>> mechanism in case I forget:
>>
>> Q3:  Is there a way to automatically expire a password?
>>
>> I have a function with the @request.restful() decorator; it should 
>> require login as well.
>>
>> Q4: Can I use @auth.requires_login() with @request.restful()
>>
>>
>> Thanks.
>>
>> Dave
>> /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] Re: link to a grid

2018-05-11 Thread Andrea Fae'
...I'm sorry...it was written in the book!! Sorry...I need to read again 
some parts of the book! Thank you

Il giorno venerdì 11 maggio 2018 02:06:26 UTC+2, Anthony ha scritto:
>
> The signature of the URL function is URL(a, c, f). If you pass only two 
> arguments, it assumes they are c and f, and if you pass only one, it 
> assumes it is f. You passed only 'static/Etichette', so it assumes that is 
> the function and therefore uses the current application and controller. It 
> should instead be:
>
> URL('static', 'Etichette', args=[row.etichetta])
>
> 'static' is a special value for the controller.
>
> Anthony
>
> On Thursday, May 10, 2018 at 6:59:45 AM UTC-4, Andrea Fae' wrote:
>>
>> Hello I have a grid with certain fields.
>> In a filed there is a name of a pdf file that I have in the folder 
>> "static/Etichette". I have a lot of pdf file in this folder and I'd like, 
>> when I click this link, to open the related file...
>>
>> This is the grid
>> grid = SQLFORM.grid(db.socio, links = [lambda row: A('Etichetta', 
>> _href=URL('static/Etichette', args=[row.etichetta]))], details=False, 
>> create=False, editable=False, deletable=False, maxtextlength=40)
>>
>> or
>>
>> grid = SQLFORM.grid(db.socio, links = [lambda row: A('Etichetta', 
>> _href=URL("static/Etichette/%s" % row.etichetta))], details=False, 
>> create=False, editable=False, deletable=False, maxtextlength=40)
>>
>>
>> This is the table
>>
>> db.define_table('socio',
>> Field('codice', type='integer', 
>> requires=[IS_NOT_EMPTY()]),
>> Field('cognome', requires=[IS_NOT_EMPTY()]),
>> Field('nome', requires=[IS_NOT_EMPTY()]),
>> Field('intestazione', requires=[IS_NOT_EMPTY()]),
>> Field('dnascita', requires=[IS_NOT_EMPTY()]),
>> Field('indirizzo', requires=[IS_NOT_EMPTY()]),
>> Field('cap', requires=[IS_NOT_EMPTY()]),
>> Field('comune', requires=[IS_NOT_EMPTY()]),
>> Field('provincia', requires=[IS_NOT_EMPTY()]),
>> Field('telefono', requires=[IS_NOT_EMPTY()]),
>> Field('codfisc', requires=[IS_NOT_EMPTY()]),
>> Field('etichetta'),
>> 
>> auth.signature,singular="Socio",plural="Soci",migrate='socio.table',
>> format='%(intestazione)s')
>>
>> How can I do?
>>
>> I have this error
>> invalid function (default/static)
>>
>> Yes...I know that there is something wrong but I don't know in this 
>> moment what...
>>
>

-- 
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: Database question: 60 boolean fields + string:list or all string:list?

2018-05-11 Thread Leonel Câmara
> On top of that the user will be able to add features not there, in a tag 
cloud format using string:list (I assume that's the best method for 
freeform data of this sort). So for example, you can add tags that say 
420-friendly or piano 

There's your answer. Forget the 60 boolean fields and just have tags.

-- 
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: Unexpected behaviour executing a query with DAL and record versioning enabled

2018-05-11 Thread 'Awe' via web2py-users
Hello Leonel,
opened this Issue on Mar 14,
still no one assigned?
Regards,
Andreas

Am Freitag, 9. März 2018 16:55:12 UTC+1 schrieb Leonel Câmara:
>
> This is definitely a bug, the solution doesn't seem easy, The problem is 
> that it should not apply the common filters on the alias used on the left 
> join again as they are already applied on the left join ON query itself. 
>   
> Please file an issue here:
> https://github.com/web2py/pydal/issues
>

-- 
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: Insert data in firebird database

2018-05-11 Thread Константин Комков
That 'example' isn't work too(((. Can anyone advice how can I insert data 
in blob field.
There are one interesting thing. This code is working.
db_xml.define_table('bin_files',
Field('id','integer'),
Field('PARENT'),
Field('SRC_FILENAME'),
Field('DATA', 'blob'),
primarykey=['id','PARENT'],
migrate=False
   )

load_img = db_xml.bin_files.insert(PARENT=entrant_id[0][0],SRC_FILENAME=i.
file,DATA='something')
After this transaction I see 'c29tZXRoaW5n' in database - great!
But when I trying load file it's don't work!
filepath = os.path.join(request.folder,'uploads')
img = db_app(db_app.doc_images.person=='{0} {1} {2}'.format(session.abit_f,
session.abit_i,session.abit_o)).select()
for i in img:
stream=open(filepath + '\\' + i.file, 'rb')
load_img = db_xml.bin_files.insert(PARENT=entrant_id[0][0],SRC_FILENAME=
i.file,DATA=stream.read())
Maybe anyone using Firebird 2.5 or have the same problem? Please, 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.