[web2py] Re: Legacy table with reserved keyword in column name

2017-10-26 Thread Val K
Hi
this should help:  
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Reserved-keywords
I think check_reserved=['common'] will solve the problem

On Thursday, October 26, 2017 at 10:56:45 PM UTC+3, Fabiano Almeida wrote:
>
> Hi!
>
> How to put in the DAL a legacy table whose column name matches reserved 
> SQL words?
>
> Traceback:
>
> SyntaxError: invalid table/column name "Message" is a "ALL" reserved 
> SQL/NOSQL keywor
>
>
>
> 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] Legacy table with reserved keyword in column name

2017-10-26 Thread Fabiano Almeida
Hi!

How to put in the DAL a legacy table whose column name matches reserved SQL
words?

Traceback:

SyntaxError: invalid table/column name "Message" is a "ALL" reserved
SQL/NOSQL keywor



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 get the last few records except the last record

2017-10-26 Thread Anthony
There's no need to select the extra record and then drop it via Python. Instead 
you can just change the range of the limitby tuple to get exactly the records 
you want.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: How to get the last few records except the last record

2017-10-26 Thread Maurice Waka
Works well.
Great!

On 26 Oct 2017 9:31 AM, "sesenmaister"  wrote:

> records  = db(db.post.author == auth.user_id).select(orderby=(db.post.ALL,
> limitby=(0,10))*[:-1]*
>
> On Thursday, October 26, 2017 at 7:03:00 AM UTC+2, Maurice Waka wrote:
>>
>> If using the code: limitby=(0,10) am able to get the last 10 records,  Is
>> there a way to get the same(last few records) except the very last
>> record(last record posted to the db) from the db.
>>  I have tried:
>> records  = db(db.post.author == auth.user_id).select(orderby=(db.post.ALL,
>> limitby=(0,-9))...getting a blank screen instead
>> regards
>>
>> --
> 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/jOt3JLi8vJw/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: Update database (multiple tables) with CSV in sequence

2017-10-26 Thread 'Matthew J Watts' via web2py-users
great, thanks for your help Dave. I'll have a go and if i have any luck
will post my code for future reference

On Mon, Oct 23, 2017 at 10:02 PM, Dave S  wrote:

>
>
> On Saturday, October 21, 2017 at 2:25:47 PM UTC-7, Matthew J Watts wrote:
>>
>> Hi all
>>
>> I'm pretty new to web2py and web development in general. I'm really stuck
>> with something and haven't been able to find a tutorial which can help me
>> out etc. I was wondering if some one could point me in the right direction.
>>
>> I have three tables. I want to upload a csv, and update each table in
>> sequence, so a newly generated primary key  can be passed to each
>> successive table.
>>
>> (1)
>> db.define_table('study_info',
>> Field('title'))
>>  One
>> to many relationship
>> (2)
>> db.define_table('',
>>
>> Field('study_info_id', 'reference study_info'),
>> Field('taxon_name', type = 'string',
>> comment='Classification of sample collected'))
>>
>> (3)
>> db.define_table('sample_data',
>>  One to many relationship
>> Field('Core_data_id', 'reference core_data'),
>> Field('value', type = 'double'))
>>
>>
>> So just to clarify , data gets entered into the first table,  the primary
>> key from table 1 is then passed to the foreign key of 2, then same again
>> for 2 to 3.
>>
>> I managed to get the function working to update one table from a csv,
>>  Would i somehow modify this with a for loop to insert one line from the
>> csv at a time?
>>
>> def import_csv():
>> from gluon.sqlhtml import form_factory
>> form = SQLFORM.factory(Field('csvfile','upload',uploadfield=False))
>> if form.process().accepted:
>> db.study_info.import_from_csv_file(request.vars.csvfile.file)
>> redirect(URL('index'))
>> return dict(form=form)
>>
>>
>>
> I see 3 possible ways to go:
>
> Probably the cleanest is to do what import_from_csv_file() does:
>
>  import csv  # it's in the standard Python library,
> csv.reader(mycsvfile, etc)
> # 
> # for each line in the file:
> lineno, line in enumerate(reader):
>validate line
>new_id = update_or_insert()
># take a look at gluon/packages/dal/pydal/objects.py, lines 911-949
># to see how column headers are handled, etc
>handle_next_table_here(..., new_id,...)
>
> The second way is similar, but puts more burden on you in preparing the
> insert
>
> file = open(mycsvfile)
> while not eof:
>line = readline(file)
>pieces = line.split(",")
>pieces = pieces.cleanup()
># cleanup is a routine you supply to validate the format of the fields
># the split and the cleanup may need to handle different delimiters
> ("csv" may actually be tab-seperated, or space-seperated)
># and if you have what looks like a delimiter in a quoted field, you
> have to deal with that, too.
># but if your csv is controlled enough, you can do this without too
> much trouble.
>new_id = update_or_insert()
>handle_next_table_here(..., new_id,...)
>
> The third choice is easy [1] but ugly, and may be slow:
>
> file1 = open(mycsvflle, "rb")
> while not eof:
>line = files1.readline()
>file2 = open(mytmpfile, "wb")
>file2.write(line)
>file2.close()
>import_from_csv_file(file2)
>newrow = db(query).select().last()
>handle_next_table_here(..., newrow.id,...)
>
>
>
> [1] okay, not dramatically easier than the first 2
>
> Good luck!
>
> /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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/JDVUaWb26ns/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: to be or not to be... run by scheduler

2017-10-26 Thread Manuele Pesenti
It seams that the parameter request.is_scheduler is always set to false 
on my colleague windows system


could it be a possible bug? Any other experience?

    M.


On 20/10/2017 17:20, Anthony wrote:

If it is a scheduler execution, request.is_scheduler will be True.

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 get the last few records except the last record

2017-10-26 Thread sesenmaister
records  = db(db.post.author == auth.user_id).select(orderby=(db.post.ALL, 
limitby=(0,10))*[:-1]*

On Thursday, October 26, 2017 at 7:03:00 AM UTC+2, Maurice Waka wrote:
>
> If using the code: limitby=(0,10) am able to get the last 10 records,  Is 
> there a way to get the same(last few records) except the very last 
> record(last record posted to the db) from the db.
>  I have tried:
> records  = db(db.post.author == auth.user_id).select(orderby=(db.post.ALL, 
> limitby=(0,-9))...getting a blank screen instead
> regards
>
>

-- 
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: do LOAD statements work in layout.html?

2017-10-26 Thread Dave S


On Wednesday, October 25, 2017 at 3:55:13 PM UTC-7, Dave S wrote:
>
> Last night, I thought I had it working.  Today it doesn't seem  to be.
>
> (I wanted to have a blurb on the page, and also be able to show the blurb 
> as an specific page).
>
> The specific page still works, using blurb.html, but the blurb doesn't 
> show on other pages with blurb.load.  I don't even see blurb.load being 
> requested in httpserver.log, which it did last night.   One obvious thought 
> is javascript blocking, but I've got my site whitelisted in noscript, and 
> the Chrome browser is also not showing it.
>
> There are other ways to handle this, but what the heck happened?
>

[Faceplant]

In a formatting tweak, I accidentally moved the LOAD into a sidebar block, 
without turning sidebars on.

[straightening tie and hornrim glasses]

Now that that's sorted, how do I limit the width of the block so that it 
isn't 2 lines by 16 inches of 10 or 12 point characters?  Wide sentences 
are harder to read.  This app uses bootstrap3 like the welcome app.

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