[web2py] Field.Virtual: unexpected behaviour

2016-05-09 Thread Val K
Hi!
I am angry, I wasted half a day to catch this error:
db.define_table('tbl',
 Field('name'),
Field.Virtual('alias_name', lambda row: row.name) # right 
notation is `row.tbl.name`
)

in controller:

rows = db(db.tbl).select() #it's OK! It doesn't cause any error, it returns 
rows!

#but when you try to:
print rows[0].alias_name   # it causes error, because there isn`t any 
key/attribute 
 like  `alias_name` 

So, how can I detect that error in Field.Virtual?
What happens if for one of the rows  Field.Virtual returns something like 
above? It won't have this field? - yes!

I spent some tests and catch, that:

Field.Virtual('alias_name', lambda row: 1/0) # causes an error when 
select()! - expected
but 
Field.Virtual('alias_name', lambda row: row.
*neverhood_will_be_processed_without_any_errors*) # but row won't have `
*neverhood**...*`






  




 







-- 
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: Field.Virtual: unexpected behaviour

2016-05-09 Thread Val K
all a little differently:
Field.Virtual('alias_name', lambda row: *None*) #- works OK! i.e. 
row.alias_name 
*exists* and row.alias_name == *None*
*but *
Field.Virtual('alias_name', lambda row: row.*bla_bla*) #- causes that row.
alias_name *doesn't* *exist at all!*



On Monday, May 9, 2016 at 7:05:27 PM UTC+3, Leonel Câmara wrote:
>
> Well the thing is 
>
> row.*neverhood_will_be_processed_without_any_errors*
>
> Doesn't cause any error because row just returns None for values that 
> aren't there so the virtual field will just have None as the value. I do 
> agree it is sort of counter-intuitive that you have to be explicit about 
> the table for Virtual fields when you don't have to almost anywhere else.
>

-- 
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: Field.Virtual: unexpected behaviour

2016-05-09 Thread Val K
it seems that `try-except` catches key/attribute error while evaluating 
field.virtual and if it happens  - doesn't create field.virtual at all 

On Monday, May 9, 2016 at 7:17:07 PM UTC+3, Val K wrote:
>
> all a little differently:
> Field.Virtual('alias_name', lambda row: *None*) #- works OK! i.e. 
> row.alias_name 
> *exists* and row.alias_name == *None*
> *but *
> Field.Virtual('alias_name', lambda row: row.*bla_bla*) #- causes that row.
> alias_name *doesn't* *exist at all!*
>
>
>
> On Monday, May 9, 2016 at 7:05:27 PM UTC+3, Leonel Câmara wrote:
>>
>> Well the thing is 
>>
>> row.*neverhood_will_be_processed_without_any_errors*
>>
>> Doesn't cause any error because row just returns None for values that 
>> aren't there so the virtual field will just have None as the value. I do 
>> agree it is sort of counter-intuitive that you have to be explicit about 
>> the table for Virtual fields when you don't have to almost anywhere else.
>>
>

-- 
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: Why is this code for getting variables from view to controller not working?

2016-05-09 Thread Val K
Hi!
*it seems that the error happens in `str(value)`*
*What is your controller like?*





On Monday, May 9, 2016 at 8:58:19 PM UTC+3, Emmanuel Dsouza wrote:
>
> in view: 
>
> *{{extend 'layout.html'}}*
> **
> 
> **
> *function myFunction(){*
> *var value = 22;*
> *ajax('{{=URL('default', 'my_action', 
>  vars=dict(value=str(value)))}}', [], 'target');*
> *}*
> **
>
> **
> *here*
> **
> **
>
> it says:
>  name 'value' is not defined
>

-- 
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: I would like to know how to redirect the url after login

2016-05-10 Thread Val K
Hi!
auth.settings.login_next = *URL(...)*





On Tuesday, May 10, 2016 at 2:50:17 AM UTC+3, cron...@udg.co.cu wrote:
>
> Hello I am new to web2py and I would like to know how to redirect the url 
> after login, so I forwarded to the same home page.
> greetings and thanks in advance
>  
> i found this code in the example app and i dont know what is the needed 
> modification
>
> {{extend 'layout.html'}}
>
> 
> {{=T('Sign Up') if request.args(0) == 'register' else T('Log In') if 
> request.args(0) == 'login' else T(request.args(0).replace('_',
> ' ').title())}}
> 
>
> 
> 
> 
> {{
> if request.args(0)=='login':
> if not 'register' in auth.settings.actions_disabled:
> form.add_button(T('Sign Up'),URL(args='register', 
> vars={'_next': request.vars._next} if request.vars._next else 
> None),_class='btn btn-default')
> pass
> if not 'request_reset_password' in 
> auth.settings.actions_disabled:
> form.add_button(T('Lost 
> Password'),URL(args='request_reset_password'),_class='btn btn-default')
> pass
> pass
> =form
> }}
> 
> 
> 
>
>
> {{block page_js}}
> 
> jQuery("#web2py_user_form input:visible:enabled:first").focus();
> {{if request.args(0)=='register':}}
> web2py_validate_entropy(jQuery('#auth_user_password'),100);
> {{elif request.args(0)=='change_password':}}
> web2py_validate_entropy(jQuery('#no_table_new_password'),100);
> {{pass}}
> 
> {{end page_js}}
>
>  
>

-- 
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: Very simple issue: redirect on login - auth.settings.login_next

2016-05-26 Thread Val K
Hi!
As I understand *requires() * designed to decorate and *back* redirection 
after  login, so it ignores  *auth.settings.login_next *

If you want to redirect after login just do it from your *check_condition()* 
directly 
 






On Thursday, May 26, 2016 at 5:15:15 PM UTC+3, 黄祥 wrote:
>
> follow the instruction is working well, thank you, but when i tried to add 
> the condition it didn't work.
> e.g.
> *controllers/default.py*
> *"""*
> *not work because of this*
> *def check_condition(): *
> *auth.settings.login_next = URL('user/profile')*
>
> *if request.function != 'user':*
> *auth.requires_login()(lambda: check_condition() )()*
> *#auth.settings.login_next = URL('user/profile')*
> *"""*
>
> def user(): 
> return dict(form=auth())
>
> any idea how to achieve it using web2py way?
>
> thanks and best regards,
> stifan
>
> On Monday, November 10, 2014 at 11:10:14 AM UTC+7, WhoSoLovesUs wrote:
>>
>> PS
>>
>> ... Glad to find this though at least, and thank you to everyone involved 
>> in the thread!
>>
>> I am a beginning user, and I'm starting at the beginning of my app's most 
>> fundamental needs (in this case of course, logging in, and what a user will 
>> see when they do so)
>>
>>
>> On Thursday, December 6, 2012 7:06:14 AM UTC-8, Kostas M wrote:
>>>
>>> Peter, I agree with you 100% regarding the ambiguous documentation, and 
>>> the lost time back and forth, among google searches and source code 
>>> reading...  I am one of them!
>>>
>>> Kostas
>>>
>>>  
>>>
 'These must point to the URL you want to redirect your users to after 
 the various possible auth actions (in case there is no referrer): '

 This is an example of documentation that can only be understood by the 
 person who wrote it, or other people who already know the answer.

 I expect everyone new to this expects setting 
 auth.setting.register_next to a URL will cause the redirection. They all 
 then find out  the hard way it does not work. Trawl through the forums and 
 try various things until coming up with a solution. I wonder how much time 
 has been wasted on this (and the login_next etc).

 Peter

>
>

-- 
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: readonly field only in SQLFORgrid edit page if field is not empty

2016-05-26 Thread Val K
Where and how can I set the db.foobar.text.writable = False?


request.args(1) = 'edit'


On Thursday, May 26, 2016 at 12:46:45 PM UTC+3, Mike Constabel wrote:
>
> Hello,
>
> I try to find a solutiuon for a hopefully simple problem.
>
> Example:
>
> db.define_table("foobar",
>   Field("uuid", "string"),
>   Field("text", "string"),
>   Field('created_on', "datetime", default=request.now))
>
> def list_order_type():
> form = SQLFORM.grid(db.foobar)
> return dict(form=form)
>
> I need that in the edit page of the grid the field "text" is readonly if 
> the field "text" is not empty and the "created_on" timestamp id older than 
> an hour.
>
> Where and how can I set the db.foobar.text.writable = False?
>
> I can use request.args(1) = 'edit', but how can I then take the row, test 
> it and set the writable to false?
>
> I don't want to validate after sending the form. The input field should be 
> initially readonly.
>
>
> Regards,
> Mike
>
>

-- 
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: Append fields within form, iteratively add fields inside form, List:string append, custom forms

2016-05-31 Thread Val K
Hi!
Try this

controller:

def create_table():
a_list = 'My skills and experience:'
form1 = SQLFORM(db.Project, hidden=dict(add_term_f1=''))
form2 = SQLFORM(db.add_list_item, submit_button=' + Add', 
hidden=dict(add_term_f2=''))
request.post_vars.added_term = request.vars.add_term_f1  and 
 request.vars.add_term_f1.split(',')
form1.process()
form1.element('input[type=submit]')['_id']='f1_submit'
form1.element('input[type=submit]')['_style']='display:none'
if not form1.accepted:
form2.process()
form2.element('input[type=submit]').update(_class='btn btn-custom')
lst=''
if form2.accepted:
a = db(db.add_list_item.id == form2.vars.id).select().first()
skills = db(db.teaching.id == a.skill_list.id).select().first()
experience = db(db.Experience.id == 
a.Experience_list.id).select().first()
skill_and_experience = skills.teach_string+':' +''+ 
experience.Experience_level
lst = request.vars.add_term_f2 and 
request.vars.add_term_f2.split(',') or []
lst.append(skill_and_experience)
lst_str =   ','.join(lst)
form2.custom.end.element('[name=add_term_f2]')['_value'] = lst_str
form1.custom.end.element('[name=add_term_f1]')['_value'] = lst_str
response.flash = T("Added Experience")
if form1.accepted:
response.flash = T("success!")

return dict(form1 = form1, form2 = form2, a_list = a_list, lst=lst)



view:

{{extend 'layout.html'}}
{{from gluon.html import * }}



{{=form1.custom.begin}}



{{=form1.custom.widget.Title}}
 
{{=form1.custom.end}}
{{=form1.custom.submit}}

{{=form2.custom.begin}}

{{=a_list}}
{{=lst}}




  
  
 
   {{=form2.custom.widget.skill_list}}   
   
{{=form2.custom.widget.Experience_list}}   
  
 
   {{=form2.custom.submit}}
  


 


{{=form2.custom.end}}
  
{{=BUTTON('Submit', _class='btn', _type='button', 
_onclick="$('#f1_submit').click()" )}} 


 
  






.input-title{
height: 100px;
width: 400px;
}

#add_list_item_skill_list{
 width: 200px;
} 
#add_list_item_Experience_list{
 width: 200px;
} 


.btn-custom { text-align:right;color: blue;width:50px; 
padding:20%;position: relative;top: -4px;left: 4px;height 20px;}   





On Saturday, May 28, 2016 at 12:22:16 AM UTC+3, Ron Chatterjee wrote:
>
> Running into some issues and hoping community help out with thoughts. How 
> do I append to list:string and using form inside a form (custom form). 
>
> Question: How do I append skill_and_experience  as a list:string into the 
> field added_term as 'English': '1 year', 'Math':'2 years',...etc. 
>
> May be there is a better way to do this, but this is how I started out 
> with. 
>
>
> *Model.py:*
>
> db.define_table( 'Experience',Field('Experience_level'), format = 
> '%(Experience_level)s')
> db.define_table( 'teaching',Field('teach_string'), format = 
> '%(teach_string)s')
>
>
> db.define_table( 'add_list_item',
> Field('skill_list', db.teaching, label='Enter Your Skills 
> sets', comment = 'Enter skills'),
> Field('Experience_list', db.Experience, label='Enter Your 
> Experience',  comment = 'Enter years'))
> 
>
> db.define_table( 'Project', 
> Field("Title", "string", 
> requires=IS_NOT_EMPTY(),default=None),
> Field("added_term", "list:string", 
> requires=IS_NOT_EMPTY()),)
>
>
>
> *Controller:*
> def create_table():
> a_list = 'My skills and experience:'
> skill_and_experience = [];
>  
> form1 = SQLFORM(db.Project)
> form2 = SQLFORM(db.add_list_item, submit_button=' + Add',).process()
> form2.element('input[type=submit]').update(_class='btn btn-custom')
> 
> if form2.accepted:
> a = db(db.add_list_item.id == form2.vars.id).select().first()
> skills = db(db.teaching.id == a.skill_list).select().first()
> experience = db(db.Experience.id == 
> a.Experience_list).select().first()
> skill_and_experience = skills.teach_string+':' +''+ 
> experience.Experience_level
> added_term.append(skill_and_experience)
> response.flash = T("Added Experience")
> 
> if form1.accepted:
> response.flash = T("success!")
> 
> return dict(form1 = form1, form2 = form2, a_list = a_list)
>
>
> *View:*
>
> {{extend 'layout.html'}}
>
> 
>
> {{=form1.custom.begin}}
>
>
> 
> {{=form1.custom.widget.Title}}
>  
> 
> {{=form2.custom.begin}}
>
> {{=a_list}}
>
>
>
> 
> 
>   
>   
>  
>{{=form2.custom.widget.skill_list}}   
>
> {{=form2.custom.widget.Experience_list}}   
>   
>  
>{{=form2.custom.submit}}
>   
> 
> 
>  
> 
> 
> {{=form2.custom.end}}
>   
>  {{=form1.custom.submit}}
> 
> 
>  
>   
> 
> 
> {{=form1.custom.end}}
> 

[web2py] update_or_insert and keyed tables

2016-10-06 Thread Val K
it seems, that *update_or_insert*  doesn't work with keyed tables,  because 
it uses *update_record* method ... It's a pity.

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

2016-10-06 Thread Val K
Glad to help you, but there isn't any code

On Thursday, October 6, 2016 at 12:47:36 AM UTC+3, 
argenio...@metamaxzone.com wrote:
>
> 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.


[web2py] Re: validate_and_insert() doesn't work for compute field

2016-10-06 Thread Val K
Yes, it's a bug:
*validate_and_insert* calls *_validate_fields*  that fills  fields with 
default values (all table fields!), so for 'y' it's *None *
from book:
" *if a value for the field is not provided*, web2py tries to compute from 
the other field values using the compute function"
but it's provided and set to* None* by  *_validate_fields!*


On Thursday, October 6, 2016 at 3:41:12 PM UTC+3, Yang wrote:
>
> OK, I packaged it. 
>
> model/test.py
> db.define_table('test',
> Field('x', 'float'),
> Field('y', 'float', compute=lambda r: r['x'] * 2))
>
> controller/default.py
> def index():
> db.test.validate_and_insert(x=1)
> db.test.insert(x=1)
> result_validated = db.test(1)
> result_insert = db.test(2)
> return locals()
>
> views/default/index.html
> {{=result_validated}}
> {{=result_insert}}
>
> The output:
>  
>
> 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.


[web2py] pair small bugs

2016-10-07 Thread Val K
1.  Trying to change 'notnull' of field that is *'reference ...'*  hasn't 
any effect at DB-level, i.e. you can set 'notnull'  (False or True) only 
once, migrate doesn't do the job  -  no error and no effect
2.  Trying to change 'notnull' of *any* field of table with *rname* causes 
an error, because  *rname is ignored *while migrate

tested with Postgres

-- 
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: pair of small bugs

2016-10-08 Thread Val K
Thank you,  Anthony!
But I think, that this fact ( web2py does not migrate changes in 
attributes) makes web2py  unsuitable for db-schema development, i.e. I have 
to consider all the details and write  holy code at once.
The situation gets worse by the fact that migrate is only half-migrate 
without any warnings - it  may be  better to have a log-file with something 
like "table ... was migrated,  but attributes .. were not changed "
It would be nice to have  something like DAL-construction-mode,  when 
changing tables definition causes dropping  all tables  (except auth_* ) 
 and recreating  from scratch 




On Saturday, October 8, 2016 at 4:43:58 PM UTC+3, Anthony wrote:
>
> From the book:
>
> Notice that web2py only migrates new columns, removed columns, and changes 
>> in column type (except in sqlite). web2py does not migrate changes in 
>> attributes such as changes in the values of default, unique, notnull, 
>> and ondelete.
>>
>
> In particular, when adding "notnull", you must first replace any existing 
> null values with something, and the DAL wouldn't know what value to use 
> (though I suppose it could assume the "default" value if one has been set). 
> Similarly for adding "unique", you must first resolve any existing 
> duplicates.
>
> 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: PostGreSQL views

2016-10-12 Thread Val K
Hi!
I use PG views quite often. Common problem is related to permissions: don't 
forget to grant privilege to web2py login role for select/reference from/to 
your handmade views. 
To define view I use db.base_table.field.clone()  - undocumented function
For example:
#definition base table
define_table('person', Field('name', represent=..., requires=..., required=
True, ...  ) )


#definition of view or just another table
define_table('sale_vw',  
   db.person.name.clone(name = 'seller_name'), # so, 
 db.sale_vw.seller_name  inherits all attrs (represent and so on ) from 
 db.person.name
   db.person.name.clone(name = 'buyer_name'), 
...
)


  



On Wednesday, October 12, 2016 at 4:54:41 AM UTC+3, Jamie Courtes wrote:
>
> Hi All,
>
> I'm working with a colleague who is in the process of learning web2py.
>
> In parallel, I have developed a relatively simplistic database in 
> PostGreSQL, with approximately a dozen tables.
>
> We've managed to get the database into web2py, and can view each of the 
> tables (and their data) in the web interface.
>
> The problem comes when trying to get data from my master view which I 
> created within the database, which joins various fields from the many 
> tables.
>
> The view works fine in pgadmin/sqlmanager, and it's simple enough that I 
> am 100% confident in my view code, but it gives me errors in the web2py 
> console when trying to view the results of the view:
>
> Before I post any error messages, I wanted some guidance on the 'right' 
> way to do this. Should I be using views with web2py? Should the same 
> functionality a view provides, be created in the web2py code rather than a 
> database view?
>
> Looking for the best way to do this, since I am unsure if using a database 
> view is even the correct way...
>
> Thanks for your time!
>
> Jamie
>
>

-- 
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: nested loops in views

2016-10-14 Thread Val K
just keep in mind simple rule:  {{pass}} == anti-indent 

On Friday, October 14, 2016 at 7:24:11 PM UTC+3, Pierre wrote:
>
> Hi,
>
> why is this not working ?
>
> {{extend 'layout.html'}}
> {{ d={'a':[1,2],'b':[3,4]} }}
> 
> {{for k,v in d.items():}}{{=k}}{{pass}}
> {{for vi in v:}}{{=vi}}{{pass}}
> 
>
>
>

-- 
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: Referencing another table

2016-10-14 Thread Val K

'reference bursary_users' and requires = [IS_IN_DB(db, 'bursary_users
.barcode')]  - I think, that  it's mutually exclusive requirements 
'reference bursary_users' == requires = IS_IN_DB(db, 'bursary_users.*id*')







On Friday, October 14, 2016 at 6:21:38 PM UTC+3, James Booth wrote:
>
> Hey guys,
>
> Excuse me if I'm missing something (or a lot), but I'm pretty experienced 
> with web2py.
>
> I have the following defined in my model:
>
> db.define_table('bursary_users',
>> Field('forename', type='string', requires=IS_NOT_EMPTY()),
>> Field('surname', type='string', requires=IS_NOT_EMPTY()),
>> Field('studentId', type='string', 
>> requires=IS_NOT_EMPTY(), unique=True),
>> Field('barcode', type='string', requires=IS_NOT_EMPTY(), 
>> unique=True),
>> Field('email', type='string', requires=IS_EMAIL(), 
>> unique=True),
>> Field('bursary', requires=IS_IN_SET(['Free school 
>> meals','Bursary','Disabled'])),
>> Field('notes', type='text'),
>> format='%(studentId)s'
>> )
>> db.define_table('bursary_entries',
>> Field('barcode', 'reference bursary_users', requires = 
>> [IS_IN_DB(db, 'bursary_users.barcode')]),
>> Field('entry_date', type='datetime', default=request.now, 
>> readable=False, writable=False),
>> format='%(barcode)s'
>> )
>
>
> When I use the SQLFORM on a page, I can enter a barcode and it validates 
> it (Fails if not in bursary_users, pass if it is). However, when I come to 
> check the database, I'm getting a '0' (Althought it is hyperlinked to 
> nothing) for the barcode value and a correct value for the entry_date.
>
> Any ideas why this is happening?
>
> Kind regards,
> James. 
>

-- 
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 create a search field(while typing display suggested pages)

2016-10-14 Thread Val K


web2py has SQLFORM.widgets.autocomplete, but you  can try chosen.js 



On Wednesday, October 12, 2016 at 4:55:46 AM UTC+3, sanjana chowdary wrote:
>
> please help me
>

-- 
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: Referencing another table

2016-10-15 Thread Val K
Keep in mind, that 
'reference ' - realized at DB-level as FK-constraint, web2py allows to 
define reference to PK only (you try to refer to not-PK field) 
requires=...   - just web2py validator  and has no effect on underlying DB 
and there isn't an autovalidation of DB manipulation from code (except 
form.process()/validate()/accepts() ).  I mean  db.bursary_entries.insert( 
barcode  = 'invalid value') - doesn't cause any error


On Saturday, October 15, 2016 at 1:14:13 PM UTC+3, James Booth wrote:
>
> Okay, that seems to work fine, I guess I just tried to implement into 
> incorrectly. Thanks for your 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.


Re: [web2py] Re: Referencing another table

2016-10-15 Thread Val K
If you want to have strict DB-constraints, you can: 

db.define_table('barcode',
Field('code', type='string', unique=True, notnull=True), #  
*consider 
just 'code', not 'barcode'* - it's necessary to prevent possible 
hard-to-catch bugs during SQLFORMs processing   
format='%(code)s'
)

db.define_table('bursary_users',
 ...
Field('barcode', type='reference barcode', notnull=True, 
unique=True),
 ...)

db.define_table('bursary_entries',
db.bursary_users.barcode.clone(), # - .clone() is 
undocumented, but why?   
Field('entry_date', type='datetime', default=request.now, 
readable=False, writable=False),
format='%(barcode)s'
)

#be careful - *above code could break your existing db-tables  *

# this solution require additional logic to process insert in bursary_
users,  look for   One form for multiple tables   

def new_user():

   #this would be invoked before insert in  db.bursary_users
   def reg_bar_code(form):
   new_code = form.vars.pop('code', None) #get user input for 
 db.barcode.code
   #any additional logic goes here
   form.vars.barcode =  db.barcode.insert(code = new_code)  # returns 
id of  new_code
# so, form.vars.barcode would be used to  insert in  db.bursary_
users.barcode

   db.bursary_users.barcode.writable = False  
 db.barcode.code.label  = 'barcode'  # 
   form=SQFORM.factory(db.barcode, db.bursary_users) 
   if form.process(onvalidation = reg_bar_code).accepted:
 db.bursary_users.insert(**db.bursary_users._filter_fields(form.
vars))
   







On Saturday, October 15, 2016 at 5:08:13 PM UTC+3, James Booth wrote:
>
> Ah okay. It should only be done via. A validated form anyway but I see the 
> potential risk. Is the other option to set the barcode as the PK in my 
> bursary_users table and 'reference' it?
>

-- 
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: No module named appname.modules.funtions

2016-10-31 Thread Val K
Be beware:
I had the same bug (No module named appname.modules.func) on windows binary 
web2py, but with weird behaviour:
if server is local - everything OK
if server is public, but request is local - everything OK
if server is public and request isn't local  -  causes an error

the reason is CAPITAL letters in directory names, i.e. in the case `MY_app` 
 it should be  exactly   `form applications.MY_app.modules...` 

  



On Tuesday, May 24, 2016 at 11:42:34 PM UTC+3, Hi Toni wrote:
>
> It seems that you are missing an (empty) file*: *
> web2py/applications/appname/modules/*__init__.py*
>
> https://docs.python.org/2/tutorial/modules.html#packages
>
>
>
>
> Am Sonntag, 22. Mai 2016 14:28:38 UTC+2 schrieb BlueShadow:
>>
>> Hi,
>> Something is very wrong with my web2py. I finally got the newest verion 
>> (2.14.6  nginx/1.4.6, Python 2.7.6 Ubuntu 16.04) on my production 
>> server. and the welcome app is running fine. when I want to use my 
>> application it creates a ticket for basically every inport:
>> Movie_Alarm.modules.plugin_multiselect_widget
>> I uncommented the multiselect plugin and I got the next:
>> No module named appname.modules.func
>> ...
>> and so on the files are in web2py/applications/appname/modules or plugins 
>> respectively. I can open them with the webinterface. So I got no clue whats 
>> going on.
>> thanks for your help and suggestions
>>
>

-- 
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: Starting scheduler worker from controller

2016-11-17 Thread Val K
I start scheduler as Linux daemon,it works fine. Can you do that?

On Thursday, November 17, 2016 at 7:41:28 PM UTC+3, Gael Princivalle wrote:
>
> Hello.
>
> Is it possible to run a scheduler worker from a controller?
> Restarting a server kill all workers. I would like to run my workers 
> automatically if the last heartbeat is old.
>
> The standard way is going to ssh and running :
>
> nohup python web2py.py -K application_name &
>
>
> I would like to have in a controller:
>
> def run_worker():
> something('nohup python web2py.py -K application_name &')
>
>
> 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.


[web2py] Re: What a good web2py application architecture looks like?

2016-11-17 Thread Val K
BO seems like stored procedures that expose secure interface to DB, but if 
it is your aim I think it would be better and more universal to have pure 
stored procedures at DB-side, no?

On Thursday, November 17, 2016 at 3:02:19 PM UTC+3, mfarees...@gmail.com 
wrote:
>
> Hi,
> I need some help from experienced web2py developers and creators. I am 
> creating a new application and would like to know what a good architecture 
> for a web2py application looks like. Here is the architecture diagram of 
> the past web2py projects I have worked on.
>
>
> 
>
>
> Thin controllers and thick models is how I'm thinking of proceeding. The 
> controllers talk to the database only via Business Objects (BO). Only BOs 
> can access the database. There is a separate folder for the BOs inside the 
> modules folder.
>
> app_name -> modules -> businessObjects -> DALs -> DalOfBO
>
> Each BO file contains a class for that BO and some methods. Should the 
> methods have database queries in the same file or should there be a 
> different file for the DAL operations, for each BO?
> Is this structure appropriate? If not, how can I make it better in order 
> to make the development and maintenance of code easier.
> 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.


[web2py] Re: Why is this query not giving me the correct set of rows as expected?

2016-11-24 Thread Val K
Field('userid') means type 'string', but auth.user_id is integer - does 
your query work without second condition?

On Thursday, November 24, 2016 at 6:21:02 PM UTC+3, Mike Stephenson wrote:
>
>  request.args[0] is just a number representing a day. What's wrong here?
>
> On Thursday, November 24, 2016 at 7:14:55 PM UTC+5:30, Marlysson Silva 
> wrote:
>>
>> what is request.args[0] ? a datetime?
>>
>> Em quinta-feira, 24 de novembro de 2016 08:38:29 UTC-3, Mike Stephenson 
>> escreveu:
>>>
>>> rows=db((str(db.emeter.instant.month) == str(request.args[0])) & 
>>> (db.emeter.userid==auth.user_id) ).select()
>>>
>>>
>>> emeter:
>>>
>>> db.define_table('emeter',
>>> Field('userid'),
>>> Field('instant', 'datetime', 
>>> default=request.utcnow+datetime.timedelta(0,19800), writable=False, 
>>> readable=False),
>>> Field('reading')
>>> )
>>>
>>>
>>> it gives me no value instead of the correct set. What's wrong here.
>>>
>>

-- 
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] improving DAL for normalized DB

2016-12-08 Thread Val K
It doesn't differ from reference fields. it is about automation distributed 
transaction. 
Table 'person' hasn't Field('alias_name' ) at db level, it's fake Field 
with reverse reference declaration ( 'storedin alias_opt.alias_name' ) that 
defines table.field that would be really involved in CRUD-process of table 
'person'

On Wednesday, December 7, 2016 at 5:29:28 AM UTC+3, Dave S wrote:
>
>
> On Tuesday, December 6, 2016 at 3:41:38 PM UTC-8, Richard wrote:
>>
>> UP, never get any answer...
>>
>
> How would this differ from reference fields?
>
> /dps
>  
>
>>
>> On Sat, Jan 23, 2016 at 4:08 PM, Val K  wrote:
>>
>>> Hi guys!
>>> I have an idea to improve DAL in scope of work with normalized DB.
>>> As known It's a common practice to avoid NULL value by creating separate 
>>> (option) table(s) to store non required fields.  
>>> So, it would be great to have a field type like "storedin 
>>> table_name.field_name" 
>>> For example:
>>>
>>> db.define_table('alias_opt', Field('name'),  Field('alias_name', 'reference 
>>> person'))
>>> db.define_table('person', Field('name'),  Field('alias_name', 'storedin 
>>> alias_opt.alias_name'))
>>>
>>> #INSERT:
>>> db.person.insert(name='Alex',  alias_name='Macedonian') 
>>> # means:
>>>id=db.person.insert(name='Alex')
>>>db.alias_opt.insert(id=id, alias_name='Macedonian')  
>>>
>>> #UPDATE:
>>> db(db.person.id==id).update(... , alias_name=None)
>>> # means:
>>>   # update person
>>>   ...
>>>   # update option  table
>>>   update_opt_args = filter_storedin_fields(update_args) 
>>>   opt_rec =  db.alias_opt(id)
>>>   opt_rec.update(update_opt_args)
>>>   if not any(opt_rec.values()): # -  all fields of option table record 
>>> is None
>>>  del  db.alias_opt(id)  
>>> else:
>>>  db.alias_opt.update_or_insert(id==id,   **update_opt_args)
>>>
>>> #DELETE:
>>> del db.person(id)  also means   del db.alias_opt(id),  like ondelete=
>>> 'CASCADE'
>>>
>>> #SELECT:
>>> rows = db(db.person).select()
>>> # means:
>>>  rows = db(db.person).select( left=[ db.alias_opt.on( db.alias_opt.id == 
>>> db.person.id ) ] )
>>> but only "storedin" fields should be selected from  db.alis_opt 
>>> and they should be accessed by row.alias_name (not only by row.
>>> joined_table.field_name )
>>>
>>> Considering, that table person could be a VIEW (i.e. JOIN is already 
>>> performed at DB level),  there is no need to make join at web2py level,
>>> it could be fixed by passing an option arg like is_view=True to 
>>> define_table() 
>>> I know, that behavior of insert/update/delete could be easy realized by 
>>> custom class based on Table 
>>> with a little hacking Field-class to intercept field type to fix it to 
>>> web2py type ( considering  person.alias_name.type == 
>>> alias_opt.alias_name.type ).
>>> But it's hard for me to change select() behavior, because there is only 
>>> common_filter, but  there isn't  common_join/common_left with providing of 
>>> maping (aliasing) joined table  fields  to  'storedin' fields. 
>>>
>>> In fact, I dream of common_join depends on discriminator field, that 
>>> will switch tables to be joined depend on discriminator value specified in 
>>> the query (something like db.object.type_id==type_id),
>>> if descriminator is not specified or couldn't be resolved at web2py 
>>> level, it performs left join all tables (from a list containing possible 
>>> common_join tables)
>>>
>>> P.S. May be I try to reinvent the wheel, so feel free to shoot me!
>>>
>>> -- 
>>> 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.


[web2py] Re: Web2py multiple table joins

2016-12-09 Thread Val K
Maybe try to replace db.auth_user.id  with  auth.user.id or just 
auth.user_id 

On Friday, December 9, 2016 at 9:13:27 AM UTC+3, mfarees...@gmail.com wrote:
>
> Hi
> I want to write a query in web2py. The purpose of this query is to return 
> all users that belong to a user group specified in the query. The 
> additional data I want with each user is his organization (if any), 
> managing_countries (if any), and shops (if any). Note that a user might 
> *either* own a shop or work in an organization, but not both. A person 
> working in an organization will also have a record in the 
> managing_countries table.
> Here is an ERD:
>
>
> 
>
>
> I wrote a query but I did not get the desired results. It is returning 
> data even when it is not present, so I think a left outer join is required 
> here.
>
> auth_managing_countries = db(db.managing_countries.user_id == 
> auth.user.id).select().first().countries
> user_role_clause = ((db.auth_group.role == UserGroups.employee) |
> (db.auth_group.role == UserGroups.owner))
> auth_id_clause= user_role_clause &
> (db.auth_group.id == db.auth_membership.group_id) &
> (db.auth_membership.user_id == db.auth_user.id)
> managing_countries_clause = (db.managing_countries.user_id == 
> db.auth_user.id) &
>   
> (db.managing_countries.countries.belongs(auth_managing_countries))
> shop_country_clause = ((db.shop.country.belongs(auth_managing_countries)) &
>(db.user_shop.shop_id == db.shop.id) &
>(db.user_shop.user_id == db.auth_user.id))
> query = auth_id_clause & managing_countries_clause | shop_country_clause
> db(query).select()
>
> 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] improving DAL for normalized DB

2016-12-09 Thread Val K
Thank you for your reply, Richard!
" a normalized way to represent web2py list:reference field with a proper 
many-to-many relation table " - yes! this is what I meant, 'alias_name' - 
just very bad example of field name  - it isn't about aliasing  - sorry for 
the mess

About views
I think I found the acceptable way (for me at least) that is:
1. Get query string by   _select()
2. Search string  and add aliases to  fields  (if required) 
3. Wrap string in  "CREATE VIEW ... AS ..." and  create view at db level by 
 db.executesql(  ) 
4. Define corresponding table for created view using 
 db.some_table.any_field.clone(name = alias_for_some_table_any_field) 

all  could be wrapped in the  function( view_query, alias_map) 
Parsing sql string (item 2) is not a better way,  but DAL doesn't support 
aliases for fields :(

P.S. db.table.field.clone() - very useful function, but still undocumented






On Friday, December 9, 2016 at 4:31:48 AM UTC+3, Richard wrote:
>
> Hello Val K,
>
> I am not sure I understand fully what your are talking about. On one hand, 
> I do understand that you would like a proper way to define SQL VIEW in 
> web2py and you propose to add a switch/flag/argument to define_table() to 
> do so, which would result in a select only table or something like that... 
> It could make sens, but I am not sure it would be accept base on my 
> experience it wouldn't pass as it seems a bit hacky and Massimo would not 
> implement it that way in DAL... Actually, I think there is no proper way to 
> implement view in DAL, and it a shame (we could have care more and answer 
> this need) that we don't have it... But you can define a view as a table in 
> web2py and use all the available feature regarding selection with this 
> "false" table (except create/read/update/delete obviously). You can also, 
> write a plain SQL SELECT and embeded it into a db.executesql() function. 
> Disavantage of the later method is that you can't access field with dot 
> notation db.table_name.field_name as web2py doesn't know about field and 
> even table name in this case, as db.executesql() return rows...
>
> On the other hand, I heard you talk about "storedin" field and aliasing 
> but I don't really understand to which common pratice you refer there... 
> Are you talking of a normalized way to represent web2py list:reference 
> field with a proper many-to-many relation table or are you talking about 
> something else? Which level of normalization are you trying to achieve with 
> aliasing and storedin... I don't understand what you refering to here.
>
>
> Thanks
>
> Richard
>
> On Thu, Dec 8, 2016 at 5:49 PM, Val K > 
> wrote:
>
>> It doesn't differ from reference fields. it is about automation 
>> distributed transaction. 
>> Table 'person' hasn't Field('alias_name' ) at db level, it's fake Field 
>> with reverse reference declaration ( 'storedin alias_opt.alias_name' ) that 
>> defines table.field that would be really involved in CRUD-process of table 
>> 'person'
>>
>> On Wednesday, December 7, 2016 at 5:29:28 AM UTC+3, Dave S wrote:
>>>
>>>
>>> On Tuesday, December 6, 2016 at 3:41:38 PM UTC-8, Richard wrote:
>>>>
>>>> UP, never get any answer...
>>>>
>>>
>>> How would this differ from reference fields?
>>>
>>> /dps
>>>  
>>>
>>>>
>>>> On Sat, Jan 23, 2016 at 4:08 PM, Val K  wrote:
>>>>
>>>>> Hi guys!
>>>>> I have an idea to improve DAL in scope of work with normalized DB.
>>>>> As known It's a common practice to avoid NULL value by creating 
>>>>> separate (option) table(s) to store non required fields.  
>>>>> So, it would be great to have a field type like "storedin 
>>>>> table_name.field_name" 
>>>>> For example:
>>>>>
>>>>> db.define_table('alias_opt', Field('name'),  Field('alias_name', 
>>>>> 'reference 
>>>>> person'))
>>>>> db.define_table('person', Field('name'),  Field('alias_name', 'storedin 
>>>>> alias_opt.alias_name'))
>>>>>
>>>>> #INSERT:
>>>>> db.person.insert(name='Alex',  alias_name='Macedonian') 
>>>>> # means:
>>>>>id=db.person.insert(name='Alex')
>>>>>db.alias_opt.insert(id=id, alias_name='Macedonian')  
>>>>>

[web2py] Re: Best way to validate individual conditional Smartgrid Forms

2017-01-20 Thread Val K
Yes! just keep in mind, that *before *call  SQLFORM.grid/smartgrid/factory 
or just SQLFORM or even FORM ( learn two  latter details) you can:
1. modify request.vars as you want:  request.vars.fieldC='smthng not none'
2. modify fields properties:  if request.vars.fieldA: 
 db.table.fieldC.required=False
3. have total control on the form using `formargs`: 
SQLFORM.smartgrid(formargs={'vars':myvars}) 
 

On Wednesday, January 18, 2017 at 9:19:55 AM UTC+3, LoveWeb2py wrote:
>
> Hello,
>
> I've been trying to string together pieces from the book and multiple 
> forums for working with the SmartGrid edit forms and I'm not sure the best 
> way to validate certain fields...
>
>
> I am currently using jQuery to hide fieldA if fieldB is selected, but I am 
> running into an error with web2py...
>
> Let's say FieldC is required and Field A are required...
>
> If FieldA is shown, and I submit the form then I get an error because 
> fieldC is empty.
>
> I was looking at the onvalidation method for sqlform.smartgrid, but I'm 
> not quite sure how to apply it or if it's necessary here.
>
> Here is my code:
>
> 
> $(document).ready(function(){
> $("select").change(function(){
> $(this).find("option:selected").each(function(){
> if($(this).attr("value")=="value1"){
> $("#table_fieldA__row").hide();
> $("#table_fieldB__row").hide();
> $("#table_fieldC__row").show();
> }
> else if($(this).attr("value")=="value2"){
> $("#table_fieldA__row").show();
> $("#table_fieldB__row").show();
> $("#table_fieldC__row").hide();
>
>
> }
> else{
> $("#table_fieldA__row").hide();
> $("#table_fieldB__row").hide();
> $("#table_fieldC__row").hide();
>
> }
> });
> }).change();
> });
> 
>
> Is there something I could be doing better inside the controller or 
> smartgrid?
>
> grid = SQLFORM.smartgrid(table.field, onvalidation=source_validate, 
> maxtextlength=100)
> if grid.create_form:
> if grid.create_form.errors:
> response.flash = "Error... please check form"
> elif grid.update_form:
> if grid.update_form.errors:
> response.flash= "Error... 3"
> else:
> return dict(grid=grid)
> return dict(grid=grid)
>
> def source_validate(form):
> #print "In onvalidation callback"
> #print form.vars
> form.errors = True  # this prevents the submission from completing
>
> # ...or to add messages to specific elements on the form
> form.errors.fielda = "Must specify a value!"
> form.errors.fieldb = "Please select a value2"
> form.errors.fieldc = "Must not be empty!"
>
> Thank you for your 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] Re: Form field defaults the second time through

2017-01-20 Thread Val K
form.vars appear only after form.process()  call (process() - 
filter/convert/format/validate request.vars to form.vars)
you have variants :
1. *before *form creation  - modify field.default
2. *before* form.process()  -  modify request.vars - 
request.vars.PostDate=... 
3. pass your own set of vars  -  form.process(vars=myvars)
4. use form.process( onvalidation=myvalidation_fun) to modify form.vars  *after 
*basic validation passed
 

On Thursday, January 19, 2017 at 10:31:15 PM UTC+3, Dave S wrote:
>
>
> I have a straight-forward controller function for entering the primary 
> data:
>
> def index():
> """
> """
> response.flash = T("Hello World")
> form = SQLFORM(db.QuarterMaster)
> form.vars.PostDate = str(request.now.year) + "-" + str(request.now.
> month) + "-" + str(request.now.day)
> if form.process().accepted:
> form.vars.PostDate = request.vars.PostDate
> response.flash = T("Thank you!")
> elif form.errors:
> response.flash = T("Please correct the errors in the form")
> else:
> response.flash = T("Please fill out the form")
> return dict(form=form)
>
>
> The intial display of the form shows the current date correctly (give or 
> take a leading 0), but after submission the PostDate field is empty.  I 
> would like to have it default to what was used the previous time through, 
> but it appears that value is dropped after the accepted branch.  What do I 
> need to do?
>
> It does not work to replace the top part with:
>
> form = SQLFORM(db.QuarterMaster)if request.vars.PostDate:
>   form.vars.PostDate = request.vars.PostDate
> else:
>   form.vars.PostDate = str(request.now.year) + "-" + str(request.now.
> month) + "-" + str(request.now.day)
> if form.process().accepted:
> # here was form.vars.PostDate = request.vars.PostDate
>
> 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: Advice on structuring my app

2017-01-21 Thread Val K
Hi, here is my solution:
There are some abstract *actions *like view/edit/delete/upload/download and 
so on
There are the *roles *that define combinations of the actions - it's the 
table that has 'value' bit field  - each bit corresponds to the action
There are the *groups *and two  symmetric relation tables: *user_group_role 
, object_group_role *, object means anything on which could be performed 
the actions
Now, the set of allowed actions on the object for the user  could be 
calculated:  
 - find `intersection` (common) groups of *user *and *object *(inner join 
on group)
* - *logical sum up  role.value (bitwise aggregate OR)  for 
*user_group_role *and for *object_group_role **= user_sum_role, 
object_sum_role  *
*allowed_actions_set* = *user_sum_role *AND *object_sum_role   *(bitwise 
AND)  

for example:  user has membership in orgA with role 'super', but orgA has 
only 'read' role on the *object - * 'super'  will be trimmed to 'read'... 
but if user also has membership under 'super' in another group which has 
'super' against the object too, role_action_set won't be trimmed  

On Tuesday, January 17, 2017 at 7:59:27 PM UTC+3, Leonel Câmara wrote:
>
> I'm in the process of turning an application that was used by a single 
> organization into one that will be used by many, I'm using regular Auth and 
> auth groups to manage which users can do what according to what groups they 
> have memberships on.  
>   
> The first problem I'm facing is that the users that belong to a given 
> auth_group will now only belong to that group in a given organization, 
> which I guess would also be a problem with regular auth functions. 
>
> Another problem is that I want the organizations to be able to share some 
> of their data with another organization.  
>   
> So, right now, I'm considering what would be the best architecture for the 
> application.  
>   
> One idea would be to store the organization the user is currently browsing 
> with (no reason to limit that one user can only belong to one organization) 
> in session, then I would have to check in each controller if the user has 
> the right group and organization for what he wants to do, this would 
> pollute my code somehow.  
>   
> Another idea is for each organization to become a group, then what I use 
> groups for right now will be permissions, this is probably the best route. 
> This would still leave the problem of making the user see the right data 
> depending on which organization he is currently browsing with.   
>   
> Any advice on how to do this as cleanly as possible in terms of code?
>

-- 
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: Form field defaults the second time through

2017-01-22 Thread Val K
Pre-populating - means just default values  which will be overwritten 
during form.process(), i.e.  form.process() reads vars values only from 
request.*post_*vars  or from 'vars' arg  - form.process(vars = {...} ) and 
ignores  pre-sets like form.vars.name=... 

There was a mistake in my  post: instead  request.vars  must be request.
*post_*vars -   I fixed this 

On Sunday, January 22, 2017 at 12:48:45 PM UTC+3, Dave S wrote:
>
>
>
> On Friday, January 20, 2017 at 9:23:37 AM UTC-8, Val K wrote:
>>
>> form.vars appear only after form.process()  call (process() - 
>> filter/convert/format/validate request.vars to form.vars)
>> you have variants :
>> 1. *before *form creation  - modify field.default
>> 2. *before* form.process()  -  modify request.vars - 
>> request.vars.PostDate=... 
>> 3. pass your own set of vars  -  form.process(vars=myvars)
>> 4. use form.process( onvalidation=myvalidation_fun) to modify form.vars  
>> *after 
>> *basic validation passed but before any db actions
>>  
>>  
>>
>>
> But what about this passage in the book?
>
>  http://web2py.com/books/default/chapter/29/07/forms-and-validators#Pre-populating-the-form
> >
> Pre-populating the form
>
> It is always possible to pre-populate a form using the syntax:
>
> 1
>
> form.vars.name = 'fieldvalue'
>
> Statements like the one above must be inserted after the form declaration 
> and before the form is accepted, whether or not the field ("name" in the 
> example) is explicitly visualized in the form.
>

-- 
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: Form field defaults the second time through

2017-01-22 Thread Val K
The problem is that one controller is used for generation and process form. 
it's like different modes 
pre-populating form by assignments  form.vars.name=...   could be used only 
for the request form, when form is submitted these assignments have no 
effect.
if you want to change anything  in the form after it was processed, you 
have to use  DOM-parsing ( something like  form[0].element('input', 
_name='...')['_value'] = ... )

Use keepvalues=True or  db.table.field.default  as suggested above (it does 
the  pre-populating during form.process())
There is brute force variant  -   self-redirection :  if 
form.process().accepted: ... *session.*flash='OK';  redirect(URL())  - but 
don't forget about args/vars/user_signature  if it matters


On Sunday, January 22, 2017 at 11:58:06 PM UTC+3, Dave S wrote:
>
>
>
> On Sunday, January 22, 2017 at 2:50:16 AM UTC-8, Val K wrote:
>>
>> Pre-populating - means just default values  which will be overwritten 
>> during form.process(), i.e.  form.process() reads vars values only from 
>> request.*post_*vars  or from 'vars' arg  - form.process(vars = {...} ) 
>> and ignores  pre-sets like form.vars.name=... 
>>
>> There was a mistake in my  post: instead  request.vars  must be request.
>> *post_*vars -   I fixed this 
>>
>>
>
> But default is what I want!  If I didn't want to be able to change the 
> value when filling out the form, I wouldn't even need to provide the field.
>
> /dps
>
>  
>
>> On Sunday, January 22, 2017 at 12:48:45 PM UTC+3, Dave S wrote:
>>>
>>>
>>>
>>> On Friday, January 20, 2017 at 9:23:37 AM UTC-8, Val K wrote:
>>>>
>>>> form.vars appear only after form.process()  call (process() - 
>>>> filter/convert/format/validate request.vars to form.vars)
>>>> you have variants :
>>>> 1. *before *form creation  - modify field.default
>>>> 2. *before* form.process()  -  modify request.vars - 
>>>> request.vars.PostDate=... 
>>>> 3. pass your own set of vars  -  form.process(vars=myvars)
>>>> 4. use form.process( onvalidation=myvalidation_fun) to modify form.vars 
>>>>  *after *basic validation passed but before any db actions
>>>>  
>>>>  
>>>>
>>>>
>>> But what about this passage in the book?
>>>
>>> >> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Pre-populating-the-form
>>> >
>>> Pre-populating the form
>>>
>>> It is always possible to pre-populate a form using the syntax:
>>>
>>> 1
>>>
>>> form.vars.name = 'fieldvalue'
>>>
>>> Statements like the one above must be inserted after the form 
>>> declaration and before the form is accepted, whether or not the field 
>>> ("name" in the example) is explicitly visualized in the form.
>>>
>>

-- 
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: Form field defaults the second time through

2017-01-23 Thread Val K
yes, self-redirection restart controller in 'request fresh form' mode, but
usually your have to re-pass to URL() args/vars which don't have relation
to the form to provide expecting behaviour - just keep in mind this.

2017-01-23 4:11 GMT+03:00 Dave S :

> On Sunday, January 22, 2017 at 2:56:07 PM UTC-8, Val K wrote:
>>
>> The problem is that one controller is used for generation and process
>> form. it's like different modes
>> pre-populating form by assignments  form.vars.name=...   could be used
>> only for the request form, when form is submitted these assignments have no
>> effect.
>> if you want to change anything  in the form after it was processed, you
>> have to use  DOM-parsing ( something like  form[0].element('input',
>> _name='...')['_value'] = ... )
>>
>> Use keepvalues=True or  db.table.field.default  as suggested above (it
>> does the  pre-populating during form.process())
>> There is brute force variant  -   self-redirection :  if
>> form.process().accepted: ... *session.*flash='OK';  redirect(URL())  -
>> but don't forget about args/vars/user_signature  if it matters
>>
>>
>>
> Okay, I guess I was expecting submission to result in a fresh form
> creation, but it takes the self-redirection to acheive that, eh?
>
> /dps
>
>
>
>> On Sunday, January 22, 2017 at 11:58:06 PM UTC+3, Dave S wrote:
>>>
>>>
>>>
>>> On Sunday, January 22, 2017 at 2:50:16 AM UTC-8, Val K wrote:
>>>>
>>>> Pre-populating - means just default values  which will be overwritten
>>>> during form.process(), i.e.  form.process() reads vars values only
>>>> from request.*post_*vars  or from 'vars' arg  - form.process(vars =
>>>> {...} ) and ignores  pre-sets like form.vars.name=...
>>>>
>>>> There was a mistake in my  post: instead  request.vars  must be
>>>> request.*post_*vars -   I fixed this
>>>>
>>>>
>>>
>>> But default is what I want!  If I didn't want to be able to change the
>>> value when filling out the form, I wouldn't even need to provide the field.
>>>
>>> /dps
>>>
>>>
>>>
>>>> On Sunday, January 22, 2017 at 12:48:45 PM UTC+3, Dave S wrote:
>>>>>
>>>>>
>>>>>
>>>>> On Friday, January 20, 2017 at 9:23:37 AM UTC-8, Val K wrote:
>>>>>>
>>>>>> form.vars appear only after form.process()  call (process() -
>>>>>> filter/convert/format/validate request.vars to form.vars)
>>>>>> you have variants :
>>>>>> 1. *before *form creation  - modify field.default
>>>>>> 2. *before* form.process()  -  modify request.vars -
>>>>>> request.vars.PostDate=...
>>>>>> 3. pass your own set of vars  -  form.process(vars=myvars)
>>>>>> 4. use form.process( onvalidation=myvalidation_fun) to modify
>>>>>> form.vars  *after *basic validation passed but before any db actions
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> But what about this passage in the book?
>>>>>
>>>>> http://web2py.com/books/default/chapter/29/07/forms-and
>>>>> -validators#Pre-populating-the-form>
>>>>> Pre-populating the form
>>>>>
>>>>> It is always possible to pre-populate a form using the syntax:
>>>>>
>>>>> 1
>>>>>
>>>>> form.vars.name = 'fieldvalue'
>>>>>
>>>>> Statements like the one above must be inserted after the form
>>>>> declaration and before the form is accepted, whether or not the field
>>>>> ("name" in the example) is explicitly visualized in the form.
>>>>>
>>>> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/hT-z8wbGr38/unsubscribe.
> To unsubscribe from this group and all its topics, 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.


Re: [web2py] Re: vue.js

2017-01-27 Thread Val K
Vue  delimiters are configurable  too!
@scaffold /static 
/js 
/main-vue.js: 
row#23 Vue.config.delimiters = ['${', '}'] - it's global default config

so, you shouldn't change web2py delimiters, just try ${message} instead 
{{message}}


On Friday, January 27, 2017 at 6:07:56 PM UTC+3, John Philip wrote:
>
> Hi Richard,
>
> no luck. I modified the view:
>
> response.delimiters = ('{[', ']}')
> 
>   {{message}}
> 
>
> This is the default/vgrid.html template
> {[=BEAUTIFY(response._vars)]}
> https://unpkg.com/vue/dist/vue.js";>
>
> I also returned empty var in the controller as you suggested but when 
> loading the view I still get {{message}}. I have no idea why? ;(
>
> thanks again,
>
> John
>
>
>
> On Friday, January 27, 2017 at 3:20:38 PM UTC+1, Richard wrote:
>>
>> Ok, first try to leave layout.html out of the way... remove the first 
>> line... It should work so far, but consider you always better put the js at 
>> the bottom of the page for faster page load and improve parsing as the js 
>> come later (after the dom) anyway...
>>
>> Do you have a controllers function for the view you try to serve? If yes 
>> do you return an empty vars :
>>
>> def view():
>> response.delimiters = ('{[', ']}')
>> return dict(empty_vars='')
>>
>> It makes sure web2py serve something.
>>
>> Try to set response.delimiters in you view at first too...
>>
>> Good luck
>>
>> Richard
>>
>>
>> On Fri, Jan 27, 2017 at 3:23 AM, 'John Philip' via web2py-users <
>> web...@googlegroups.com> wrote:
>>
>>> Hi Richard,
>>>
>>> thanks for your reply. I'm did change the delimiter as you described in 
>>> the model. I changed the delimiters in all of the html files in view. 
>>> response.delimiters = ('{[',']}'. I have a snippet from the vuejs 
>>> website. However when loading the view it does not seem to recognise 
>>> {{message}}. Any help would be appreciated!! 
>>>
>>> thanks,
>>>
>>> John
>>>
>>> {[extend 'layout.html']}
>>> https://unpkg.com/vue/dist/vue.js";>
>>>
>>> 
>>> new Vue({
>>>   el: '#app',
>>>   data: {
>>> message: 'Hello Vue.js!'
>>>   }
>>> })
>>>
>>> 
>>>   {{message}}
>>> 
>>>
>>> This is the default/vgrid.html template
>>> {[=BEAUTIFY(response._vars)]}
>>>
>>> On Thursday, January 26, 2017 at 4:38:54 PM UTC+1, Richard wrote:

 Do you use the web2py layout.html?

 Did you set proper web2py delimiters?

 http://web2py.com/books/default/chapter/29/05/the-views#The-views

 Vue.JS use {{}} as web2py you need to change web2py delimiters, I like 
 (so it stays readable) :

 response.delimiters = ('{[',']}')


 Richard


 On Thu, Jan 26, 2017 at 10:26 AM, 'John Philip' via web2py-users <
 web...@googlegroups.com> wrote:

> Hi Massimo,
>
> I downloaded your scaffolding app but for some reason in the main.html 
> file vuejs does not seem to recognize ${doc.title} and ${doc.body} . Am I 
> missing something?
>
> thanks and regards,
>
> John
>
> On Sunday, September 25, 2016 at 5:25:51 AM UTC+2, Massimo Di Pierro 
> wrote:
>
>> I am becoming a huge fan of vue.js. Any other user here?
>>
> -- 
> 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+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.


[web2py] Re: Using jquery and ajax to change form input fields

2017-01-27 Thread Val K
you do an *ajax *request and *immediately * try to use ajax-results

On Friday, January 27, 2017 at 5:48:59 PM UTC+3, Morganti wrote:
>
> Hi guys,
>
> I have some extra felds no auth_user. I need to complete some fields after 
> one filled in.
>
> I am able to read this field using jquery..blur and using ajax to collect 
> these fields from a external webservice and putting the results on hidden 
> div and input fiedls. Now I need to use these input fields to fill the 
> correct fields 
>

> I am using the commands:
>
> 
>   jQuery(document).ready(function(){
> jQuery('#auth_user_cep').blur(function(){
>   ajax('{{=URL('cadastro', 'preenche_cep')}}', ['cep'], 'preenchecep');
>   jQuery('#auth_user_endereco').val(jQuery('#pendereco').val());
>   jQuery('#auth_user_bairro').val(jQuery('#pbairro').val());
>   jQuery('#auth_user_cidade').val(jQuery('#pcidade').val());
> });
>   });
> 
>
> But the auth_user fields are not being changed. If I try to execute on 
> console of browser, I can change them. But, by using the scricpt, no!
>
> Can you give some directions?
>
> Thanks a lot your helping.
> BR
> André
>

-- 
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: id table in web2py contain uuid

2017-01-27 Thread Val K
db.define_table(...Field('uuid_field'),
 
primarykey=['uuid_field'] 
) - no?



On Thursday, January 26, 2017 at 7:15:40 AM UTC+3, 黄祥 wrote:
>
> let say i got the csv file from another web app, in that csv file contain 
> a field id that contain uuid
> e.g. 
> a.csv (got from another web app)
> Id,Name
> 58801d5a3f9591dc47fbcc39,a
> 58801e67fc61af1a706ac9e1,b
>
> is it possible to have id table in web2py that contain uuid?
> how to define table in dal to face this case?
>
> thanks and 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] Re: Simple search query form, but display data on another page. I know this can't be this hard!

2017-01-27 Thread Val K
as I understand, as 'results' page you mean just another *browser *page, if 
so - pass to your FORM attr _target='_blank'
  FORM(... _target='_blank') - isn't tested but should work, because  this: 
 A(_href='...', _target='_blank') - works fine


On Saturday, January 21, 2017 at 3:42:22 AM UTC+3, Reed Crowe wrote:
>
> New to web2py. What I am doing should be very simple, but can not get it 
> to work. 
>
> I have a simple search form:
> def search_form():
> results=None
> headers=['Jira Id', 'Customer Name', 'Device Type', 'Serial Number', 
> 'Driver Version', 'Firmware Version', 'Sector Size', 'Free LEBs', 'Bytes 
> Read', 'Bytes Written', 'OS']
> form=FORM(TABLE(TR("Search By Jira 
> Id",INPUT(_type="text",_name="jira_id", default=None)),
> TR("Search By Customer 
> Name",INPUT(_type="text",_name="customer_name", default=None)),
> TR("Search By Device 
> Type",INPUT(_type="text",_name="device_type", default=None)),
> TR("",INPUT(_type="submit",_value="SUBMIT"
> if form.accepts(request,session):
> response.flash="form accepted"
> if form.vars:
> jira_id = request.vars.jira_id
> customer_name = request.vars.customer_name
> device_type = request.vars.device_type
> query = ((db.bugreport.id == db.iomemory.bug_report) &
>(db.iomemory.bug_report == db.system.bug_report) &
>(db.bugreport.id == db.system.bug_report))
> if jira_id:
> query &= db.bugreport.jira_id == jira_id
> if customer_name:
> query &= db.bugreport.customer_name == customer_name
> if device_type:
>   query &= db.iomemory.device_type == device_type
> try:
> results = db(query).select(db.bugreport.jira_id,
> db.bugreport.customer_name,
> db.iomemory.device_type,
> db.iomemory.serial_number,
> db.iomemory.driver_version,
> db.iomemory.firmware_version,
> db.iomemory.sector_size,
> db.iomemory.free_lebs,
> db.iomemory.bytes_read,
> db.iomemory.bytes_written,
> db.system.os,
> db.system.kernel_version,
> db.system.cpu_info,
> db.system.mem_info,
> db.system.num_cpus,
> db.system.raid_type,
> db.system.filesystem)
> except Exception, e:
> redirect(URL('error', vars=dict(e=e)))
> return dict(form=form, results=results)
>
> And this works OK, but I don't want the results to show up on the same 
> form page. I want it to display on a 'results' page.
>
> I tried to put the db query in another function and called it like this 
> from the form:
>
> def search_form():
> #headers=['Jira Id', 'Customer Name', 'Device Type', 'Serial Number', 
> 'Driver Version', 'Firmware Version', 'Sector Size', 'Free LEBs', 'Bytes 
> Read', 'Bytes Written', 'OS']
> form=FORM(TABLE(TR("Search By Jira 
> Id",INPUT(_type="text",_name="jira_id", default=None)),
> TR("Search By Customer 
> Name",INPUT(_type="text",_name="customer_name", default=None)),
> TR("Search By Device 
> Type",INPUT(_type="text",_name="device_type", default=None)),
> TR("",INPUT(_type="submit",_value="SUBMIT"
> if form.accepts(request,session):
> response.flash="form accepted"
> if form.vars:
> jira_id = request.vars.jira_id
> customer_name = request.vars.customer_name
> device_type = request.vars.device_type
> search_results(jira_id, customer_name, device_type) 
> ***HERE
> elif form.errors:
> response.flash="form is invalid"
> else:
> response.flash="please fill in the form"
> return dict(form=form)
>
> and
>
> def search_results(jira_id, customer_name, device_type):
> query = ((db.bugreport.id == db.iomemory.bug_report) &
>  (db.iomemory.bug_report == db.system.bug_report) &
>  (db.bugreport.id == db.system.bug_report))
> if jira_id:
> query &= db.bugreport.jira_id == jira_id
> if customer_name:
> query &= db.bugreport.customer_name == customer_name
> if device_type:
>   query &= db.iomemory.device_type == device_type
> results = None
> results = db(query).select(db.bugreport.jira_id,
> db.bugreport.customer_name,
>  

[web2py] Re: Using jquery and ajax to change form input fields

2017-01-27 Thread Val K
str() - doesn't work with uincode -  try unicode(session.cep['logradouro']) 
or unicode(session.cep['logradouro'], 'utf-8') 

On Friday, January 27, 2017 at 11:51:49 PM UTC+3, Morganti wrote:
>
> Hi, 
>
> I just using web2py book.
>
> Using that example jQuery and Ajax am getting the population of the 
> fields. I changed all code above sent. But, now, I am having problems with 
> utf-8. I mean, when I received any data with special character like 'á' or 
> 'ç', the data is not putting in the field
>
> The code is like:
>
> jQuery('#auth_user_cep').blur(function(){
>   ajax('{{=URL('cadastro', 'preenche_cep')}}', ['cep'], ':eval');
> });
>
> and the controller sending like
>
> return "jQuery('#auth_user_endereco').val(%s);" % 
> repr(str(session.cep['logradouro']))
>
> When the session.cep['logradouro']) there is no special character (utf-8), 
> ok! It´s running, but, when utf-8 is presented, nothing.
>
> I tried to use string.decode('utf-8') and sting not running.
>
> I almost getting it.
>
> Thanks a lot your supporting.
> Best regards
> André
>
>
> Em sexta-feira, 27 de janeiro de 2017 18:00:57 UTC-2, Val K escreveu:
>>
>> you do an *ajax *request and *immediately * try to use ajax-results
>> look for  $.ajax() in jQuery docs
>>
>> On Friday, January 27, 2017 at 5:48:59 PM UTC+3, Morganti wrote:
>>>
>>> Hi guys,
>>>
>>> I have some extra felds no auth_user. I need to complete some fields 
>>> after one filled in.
>>>
>>> I am able to read this field using jquery..blur and using ajax to 
>>> collect these fields from a external webservice and putting the results on 
>>> hidden div and input fiedls. Now I need to use these input fields to fill 
>>> the correct fields 
>>>
>>
>>> I am using the commands:
>>>
>>> 
>>>   jQuery(document).ready(function(){
>>> jQuery('#auth_user_cep').blur(function(){
>>>   ajax('{{=URL('cadastro', 'preenche_cep')}}', ['cep'], 
>>> 'preenchecep');
>>>   jQuery('#auth_user_endereco').val(jQuery('#pendereco').val());
>>>   jQuery('#auth_user_bairro').val(jQuery('#pbairro').val());
>>>   jQuery('#auth_user_cidade').val(jQuery('#pcidade').val());
>>> });
>>>   });
>>> 
>>>
>>> But the auth_user fields are not being changed. If I try to execute on 
>>> console of browser, I can change them. But, by using the scricpt, no!
>>>
>>> Can you give some directions?
>>>
>>> Thanks a lot your helping.
>>> BR
>>> André
>>>
>>

-- 
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: id table in web2py contain uuid

2017-01-27 Thread Val K
'just wondering is the default id on table that is generated by dal can be 
replace from integer auto increment into uuid type ?' - I do it  everyday!


On Saturday, January 28, 2017 at 12:50:24 AM UTC+3, 黄祥 wrote:
>
> it just created the new field on table name uuid and assign it as a 
> primary key, so the result on table field is :
> id, uuid, name
> so that's what i do right now
> e.g.
> *models/db.py*
> db.define_table('test',
> Field('uuid'),
> Field('name') )
>
> *controllers/default.py*
> def import_csv():
> form = SQLFORM.factory(Field('csvfile', 'upload', uploadfield = False) 
> )
> form.process()
> if form.accepted:
> csvtxt = request.vars.csvfile.file.read()
> csvtxt = csvtxt.replace('Id,Name', 'uuid,name')
> db.test.import_from_csv_file(StringIO(csvtxt) ) #Import CSV file 
> in cm1_for_update table
> return dict(form = form)
>
> just wondering is the default id on table that is generated by dal can be 
> replace from integer auto increment into uuid type ?
>
> thanks and 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] Re: Using jquery and ajax to change form input fields

2017-01-28 Thread Val K
Hi!
it seems that there isn't in the  of your 
html or $.ajax  *contentType*  settings are changed from 'utf-8'  to 
'latin-1' 

On Saturday, January 28, 2017 at 4:07:32 PM UTC+3, Morganti wrote:
>
> Hi,
>
> Your suggestion was not enouth, still not running, but, I used the idea 
> and studied more and got the solution.
>
> repr(x.decode('utf-8)').encode('latin_1'))
>
> where x=session.cep['logradouro']
>
> Thanks a lot your helping.
>
> Best regards
>
> Em sexta-feira, 27 de janeiro de 2017 19:36:24 UTC-2, Val K escreveu:
>>
>> str() - doesn't work with uincode -  try 
>> unicode(session.cep['logradouro']) or unicode(session.cep['logradouro'], 
>> 'utf-8') 
>>
>> On Friday, January 27, 2017 at 11:51:49 PM UTC+3, Morganti wrote:
>>>
>>> Hi, 
>>>
>>> I just using web2py book.
>>>
>>> Using that example jQuery and Ajax am getting the population of the 
>>> fields. I changed all code above sent. But, now, I am having problems with 
>>> utf-8. I mean, when I received any data with special character like 'á' or 
>>> 'ç', the data is not putting in the field
>>>
>>> The code is like:
>>>
>>> jQuery('#auth_user_cep').blur(function(){
>>>   ajax('{{=URL('cadastro', 'preenche_cep')}}', ['cep'], ':eval');
>>> });
>>>
>>> and the controller sending like
>>>
>>> return "jQuery('#auth_user_endereco').val(%s);" % 
>>> repr(str(session.cep['logradouro']))
>>>
>>> When the session.cep['logradouro']) there is no special character 
>>> (utf-8), ok! It´s running, but, when utf-8 is presented, nothing.
>>>
>>> I tried to use string.decode('utf-8') and sting not running.
>>>
>>> I almost getting it.
>>>
>>> Thanks a lot your supporting.
>>> Best regards
>>> André
>>>
>>>
>>> Em sexta-feira, 27 de janeiro de 2017 18:00:57 UTC-2, Val K escreveu:
>>>>
>>>> you do an *ajax *request and *immediately * try to use ajax-results
>>>> look for  $.ajax() in jQuery docs
>>>>
>>>> On Friday, January 27, 2017 at 5:48:59 PM UTC+3, Morganti wrote:
>>>>>
>>>>> Hi guys,
>>>>>
>>>>> I have some extra felds no auth_user. I need to complete some fields 
>>>>> after one filled in.
>>>>>
>>>>> I am able to read this field using jquery..blur and using ajax to 
>>>>> collect these fields from a external webservice and putting the results 
>>>>> on 
>>>>> hidden div and input fiedls. Now I need to use these input fields to fill 
>>>>> the correct fields 
>>>>>
>>>>
>>>>> I am using the commands:
>>>>>
>>>>> 
>>>>>   jQuery(document).ready(function(){
>>>>> jQuery('#auth_user_cep').blur(function(){
>>>>>   ajax('{{=URL('cadastro', 'preenche_cep')}}', ['cep'], 
>>>>> 'preenchecep');
>>>>>   jQuery('#auth_user_endereco').val(jQuery('#pendereco').val());
>>>>>   jQuery('#auth_user_bairro').val(jQuery('#pbairro').val());
>>>>>   jQuery('#auth_user_cidade').val(jQuery('#pcidade').val());
>>>>> });
>>>>>   });
>>>>> 
>>>>>
>>>>> But the auth_user fields are not being changed. If I try to execute on 
>>>>> console of browser, I can change them. But, by using the scricpt, no!
>>>>>
>>>>> Can you give some directions?
>>>>>
>>>>> Thanks a lot your helping.
>>>>> BR
>>>>> André
>>>>>
>>>>

-- 
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] Form DOM: Search selected option's text

2015-12-10 Thread Val K
Hi!
It just to help others

I wasted a pair hours to find  right matching expression for searching 
selected option's  *text*-value (not key-value ). It must be like:

selected_opt_text = form.element('[name=my_select_field_name]  option[
*selected=selected*]')[0]

just *'... option[selected]'* matches *any* option  in web2py, but work 
properly in JQuery (HTML5 at least).


-- 
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: Form DOM: Search selected option's text

2015-12-11 Thread Val K
Done! <https://github.com/web2py/web2py/issues/1125>

On Friday, December 11, 2015 at 5:42:14 AM UTC+3, Massimo Di Pierro wrote:
>
> good catch! Please open a bug report. we aim to make the element(..) args 
> as compatible as possible to jQuery.
>
> On Thursday, 10 December 2015 14:10:01 UTC-6, Val K wrote:
>>
>> Hi!
>> It just to help others
>>
>> I wasted a pair hours to find  right matching expression for searching 
>> selected option's  *text*-value (not key-value ). It must be like:
>>
>> selected_opt_text = form.element('[name=my_select_field_name]  option[
>> *selected=selected*]')[0]
>>
>> just *'... option[selected]'* matches *any* option  in web2py, but work 
>> properly in JQuery (HTML5 at least).
>>
>>
>>

-- 
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: Pre-populated Forms

2015-12-11 Thread Val K
1. get prototype record
2. overwrite  field.default  with corresponding prototype value  
3. don't pass record to SQLFORM 

On Monday, December 7, 2015 at 7:15:46 AM UTC+3, Anthony Smith wrote:
>
> Hi All, 
>
> I have a products table:
>  db.define_table('product',
> Field('product_name'),
> Field('active_ingredient'),
> Field('batch_no'),
> Field('expiry_date','date'),
> Field('product_type', 
> requires=IS_IN_SET(PRODUCTTYPES),default= PRODUCTTYPES[0]),
> Field('withholding_period','integer'),
> Field('ESI_withholding','integer'),
> Field('qty','integer'),
> Field('date_purchased','date', default = request.now),
> Field('purchased_from', 
> requires=IS_IN_DB(db,'company.company_name','%(company_name)s')),
> (auth.signature),
> format='%(product_name)s %(batch_no)s')
>
> I can edit the product with the following controller:
> def edit_product():
> product_id = request.args(0,cast=int)
> product = db.product(product_id) or error()
> if not product.created_by==me:
> product.created_by.writable = True
> else:
> product.created_by.writable = False
> form = SQLFORM(db.product,product,
>showid=False,
>
> deletable=(product.created_by==me)).process(onsuccess=auth.archive)
> if form.accepted:
> session.flash="Edit Successful"
> redirect(URL('products'))
> return locals()
>
> At times I need to add new products but only some of the fields change 
> E.G. batch_no, expiry_date, and supplier. 
> In short if need to add similar item that I already have in the products 
> table 
>
>
> thanks 
>
> 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: how to wrap an already existing input element in a new div in web2py

2015-12-18 Thread Val K
if you mean  custom view of SQLFORM you can try something like this:
def your_controller()
...
   form=SQLFORM(...) # or SQLFORM.factory
   ...
   form.process()
   ...
   # creating view - must be after form.process() 

   fcw = form.custom.widget # see web2py book
   fcl = form.custom.label
  
   v_div = DIV() # main container 
   v_div.append(STYLE( 'table>tbody>tr>td {height:40px;}'  ))

   tbl = TABLE(_class='table table-bordered table-hover')
   tbl.append(TR( fcl.field_1 , fcw.field_1  )) # - pair  label/input
   tbl.append(TR( fcl.field_2 , fcw.field_2  ))
   
   fcw.field_1['_style']='background-color:gray' 
 
   v_div.append(tbl)

   v_div.append(form.custom.submit)
   v_div.append(form.custom.end)
   
   return  dict(v=v_div)



On Thursday, December 17, 2015 at 9:12:00 AM UTC+3, Sujata Aghor wrote:
>
>
> how to wrap an already existing input element in a new div in 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] Re: Pre-populated Forms

2015-12-18 Thread Val K
If your app has a create-controller (I believe it has), you can just add to 
it some code like this:

def  your_create_controller():

   templ_rec_id =  request.args(0) # means request like 
'http://.../your_create_controller/123'  123 - id of existing record
   # notice that 
'http://.../your_create_controller' 
will work as usual!
   if  templ_rec_id: # pre-populate form 
   rec = db.product(templ_rec_id)
   if rec:
for f in your_fields_list: # [db.product.product_name, 
db.product.product_type', ...]
f.default = rec[f.name]
 
# that's all!

   



On Wednesday, December 16, 2015 at 10:00:35 AM UTC+3, Anthony Smith wrote:
>
> Hi, 
> Not really as new to this and working my way through it slowly, but best I 
> keep on searching 
>
> cheers
>
> Anthony
>
> On Tuesday, 15 December 2015 05:19:30 UTC+11, villas wrote:
>>
>> By 'prototype' I believe he means the record which you wish to use as a 
>> 'template'.
>>
>> 1. Find your 'template' record which will be used for setting the default 
>> values of the fields in the new record.
>> 2. Set the field.default accordingly.
>> 3. Do not pass a record to SQLFORM.  If you do,  it will update that 
>> record.  It is presumed that you will wish to create a new record.
>>
>> Hope that helps to clarify ValK's response.
>> All the best.
>>
>>
>> On Sunday, 13 December 2015 17:53:36 UTC, Anthony Smith wrote:
>>>
>>> Hi Val,
>>>
>>> Thanks for your reply, but unable to find any about get prototype record 
>>> in the book.
>>>
>>> Do you have an examples 
>>>
>>> Thanks
>>>
>>> Anthony
>>>
>>> On Saturday, 12 December 2015 06:03:26 UTC+11, Val K wrote:
>>>>
>>>> 1. get prototype record
>>>> 2. overwrite  field.default  with corresponding prototype value  
>>>> 3. don't pass record to SQLFORM 
>>>>
>>>> On Monday, December 7, 2015 at 7:15:46 AM UTC+3, Anthony Smith wrote:
>>>>>
>>>>> Hi All, 
>>>>>
>>>>> I have a products table:
>>>>>  db.define_table('product',
>>>>> Field('product_name'),
>>>>> Field('active_ingredient'),
>>>>> Field('batch_no'),
>>>>> Field('expiry_date','date'),
>>>>> Field('product_type', 
>>>>> requires=IS_IN_SET(PRODUCTTYPES),default= PRODUCTTYPES[0]),
>>>>> Field('withholding_period','integer'),
>>>>> Field('ESI_withholding','integer'),
>>>>> Field('qty','integer'),
>>>>> Field('date_purchased','date', default = request.now),
>>>>> Field('purchased_from', 
>>>>> requires=IS_IN_DB(db,'company.company_name','%(company_name)s')),
>>>>> (auth.signature),
>>>>> format='%(product_name)s %(batch_no)s')
>>>>>
>>>>> I can edit the product with the following controller:
>>>>> def edit_product():
>>>>> product_id = request.args(0,cast=int)
>>>>> product = db.product(product_id) or error()
>>>>> if not product.created_by==me:
>>>>> product.created_by.writable = True
>>>>> else:
>>>>> product.created_by.writable = False
>>>>> form = SQLFORM(db.product,product,
>>>>>showid=False,
>>>>>
>>>>> deletable=(product.created_by==me)).process(onsuccess=auth.archive)
>>>>> if form.accepted:
>>>>> session.flash="Edit Successful"
>>>>> redirect(URL('products'))
>>>>> return locals()
>>>>>
>>>>> At times I need to add new products but only some of the fields change 
>>>>> E.G. batch_no, expiry_date, and supplier. 
>>>>> In short if need to add similar item that I already have in the 
>>>>> products table 
>>>>>
>>>>>
>>>>> thanks 
>>>>>
>>>>> 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] DB design

2015-12-26 Thread Val K
I'm not IT-specialist, but I know any theory has own root-idea that may be 
explained by fingers. I was looking for it in DB theory and I've found it 
for myself! It is "PerformanceDBA" 's articles at StackOverflow. I think 
these articles may be very useful for everyone.

-- 
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: This jquery conditional form at pg 505 in book doesn't work. What's the problem?

2016-01-14 Thread Val K
Hi!
Try to replace *.attr('checked')*   with  *.prop('checked')*

On Thursday, January 14, 2016 at 12:32:46 PM UTC+3, aston...@gmail.com 
wrote:
>
> I am using the latest web2py version
>
> On Thursday, January 14, 2016 at 2:58:00 PM UTC+5:30, aston...@gmail.com 
> wrote:
>>
>> db = DAL('sqlite://db.db')
>> db.define_table('taxpayer',
>> Field('name'),
>> Field('married', 'boolean'),
>> Field('spouse'))
>>
>> def conditionalform():
>> form = SQLFORM(db.taxpayer)
>> if form.process().accepted:
>> response.flash = 'record inserted'
>> return locals()
>>
>>
>> {{extend 'layout.html'}}
>> {{=form}}
>> 
>> jQuery(document).ready(function(){
>> jQuery('#taxpayer_spouse__row').hide();
>> jQuery('#taxpayer_married').change(function(){
>> if(jQuery('#taxpayer_married').attr('checked'))
>> jQuery('#taxpayer_spouse__row').show();
>> else jQuery('#taxpayer_spouse__row').hide();});
>> });
>> 
>>
>>

-- 
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: Hide form field

2016-01-14 Thread Val K
hidden=dict(...) - just *extra *hidden fields, it doesn't change attributes 
of any Field(...) 

On Thursday, January 14, 2016 at 12:20:22 PM UTC+3, desta wrote:
>
> Thanks Massimo. I tried what you suggested but they are still visible.
>
> I was able to achieve what I want using:
> form = SQLFORM.factory(hidden=dict(year='', month=''))
>
>
>
> On Thursday, January 14, 2016 at 7:40:29 AM UTC+2, Massimo Di Pierro wrote:
>>
>> form = SQLFORM.factory(
>>   Field('year', label='Year'),
>>   Field('month', label='Month'),
>>   hidden=dict(fieldname='field value'))
>>
>>
>> On Wednesday, 13 January 2016 11:21:11 UTC-6, desta wrote:
>>>
>>> Thank you Anthony for the help.
>>>
>>> I am not sure how to use this though. Reading the documentation I 
>>> construct my form as follows:
>>>
>>> form = SQLFORM.factory(
>>>   Field('year', label='Year'),
>>>   Field('month', label='Month'))
>>>
>>> How do I apply the hidden part you described?
>>>
>>> Thanks again.
>>>
>>>
>>> On Wednesday, January 13, 2016 at 6:55:05 PM UTC+2, Anthony wrote:

 SQLFORM.factory(..., hidden=dict(fieldname='field value'))

 Anthony

 On Wednesday, January 13, 2016 at 11:35:57 AM UTC-5, desta wrote:
>
> I am generating a form using SQLFORM.factory() and I would like to 
> create a hidden field. I tried doing this by setting readable and 
> writable 
> to False, but the field dissapears from HTML.
>
> Is there a way to make it hidden but still accessible in HTML as I 
> want to set its value with Javascript.
>
> Thank you.
>


-- 
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: Field Type Data

2016-01-14 Thread Val K
Hi!
See IS_DATETIME 

 
validator in the web2py book


On Thursday, January 14, 2016 at 4:49:17 AM UTC+3, Lorenzo Zonca wrote:
>
> Goodmorning  to everyone. 
>
> Through a field "date " with calendar of a CRUD , how can I store a date 
> with this syntax 
>
> eg . Monday, 2 May - 2016 ( day - number of day - month - year ) 
>
>
> Thank you

-- 
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: Field Type Data

2016-01-14 Thread Val K
As I see you want to customize date format at form level, i.e.  user picks 
the date from calendar and the field is filled with 'Monday ...' (name of 
the day)
If  it's what you want you can use the following:
There are two JS-variables are used by calendar  (see 
your_app/views/web2py_ajax.html):
var w2p_ajax_date_format = "{{=T('%Y-%m-%d')}}";
var w2p_ajax_datetime_format = "{{=T('%Y-%m-%d %H:%M:%S')}}"; 

You can change these vars in web2py_ajax.html (global change) or just 
overwrite them at veiw level   
Calendar format date  - http://www.dynarch.com/jscal/#sec22
P.S. It seems web2py IS_DATE validator doesn't recognize names of the days  
So, you have to write your own

On Thursday, January 14, 2016 at 4:49:17 AM UTC+3, Lorenzo Zonca wrote:
>
> Goodmorning  to everyone. 
>
> Through a field "date " with calendar of a CRUD , how can I store a date 
> with this syntax 
>
> eg . Monday, 2 May - 2016 ( day - number of day - month - year ) 
>
>
> Thank you

-- 
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: connection string syntax of postgres on pythonanywhere

2016-01-16 Thread Val K
try this
'postgres://alexglaros:myPassWord@alexglaros-97. 
postgres 

.pythonanywhere-services.com:10097/postgres_es 
'

On Saturday, January 16, 2016 at 11:33:29 AM UTC+3, Alex Glaros wrote:
>
> what is connection string syntax for pythonanywhere.com postgres?
>
> tried many combinations:
>
> db = DAL('postgres://alexglaros:myPassWord/
> alexglaros-97.postgres_es.pythonanywhere-services.com',pool_size=1,check_reserved=['all'],
>  
> migrate_enabled=True, lazy_tables=True)
>
> the name of database is postgres_es
>
> when I created the database, this information was displayed from 
> pythonAnywhere:
>
> Address:
>
> alexglaros-97.postgres.pythonanywhere-services.com
>
> Port:
> 10097
>
> Also, will it hurt if I don't delete the old sqlLite databases?
>
> 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.


[web2py] Re: SQLFORM.grid and jQuery-bootgrid help

2016-01-17 Thread Val K
Hi!

> Using Bootgrid the TD column html is converted into string.

It's very strange, do you check your SQLFORM.grid  without using Bootgrid? 
May be it happens (html to string) at server-side? 
In your example  why do you set *data-formatter* if TD contains already 
rendered link?


On Sunday, January 17, 2016 at 1:44:07 PM UTC+3, piero crisci wrote:
>
> Hi
> I am new using jQuery and not very skilled in general with Javascript.
> I am using the Basic Jquery Bootgrid example 
> on a SQLFORM.grid and it worked 
> fine, except for one thing.
> One of the TD column contains a "Server Generated link" with 
> user_signature. 
> Using Bootgrid the TD column html is converted into string.
> I recreated the link with the javascript as showed in the examples but I 
> would like to use the link created from server side. 
> Anyone using the bootgrid knows if there is a property that i can use to 
> let Jquery Bootgrid not modify the link rendered by the server?
>
> Here is an example of what I did (3rd TD tag)
> 
> 
> 
> ID
> Sender
>  data-order="desc">Received
> 
> 
> 
> 
> 10238
> xx...@pingpong.com 
> http://www.google.com/>?book=Pippo&signature=32hih327dsa*">Book
> 
> 
> 
> I would like to keep the red link is it possible?
>
> Thanks for help
> Kind Regards
> Piero
>

-- 
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: best advice on customer/client picklist popup.

2016-01-18 Thread Val K
Hi Lucas!
I had similar problem and here is my solution:
For search I use SQLFORM.grid with  buttons (button per row)  having 
data-attributes,  for example, in your case attrs may be: data-client_id,   
data-client_name   with corresponding values
Then I use LOAD() with ajax_trap=True to embed SQLFORM.grid  to the main 
page (also it may be turned into  modal dialogue using bootstrap )
There is the hidden field at the main page to hold  selection data that 
would be sent (client_id) and the html-element to represent the 
 selection  (client_name) 
Now, all that's left to do - little script, like this:
$(document).on('click', ':button[data-client_id]', function(e)
{
  $('#client_id_hidden_field').val(  $(e.target).data('client_id') );
  $('#client_name_html_elem').html(  $(e.target).data('client_name') );
}
)



On Sunday, January 17, 2016 at 5:54:32 PM UTC+3, lucas wrote:
>
> oh, i forgot to mention, that i know how to do an ajax query and pass post 
> variable to it using web2py.  i don't know the best javascript/jQuery 
> method for creating and displaying the proper HTML code and 
> inputs/buttons/and such, and then pass the result back to the main parent 
> page.
>

-- 
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] improving DAL for normalized DB

2016-01-23 Thread Val K
Hi guys!
I have an idea to improve DAL in scope of work with normalized DB.
As known It's a common practice to avoid NULL value by creating separate 
(option) table(s) to store non required fields.  
So, it would be great to have a field type like "storedin 
table_name.field_name" 
For example:

db.define_table('alias_opt', Field('name'),  Field('alias_name', 'reference 
person'))
db.define_table('person', Field('name'),  Field('alias_name', 'storedin 
alias_opt.alias_name'))

#INSERT:
db.person.insert(name='Alex',  alias_name='Macedonian') 
# means:
   id=db.person.insert(name='Alex')
   db.alias_opt.insert(id=id, alias_name='Macedonian')  

#UPDATE:
db(db.person.id==id).update(... , alias_name=None)
# means:
  # update person
  ...
  # update option  table
  update_opt_args = filter_storedin_fields(update_args) 
  opt_rec =  db.alias_opt(id)
  opt_rec.update(update_opt_args)
  if not any(opt_rec.values()): # -  all fields of option table record is 
None
 del  db.alias_opt(id)  
else:
 db.alias_opt.update_or_insert(id==id,   **update_opt_args)

#DELETE:
del db.person(id)  also means   del db.alias_opt(id),  like ondelete=
'CASCADE'

#SELECT:
rows = db(db.person).select()
# means:
 rows = db(db.person).select( left=[ db.alias_opt.on( db.alias_opt.id == db.
person.id ) ] )
but only "storedin" fields should be selected from  db.alis_opt 
and they should be accessed by row.alias_name (not only by 
row.joined_table.field_name 
)

Considering, that table person could be a VIEW (i.e. JOIN is already 
performed at DB level),  there is no need to make join at web2py level,
it could be fixed by passing an option arg like is_view=True to 
define_table() 
I know, that behavior of insert/update/delete could be easy realized by 
custom class based on Table 
with a little hacking Field-class to intercept field type to fix it to 
web2py type ( considering  person.alias_name.type == 
alias_opt.alias_name.type ).
But it's hard for me to change select() behavior, because there is only 
common_filter, but  there isn't  common_join/common_left with providing of 
maping (aliasing) joined table  fields  to  'storedin' fields. 

In fact, I dream of common_join depends on discriminator field, that will 
switch tables to be joined depend on discriminator value specified in the 
query (something like db.object.type_id==type_id),
if descriminator is not specified or couldn't be resolved at web2py level, 
it performs left join all tables (from a list containing possible 
common_join tables)

P.S. May be I try to reinvent the wheel, so feel free to shoot me!

-- 
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: OFF TOPIC: Collaborative data modeling environment

2016-02-07 Thread Val K
Hi Alex!
Furtunaly, I'm thinking about the same! I mean the synchronization 
Postgres-DAL while developing. First of all,  I belive you can find the 
script *extract_pgsql_models.py* in your web2py/scripts directiory, but it 
just generates models to stdout and you can improve it but why?
So, I did  some universal VIEWs  that  grab  tables and views definition ( 
schemas from *search_path only* are processed - see *current_schemas()*  pg 
function) and represents them in eatable state for DAL.
Here are they - see below. Keep in mind *column_vw* depends on others, so 
it must be latest creation. After that, you can select any/all table 
definition from *column_vw* having  schema, table name, column name, column 
pg_type, column web2py_type (including 'reference table_name' ),  defaults, 
nullable. Now you can easy  generate DAL models on the fly!  It's just the 
cost of performance, but it's always possible to generate a "hard copy" for 
production. 

*model_gen* - separate schema to filter out VIEWs-for-DAL own definition, 
so you should create this schema first of all.


Tables
CREATE OR REPLACE VIEW model_gen.*table_vw* AS  
 SELECT tables.table_catalog,
tables.table_schema,
tables.table_name,
tables.table_type,
tables.self_referencing_column_name,
tables.reference_generation,
tables.user_defined_type_catalog,
tables.user_defined_type_schema,
tables.user_defined_type_name,
tables.is_insertable_into,
tables.is_typed,
tables.commit_action
   FROM information_schema.tables
  WHERE (tables.table_schema::text IN ( SELECT ss.s
   FROM unnest(current_schemas(false)) ss(s)));


Prymary keys
CREATE OR REPLACE VIEW model_gen.*cons_pku_vw* AS 
 SELECT table_constraints.table_schema,
table_constraints.table_name,
constraint_column_usage.column_name AS col_name,
table_constraints.constraint_type AS cons_type,
table_constraints.constraint_name AS cons_pku_name,
count(*) OVER (PARTITION BY table_constraints.constraint_name) AS 
col_in_cons,
key_column_usage.ordinal_position AS cons_position
   FROM information_schema.table_constraints
 JOIN information_schema.constraint_column_usage USING 
(constraint_catalog, constraint_schema, constraint_name, table_catalog, 
table_schema, table_name)
 JOIN information_schema.key_column_usage USING (constraint_catalog, 
constraint_schema, constraint_name, table_catalog, table_schema, 
table_name, column_name)
  WHERE (table_constraints.table_schema::name IN ( SELECT ss.s
   FROM unnest(current_schemas(false)) ss(s))) AND 
table_constraints.table_schema::text <> 'model_gen'::text
  ORDER BY table_constraints.table_schema, table_constraints.table_name, 
table_constraints.constraint_name;

Foreign keys
CREATE OR REPLACE VIEW model_gen.*cons_fk_vw* AS 
 SELECT key_col_use.constraint_name AS cons_fk_name,
key_col_use.table_schema,
key_col_use.table_name,
key_col_use.column_name AS col_name,
cons_col_use.table_schema AS ref_schema,
cons_col_use.table_name AS ref_table,
cons_col_use.column_name AS ref_col,
ref_cons.update_rule,
ref_cons.delete_rule,
key_col_use.ordinal_position
   FROM information_schema.key_column_usage key_col_use
 JOIN information_schema.referential_constraints ref_cons USING 
(constraint_catalog, constraint_schema, constraint_name)
 JOIN information_schema.table_constraints t_cons USING 
(constraint_catalog, constraint_schema, constraint_name, table_catalog, 
table_schema, table_name)
 JOIN information_schema.constraint_column_usage cons_col_use ON 
cons_col_use.constraint_name::text = ref_cons.unique_constraint_name::text
  WHERE (key_col_use.table_schema::name IN ( SELECT ss.s
   FROM unnest(current_schemas(false)) ss(s))) AND 
key_col_use.table_schema::text <> 'model_gen'::text AND 
t_cons.constraint_type::text = 'FOREIGN KEY'::text
  ORDER BY key_col_use.table_schema, key_col_use.table_name, 
key_col_use.column_name;



All together
CREATE OR REPLACE VIEW model_gen.*column_vw* AS 
 SELECT columns.table_schema,
columns.table_name,
columns.column_name AS col_name,
columns.data_type AS col_type,
CASE
WHEN "left"(columns.column_default::text, 7) = 'nextval'::text 
OR cons_pku_vw.cons_type::text = 'PRIMARY KEY'::text THEN 'id'::character 
varying
WHEN cons_fk_vw.col_name IS NOT NULL THEN concat('reference ', 
cons_fk_vw.ref_table)::character varying
WHEN "left"(columns.data_type::text, 9) = 'character'::text 
THEN 'string'::character varying
WHEN columns.data_type::text = ANY 
(ARRAY['timestamp'::character varying::text, 'timestamp without time 
zone'::character varying::text]) THEN 'datetime'::character varying
WHEN columns.data_type::text = ANY (ARRAY['time'::character 
varying::text, 'time without time zone'::character varying::text]) THEN 
'time'::character varying
WHEN columns.data_type::text = ANY (ARRAY['integer'::character 
var

[web2py] Embedding Rapydscript

2016-02-07 Thread Val K
Hi!
Coding Python with switching to coding JS - really painful.
So, I tried Rapydscript (RS) and I like it very much! Unfortunately,  I 
couldn't find how  to automate compilation RS-files to pure JS.
Here is my solution to embed RS to web2py

   1. Download and install Node.js  to anywhere 
   (RS-compiler works on it, i.e. it's required only for developing, it won't 
   be a dependence of your web2py project)
   2. Download and unpack Rapydscript   to 
   anywhere. Or you can done it using GIT, as suggested in the manual (it's 
   version 0.3.9 at the moment and it works w/o GIT-install)
   3. Code a little module to automate compilation your RS-files to pure JS 
   and place it in* your_w2p_app/modUles* dir, here is my one
   
import sys
import os
from stat import ST_MTIME
import json as js
import subprocess as subp
import portalocker

get_fname = lambda full_name: os.path.split(full_name)[1]

def change_ext(f_name, ext):
return os.path.splitext(f_name)[0] + ext

def clear_file(f):
f.seek(0)
f.truncate()

class  _log(object): # used to track changes to avoid parallel and extra 
recompilation 

def __init__(self, f_name):
self.f_name=f_name
self.error={}
self.f_obj=None
self.log = None

def open_read(self):
f_name=self.f_name
try:
if os.path.isfile(f_name):  
md='r+'
else:
md='w'
f = open(f_name, md)
self.f_obj = f
portalocker.lock(f, portalocker.LOCK_EX )
if md=='r+':
tmp= f.read()
self.log = (tmp and js.loads(tmp)) or {}
else:
self.log = {}
except :
 self.error['open_read'] = sys.exc_info()[0]
return  self.error['open_read'] is None

def save(self):
if not self.f_obj:
return
try:
clear_file(self.f_obj)
self.f_obj.write(js.dumps(self.log))
self.f_obj.close()
except :
 self.error['save'] = sys.exc_info()[0]

def set_compile_time(self, pyj_fname):
if self.log is None:
return
f_stat = os.stat(pyj_fname)
self.log[ get_fname(pyj_fname) ] = f_stat[ST_MTIME]

def is_up_to_date(self, pyj_fname):
if self.log is None:
return False
f_stat = os.stat(pyj_fname)
return self.log[ get_fname(pyj_fname) ] == f_stat[ST_MTIME]


class rs_compiler(object):
def __init__(self, path_to_nodejs, path_to_RS):
self.node = path_to_nodejs
self.rs_engine = path_to_RS
self.last_ret_code = None
self.last_rslts = None

def _rs_compile(self, src, dst, log, force_compile=False):
ret = None
if force_compile or not log.is_up_to_date(src) or not 
os.path.isfile(dst):
ret = subp.call( [self.node, self.rs_engine, src, '-p', '-o', 
dst])
if ret==0:
 log.set_compile_time(src)
self.last_ret_code = ret
return ret

def rs_compile_dir(self, src, dst, force_compile=False):

log = _log(os.path.join(dst, 'compile_inf.json' ))   # 
'compile_inf.json' 
 - contains dict  { 'file_1.pyj' : ST_MTIME,  'file_2.pyj' : ST_MTIME ...  } 
 

#  it will be 
created/overwrited in the same dir as JS-files
if not log.open_read():
  return {};

joinp = os.path.join
all_dir = os.listdir(src)
src_files = [f for f in all_dir if os.path.isfile(joinp(src, f)) 
and f[-4:]=='.pyj']
ret={}
for f in src_files:
src_f =  joinp(src, f)
dst_f =  joinp(dst, change_ext(f, '.js'))
self._rs_compile(src_f, dst_f, log, 
 force_compile=force_compile)
rslt=dict(
ret_code = self.last_ret_code,
open_read = log.error.get('open_read', None),
log_save_err = log.error.get('save', None),
)
ret[f] = rslt
self.last_rslts=ret
log.save()
return ret



def main():
   pass

if  __name__ == '__main__':
main()



Now, to automate compilation you can place some code like below in db.py 
(or in another model-file)

...
import rs_compiler

def compile_pyj():
node='path_to/nodejs/node.exe'
rs_engine = 'path_to/RapydScript-master/bin/rapydscript'
rs = rs_compiler.rs_compiler(node, rs_engine)
src = os.path.join(request.folder, 'private') # I place my RS-files in 
'w2p_app/private' 
dir  - you can choose another one 
dst = os.path.join(request.folder, 'static/js') 

print rs.rs_compile_dir(src, dst) # compile each src/file_name.pyj   to 
 dst/file_name.js  - overwriting JS-files without any warning!

compile_pyj()


   






-- 
Resources:
- http://web2py

[web2py] Re: web2py UnicodeDecodeError: 'utf8' codec can't decode byte 0xc7 in position 15: invalid continuation

2016-02-08 Thread Val K
Hi!
I had a similar problem with MS Access. Error like this means that your 
database encoding isn't utf-8, you should figure out which is it?
After that, you can try to set db_codec to  proper encoding (see DAL 
signature in the web2py book) 



On Thursday, February 4, 2016 at 5:52:02 PM UTC+3, Fábio Filho wrote:
>
>
> I'm using a firebird legacy database and when I make this query:
>
> dbFb.INVENTORY.CODE==3
>
> i got this output error:
>
> UnicodeDecodeError: 'utf8' codec can't decode byte 0xc7 in position 15: 
> invalid continuation
>
>
> *there is a field called 'name', and when dbFb.INVENTORY.CODE==3,*
> *the field name has a word 'ç' in its value *
>
> Anyone can help me?
>
>
>

-- 
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] Embedding Rapydscript

2016-02-08 Thread Val K
I think that scheduler is designed for asynchronous tasks, but I want to 
see changes effect immediately after edit/save pyj-file(s) and update web 
page. So, all pyj-files must be checked for out-of-date and recompiled (if 
there is anyone) per request call. I believe that cool IDEs allow doing 
this  w/o extra coding, but I use Pyscripter only. 


On Monday, February 8, 2016 at 11:50:08 AM UTC+3, mcm wrote:
>
> Very nice.
> Did you evaluate running compile_pyjs() as a web2py's scheduler task?
> It could simplify your code and make it more resilient.
>
>
> 2016-02-08 0:20 GMT+01:00 Val K >:
>
>> Hi!
>> Coding Python with switching to coding JS - really painful.
>> So, I tried Rapydscript (RS) and I like it very much! Unfortunately,  I 
>> couldn't find how  to automate compilation RS-files to pure JS.
>> Here is my solution to embed RS to web2py
>>
>>1. Download and install Node.js <http://Nodejs.org> to anywhere 
>>(RS-compiler works on it, i.e. it's required only for developing, it 
>> won't 
>>be a dependence of your web2py project)
>>2. Download and unpack Rapydscript   <http://rapydscript.pyjeon.com>to 
>>anywhere. Or you can done it using GIT, as suggested in the manual (it's 
>>version 0.3.9 at the moment and it works w/o GIT-install)
>>3. Code a little module to automate compilation your RS-files to pure 
>>JS and place it in* your_w2p_app/modUles* dir, here is my one
>>
>> import sys
>> import os
>> from stat import ST_MTIME
>> import json as js
>> import subprocess as subp
>> import portalocker
>>
>> get_fname = lambda full_name: os.path.split(full_name)[1]
>>
>> def change_ext(f_name, ext):
>> return os.path.splitext(f_name)[0] + ext
>>
>> def clear_file(f):
>> f.seek(0)
>> f.truncate()
>>
>> class  _log(object): # used to track changes to avoid parallel and extra 
>> recompilation 
>>
>> def __init__(self, f_name):
>> self.f_name=f_name
>> self.error={}
>> self.f_obj=None
>> self.log = None
>>
>> def open_read(self):
>> f_name=self.f_name
>> try:
>> if os.path.isfile(f_name):  
>> md='r+'
>> else:
>> md='w'
>> f = open(f_name, md)
>> self.f_obj = f
>> portalocker.lock(f, portalocker.LOCK_EX )
>> if md=='r+':
>> tmp= f.read()
>> self.log = (tmp and js.loads(tmp)) or {}
>> else:
>> self.log = {}
>> except :
>>  self.error['open_read'] = sys.exc_info()[0]
>> return  self.error['open_read'] is None
>>
>> def save(self):
>> if not self.f_obj:
>> return
>> try:
>> clear_file(self.f_obj)
>> self.f_obj.write(js.dumps(self.log))
>> self.f_obj.close()
>> except :
>>  self.error['save'] = sys.exc_info()[0]
>>
>> def set_compile_time(self, pyj_fname):
>> if self.log is None:
>> return
>> f_stat = os.stat(pyj_fname)
>> self.log[ get_fname(pyj_fname) ] = f_stat[ST_MTIME]
>>
>> def is_up_to_date(self, pyj_fname):
>> if self.log is None:
>> return False
>> f_stat = os.stat(pyj_fname)
>> return self.log[ get_fname(pyj_fname) ] == f_stat[ST_MTIME]
>>
>>
>> class rs_compiler(object):
>> def __init__(self, path_to_nodejs, path_to_RS):
>> self.node = path_to_nodejs
>> self.rs_engine = path_to_RS
>> self.last_ret_code = None
>> self.last_rslts = None
>>
>> def _rs_compile(self, src, dst, log, force_compile=False):
>> ret = None
>> if force_compile or not log.is_up_to_date(src) or not 
>> os.path.isfile(dst):
>> ret = subp.call( [self.node, self.rs_engine, src, '-p', '-o', 
>> dst])
>> if ret==0:
>>  log.set_compile_time(src)
>> self.last_ret_code = ret
>> return ret
>>
>> def rs_compile_dir(self, src, dst, force_compile=False):
>>
>> log = _log(os.path.join(dst, 'compile_inf.json' ))   # 
>> 'compile_inf.json' 
>>  - contains dict 

[web2py] Re: OFF TOPIC: Collaborative data modeling environment

2016-02-08 Thread Val K
It seems you haven't Python installed on your comp (Python isn't windows 
standard), you can try to use web2py/py.exe to process python-files  

On Monday, February 8, 2016 at 11:14:35 PM UTC+3, Alex Glaros wrote:
>
> looks like what I need Val
>
> can you direct me in how to run it?
>
> I typed Mariano's extract_pgsql_models.py command line in a windows 
> machine and got:'python' is not recognized as an internal or external 
> command, operable program or batch file.
>
> thanks
>
> 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: need help connecting to a second database for a copy of application

2016-02-08 Thread Val K
Hi!

1.  I believe one pg-install=one pg-server
2. I think that pg listens only one port until you set another one and 
restart server 

Why do you think you have to have another pg-server? One pg-server can 
services many  databases - just use different names for DAL, i.e. db=DAL() 
db1=DAL() to connect 

May be  you don't even  need another database!
If all db-tables are located  in  one schema you can just create another 
one and copy tables to it.
pg supports safe mode  schema-per-user/role  - see pgdoc  


 


On Friday, January 29, 2016 at 12:51:02 AM UTC+3, Jordan Myers wrote:
>
> Hello everyone,
> I've developed an application that uses postgresql as its backend and I 
> want to make a copy of the application on the same server (running on the 
> same instance of web2py) to be used as the deployed version while I 
> continue work on the development version. I used web2py to package and then 
> reload the application under a new name "deploy." and now I'm trying to set 
> up the deploy database.
>
> I tried setting up another postgresql server, but it doesn't seem to let 
> me listen on two different ports (which I assume I would need because I 
> want to access two different database spaces at the same time). So I 
> decided to just try a completely different database like MSSQL, but it kept 
> complaining about an unknown data source and unknown server and after a 
> week of trying to debug it I'm ready to give up. I've run into a similar 
> issue with FireBird
>
> Does anyone have any recommendations for a painless way of setting up a 
> second database server, or some insight into my problems with 
> postgresql/MSSQL/FireBird? The only requirement is that it is a relational 
> database that can handle concurrent read-writes (and is supported by 
> web2py). 
>
> Thanks,
> -Vladimir
>

-- 
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: Displalay a form in light box or pop up window in view

2016-02-11 Thread Val K
Hi!
Here is my solution.  I have modal_wrapper function. In controller file, I 
have two controllers -  main_page and modal_content: 



def main_page():

main_pg=DIV()

m_cont = LOAD(f='*modal_content**.load*', ajax=True, ajax_trap=True  )  

dialog = modal_wrapper(m_cont, _id='*cont_id*', header='Header', 
footer='footer')

show_modal_btn = BUTTON( 'Show modal',
   _type="button",
   _class = "btn 
btn-default",
   _onclick=""" $('#
*cont_id*').modal('show')   """)

#don't forget to add dialog and show_modal_btn to main page
main_pg.append(show_modal_btn)   # or main_pg.append( DIV(show_modal_btn) 
 ) or something else
main_pg.append(dialog)

   return dict(main_pg = main_pg)




# keep in mind just one thing:
#   this controller is exposed by *.load, so it must return a dict of ONE 
element 
#   to return more than one element - wrap all in one DIV:
#   ret = DIV()
#   ret.append( ... ) 
#   ret.append( form )  
#  ret.append( ... )
#  return dict(ret = ret) 

def modal_content():

form = SQLFORM(...) # or even form = SQLFORM.grid(...)

return dict(form=form)



# means bootstrap 3
def modal_wrapper(content, _id, header='', footer=''):

main_wrap = DIV('',  _class="modal fade",  _role="dialog", _id=_id, 
_tabindex="-1" )
title_id = _id + '_title'
main_wrap['_aria-labelledby']=title_id

dialog_div=DIV('', _class="modal-dialog" , _role="document")
content_div=DIV('', _class="modal-content")
header_div = DIV( _class="modal-header")

close_cross = BUTTON(
SPAN(XML('×'), **{'_aria-hidden':"true"}),
_type="button",  _class="close",
 data={'dismiss':"modal"},
 **{'_aria-label':"Close"}
 )
title_h4 = H4( header,  _class="modal-title",  _id = title_id)
body_div = DIV( content, _class="modal-body")


close_btn = BUTTON('Close',  _type="button", _class="btn btn-default", 
data={'dismiss':"modal"})
footer_div =  DIV( footer, close_btn, _class="modal-footer")

# gluon all
main_wrap[0] = dialog_div
dialog_div[0] = content_div

header_div.append(close_cross)
header_div.append(title_h4)

[content_div.append(c) for c in (header_div, body_div, footer_div)]
return main_wrap








On Thursday, February 11, 2016 at 8:07:32 PM UTC+3, billmac...@gmail.com 
wrote:
>
> Thank you for your answer Massimo. When I implemented this. 
>
> Apply To This Post
>
> It shows me a button and then I get redirected to another page. I just 
> wanted a pop up window open up with a form to submit that user can move 
> around without being redirected to another page.
>
>
>
>
>
> On Wednesday, February 10, 2016 at 10:51:11 PM UTC-5, Massimo Di Pierro 
> wrote:
>>
>> I see you want a different window, not a modal.
>>
>> then you have to put the form logic in its own controller action and call 
>> it from js
>>
>> click 
>> me
>>
>> On Wednesday, 10 February 2016 18:00:44 UTC-6, billmac...@gmail.com 
>> wrote:
>>>
>>> Thank you for the answer Massimo. I did this like you said to put the 
>>> form in the body in index/popup.html however, it didn't pop up like the 
>>> example in the link above. Instead I got it in the same browser. I am 
>>> guessing my implementation is wrong.
>>>
>>> 
>>>   
>>> 
>>>   
>>> >> aria-hidden="true">×
>>> Modal title
>>>   
>>>   
>>> 
>>>   {{=form}}
>>>   
>>>   
>>>   
>>> >> data-dismiss="modal">Close
>>> Save 
>>> changes
>>>   
>>> 
>>>   
>>> 
>>>
>>>
>>>
>>>
>>> On Wednesday, February 10, 2016 at 5:06:28 PM UTC-5, Massimo Di Pierro 
>>> wrote:

 Bootstrap3 has built-int modals: 
 https://nakupanda.github.io/bootstrap3-dialog/
 You can but {{=form}} in the body of the modal.

 On Tuesday, 9 February 2016 14:26:05 UTC-6, billmac...@gmail.com wrote:
>
> Hello, A new user migrating from Django to web2py and absolutely 
> loving it. A quick question. How do I use a light box or a pop up window 
> to 
> display a form in my view?
>
>
> for example in default/index.html
>
> {{=form}}
>
> Want to show that form  in a pop up window.  
>


-- 
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: Problems with Upload files

2016-02-11 Thread Val K
1. If you specify uploadfolder, it must be absolute path - something like 
os.path.join(request.folder, 'path_relative_to_your_app')
2. To store file I use like this:
   dst = open('your_file_absolute_name', 'wb')
   shutil.copyfileobj(form.vars.file, dst)
   dst.close()

  it works


On Friday, February 12, 2016 at 1:51:33 AM UTC+3, Alfonso Serra wrote:
>
> Ok the first mistake ive made
> file.seek(0) returns None so file.seek(0).read() doesnt make sense.
>
>

-- 
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: Displalay a form in light box or pop up window in view

2016-02-11 Thread Val K
LOAD() works like URL(), so,  to pass args/vars to modal_content you could 
write
m_cont = LOAD(f='*modal_content**.load*', *args=[ ],  vars={ }*,   
ajax=True, ajax_trap=True  )  # see LOAD in web2py book

in modal_content controller there is nothing new, everything is as usual  
def modal_content():
   arg_0 = request.args(0)
   a = request.vars.a

  

On Friday, February 12, 2016 at 1:16:35 AM UTC+3, billmac...@gmail.com 
wrote:
>
> Thank you! Val  and the app works great.
>
> One question:
>
> Instead of controller, I have the button displayed in the view as:
>
> {{=BUTTON( 'Apply',_type="button",_class = "btn 
> btn-default",_style="background-color:green;background-image:none",_onclick="""
>  
> $('#cont_id').modal('show')   """ )}}
>
> It works, however, I need to pass an argument to my controller 
> "modal_content". How do I  pass a request.args(0) from my view to the 
> controller in above? Just like I would do 
>
>   onclick='window.open("{{=URL("*modal_content*",args=something.id)}}", 
> "mywindow");'>Apply
>
>
> Since I don't see the URL or callback to the javascript. Thanks in advance.
>
>
> On Thursday, February 11, 2016 at 4:27:22 PM UTC-5, Val K wrote:
>>
>> Hi!
>> Here is my solution.  I have modal_wrapper function. In controller file, 
>> I have two controllers -  main_page and modal_content: 
>>
>>
>>
>> def *main_page*():
>>
>> main_pg=DIV()
>> 
>> m_cont = LOAD(f='*modal_content**.load*', ajax=True, ajax_trap=True 
>>  )  
>>
>> dialog = modal_wrapper(m_cont, _id='*cont_id*', header='Header', 
>> footer='footer')
>> 
>> show_modal_btn = BUTTON( 'Show modal',
>>_type="button",
>>_class = "btn 
>> btn-default",
>>_onclick=""" $('#
>> *cont_id*').modal('show')   """)
>>
>> #don't forget to add dialog and show_modal_btn to main page
>> main_pg.append(show_modal_btn)   # or main_pg.append( 
>> DIV(show_modal_btn) 
>>  ) or something else
>> main_pg.append(dialog)
>>
>>return dict(main_pg = main_pg)
>>
>>
>>
>>
>> # keep in mind just one thing:
>> #   this controller is exposed by *.load, so it must return a dict of ONE 
>> element 
>> #   to return more than one element - wrap all in one DIV:
>> #   ret = DIV()
>> #   ret.append( ... ) 
>> #   ret.append( form )  
>> #  ret.append( ... )
>> #  return dict(ret = ret) 
>>
>> def *modal_content*():
>> 
>> form = SQLFORM(...) # or even form = SQLFORM.grid(...)
>>
>> return dict(form=form)
>>
>>
>>
>> # means bootstrap 3
>> def* modal_wrapper*(content, _id, header='', footer=''):
>>
>> main_wrap = DIV('',  _class="modal fade",  _role="dialog", _id=_id, 
>> _tabindex="-1" )
>> title_id = _id + '_title'
>> main_wrap['_aria-labelledby']=title_id
>>
>> dialog_div=DIV('', _class="modal-dialog" , _role="document")
>> content_div=DIV('', _class="modal-content")
>> header_div = DIV( _class="modal-header")
>>
>> close_cross = BUTTON(
>> SPAN(XML('×'), **{'_aria-hidden':"true"}),
>> _type="button",  _class="close",
>>  data={'dismiss':"modal"},
>>  **{'_aria-label':"Close"}
>>  )
>> title_h4 = H4( header,  _class="modal-title",  _id = title_id)
>> body_div = DIV( content, _class="modal-body")
>>
>>
>> close_btn = BUTTON('Close',  _type="button", _class="btn 
>> btn-default", data={'dismiss':"modal"})
>> footer_div =  DIV( footer, close_btn, _class="modal-footer")
>>
>> # gluon all
>> main_wrap[0] = dialog_div
>> dialog_div[0] = content_div
>>
>> header_div.append(close_cross)
>> header_div.

[web2py] Re: Problems with Upload files

2016-02-11 Thread Val K

I think you haven't from.process()
form=SQLFORM()  # or SQLFORM.factory   - just  makes a set of 
html-like-component (set of DIV(), INPUT() and so on)
form.process() - filters and fills form with request.vars, does validation 
 and so on



On Friday, February 12, 2016 at 2:50:14 AM UTC+3, Alfonso Serra wrote:
>
> Hi val thanks for your answer.
>
> Althought as you said, an absolute path is safer, a relative path as i 
> have in the field form, looks like it works.
>
> I got that part covered with:
> filename = form1.vars.csvfile
> file = request.post_vars.csvfile.file
> file.seek(0) #something is consuming the file so i gotta rewind
> content = file.read()
> dest = os.path.join(os.path.abspath("."), uploadfolder)
> dest = os.path.join(dest, filename)
>
> with open(dest, "wb") as f:
> f.write(content)
>
> idk why but form.vars.myfile is storing only the filename of the 
> automatically created file inside the upload folder.
> Im reading the submitted file from request.post_vars.csvfile and using 
> form.vars.myfile to store the content manually.
>
>
>>>

-- 
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: Problems with Upload files

2016-02-12 Thread Val K
Upload field has custom_store param-see 
https://www.google.ru/url?q=https://groups.google.com/forum/m/%23!topic/web2py/8X-QlbtyxEQ&sa=U&ved=0ahUKEwiL2r_DlvLKAhWBOSwKHYgSDIwQFggNMAA&sig2=WkaSH-wCNyJiXG0Su3f8uA&usg=AFQjCNEu9h6olQktR8ir7Lk7KgBi1y8aoA

-- 
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: File picker

2016-02-12 Thread Val K
http://www.web2py.com/books/default/chapter/29/14/other-recipes#Publishing-a-folder

On Tuesday, February 9, 2016 at 5:35:41 AM UTC+3, Heinrich Piard wrote:
>
> Hi all,
>
> does anyone have an example of a web button which allows me to browse 
> through the local file system on the web server to pick a file?
>

-- 
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: Displalay a form in light box or pop up window in view

2016-02-12 Thread Val K

I mean passing args/vars in main_page(): 

def main_page():

main_pg=DIV()

m_cont = LOAD(f='*modal_content**.load*', *args=[ ], 
 vars={ }*,   ajax=True, ajax_trap=True  )  
   ...



But may be you want to pass something from client side, i.e. args  are 
defined by some user action.
What exactly do you want to do?





On Friday, February 12, 2016 at 10:00:22 PM UTC+3, billmac...@gmail.com 
wrote:
>
> In the book it says load in the view. Nothing in the controller.  I was 
> just wondering if we can add a button in the view and call the ajax from 
> the view with the argument. If we need to call the LOAD from the view, its
>
> {{=LOAD('default','manage_things',ajax=True)}}
>
> Then it fails for m_count. 
>
>
> On Friday, February 12, 2016 at 12:20:10 AM UTC-5, Val K wrote:
>>
>> LOAD() works like URL(), so,  to pass args/vars to modal_content you 
>> could write
>> m_cont = LOAD(f='*modal_content**.load*', *args=[ ],  vars={ }*,   
>> ajax=True, ajax_trap=True  )  # see LOAD in web2py book
>>
>> in modal_content controller there is nothing new, everything is as usual  
>> def modal_content():
>>arg_0 = request.args(0)
>>a = request.vars.a
>>
>>   
>>
>> On Friday, February 12, 2016 at 1:16:35 AM UTC+3, billmac...@gmail.com 
>> wrote:
>>>
>>> Thank you! Val  and the app works great.
>>>
>>> One question:
>>>
>>> Instead of controller, I have the button displayed in the view as:
>>>
>>> {{=BUTTON( 'Apply',_type="button",_class = "btn 
>>> btn-default",_style="background-color:green;background-image:none",_onclick="""
>>>  
>>> $('#cont_id').modal('show')   """ )}}
>>>
>>> It works, however, I need to pass an argument to my controller 
>>> "modal_content". How do I  pass a request.args(0) from my view to the 
>>> controller in above? Just like I would do 
>>>
>>>  Apply
>>>
>>>
>>> Since I don't see the URL or callback to the javascript. Thanks in 
>>> advance.
>>>
>>>
>>> On Thursday, February 11, 2016 at 4:27:22 PM UTC-5, Val K wrote:
>>>>
>>>> Hi!
>>>> Here is my solution.  I have modal_wrapper function. In controller 
>>>> file, I have two controllers -  main_page and modal_content: 
>>>>
>>>>
>>>>
>>>> def *main_page*():
>>>>
>>>> main_pg=DIV()
>>>> 
>>>> m_cont = LOAD(f='*modal_content**.load*', ajax=True, 
>>>> ajax_trap=True  )  
>>>>
>>>> dialog = modal_wrapper(m_cont, _id='*cont_id*', header='Header', 
>>>> footer='footer')
>>>> 
>>>> show_modal_btn = BUTTON( 'Show modal',
>>>>_type="button",
>>>>_class = "btn 
>>>> btn-default",
>>>>_onclick=""" 
>>>> $('#*cont_id*').modal('show')   """)
>>>>
>>>> #don't forget to add dialog and show_modal_btn to main page
>>>> main_pg.append(show_modal_btn)   # or main_pg.append( 
>>>> DIV(show_modal_btn) 
>>>>  ) or something else
>>>> main_pg.append(dialog)
>>>>
>>>>return dict(main_pg = main_pg)
>>>>
>>>>
>>>>
>>>>
>>>> # keep in mind just one thing:
>>>> #   this controller is exposed by *.load, so it must return a dict of 
>>>> ONE element 
>>>> #   to return more than one element - wrap all in one DIV:
>>>> #   ret = DIV()
>>>> #   ret.append( ... ) 
>>>> #   ret.append( form )  
>>>> #  ret.append( ... )
>>>> #  return dict(ret = ret) 
>>>>
>>>> def *modal_content*():
>>>> 
>>>> form = SQLFORM(...) # or even form = SQLFORM.grid(...)
>>>>
>>>> return dict(form=form)
>>>>
>>>>
>>>>
>>>> # means bootstrap 3
>>>> def* modal_wrapper*(content, _id, header='', footer=''):
>>>>
>>>> main_wrap = DIV('',  _class=&q

[web2py] Re: reading from external db

2016-02-14 Thread Val K
Be careful with legacy databases! You can do involuntary changes by 
db.define_table(),  to avoid this use migrate=False.
If you're going to read only (i.e. only select-query), connect to DB using 
limited user/role account   

On Saturday, February 13, 2016 at 1:01:36 AM UTC+3, yarecki wr wrote:
>
> I'm quite new to Python and web2py hence when I started a little project 
> for displaying some stats on a website I quickly got to points where I just 
> got stack. I'll describe one hopefully someone would help with and provide 
> some explanations. Basically it work but for the moment mostly manual which 
> isn't that great. I define my table
>
> db.define_table('table_1',
>Field('name',length=20,label='Name')...
>...
>format='%(Name)s'
> )
> ### then in Controler
>
> def stats():
>db.table_1.id.readable = False
>db.table_1.stat1.represent = lambda value, row: stat(value)...
>...
>return dict(stattable=SQLFORM.grid(db.table_1, 
> This gives me a nice web page where I can display all my stats and modify 
> them as needed.
>
> Then the need came to automate it somehow so I created a simple mySQL db 
> where I feed my stats. New to databases so that was another challenge but I 
> found a YT the basics of mySQL in 30 minutes :) Now I'd like to get the 
> data from the external db to replace the values in w2p internal db where a 
> row with the same name exists and add new rows where it doesn't.
>
> import mySQLdb
> def stat_db():
> statdb = MySQLdb.connect(host=
> cur = statdb.cursor()   ### I goggled this bit :)
>
> ### here are my internal db fields
> fields = db(db.table_1.id>0).select(db.tabela_1.name, distinct=True, 
> orderby=db.table_1.name)  
> ### and the external db rows
> cur.execute("select * from statdb")
> rows= cur.fetchall()
>
> So I suppose this gets all the rows from my external db but no idea how I 
> would look for the right row in the internal db to replace the values. The 
> common field in both db's is the 'name'. 
>

-- 
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: regarding permission

2016-02-17 Thread Val K
Hi!
There is a model only in your message, what does your controller like? 
After "auth = Auth(db)",  auth.user_id == id of logged in user (None means 
nobody logged in) 
 

On Wednesday, February 17, 2016 at 12:36:53 PM UTC+3, prashant joshi wrote:
>
> is there any way to provide permission to the admin to update and delete 
> data from the table and provide user only to read it?
>
>  
> db = DAL("postgres://postgres:postgres@localhost:5432/tripti1")
> from gluon.tools import Auth
> auth = Auth(db)
> auth.define_tables(username=False,signature=False)
>
>
>
> db.define_table('stud_person',
>   Field('image', 'upload'),
>   Field('first_name', requires=IS_NOT_EMPTY()),
>   Field('middle_name', requires=IS_NOT_EMPTY()),
>   Field('last_name', requires=IS_NOT_EMPTY()),
>   Field('email_id', requires=IS_NOT_EMPTY()))
>
>
> till now i have done this after this what to do i'm not getting?can anyone 
> help me???
>
>

-- 
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.factory - form.process().accepted fails first time but works after that

2016-02-17 Thread Val K
It seems after first click your form is reloaded, may be there is nested 
forms in your html-page or  something else.
What does your LOAD-call like? try  ajax=true or  ajax_trap=true 


On Wednesday, February 17, 2016 at 12:17:04 AM UTC+3, Jim S wrote:
>
> I have a simple SQLFORM.factory form.
>
> Sometimes when I click on the submit button the 
> form.process(keepvalues=True).accepted returns False - clicking on enter 
> immediately following results in it returning True.  I'm not getting any 
> error or flash messages.
>
> I don't know where to begin looking for my problem.
>
> Here is the relevant code:
>
> fields = []
> fields.append(Field('brix_level', 'decimal(5,2)', required=True, requires=
> IS_FLOAT_IN_RANGE(70, 99),
>  default=wo.brix_level))
>
> form = SQLFORM.factory(*fields)
>
> form.element(_name='brix_level').update(_class='form-control')
>
> if form.process(keepvalues=True).accepted:
>
> Sometimes it will return False, and then re-submitting with no changes on 
> screen, it will return True.
>
> This is happening in my form that is in a LOADed Component in a bootstrap 
> modal window.
>
> Sequence of events:
>
> 1. Click button to display the modal window and the form.
> 2. Change brix level from 86 to 85
> 3. Click on submit
>
> form.process().accepted returns False
>
> brix level on the form field returns to 86
>
> 4. Change brix level from 86 to 85
> 5. Click on Submit
>
> Everything works fine...
>
> Any ideas what I'm missing?
>
> -Jim
>

-- 
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: Prepping upload file browser

2016-02-20 Thread Val K
It's possible - just write your own browser ;)
You can't access the file system from any browser due to security reasons 

On Saturday, February 20, 2016 at 4:25:46 AM UTC+3, Dave S wrote:
>
> Using SQLFORM for a table with a Field('x', 'upload'), is there a way to 
> tell the file chooser widget what directory to start in (which will vary 
> with client OS) ?  I'm interested in uploading files that are 
> domain-specific, and which can be expected to be in certain places.
>
> /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] Handling JSON stream

2016-02-21 Thread Val K
How do you serialize form?
Jquery.param makes json in extended format by default, try use traditional=true

-- 
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: Handling JSON stream

2016-02-21 Thread Val K
Maybe I mistake, but JSON means arrays ([1,2, "any string", 5]) , hashes 
({"a":1, "b":"any string"}) and combinations ([{"a": [1,2,3], "b":2 }, 2,3 
]), 
so , "a:7:{..." - isn't JSON

On Sunday, February 21, 2016 at 2:46:47 PM UTC+3, Kenneth wrote:
>
> Hi,
>
> I don't access to change the webform, so I need to get by what I receive. 
> It is a standard webform in Drupal that sends the JSON. 
>
>
> Kenneth
>
>
> Den söndag 21 februari 2016 kl. 13:01:40 UTC+2 skrev Val K:
>>
>> How do you serialize form?
>> Jquery.param makes json in extended format by default, try use 
>> traditional=true
>
>

-- 
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] Receiving array passed in from jQuery $.ajax() into Storage object

2016-02-22 Thread Val K
How about including in web2py this 
module?
Here is my variant returning Storage (original returns dict).
Usage: 
post_vars = jquery_unparam_w2p(request.body.read())


# -*- coding: utf-8 -*-
# based on jquery-unparam 2.0.0

import re

try:
from urllib import unquote_plus
except ImportError:
from urllib.parse import unquote_plus

from gluon.tools import Storage

def parse_key_pair(keyval):
keyval_splitted = keyval.split('=', 1)
if len(keyval_splitted) == 1:
key, val = keyval_splitted[0], ''
else:
key, val = keyval_splitted
if key == '':
return Storage()

groups = re.findall(r"\[.*?\]", key)
groups_joined = ''.join(groups)
if key[-len(groups_joined):] == groups_joined:
key = key[:-len(groups_joined)]
for group in reversed(groups):
if group == '[]':
val = [val]
else:
val = Storage({group[1:-1]: val})
return Storage( {key: val})


def merge_two_structs(s1, s2):
if isinstance(s1, list) and \
   isinstance(s2, list):
return s1 + s2

if isinstance(s1, dict) and \
   isinstance(s2, dict):

retval = Storage( s1.copy())

for key, val in s2.items():
if retval.get(key) is None:
retval[key] = val
else:
retval[key] = merge_two_structs(retval[key], val)
return retval
return s2


def merge_structs(structs):
if len(structs) == 0:
return None
if len(structs) == 1:
return structs[0]
first, rest = structs[0], structs[1:]
return merge_two_structs(first, merge_structs(rest))


def jquery_unparam_unquoted(jquery_params):
pair_strings = jquery_params.split('&')
key_pairs = [parse_key_pair(x) for x in pair_strings]
return merge_structs(key_pairs)


def jquery_unparam_w2p(jquery_params):
return jquery_unparam_unquoted(unquote_plus(jquery_params))


if __name__ == '__main__':
pass






On Tuesday, September 18, 2012 at 8:03:13 AM UTC+3, Osman Masood wrote:
>
> Thanks, Bruno! I actually don't care about the order of rows so 
> request.vars.values() worked for me.
>
> Excellent.
>
> On Monday, September 17, 2012 6:32:27 PM UTC-7, rochacbruno wrote:
>>
>>
>> You can do something like this:
>>
>> In [17]: request_vars =  {'table[0][]': ['1', '2'], 'table[1][]': ['3', 
>> '4']}
>> In [18]: table = request_vars.values()
>> In [19]: table[0]
>> Out[19]: ['1', '2']
>> In [20]: table[1]
>> Out[20]: ['3', '4']
>>
>> or to be sure about the sequence.
>>
>> In [25]: request_vars =  {'table[0][]': ['1', '2'], 'table[1][]': ['3', 
>> '4']}
>> In [26]: table = [request_vars['table[%s][]' % i] for i in 
>> range(len(request_vars))]
>> In [27]: table[0]
>> Out[27]: ['1', '2']
>> In [28]: table[1]
>> Out[28]: ['3', '4']
>>
>>
>>
>>
>>
>>

-- 
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] DAL: query using JSON field

2016-02-28 Thread Val K
Hi!
Is there any way to produce query using JSON field?
It seems that web2py  treats args  of  that query as string:
db(db.tabl.json_fld==[1])._select() - "... WHERE tabl.json_fld=='[1]'"
db(db.tabl.json_fld[0]==1)._select() - "... WHERE 
(SUBSTR(tabl.json_fld,1,(2 - 1)) = '1')"

I use PostgreSQL and I have to force Postgres to hold JSON as plane text?


-- 
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: DAL: query using JSON field

2016-02-28 Thread Val K
Thank you  Anthony for your reply!
 In fact, I don't store data in json, I use it  in views only. I mean 
something like:

SELECT  person.id, person.name, row_to_json(alias.*) as person_alias FROM 
person, alias WHERE  person.id = alias.person_id
 
I've found yet another  solution - I can create a dummy view  just for query 
 using  alias field:
 
SELECT  person.id, person.name, alias.id, alias.alias  FROM person, alias 
WHERE  person.id = alias.person_id

and make the trick:

ids_select_query = db(db.dummy_vw.alias == v &/| any_extra_query )._select(
db.dummy_vw.person.id) # note _select()  - just SQL-string, no DB-processing

rows = db(db.person_vw.id.belongs(ids_select_query)).select()







On Sunday, February 28, 2016 at 4:53:06 PM UTC+3, Anthony wrote:
>
> Most databases do not have native JSON types with the ability to query 
> within the JSON columns, so the DAL does not include that functionality -- 
> it just stores and retrieves the JSON.
>
> You should be able to construct the appropriate Postgres WHERE clause 
> manually and submit that as the query:
>
> db('JSON where clause').select(db.table.ALL)
>
> Note, do not include "WHERE" in the query -- the DAL will add that. Also, 
> because this query is opaque to the DAL, you must specify fields to select 
> in the .select() call so the DAL knows what table to query.
>
> Anthony
>
> On Sunday, February 28, 2016 at 7:56:21 AM UTC-5, Val K wrote:
>>
>> Hi!
>> Is there any way to produce query using JSON field?
>> It seems that web2py  treats args  of  that query as string:
>> db(db.tabl.json_fld==[1])._select() - "... WHERE tabl.json_fld=='[1]'"
>> db(db.tabl.json_fld[0]==1)._select() - "... WHERE 
>> (SUBSTR(tabl.json_fld,1,(2 - 1)) = '1')"
>>
>> I use PostgreSQL and I have to force Postgres to hold JSON as plane text?
>>
>>
>>

-- 
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: Join subqueries

2016-02-29 Thread Val K
Hi!
There are many aliases with sub select  in your query, it's difficult to 
understand tables structure.
Post tables definition and some comment about what do you want to do, please




On Monday, February 29, 2016 at 8:11:09 AM UTC+3, Bill Black wrote:
>
> SELECT a.*,b.num_passed
>   FROM (SELECT q.id,q.name,count(t.id) AS num_q
> FROM quiz AS q
>   JOIN question AS t ON q.id=t.quiz_id GROUP BY q.id)
> AS a
>   JOIN (SELECT quiz_id,count(passed) AS num_passed FROM result GROUP BY 
> quiz_id)
> AS b ON a.id=b.quiz_id;
> I need to join these two selects.
> I've spent all morning trying to get it to work in dal. But I don't think 
> it can be done...
> Just posting here in case there is a way to do this before resorting to 
> executesql.
> 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.


[web2py] Re: constraints

2016-02-29 Thread Val K
I see serial(fk) in your tables definition, but FK couldn't be serial, 
serial means generative  id by sequence 
There is a little singularity in web2py - if you specify "id" as "reference 
..." but don't specify it  as primarykey=['id'] explicit then web2py treats 
it as serial id and ignores fk- constraint!
so, if you want to have id (pk) as fk you have to:
db.define_table(... Field('id', 'reference ...')...  primarykey=['id'] )


On Sunday, February 28, 2016 at 9:20:58 PM UTC+3, prashant joshi wrote:
>
> how to conecting table??
> how to use refernce??
>

-- 
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() control detect_record_change

2016-02-29 Thread Val K
Hi!
Web2py does following (roughly):
- retrieves DB-record to update and compute hash that is function(record)
- stores record-hash and *formkey* as {formkey:hash} in session, so, even 
the same user opens many forms for the same record, after confirming one of 
them he'll receive warning while confirming others
- after form().accepted,  web2py retrieves record from DB again, computes 
hash again, retrieves stored hash by fromkey from submitted from,compares 
them and perform update if they are equal

But still there is a tiny gap between retrieving_computing_comparing and 
updating!
For the "absolute" safety you have to retrieve record for checking by 
SELECT FOR UPDATE, and it seems that DAL supports it
 (see 
http://pydal.readthedocs.org/en/latest/_modules/pydal/adapters/base.html?highlight=for%20update)
 
   
So, you can:
db().select(... for_update=
True) 
Keep in maind:
- There is  no locking between requests (one request - one DB-transaction, 
after transaction end FOR UPDATE LOCK is released)
- use it  to retrieve for checking only, i.e. *immediately before *
updating, 


On Friday, February 26, 2016 at 6:03:30 PM UTC+3, dome...@gmail.com wrote:
>
> Ante todo, un saludo al Sr. Massimo Di Pierro y toda la colectividad que 
> lo secunda, por este excelente framework, que no deja de sorprenderme.
>
>  
>
> Contexto del problema:
>
>Versión de web2py: 2.13.4 para windows (EXE) (siempre voy al día ;-))
>
>Sistema operativo: windows XP SP3.
>
>Db: postgresql 9.4
>
>  
>
> Estoy usando como mecanismo general de tratamiento CRUD y funcionalidad 
> asociada a los reg.de una tabla, el método SQLFORM(grid).
>
> Pero me tope con un problema no menor: dos (o más) usuarios que acceden al 
> mismo registro en un mismo lapso de tiempo -están mirando la misma 
> información obviamente-, uno de ellos denominado “primero”, actualiza los 
> datos -nada que objetar-, pero luego, un “segundo usuario”, que tiene 
> todavía una "vista de datos viejos", al dar confirmar para actualizar los 
> suyos, termina realizando cambios sobre datos no previamente refrescados  
> como 
> correspondería, si no que, además, campos que “segundo” no actualizó y 
> están con valores “de la vista vieja”…..¡¡ se terminan restaurando ¡!!, 
> anulando los valores que  “primero” realizó…..
>
>  
>
>  No encontré un mecanismo para detectar este hecho, y proceder a advertir 
> a los usuarios, que deben refrescar los datos para proceder nuevamente a 
> realizar cambios si corresponde, similar al que si poseen los formularios 
> individuales con SQLFORM(form), como es, la acción DETECT_RECORD_CHANGE 
> para el evento PROCESS().
>
>  
>
> Aclaro que no me estoy refiriendo al mecanismo transaccional de web2py y 
> la DB -uso POSTGRESQL-, que funciona correctamente.
>
>
> La solución que busco -si alguien ya la descubrió- , sería un mecanismo 
> general para SQLFORM(grid), no para uno en particular. Quiero evitar el 
> crear y asignar FORMs individuales para SQLFORM(grid) dado que, obviamente, 
> se dispararían los tiempos de desarrollo, incrementando innecesariamente, 
> la cantidad de objetos de la aplicación.
>
> Previamente, intenté solucionar esto en el evento ONVALIDATION, 
> consultando el objeto form que recibe como parámetro, en sus atributos 
> (record, latest, detect_changed, detect_record_change). Pero no obtuve 
> resultados.
>
> La idea, es que esto debiera ser un chequeo normal del GRID y cualquier 
> otro tipo de  FORM. Inclusive, debiera estar siempre activado y poder 
> devolver un error específico y/o realizar una acción a sus efectos.
>
>
> Gracias de antemano desde Montevideo/Uruguay.
>

-- 
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: Join subqueries

2016-02-29 Thread Val K
is it what you want?:

SELECT quiz.id,
   quiz.name,
   count(question.quiz_id) AS num_q,
   count(result.passed) AS num_passed
   FROM quiz
   JOIN question ON question.quiz_id=quiz.id
   JOIN result ON result.quiz_id=quiz.id
   GROUP BY quiz.id, quiz.name



-- or the same:

SELECT quiz.id,
   quiz.name,
   count(question.quiz_id) AS num_q,
   count(result.passed) AS num_passed
   FROM quiz
   WHERE  question.quiz_id=quiz.id
 AND  result.quiz_id=quiz.id
   GROUP BY quiz.id, quiz.name

-- web2py 

db((question.quiz_id == quiz.id ) & (result.quiz_id == quiz.id)).select( 
groupby=[db.quiz.id, db.quiz.name])
 





On Monday, February 29, 2016 at 9:33:31 PM UTC+3, Bill Black wrote:
>
> // I've left out fields that are irrelevant to the problem
>
> Table quiz | name (varchar)
> Table question | quiz_id (fk)
> Table result | quiz_id (fk), passed (boolean)
>
> quiz - question, quiz - result are one to many relations.
>
> I'm trying to get the 'quiz name, # of questions in the quiz, # of passed 
> (result) for the quiz'
>
>
> On Monday, February 29, 2016 at 12:43:41 PM UTC-5, Val K wrote:
>>
>> Hi!
>> There are many aliases with sub select  in your query, it's difficult to 
>> understand tables structure.
>> Post tables definition and some comment about what do you want to do, 
>> please
>>
>>
>> On Monday, February 29, 2016 at 8:11:09 AM UTC+3, Bill Black wrote:
>>>
>>> SELECT a.*,b.num_passed
>>>   FROM (SELECT q.id,q.name,count(t.id) AS num_q
>>>   FROM quiz AS q
>>> JOIN question AS t ON q.id=t.quiz_id GROUP BY q.id)
>>> AS a
>>>   JOIN (SELECT quiz_id,count(passed) AS num_passed FROM result GROUP BY 
>>> quiz_id)
>>> AS b ON a.id=b.quiz_id;
>>> I need to join these two selects.
>>> I've spent all morning trying to get it to work in dal. But I don't 
>>> think it can be done...
>>> Just posting here in case there is a way to do this before resorting to 
>>> executesql.
>>> 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.


[web2py] Re: Join subqueries

2016-02-29 Thread Val K
Yes, it's impossible by one dal-query, but still you can use web2py power:

args = Storage(
num_q =  db(db.question.quiz_id == 
db.quiz.id)._select(db.quiz.ALL, 
'count(*) as num_q' ,  groupby=[db.quiz.id])
num_passed = db(db.result.quiz_id   == 
db.quiz.id)._select(db.quiz.id, 
 'count(*) as num_passed',  groupby=[db.quiz.id])
sql_str = 'SELECT num_q.*, num_passed.num_passed  FROM (%(num_q)s) 
AS num_q  JOIN (%(num_passed)s) AS num_passed ON num_q.quiz_id=
num_passed.quiz_id'
   }

rows = db.executesql(args.sql_str % args, fields = list(db.tbl_holder))


 




  

   


On Monday, February 29, 2016 at 9:33:31 PM UTC+3, Bill Black wrote:
>
> // I've left out fields that are irrelevant to the problem
>
> Table quiz | name (varchar)
> Table question | quiz_id (fk)
> Table result | quiz_id (fk), passed (boolean)
>
> quiz - question, quiz - result are one to many relations.
>
> I'm trying to get the 'quiz name, # of questions in the quiz, # of passed 
> (result) for the quiz'
>
>
> On Monday, February 29, 2016 at 12:43:41 PM UTC-5, Val K wrote:
>>
>> Hi!
>> There are many aliases with sub select  in your query, it's difficult to 
>> understand tables structure.
>> Post tables definition and some comment about what do you want to do, 
>> please
>>
>>
>> On Monday, February 29, 2016 at 8:11:09 AM UTC+3, Bill Black wrote:
>>>
>>> SELECT a.*,b.num_passed
>>>   FROM (SELECT q.id,q.name,count(t.id) AS num_q
>>>   FROM quiz AS q
>>> JOIN question AS t ON q.id=t.quiz_id GROUP BY q.id)
>>> AS a
>>>   JOIN (SELECT quiz_id,count(passed) AS num_passed FROM result GROUP BY 
>>> quiz_id)
>>> AS b ON a.id=b.quiz_id;
>>> I need to join these two selects.
>>> I've spent all morning trying to get it to work in dal. But I don't 
>>> think it can be done...
>>> Just posting here in case there is a way to do this before resorting to 
>>> executesql.
>>> 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.


[web2py] Re: How to insert different grid elements in tab panels?

2016-03-02 Thread Val K
As I know it's impossible to have 2 "static" (not ajax)  SQLFORM.grids at 
the same page, because each of them will treat request.args  as its own 


On Wednesday, March 2, 2016 at 8:12:49 PM UTC+3, Ron Chatterjee wrote:
>
>
> If I have two independent grid, when I search in one grid, it gets 
> redirected to the other tab. And I noticed this with other tab panel as 
> well.  
>
>
>
> 
>   
> My Projects
> My Payments
> My Contacts
>   
>   
> 
>   {{=grid1}}
>   
>   
> {{=grid2}}
>   
>   
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam 
> nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat 
> volutpat.
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam 
> nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat 
> volutpat.
> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam 
> nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat 
> volutpat.
>   
> 
>
> 
> $( "#tabs" ).tabs();
> 
>
>

-- 
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] PostgreSQL: json_agg()

2016-03-06 Thread Val K
Hi!
This is useful aggregate function for PG-users (tested with PostgreSQL 9.3 
):

def json_agg_sql(flds_lst, as_alias):
json_fld_sql = """ '"%s":' || to_json(%s) """
json_row = [json_fld_sql  % (f.name, f.name) for  f in flds_lst]
json_row_sql = "'{' || " + "|| ',' ||".join(json_row) + " || '}'"
json_agg_sql =  'json_agg((%s)::json) AS %s' % (json_row_sql, 
as_alias)
return json_agg_sql


usage:

rows= db().select(db.table.*field, ...* , json_agg_sql([db.table.*field_1*, 
db.table.*field_2*], as_alias='*your_alias*'),  groupby=[db.table.*field, 
...*] )

rows[0].table.*field*  #  - access to "group by" field 

rows[0].*your_alias*[0]   #  - access to "json_agg"  record
rows[0].*your_alias*[0]['*field_1*']   #  - access to "json_agg" field

 

Note that it's possible to have more than one *json_agg*  in one *select!* 
just  use different aliases



-- 
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 i can do a form factory 2 tables with bulkdata

2016-03-10 Thread Val K
Hi!

   1. it is not quite clear for me, what  is the goal of client/property 
   fields? Are they search fields? 
   2. If you want user to fill/edit/del all these fields (without server 
   interaction) and submit result at once - it's impossible without having 
   some JS-coding 
   3. Your Bulkdata looks like grid, so you can use SQLFORM.grid, but it 
   requires real DB-table  and performs submission per record add/edit/del, 
   i.e. all user actions will be submitted immediately, so, special submit 
   button is useless.

But still it's possible to be realized by web2py power only! (w/o JS-coding)
What you have to do: 

   1. Create dummy table to process bulkdata add/edit/del, it should have 
   extra field "user_id" -   reference to auth_user.id (we don't want user to 
   see what another one  is doing )
   2. Create 2 controllers  - one to process main page and final 
   user submission ( now, submit-button is useful;) ), another  - to process 
   bulkdata only (returning something 
   like SQLFORM.grid(dummy_table.user_id==auth.user_id)  ).
   3. Embed bulkdata_controller to main_page_controller using smth like 
   =LOAD('bulkdata_controller', ajax=True) - see the  book
   4. When user performs final submission  - do what you want to do  using 
   dummy-table data filtering by auth.user_id, then delete bulckdata records 
   (using filtering by auth.user_id of course)


There is an issue  - is it possible  dummy-table id overflow? 
To avoid this you can use 'big-id' type for  id-field and perform 
periodical (Sunday night or 31 October ) truncation all dummy-table records 
 with restart id-counter (or just recreate table)





On Wednesday, March 9, 2016 at 7:12:14 PM UTC+3, Yoel Baez wrote:
>
>
> I need to do something like this in web2py... please help me..
>
> Regards,
> Yoel
>
>
>
> 
>

-- 
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] DAL: reference to FK-field causes an error

2016-03-12 Thread Val K
Hi!
I have a problem - look at example:

db.define_table('a_tbl', Field('name'))
db.define_table('b_tbl', Field('id', 'reference a_tbl') ,Field('name'), 
primarykey=['id'])
db.define_table('c_tbl', Field('b_tbl_id', 'reference b_tbl') 
,Field('name'))


*c_tbl* definition causes an error (see below) because there is  *b_tbl_id*  
field that references to *b_tbl* that has *id*  reference to *a_tbl* 

Is this a bug?



--

 'foreign_key'

web2py™Version 2.13.4-stable+timestamp.2015.12.26.04.59.39PythonPython 
2.7.9: 


*File D:\web2py_last\web2py\gluon\packages\dal\pydal\adapters\base.py in 
create_table at line 303*
Function argument list

(self=, table=, migrate=True, fake_migrate=False, polymodel=None)
Code listing

298.
299.
300.
301.
302.
303.

304.
305.
306.
307.


# must be PK reference or unique
if getattr(rtable, '_primarykey', None) and rfieldname in 
rtable._primarykey or \
rfield.unique:
ftype = types[rfield.type[:9]] % \
dict(length=rfield.length)

# multicolumn primary key reference?
if not rfield.unique and len(rtable._primarykey)>1:
# then it has to be a table level FK
if rtablename not in TFK:




-- 
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: DAL: reference to FK-field causes an error

2016-03-12 Thread Val K
I explicitly define 'id' as primary key in b_tbl, in this case web2py 
creates table with id as just INTEGER (not incremental)  - I've checked it, 
 -  it isn't problem   
The problem is that web2py doesn't perform recursively search for base type 
of referenced field.
It consider that FK-field couldn't reference to another FK-field  

  



On Saturday, March 12, 2016 at 2:19:28 PM UTC+3, 黄祥 wrote:
>
> pls try :
> db.define_table('b_tbl', Field('a_tbl_id', 'reference a_tbl') 
> ,Field('name') )
> db.define_table('c_tbl', Field('b_tbl_id', 'reference b_tbl') 
> ,Field('name') )
>
> i think in b_tbl, field id is already there as the integer auto increment 
> primary key, so when you redefine another field with the same name, it can 
> cause an error.
>
> 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] Re: DAL: reference to FK-field causes an error

2016-03-12 Thread Val K
OK! Let's dance

This doesn't work (with SQLite at least):
db.define_table('a_tbl', Field('id', 'integer'),  Field('name'), 
primarykey=['id'] ) # one keyed table
db.define_table('b_tbl', Field('id', 'reference a_tbl.id'), Field('name'), 
primarykey=['id']) # another keyed table

 near "name": syntax error


sql.log:
*CREATE TABLE b_tbl(*
*id INTEGER, CONSTRAINT  "FK_b_tbl_id__constraint" FOREIGN KEY (id) 
REFERENCES a_tbl (id) ON DELETE CASCADE,**name CHAR(512),**PRIMARY 
KEY(id)) ;*


This doesn't work too:
db.define_table('a_tbl', Field('id', 'integer'),  Field('name'), 
primarykey=['id'] ) # one keyed table
db.define_table('b_tbl', Field('id', db.a_tbl), Field('name'), 
primarykey=['id']) # another keyed table
it produces the same sql.log and causes the same error  - expected


But this  works!:
db.define_table('a_tbl', Field('id', 'id'),  Field('name') ) # not keyed 
table
db.define_table('b_tbl', Field('id', 'reference a_tbl'), Field('name'), 
primarykey=['id']) #  keyed table that references to not keyed table


it produces another sql.log:
CREATE TABLE b_tbl(
id INTEGER REFERENCES a_tbl (id) ON DELETE CASCADE  NOT NULL ,
name CHAR(512),
PRIMARY KEY(id)) ;












On Saturday, March 12, 2016 at 8:54:37 PM UTC+3, Anthony wrote:
>
> Not sure if it's a bug, but the book does say:
>
>- Keyed tables can only reference other keyed tables.
>- Referencing fields must use the reference tablename.fieldname format.
>
> Anthony
>
> On Saturday, March 12, 2016 at 4:52:53 AM UTC-5, Val K wrote:
>>
>> Hi!
>> I have a problem - look at example:
>>
>> db.define_table('a_tbl', Field('name'))
>> db.define_table('b_tbl', Field('id', 'reference a_tbl') ,Field('name'), 
>> primarykey=['id'])
>> db.define_table('c_tbl', Field('b_tbl_id', 'reference b_tbl') 
>> ,Field('name'))
>>
>>
>> *c_tbl* definition causes an error (see below) because there is  
>> *b_tbl_id*  field that references to *b_tbl* that has *id*  reference to 
>> *a_tbl* 
>>
>> Is this a bug?
>>
>>
>>
>>
>> --
>>
>>  'foreign_key'
>>
>> web2py™Version 2.13.4-stable+timestamp.2015.12.26.04.59.39PythonPython 
>> 2.7.9: 
>>
>>
>> *File D:\web2py_last\web2py\gluon\packages\dal\pydal\adapters\base.py in 
>> create_table at line 303*
>> Function argument list
>>
>> (self=, table=> (id,name)>, migrate=True, fake_migrate=False, polymodel=None)
>> Code listing
>>
>> 298.
>> 299.
>> 300.
>> 301.
>> 302.
>> 303.
>>
>> 304.
>> 305.
>> 306.
>> 307.
>>
>>
>> # must be PK reference or unique
>> if getattr(rtable, '_primarykey', None) and rfieldname in 
>> rtable._primarykey or \
>> rfield.unique:
>> ftype = types[rfield.type[:9]] % \
>> dict(length=rfield.length)
>>
>> # multicolumn primary key reference?
>> if not rfield.unique and len(rtable._primarykey)>1:
>> # then it has to be a table level FK
>> if rtablename not in TFK:
>>
>>
>>
>>
>>

-- 
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: DAL: reference to FK-field causes an error

2016-03-12 Thread Val K

I've solved my problem  - just additional condition 
in dal\pydal\adapters\base.py:

298.
299.
300.
301.
302.
303.

304.
305.
306.
307.


# must be PK reference or unique
if rfield.type[:10] != 'reference ' and rfield.type[:14] != 
'big-reference ' and \
getattr(rtable, '_primarykey', None) and rfieldname in 
rtable._primarykey or \
rfield.unique:
ftype = types[rfield.type[:9]] % \
dict(length=rfield.length)

# multicolumn primary key reference?
if not rfield.unique and len(rtable._primarykey)>1:
# then it has to be a table level FK
if rtablename not in TFK:


works fine!




On Sunday, March 13, 2016 at 12:17:06 AM UTC+3, Val K wrote:
>
> OK! Let's dance
>
> This doesn't work (with SQLite at least):
> db.define_table('a_tbl', Field('id', 'integer'),  Field('name'), 
> primarykey=['id'] ) # one keyed table
> db.define_table('b_tbl', Field('id', 'reference a_tbl.id'), 
> Field('name'), primarykey=['id']) # another keyed table
>
>  near "name": syntax error
>
>
> sql.log:
> *CREATE TABLE b_tbl(*
> *id INTEGER, CONSTRAINT  "FK_b_tbl_id__constraint" FOREIGN KEY (id) 
> REFERENCES a_tbl (id) ON DELETE CASCADE,**name CHAR(512),**
> PRIMARY KEY(id)) ;*
>
>
> This doesn't work too:
> db.define_table('a_tbl', Field('id', 'integer'),  Field('name'), 
> primarykey=['id'] ) # one keyed table
> db.define_table('b_tbl', Field('id', db.a_tbl), Field('name'), 
> primarykey=['id']) # another keyed table
> it produces the same sql.log and causes the same error  - expected
>
>
> But this  works!:
> db.define_table('a_tbl', Field('id', 'id'),  Field('name') ) # not keyed 
> table
> db.define_table('b_tbl', Field('id', 'reference a_tbl'), Field('name'), 
> primarykey=['id']) #  keyed table that references to not keyed table
>
>
> it produces another sql.log:
> CREATE TABLE b_tbl(
> id INTEGER REFERENCES a_tbl (id) ON DELETE CASCADE  NOT NULL ,
> name CHAR(512),
> PRIMARY KEY(id)) ;
>
>
>
>
>
>
>
>
>
>
>
>
> On Saturday, March 12, 2016 at 8:54:37 PM UTC+3, Anthony wrote:
>>
>> Not sure if it's a bug, but the book does say:
>>
>>- Keyed tables can only reference other keyed tables.
>>- Referencing fields must use the reference tablename.fieldname 
>>format.
>>
>> Anthony
>>
>> On Saturday, March 12, 2016 at 4:52:53 AM UTC-5, Val K wrote:
>>>
>>> Hi!
>>> I have a problem - look at example:
>>>
>>> db.define_table('a_tbl', Field('name'))
>>> db.define_table('b_tbl', Field('id', 'reference a_tbl') ,Field('name'), 
>>> primarykey=['id'])
>>> db.define_table('c_tbl', Field('b_tbl_id', 'reference b_tbl') 
>>> ,Field('name'))
>>>
>>>
>>> *c_tbl* definition causes an error (see below) because there is  
>>> *b_tbl_id*  field that references to *b_tbl* that has *id*  reference 
>>> to *a_tbl* 
>>>
>>> Is this a bug?
>>>
>>>
>>>
>>>
>>> --
>>>
>>>  'foreign_key'
>>>
>>> web2py™Version 2.13.4-stable+timestamp.2015.12.26.04.59.39PythonPython 
>>> 2.7.9: 
>>>
>>>
>>> *File D:\web2py_last\web2py\gluon\packages\dal\pydal\adapters\base.py in 
>>> create_table at line 303*
>>> Function argument list
>>>
>>> (self=, table=>> (id,name)>, migrate=True, fake_migrate=False, polymodel=None)
>>> Code listing
>>>
>>> 298.
>>> 299.
>>> 300.
>>> 301.
>>> 302.
>>> 303.
>>>
>>> 304.
>>> 305.
>>> 306.
>>> 307.
>>>
>>>
>>> # must be PK reference or unique
>>> if getattr(rtable, '_primarykey', None) and rfieldname in 
>>> rtable._primarykey or \
>>> rfield.unique:
>>> ftype = types[rfield.type[:9]] % \
>>> dict(length=rfield.length)
>>>
>>> # multicolumn primary key reference?
>>> if not rfield.unique and len(rtable._primarykey)>1:
>>> # then it has to be a table level FK
>>> if rtablename not in TFK:
>>>
>>>
>>>
>>>
>>>

-- 
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: DAL: reference to FK-field causes an error

2016-03-13 Thread Val K

About my 'Let's dance' -comment  - there is already opened issue 
https://github.com/web2py/pydal/issues/314  (SQLite syntax error in case of 
reference to keyed table)
I opened *one* <https://github.com/web2py/pydal/issues/336>yet about 
reference to FK-field


On Sunday, March 13, 2016 at 3:51:59 AM UTC+3, Anthony wrote:
>
> You can submit an issue to the pyDAL repo.
>
> On Saturday, March 12, 2016 at 6:03:10 PM UTC-5, Val K wrote:
>>
>>
>> I've solved my problem  - just additional condition 
>> in dal\pydal\adapters\base.py:
>>
>> 298.
>> 299.
>> 300.
>> 301.
>> 302.
>> 303.
>>
>> 304.
>> 305.
>> 306.
>> 307.
>>
>>
>> # must be PK reference or unique
>> if rfield.type[:10] != 'reference ' and rfield.type[:14] != 
>> 'big-reference ' and \
>> getattr(rtable, '_primarykey', None) and rfieldname in 
>> rtable._primarykey or \
>> rfield.unique:
>> ftype = types[rfield.type[:9]] % \
>> dict(length=rfield.length)
>>
>> # multicolumn primary key reference?
>> if not rfield.unique and len(rtable._primarykey)>1:
>> # then it has to be a table level FK
>> if rtablename not in TFK:
>>
>>
>> works fine!
>>
>>
>>
>>
>> On Sunday, March 13, 2016 at 12:17:06 AM UTC+3, Val K wrote:
>>>
>>> OK! Let's dance
>>>
>>> This doesn't work (with SQLite at least):
>>> db.define_table('a_tbl', Field('id', 'integer'),  Field('name'), 
>>> primarykey=['id'] ) # one keyed table
>>> db.define_table('b_tbl', Field('id', 'reference a_tbl.id'), 
>>> Field('name'), primarykey=['id']) # another keyed table
>>>
>>>  near "name": syntax error
>>>
>>>
>>> sql.log:
>>> *CREATE TABLE b_tbl(*
>>> *id INTEGER, CONSTRAINT  "FK_b_tbl_id__constraint" FOREIGN KEY (id) 
>>> REFERENCES a_tbl (id) ON DELETE CASCADE,**name CHAR(512),**
>>> PRIMARY KEY(id)) ;*
>>>
>>>
>>> This doesn't work too:
>>> db.define_table('a_tbl', Field('id', 'integer'),  Field('name'), 
>>> primarykey=['id'] ) # one keyed table
>>> db.define_table('b_tbl', Field('id', db.a_tbl), Field('name'), 
>>> primarykey=['id']) # another keyed table
>>> it produces the same sql.log and causes the same error  - expected
>>>
>>>
>>> But this  works!:
>>> db.define_table('a_tbl', Field('id', 'id'),  Field('name') ) # not keyed 
>>> table
>>> db.define_table('b_tbl', Field('id', 'reference a_tbl'), Field('name'), 
>>> primarykey=['id']) #  keyed table that references to not keyed table
>>>
>>>
>>> it produces another sql.log:
>>> CREATE TABLE b_tbl(
>>> id INTEGER REFERENCES a_tbl (id) ON DELETE CASCADE  NOT NULL ,
>>> name CHAR(512),
>>> PRIMARY KEY(id)) ;
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Saturday, March 12, 2016 at 8:54:37 PM UTC+3, Anthony wrote:
>>>>
>>>> Not sure if it's a bug, but the book does say:
>>>>
>>>>- Keyed tables can only reference other keyed tables.
>>>>- Referencing fields must use the reference tablename.fieldname 
>>>>format.
>>>>
>>>> Anthony
>>>>
>>>> On Saturday, March 12, 2016 at 4:52:53 AM UTC-5, Val K wrote:
>>>>>
>>>>> Hi!
>>>>> I have a problem - look at example:
>>>>>
>>>>> db.define_table('a_tbl', Field('name'))
>>>>> db.define_table('b_tbl', Field('id', 'reference a_tbl') 
>>>>> ,Field('name'), primarykey=['id'])
>>>>> db.define_table('c_tbl', Field('b_tbl_id', 'reference b_tbl') 
>>>>> ,Field('name'))
>>>>>
>>>>>
>>>>&g

[web2py] Re: Advice for small database on GAE

2016-03-13 Thread Val K
Hi!
If your DB is so small and could be entirely placed in memory, you could 
have one yet  web2py app  on  PythonAnywhere.com  ( it's free)  and use it 
as just data source.
I mean  - "every couple of months with 3 or 4 more" your GAE app reload all 
data from your  PythonAnywhere app 


On Friday, March 11, 2016 at 12:07:01 AM UTC+3, Brendan wrote:
>
> Hi
>
> I have a web2py app on GAE at the moment that takes some of its data by 
> parsing a hard coded string constant (at the moment, it has a half a dozen 
> rows each with half a dozen or so columns). 
> I plan to expand this to have dozens of rows and updated every couple of 
> months with 3 or 4 more. I was planning on doing this with a local sqlite 
> database but GAE doesn't seem to support it. 
> My question is:
>
> * if I import the db into the GAE datastore how do I update it? 
>
> - If I have a local sqlite db then I can simply upload a new copy of the 
> db. 
> - Do I need to write a GAE interface to add entries (I'd rather do it 
> locally). 
> - Do I run a db restore from a local copy?
> - if I add columns later does this cause GAE any heartache?
>
> I am thinking that using the datastore will be overkill and I should just 
> serialise the db (JSON? Configparser? yaml?) then deserialise/treat it as a 
> dictionary in memory at run time.
> Advice?
>
> Thanks
>
>
> Brendan
>
>  
>

-- 
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: fighting with the widget

2016-03-15 Thread Val K
See web2py.js 
There is :
$(ul).find(":text").after('+ -').
keypress(function(e) {
return(e.which == 13) ? pe(ul, e) : true;
  }).next().click(function(e) {
pe(ul, e);
e.preventDefault();
  }).next().click(function(e) {
rl(ul, e);
e.preventDefault();
  }); 


you can overwrite it as you want




On Tuesday, March 15, 2016 at 10:11:10 PM UTC+3, Pierre wrote:
>
> ok. l see the list:string class  : class ListWidget(StringWidget)
> what i'd like to do is keep the default design and sqlform structure 
> associated to list:string fields but to have my own javascript to manage a 
> few things
>
> in particular the use of Jquery on() or Jquery delegate() to watch the + 
> and -  buttons clicks events generates conflicts
>
> how do I 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: iterating through form fields with rows

2016-03-15 Thread Val K
Hi!
Just for clarity: 
*row.field_name* - access to field value of *record retrieved from DB *( by 
db().select() ) 
*form.vars.field_name *- access to field value of *submitted from *(  
*after* form.process() )

form.vars - just a Storage() object  like a dict()

form.vars.keys() - list of all field_names
form.vars.values() - list of all field_values







On Tuesday, March 15, 2016 at 11:22:45 PM UTC+3, aetag...@gmail.com wrote:
>
> I have a table defined with 3 input fields and then an upload field. The 
> upload field is used to take the values that are entered by the user and 
> input them into a file which contains all form field values from the 
> session.
>
> The form is generated dynamically, so the number of form fields varies 
> with each session. 
>
> I am stuck on figuring out how to capture the individual form field 
> values. I am unsure if maybe I should be reading these into an array and 
> then populating the file? 
>
>
> If the form that is generated contains only one instance of the form 
> fields, I can grab these values by doing row.field1, row.field2, row.field3.
>
> I was wondering if web2py contains a method for dealing with the multiple 
> instances of form fields?
> For example, if the user created two instances of the form fields I would 
> capture values like this:
> row.field1_0, row.field2_0, row.field3_0
> row.field1_1, row.field2_1, row.field2_1
>
> However this does not work..
> I have tried doing variations of the following:
>
> for i in row.field1:
> print row.field1
>
>
> When I run this with a session containing the form with two instances of 
> form fields it will show me the values that were inputted for that session 
> in field1_0, as well as field1_1. So I am able to at least see that it is 
> capturing the separate entries in the single form. I am just not sure how 
> can I can iterate through the form fields or if there is a keyword or 
> method within web2py which will allow me to do this so I can place them 
> accordingly before the file is uploaded.
>
>

-- 
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: fighting with the widget

2016-03-15 Thread Val K
OOPs!
I make my widgets exactly this way (another class),  but Pierre  wants to 
customize existing - let's give him a chance ;)

On Tuesday, March 15, 2016 at 11:52:22 PM UTC+3, Niphlod wrote:
>
> actually you picked up a good example on how to override properly 
> web2py.js the new scaffolding app overwrites the default string widget 
> with one that is more in line with bootstrap3 (see 
> welcome/static/js/web2py-bootstrap3.js).
>
> anyhow, if you want no interactions whatsoever with web2py.js 
> or web2py-bootstrap3.js , just use a different class name (i.e. not 
> .w2p_list)
>
> On Tuesday, March 15, 2016 at 9:44:04 PM UTC+1, Val K wrote:
>>
>> See web2py.js 
>> There is :
>> $(ul).find(":text").after('+ -').
>> keypress(function(e) {
>> return(e.which == 13) ? pe(ul, e) : true;
>>   }).next().click(function(e) {
>> pe(ul, e);
>> e.preventDefault();
>>   }).next().click(function(e) {
>> rl(ul, e);
>> e.preventDefault();
>>   }); 
>>
>>
>> you can overwrite it as you want
>>
>>
>>
>>
>> On Tuesday, March 15, 2016 at 10:11:10 PM UTC+3, Pierre wrote:
>>>
>>> ok. l see the list:string class  : class ListWidget(StringWidget)
>>> what i'd like to do is keep the default design and sqlform structure 
>>> associated to list:string fields but to have my own javascript to manage a 
>>> few things
>>>
>>> in particular the use of Jquery on() or Jquery delegate() to watch the + 
>>> and -  buttons clicks events generates conflicts
>>>
>>> how do I 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: fighting with the widget

2016-03-15 Thread Val K
There is no problem with bootstrap - you can write your own widgets using 
its classes, 
but if you customize/override  web2py.js/web2py-bootsrup3.js/widgtes.py 
 you have a chance to get a pain with updating web2py (bootstrap is updated 
much rarely)

optimal solution (I think) 
-  write your own widget  python-part  and place it in the module (in 
your_app/modules  or   web2py/site-packages  - to have access from all 
 apps)
-  write your own  js-part ( separate file in static/js )

to avid js-conflicts don't use web2py CSS-classes/attrs/data-  (like w2p_*) 
  - change it to yours  and  wrap  all your js-fun in  JQuery plugin (like 
 $.your_plugin = { all your js-code })


On Wednesday, March 16, 2016 at 1:14:10 AM UTC+3, Pierre wrote:
>
> If I want to define another class like
>
> class MyListWidget(StringWidget):
>
>
> what's the location to put this code ?
>

-- 
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] please help with new widgets

2016-03-15 Thread Val K
Date/Time/Datetime Widget - doesn't become hidden after click on another 
input  ( have to click on any non-input,  tested in Opera)


On Tuesday, March 15, 2016 at 9:40:39 AM UTC+3, Sukrut Joshi wrote:
>
> please send me college management system which developed in web2py..
> which contain
> 'student
> 'staff 
> fees
> attendence
> library module
>
>
> On Mon, Mar 14, 2016 at 11:32 PM, Dave S 
> > wrote:
>
>>
>>
>> On Monday, March 14, 2016 at 10:55:53 AM UTC-7, Dave S wrote:
>>>
>>>
>>>
>>> On Monday, March 14, 2016 at 12:41:03 AM UTC-7, José L. wrote:

 Massimo, I'm missing all the time a grid (sqlgrid) widget in these 
 examples. Aren't you considering it, or it's just it's not needed as the 
 style will apply and look good in the three cases?
 Sqlgrid is one of the most powerful objects in web2py forms and I think 
 most of us could not live without it ;)

>>>
>>> He's got a replacement in mind, and this is a preparatory step.  The new 
>>> one is going to be in Forms.py, and I think he's posted a simple example in 
>>> another thread.
>>>
>>
>>
>> form.py, which is mentioned at the top of the thread, but the only 
>> discussion is in the dev group, where this example was shown:
>>
>> ef index():
>> from gluon.form import Form
>> form = Form(db.thing, request.args(0))
>> if form.accepted: ...
>> elif form.errors: ...
>> else: ...
>> return dict(form=form)
>>
>> or
>>
>> def index():
>> from gluon.form import Form
>> form = Form([Field(’name’),Field(‘age’,’integer’)])
>> if form.accepted: ...
>> elif form.errors: ...
>> else: ...
>> return dict(form=form)
>>
>>
>> /dps
>>  
>>
>>>  
>>>
>>
 2016-03-14 7:34 GMT+01:00 joseph simpson :

> Should be:
>
> http://mdipierro.github.io/stupid.css/widgets/materialize.html
>
> On Sun, Mar 13, 2016 at 11:32 PM, joseph simpson  
> wrote:
>
>> I get a 404 on the:
>>
>> http://mdipierro.github.io/stupid.css/widgets/metarialize.html
>>
>> page..
>>
>> Take care and have fun..
>>
>> Joe
>>
>> On Sun, Mar 13, 2016 at 5:06 PM, Massimo Di Pierro <
>> massimo@gmail.com> wrote:
>>
>>> can somebody help me with this little project?
>>>
>>> http://mdipierro.github.io/stupid.css/widgets/index.html
>>> http://mdipierro.github.io/stupid.css/widgets/bootstrap.html
>>> http://mdipierro.github.io/stupid.css/widgets/metarialize.html
>>>
>>> Specifically, can you read the instructions? Do they make sense? can 
>>> you help extend them? Does everything work for you?
>>> I am planning to release a new library for web2py called form.py 
>>> that will replace SQLFORM and use the new widgets.
>>>
>>> Massimo
>>>
>>> -- 
>>> 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.
>>>
>>
>>
>>
>> -- 
>> Joe Simpson
>> “Reasonable people adapt themselves to the world. Unreasonable 
>> people attempt to adapt the world to themselves. All progress, 
>> therefore, depends on unreasonable people.”
>> George Bernard Shaw
>>
>
>
>
> -- 
> Joe Simpson
> “Reasonable people adapt themselves to the world. Unreasonable people 
> attempt to adapt the world to themselves. All progress, therefore, 
> depends on unreasonable people.”
> George Bernard Shaw
>
> -- 
> 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+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Resources:
- http://web2py.

[web2py] Re: multiple id selection using request.vars.name

2016-03-20 Thread Val K
ids= isinstance(request.vars.name, basestring) and [ids] or ids # so it 
 will be a list in anyway
post_selected= db(Post._id.belongs(ids)).select()


On Sunday, March 20, 2016 at 12:41:24 AM UTC+3, Ron Chatterjee wrote:
>
>
> I have checkbox and from there I read my ids, which is request.vars.name 
> generated from a button in view  value= {{='22' }} />
>
>
> In my controller I use
>
> Post_selected   = db.Post(request.vars.name);
>
> It works fine if one id is selected lets say '22'.
>
> if
> request.vars.name
> '22'
>
> len(request.vars.name) is  2.
>
> but if
> request.vars.name
> ['22', '23']
>
> len(request.vars.name) = is also 2
>
>
> So, I am having hard time looping through the array and distinguish them.
>
> What would be the best way to get all the posts of selected id, ['22'] and 
> for multiple checkbox selection lets say ['22','23','24'] with 
> request.vars.name
>
> In other words, if my request.vars.name is ['22','23','24'] I get all the 
> posts associated with the id. If one e.g., '22', then just one.  Thanks in 
> advance.
>

-- 
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: custom authentication

2016-03-20 Thread Val K
Store user_id (or something else)  in session  and write your own decorator 
or just test in your controller "who is logged in"




On Saturday, March 19, 2016 at 2:31:11 PM UTC+3, T.R.Rajkumar wrote:
>
> I have the username, password, role in legacy SQL server database. In my 
> login from I check the credentials against the above database. Now how to 
> restrict access to controller functions, since I am not using Auth. 
> Pl.guide.
>

-- 
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] Serialize object having js-function()

2016-04-27 Thread Val K
Hi! 
I made mini but useful and universal class to hold json-serializable 
objects.
Main goal - serialize objects having items-function() as js-objects


from types import MethodType
from gluon.contrib  import simplejson as sj

class Smart_Storage(dict):
"""
A Smart_Storage object is like a dictionary but:
- set/get value:
obj['foo'] == obj.foo
- set/get attribute:
# use `._.` or `._['attr_name']`  to set attribute
obj._.attr = 'I`m attribute but not data!!!'
obj._['another_attr'] = 'I`m another one'
# set/update many attributes
obj._.update(dict(...))

# use dot only to get attribute
print obj.attr
# remember that
obj['any_attr'] == None
# but don't forget
obj.__dict__['any_attr'] == obj.any_attr

- bind/call method:
# use `._['@...']` to bind method
obj._['@my_meth'] = lambda self: 'I`m method of %s' % self
# nothing new
obj.my_meth()

- finally obj.__json__():
# works recursively
# for item that is Smart_Storage instance - item.__json__() will be 
applied
obj.__json__(only = None, exclude = None, values_only = False)

- and obj.__formatters__():
# use __formatters__ to control serialization *(note double quote)*
obj.__formatters__['key_name'] = lambda self, k, v: 
self.check_access(k) and v or '"-access denied-"'
# or just
obj.__formatters__['key_name'] = '"key = %(k)s,  value = %(v)s"'
# serialize web2py helpers
obj.html = DIV()
obj.__formatters__['html'] = lambda self, k, v: '"%s"' % v.xml()
# serialize js-function/object for embedding as script
obj.name='John'
obj.surname='Smith'
obj.who_are_you = "function(){ console.log( 'I`m', this.name, 
this.surname );}"
obj.__formatters__['who_are_you'] = '%(v)s' # not '"%(v)s"'
obj._['@xml'] = lambda self: \
SCRIPT( '\n'.join([
'var obj = %s;',
'obj.who_are_you();',
 ]) % self.__json__()
).xml()
...
# in the view just
{{ =obj }}
# that will be

"""

__getattr__ = dict.get
__getitem__ = dict.get
__delattr__ = dict.__delitem__
__repr__ = lambda self: '' % dict.__repr__(self)

class Add_Attr:

def __init__(self, mystor_obj, args=None):
self.__dict__['mystor_obj'] = mystor_obj
if args:
self.update(args)

def __setattr__(self, k, v):
if k in self.mystor_obj:
raise RuntimeError('"%s" is in keys' % k)
self.mystor_obj.__dict__[k] = v

def __setitem__(self, k ,v):
if k[0] in '0123456789&#.%$':
raise RuntimeError('"%s" is invalid name' % k)
if k[0]=='@':
v = MethodType(v, self.mystor_obj)
k=k[1:]
self.__setattr__(k ,v)


def update(self, d):
[self.__setattr__(k, d[k]) for k in d]


def __setattr__(self, k, v):
if k in self.__dict__:
raise RuntimeError('"%s" is in __dict__' % k)
dict.__setitem__(self, k, v)

def __init__(self, *a, **kwargs):
_ = kwargs.pop('_', None)
if 0:
self._ = None
self.__formatters__ = {}
dict.__init__(self, *a, **kwargs)
self.__dict__['_'] = Smart_Storage.Add_Attr(self, _)
self.__dict__['__formatters__'] = {}

def __json_pair__(self, k, v):
formatter = self.__formatters__.get(k, None)
if formatter is not None:
if callable( formatter):
ret = formatter(self, k, v)
elif isinstance(formatter, basestring):
ret = formatter % dict(k=k, v=v)
else:
raise RuntimeError('Unsupported formatter for  %s : "%s"' % 
(k, formatter))
else:
if isinstance(v, Smart_Storage):
ret = v.__json__()
elif isinstance(v, (list, tuple)):
json_lst= [isinstance(it, Smart_Storage) and it.__json__() 
or sj.dumps(it) \
for it in v]
ret= '[%s]'% ','.join(json_lst)
else:
ret = sj.dumps(v)

return (k, ret)


def __json__(self, only = None, exclude = None, values_only = False):
"""
- only / exclude - filter out keys, 'exclude' applies after 'only', 
so:
(only = ['a', 'b', 'c'], exclude = ['b']) == (only = ['a', 'c'])
- values_only = Tru

[web2py] Re: I need help with db.executesql()

2016-04-28 Thread Val K
is there "# -*- coding: utf-8 -*-"  as first line of your file.py?

On Friday, April 22, 2016 at 4:13:54 PM UTC+3, c.lp...@gmail.com wrote:
>
> hi,All:
>when i execute the following code:
> >>> from gluon import *
> >>> db = 
> DAL('db2:pyodbc://DSN=mydb;uid=db2inst1;pwd=ok896d;',db_codec='UTF-8')
> >>> db.executesql("insert into mytable(branch,name)values('11','河地')")
> >>> db.commit()
> the result is:
> 11河地
> if i replaced:
> >>> db.executesql("insert into 
> mytable(branch,name)values('11','河地')".decode('utf-8'))
> >>> db.commit()
> the result is normal.my question is how can it works normally without 
> decode()? 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] Re: How can I pre populate a option column of a form?

2016-04-28 Thread Val K
'form.vars.field = any'  must be placed before form.process()
So, in your case:
form = SQLFORM(db.pratiche)
form.vars.stato_pratica = 'aperta'
form.add_button('Back', URL('index'))
if form.process().accepted:


On Friday, April 22, 2016 at 12:23:59 AM UTC+3, Andrea Marin wrote:
>
> Trans a lot 
>
> Il giorno 21 apr 2016, alle ore 05:22, Michael Beller  > ha scritto:
>
> before you call SQLFORM, insert:
> db.pratiche.stato_pratica.default = 'aperta'
>
>
>
> On Wednesday, April 20, 2016 at 6:05:06 PM UTC-4, Andrea Marin wrote:
>>
>> Hi I have this type of form in my model file:
>>
>> db.define_table('pratiche',
>> Field('nome', requires=IS_NOT_EMPTY()),
>> Field('descrizione', 'text', requires=IS_NOT_EMPTY()),
>> Field('tipo_allegato', requires=IS_IN_SET(['mandato', 
>> 'comparsa preliminare', 'relazione ctu', 'parcella'])),
>> Field('doc_filename'),
>> Field('doc', 'upload'),
>> Field('stato_pratica', requires=IS_IN_SET(['aperta', 
>> 'attesa', 'chiusa'])),
>> auth.signature)
>>
>>
>> I want to setup a default value for field stato_pratica to 'aperta' every 
>> time a user create a new record
>> This is my controller function to create a new record
>>
>> def create():
>> form = SQLFORM(db.pratiche).process()
>> form.vars.stato_pratica = 'aperta'
>> form.add_button('Back', URL('index'))
>> if form.accepted:
>> session.flash = T('Posted')
>> redirect(URL('index'))
>> elif form.errors:
>> session.flash = T('Il form ha degli errori')
>> return locals()
>>
>> I try to set form.values.stato_pratica = 'aperta' but it not works.
>>
>> 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 a topic in the 
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/web2py/QJ1aaP5Febo/unsubscribe.
> To unsubscribe from this group and all its topics, 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] Re: login by ajax

2016-05-04 Thread Val K
Hi!
It seems, that  ajax_login isn't exist yet?

if not user:
self.log_event(self.messages['login_failed_log'],
   request.post_vars)
# invalid login
session.flash = self.messages.invalid_login
callback(onfail, None)
redirect(
self.url(args=request.args, 
vars=request.get_vars),
client_side=settings.client_side)




On Saturday, March 2, 2013 at 5:46:53 PM UTC+3, Phyo Arkar wrote:
>
> If you worry about your credentials visibility over the wire , SSL.
> If you worry about your credentials visibility on the screen , None 
> actually.
>
> On Sat, Mar 2, 2013 at 5:54 AM, Alan Etkin  > wrote:
>
>> +1 for auth,ajax_login()
>>
>>
>> I'm also interested in a bare ajax login feature, but, what about the 
>> security risks of passing credentials with javascript in the background? 
>> What are the issues to take in account for that feature? I there any 
>> standard way of securing the passwords and other sensible data that can be 
>> used?
>>
>> -- 
>>  
>> --- 
>> 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/groups/opt_out.
>>  
>>  
>>
>
>

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


  1   2   3   4   >