[web2py] best practice for create table base on user insert

2017-07-25 Thread 黄祥
let say i have table that will create a new table base on user input on 
that table
*e.g.*
*models/db_schema_1_chart_of_account.py*
def __after_insert_chart_of_account(f, id):
name = f['name']
table_name = name.replace(' ','_').lower()
filename = os.path.join(request.folder, 'models', 'db_schema_3_%s.py') % 
(table_name)
if not os.path.exists(filename):
define_table = "db.define_table('%s', detail_coa)"  % (table_name)
file = open(filename, "w")
file.write('# -*- coding: utf-8 -*-')
file.write('\n')
file.write(define_table)
file.close()

*models/db_schema_2_account.py*
def __after_insert_account(f, id):
name = f['name']
query_ar = (db.chart_of_account.classification == 'Account Receivable')
row_ar = db(query_ar).select().last()
code_ar = int(row_ar.code) + 1
db.chart_of_account.insert(code = code_ar, name = 'Account Receivable %s' % 
(name), 
  classification = 'Account Receivable')
query_ap = (db.chart_of_account.classification == 'Account Payable')
row_ap = db(query_ap).select().last()
code_ap = int(row_ap.code) + 1
db.chart_of_account.insert(code = code_ap, name = 'Account Payable %s' % 
(name), 
  classification = 'Account Payable')

*controllers/install.py*
def index():
db.chart_of_account.bulk_insert([
{"code" : "110", "name" : "Account Receivable", 
 "classification" : "Account Receivable"}, 
{"code" : "200", "name" : "Account Payable", 
 "classification" : "Account Payable"}, 
 ] )
db.account.bulk_insert([
{"name" : "Account0"}, 
{"name" : "Account1"}, ] )

*Question :*
- is it best practice to do like example code above? tested it with small 
data (install/index) but feel slow respond, because perhaps, the table in 
models is load in every request, even the current data is small. any others 
ideas?

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: sqlform.grid maxtextlengths shoots blanks

2017-07-25 Thread Seth J
I have a similar problem with maxtextlengths and I do have the "represent" 
attribute set like so:
Field('f_last_change', type='text',
  label=T('Latest Changes'),
  default = '',
  represent=lambda text, row: HTML(XML('' if text is 
None else text.replace('\n', '')), sanitize=True, 
permitted_tags=['br/'])
 )

Any suggestions how to keep the formatting, but still have field 
truncated?  Thanks!!!


On Friday, June 12, 2015 at 12:07:20 PM UTC-4, Anthony wrote:
>
> Which version of web2py? Also, have you set the "represent" attribute on 
> the field in question?
>
> And just to be clear, is the problem that the actual text truncation isn't 
> happening where you expect, or is it just that the physical width of the 
> table column is smaller than you'd like? Maybe show a screenshot.
>
> Anthony
>
> On Friday, June 12, 2015 at 12:27:27 AM UTC-4, jackso...@quantachrome.com 
>  wrote:
>>
>> I get the same truncated display for the log message text no matter what 
>> I set maxtextlengths...This app is rock+1 on the IQ simplicity scale and 
>> yet it does not work...BTW: I removed all layouts stuff so its not some css 
>> problem. The truncated fields are what the grid wants to display. Its like 
>> the grid is on autopilot, any suggestions???
>>
>> MODEL:
>>
>> db2 = DAL('sqlite://autoflowLog.sqlite')
>> db2.define_table('log_messages',
>> Field('time_stamp', length=30),
>> Field('log_message_text', length = 256))
>> db2.log_messages.id.readable = False
>>
>> VIEW:
>>
>> AutoFlow Log
>> Log Messages:
>> {{=form}}
>>
>>
>> CONTROLLER:
>>
>> def display_log():
>> grid = SQLFORM.grid(db2.log_messages, editable = False, searchable = 
>> False,formstyle = 'divs',maxtextlengths={'log_messages.log_message_text' : 
>> 80})
>> return dict(form=grid)
>>
>

-- 
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: appadmin

2017-07-25 Thread LC LC
Solved : 
https://stackoverflow.com/questions/8643664/new-database-refuses-to-show-up-in-web2py-appadmin


Le mardi 25 juillet 2017 21:37:47 UTC+2, LC LC a écrit :
>
> Hi,
>
> Why can i see tables like auth_user, auth_group, auth_event in appadmin.
> the tables exist however ..
> 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] SQLTABLE, columns, and joins

2017-07-25 Thread Dave S
Last night I couldn't figure out to use SQLTABLE's columns param when ROWS 
I'm trying to display are from an inner join.  The ROW objects are composed 
of dict-like objects for both [or more] tables, i.e.,
{{segment={id=1234567890, waypoint="Thishereplace",route="thataway", partof=
666}},
 {run={id=666,description="InAHandbasket"}}

(my apologies if some of those brackets should be square instead of curly; 
I forgot to cuttenpaiste last night when the examples were dancing before 
my eyes)

In the columns param, [db.run.id, ...] didn't work, and [run[].id, ...] 
didn't work, and I don't think [myrows.run.id, ...] worked (where myrows is 
the query result).  And query results don't name the ROW structure inside 
the ROWS.  So what would work?

BTW, I did find a way around this problem ... make the select() do just the 
fields needed for the display, which I understand to be the way 
SQLFORM.grid works.  Oh, and I probably could use this project as a way to 
learn to use datatables or a similar js library.  But is there an answer to 
my original approach?

T'anks
/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] appadmin

2017-07-25 Thread LC LC
Hi,

Why can i see tables like auth_user, auth_group, auth_event in appadmin.
the tables exist however ..
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: redirect if registration is pending

2017-07-25 Thread Leonel Câmara
Nope, that option doesn't exist yet.  
  
You can go around this by using auth.settings.login_onvalidation and 
putting a function there that checks for that, sets an appropriate 
session.flash with auth.messages.registration_pending, and redirects. 
  
You can also submit an issue in github and ask that the option is added. 
You can also add it yourself as it wouldn't be hard and it kind of makes 
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] redirect if registration is pending

2017-07-25 Thread Mark Billion
Dumb question and Im sure that there is an answer that Im missing, but when 
in doubt

App requires registration to be approved and if its not, it redirects to 
the home screen and flashes the standard message.  If I want to redirect a 
login where the user is pending approval to a different page, what is the 
code for that?

ie, something like: auth.settings.register_pending__next = 'foo'

Any thoughts?

-- 
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: wrapping long text lengths in grid/smartgrid

2017-07-25 Thread Anthony
On Monday, July 24, 2017 at 2:04:19 AM UTC-4, rāma wrote:
>
> Still no solution?
>

The grid now includes a  element with  elements like the 
following:



So, you can use CSS rules to control the width of columns based on field 
names or column numbers.

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: After update can't connect Oracle

2017-07-25 Thread Вячеслав Анатольевич
Hi, another error in oracle (can't create auth_  tables):

 not all arguments converted during string 
formatting

File "D:\Web\server\web2py\gluon\packages\dal\pydal\adapters\oracle.py", line 
70, in create_sequence_and_triggers
'MINVALUE -1;' % sequence_name)
TypeError: not all arguments converted during string formatting

Function argument list

(self=, query='CREATE TABLE "auth_user"(\n 
"id" NUMBER PRIMAR...HAR2(512),\n "registration_id" VARCHAR2(512)\n);', 
table=, **args={})


65.
66.
67.
68.
69.
70.

71.
72.
73.
74.

sequence_name = table._sequence_name
trigger_name = table._trigger_name
self.execute(query)
self.execute(
'CREATE SEQUENCE %s START WITH 1 INCREMENT BY 1 NOMAXVALUE ' +
'MINVALUE -1;' % sequence_name)

self.execute(_trigger_sql % dict(
trigger_name=trigger_name, tablename=tablename,
sequence_name=sequence_name,
id=id_name)

any ideas?

-- 
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: grid for data entry

2017-07-25 Thread Nico de Groot
Looks like you specify the left relation also in the select clause. Debugging 
tip: you can use _select() to see the SQL generated by the DAL. 
To get answers in the forum, it helps if you convert your question to an 
minimal example using easy to grasp tablenames and relations.

Nico de Groot 

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