[web2py] how to call sqlform from a view

2013-01-17 Thread Alex Glaros
The example at http://web2py.com/books/default/chapter/29/07#SQLFORM shows 
this function below. But what is the syntax for calling a function from a 
view?

Would it be this?  {{=display_form()}}

thanks,

Alex Glaros


def display_form():
   form = SQLFORM(db.person)
   if form.process().accepted:
   response.flash = 'form accepted'
   elif form.errors:
   response.flash = 'form has errors'
   else:
   response.flash = 'please fill out the form'
   return dict(form=form)




-- 





[web2py] Are there conditions under which labels are not shown in SQLForm ?

2013-01-17 Thread GeeksRule
I have an SQLForm, and have a dictionary of labels, but they aren't been 
overriden :

{'fname':'First name: ', 'lname':'Last name : ', 'Published_Datetime':'Date 
when you published : '}

here "fname" is the column name in th database.

are there any conditions where the labels I provide won't work ?

-- 





[web2py] Re: change string format of date picker

2013-01-17 Thread Tim Richardson


On Thursday, 17 January 2013 14:56:51 UTC+11, Massimo Di Pierro wrote:
>
> Does this help? 
> http://web2py.com/books/default/chapter/29/03#On-date,-datetime-and-time-format
>
>
My little problem was that I'm using some legacy code, which wanted dates 
as strings in dd-mm-. The date picker returns strings -mm-dd. 
Mostly in my app, -mm-dd is exactly ok, but there is this one instance 
where dd-mm- is required. So I wondered if there was an easy way to 
change behaviour of the widget, one-time (so I don't want to change 
application-wide defaults). The jquery docs suggest only javascript can do 
it. In the end I just used datetime to convert it to a date and back to a 
string in my required format. 


 

> On Wednesday, 16 January 2013 21:24:06 UTC-6, Tim Richardson wrote:
>>
>> I'm using the date picker in a form by using _class='date'
>> Can I change the format of the string returned?
>>
>>

-- 





[web2py] Re: change string format of date picker

2013-01-17 Thread Tim Richardson
HI Massimo, the anchor in the URL reference to the book doesn't work, by 
the way, not for me anyway . 


On Thursday, 17 January 2013 14:56:51 UTC+11, Massimo Di Pierro wrote:
>
> Does this help? 
> http://web2py.com/books/default/chapter/29/03#On-date,-datetime-and-time-format
>
> On Wednesday, 16 January 2013 21:24:06 UTC-6, Tim Richardson wrote:
>>
>> I'm using the date picker in a form by using _class='date'
>> Can I change the format of the string returned?
>>
>>

-- 





[web2py] Re: 'DAL' object has no attribute 'auth_wiki' - trunk version

2013-01-17 Thread Alan Etkin

>
> Working on trying out the json support but db won't get past this error.


This is a bug introduced when templates were restored conditionally. The 
remplates query should be executed after defining the wiki tables, I'll 
send a patch asap.

-- 





[web2py] Re: MongoDB 'document' or 'dict' filetype

2013-01-17 Thread Alan Etkin

>
> At the moment MongodbAdapter only has these filetypes


The MongoDBAdapter now supports storing JSON documents, plus a json widget 
and IS_JSON validator. See this slice for more details:
http://www.web2pyslices.com/slice/show/1580/save-the-earth-from-a-total-data-mess-with-mongodbadapter

-- 





[web2py] auth.wiki doesn't find pages without tags

2013-01-17 Thread Vinicius Assef
I've had a problem today, trying to search auth.wiki pages without
tags, but they aren't found.

As tags aren't required to save a page, I think this is a problem in
Wiki.search() method.

What do you think?

-- 





[web2py] 'DAL' object has no attribute 'auth_wiki' - trunk version

2013-01-17 Thread Bill Thayer
Working on trying out the json support but db won't get past this error.

Traceback (most recent call last):
  File "C:\web2py_src_2.2.1\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
  File "C:/web2py_src_2.2.1/web2py/applications/TAMOTO/models/db.py" 
, line 73, in 

auth.wiki(resolve=False)
  File "C:\web2py_src_2.2.1\web2py\gluon\tools.py", line 3330, in wiki
templates=templates)
  File "C:\web2py_src_2.2.1\web2py\gluon\tools.py", line 4766, in __init__
templates = db.auth_wiki.tags.contains('template')&\
  File "C:\web2py_src_2.2.1\web2py\gluon\dal.py", line 7256, in __getattr__
return ogetattr(self, key)
AttributeError: 'DAL' object has no attribute 'auth_wiki'


-- 





[web2py] Re: how to make a page auto scroll to previous viewing point after refresh...

2013-01-17 Thread Alan Etkin

>
> if i scroll down a page, and click some link that redirects back to the 
> page


You could build the feature yourself, with this tools.

http://api.jquery.com/focus/
http://api.jquery.com/ready/
http://api.jquery.com/click/

And you will need also to pass the element's id to the controller so it 
knows which element should have the focus on page load.
 

-- 





[web2py] Re: Triggering imports during web2py startup

2013-01-17 Thread Daniel Gonzalez
That is true ... per-process. If my apache server has several processes, I 
must make sure that all processes are triggered. This is difficult to 
guarantee.

On Thursday, January 17, 2013 8:50:53 PM UTC+1, Niphlod wrote:
>
> I'm not very well versed in all the intricacies, but if the "layer" calls 
> os.fork() (if you're on linux, that's probably what the underlying server 
> does) your import will happen only on the first request. 
> All the subsequent should not import anything because they will "acquire" 
> the current status of the process when they are forked. 
> There are some options in most of the "layers" (being apache, uwsgi, and 
> so on) to tell the interpreter to completely restart the process after a 
> while, but if you have those issues you'll be better off never forcing a 
> restart of the interpreter.
>
> On Wednesday, January 16, 2013 5:47:18 PM UTC+1, Daniel Gonzalez wrote:
>>
>> That would work, and is what I am planning to do, but: how can I 
>> guarantee that all processes (threads?) have been targetted?.
>> I guess this is not possible, unless I start at least N parallel 
>> requests, N being the number of processes ...
>>
>> On Wednesday, January 16, 2013 5:37:24 PM UTC+1, Niphlod wrote:
>>>
>>> do an "outside" request as soon as you reload apache with curl ?
>>>
>>> Il giorno mercoledì 16 gennaio 2013 12:06:14 UTC+1, Daniel Gonzalez ha 
>>> scritto:

 Hi,

 In my models I am importing third party libraries. Importing those 
 libraries takes time (3s) which means the first requests (one per process) 
 take long time to be served.

 Do you have any suggestion on how to trigger the importing before the 
 first requests arrive? I am running web2py via apache / mod_wsgi.

 Thanks,
 Daniel

>>>

-- 





[web2py] Re: Problems with auth.login_bare when using postgres

2013-01-17 Thread Daniel Gonzalez
M, not really: I still need to create the database. Maybe web2py can do 
that for me if I start with a blank postgres database, but I am not 
familiar with that, so this was an easier path for me.

By the way, I found out another problem: we need "serial PRIMARY KEY", so 
the sed script must be changed to include:

s/INTEGER PRIMARY KEY AUTOINCREMENT/serial PRIMARY KEY/

And the postgres sequences must be initialized after import:

select setval(pg_get_serial_sequence('auth_user'   , 'id'), (select max(
id) from auth_user) );
select setval(pg_get_serial_sequence('fulluser', 'id'), (select max(
id) from fulluser) );
select setval(pg_get_serial_sequence('auth_group'  , 'id'), (select max(
id) from auth_group) );
select setval(pg_get_serial_sequence('auth_membership' , 'id'), (select max(
id) from auth_membership) );
select setval(pg_get_serial_sequence('auth_permission' , 'id'), (select max(
id) from auth_permission) );
select setval(pg_get_serial_sequence('auth_event'  , 'id'), (select max(
id) from auth_event) );
select setval(pg_get_serial_sequence('auth_cas', 'id'), (select max(
id) from auth_cas) );



On Thursday, January 17, 2013 8:52:03 PM UTC+1, Niphlod wrote:
>
> yep, probably exporting all to csv and reimporting would have you saved a 
> bit of hassle.
>
> On Wednesday, January 16, 2013 5:43:09 PM UTC+1, Daniel Gonzalez wrote:
>>
>> I found the problem: CHAR fields in postgres (the default that the .dump 
>> command in sqlite is generating) will be extended with spaces to fill the 
>> available length in postgres, so that username/password do not match 
>> anymore.
>>
>> I have modified my import script like this:
>>
>> import_from_sqlite_ ( ) {
>> # Set the following:
>> #  WEB2PY_PG_DB : the name of the database in postgres to import to
>> #  SQLITE_FILE: the location of the sqlite file
>> #  PG_USER  : the postgres user
>> #  PG_PWD   : the potgres password
>> #
>> sql_dump="/tmp/from_sqlite.sql"
>> # Dump the data:
>> #   - PRAGMA and AUTOINCREMENT are not supported in postgres
>> #   - sqlite_sequence is specific to sqlite
>> #   - CHAR will have fixed size in postgres, so it will be filled 
>> with empty spaces. Use VARCHAR instead.
>> sqlite3 $SQLITE_FILE .dump | sed -e 
>> '/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//;s/ 
>> CHAR/ VARCHAR/' > $sql_dump
>> # Drop / recreate database
>> sudo -u postgres dropdb $WEB2PY_PG_DB
>> sudo -u postgres createdb -O $PG_USER -E UTF8 $WEB2PY_PG_DB
>> # Import the data
>> sudo -u postgres PGPASSWORD=$PG_PWD psql -h localhost -U $PG_USER -d 
>> $WEB2PY_PG_DB < $sql_dump
>> # Show some data, to see if the import worked fine
>> sudo -u postgres psql -l
>> echo "\dt" | sudo -u postgres psql -d $WEB2PY_PG_DB
>> echo "select * from auth_user;" | sudo -u postgres psql -d 
>> $WEB2PY_PG_DB
>> rm -f $sql_dump
>> }
>>
>>
>> Be careful with this, since it will drop and recreate the database. Also, 
>> the changes to the sqlite dump are very specific to my situation. YMMV.
>>
>> On Wednesday, January 16, 2013 4:06:23 PM UTC+1, Daniel Gonzalez wrote:
>>>
>>> Hi,
>>>
>>> The following code was working when using SQLite, and now that I have 
>>> moved to postgres it is failing:
>>>
>>> auth.login_bare(request.vars.email, request.vars.password)
>>>
>>> I have the passwords for the time being in plaintext, both in postgres 
>>> and SQLite. I have imported the data to postgres like this:
>>>
>>> # PRAGMA and AUTOINCREMENT are not supported in postgres
>>> # sqlite_sequence is specific to sqlite
>>> sqlite3 storage.sqlite .dump | sed -e 
>>> '/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//' > /tmp/from_sqlite.sql
>>> sudo -u postgres PGPASSWORD=mypass psql -h localhost -U myuser -d 
>>> web2py_wavportal < /tmp/from_sqlite.sql
>>>
>>> I have verified that the data in postgres looks fine:
>>>
>>> web2py_wavportal=# \dt
>>>   List of relations
>>>  Schema |  Name   | Type  |   Owner   
>>> +-+---+---
>>>  public | auth_cas| table | wavportal
>>>  public | auth_event  | table | wavportal
>>>  public | auth_group  | table | wavportal
>>>  public | auth_membership | table | wavportal
>>>  public | auth_permission | table | wavportal
>>>  public | auth_user   | table | wavportal
>>>  public | fulluser| table | wavportal
>>> (7 rows)
>>>
>>> The credentials in auth_user are as expected, but auth.login_bare is 
>>> failing. Why could that be?
>>>
>>> Thanks,
>>> Daniel
>>>
>>

-- 





[web2py] Re: Can anyone create anyone create some helpful stuff on Codeacademy..??

2013-01-17 Thread howesc
any specific tutorial requests?  perhaps that will help get some potential 
educators going.

On Wednesday, January 16, 2013 8:43:11 AM UTC-8, Dreamer wrote:
>
> Hi guys,
> I am  a noob to programming after a lot of reading and trying my hands at 
> my languages i decided python as a language of choice...
> similiarly web2py has been my crush for some time nowso i was just 
> looking for some python champ to help out people like me with a structure 
> that codecademy offers..i know some Django users are getting on with django 
> lessonsso if our user base manages to put some tuts out there it would 
> be a great help since i love the web2py framework and i know many out there 
> would love it too...thank you
>

-- 





[web2py] SQLFORM.grid with multiple LEFT OUTER JOINs

2013-01-17 Thread Jim S
Is there a way to specify 2 left outer joins for a SQLFORM.grid?

I tried this:

query = (db.feedLoad.deliverOn==datetime.datetime.today())&(
db.feedLoad.siteId==1)

fields = [db.feedLoad.siteId, db.feedOrderLine.productSiteId, 
db.feedLoad.deliverOn, db.feedLoad.loadNumber, 
db.feedOrder.customerName, db.feedOrder.customerCityState,
db.feedOrder.dropShipName, db.feedOrder.dropShipCityState,
db.feedLoad.driverId, db.feedOrder.orderNumber,
db.feedOrderLine.productNumber, db.feedOrderLine.productName]

left = 
db.feedOrder.on(db.feedLoad.feedLoadId==db.feedOrder.feedLoadId).db.feedOrderLine.on(db.feedOrder.feedOrderId==db.feedOrderLine.feedOrderId)

grid = SQLFORM.grid(query, left=left)

This works but I get WAY more records than I should

-- 





[web2py] how to make a page auto scroll to previous viewing point after refresh...

2013-01-17 Thread sasogeek
if i scroll down a page, and click some link that redirects back to the 
page, how do i make the page auto scroll down to the same place it was 
before i clicked the link?

-- 





[web2py] smartgrid - display linked_tables link as a dropdown button instead

2013-01-17 Thread Jim S
I have a number of smartgrids built where the number of linked tables is 
pushing the other edit/delete buttons off the right of the page.  I'm 
wondering if there is a simple way that I've missed where you can put your 
linked_table links into a dropdown button of different 'actions' you could 
perform on the row.  Seems like this should be easy with the fancy twitter 
bootstrap buttons available.  Also, can I override the default buttons 
(display/edit/delete) with some twitter bootstrap buttons?

Should this be an enhancement request?

-- 





[web2py] Re: Problems with auth.login_bare when using postgres

2013-01-17 Thread Niphlod
yep, probably exporting all to csv and reimporting would have you saved a 
bit of hassle.

On Wednesday, January 16, 2013 5:43:09 PM UTC+1, Daniel Gonzalez wrote:
>
> I found the problem: CHAR fields in postgres (the default that the .dump 
> command in sqlite is generating) will be extended with spaces to fill the 
> available length in postgres, so that username/password do not match 
> anymore.
>
> I have modified my import script like this:
>
> import_from_sqlite_ ( ) {
> # Set the following:
> #  WEB2PY_PG_DB : the name of the database in postgres to import to
> #  SQLITE_FILE: the location of the sqlite file
> #  PG_USER  : the postgres user
> #  PG_PWD   : the potgres password
> #
> sql_dump="/tmp/from_sqlite.sql"
> # Dump the data:
> #   - PRAGMA and AUTOINCREMENT are not supported in postgres
> #   - sqlite_sequence is specific to sqlite
> #   - CHAR will have fixed size in postgres, so it will be filled 
> with empty spaces. Use VARCHAR instead.
> sqlite3 $SQLITE_FILE .dump | sed -e 
> '/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//;s/ 
> CHAR/ VARCHAR/' > $sql_dump
> # Drop / recreate database
> sudo -u postgres dropdb $WEB2PY_PG_DB
> sudo -u postgres createdb -O $PG_USER -E UTF8 $WEB2PY_PG_DB
> # Import the data
> sudo -u postgres PGPASSWORD=$PG_PWD psql -h localhost -U $PG_USER -d 
> $WEB2PY_PG_DB < $sql_dump
> # Show some data, to see if the import worked fine
> sudo -u postgres psql -l
> echo "\dt" | sudo -u postgres psql -d $WEB2PY_PG_DB
> echo "select * from auth_user;" | sudo -u postgres psql -d 
> $WEB2PY_PG_DB
> rm -f $sql_dump
> }
>
>
> Be careful with this, since it will drop and recreate the database. Also, 
> the changes to the sqlite dump are very specific to my situation. YMMV.
>
> On Wednesday, January 16, 2013 4:06:23 PM UTC+1, Daniel Gonzalez wrote:
>>
>> Hi,
>>
>> The following code was working when using SQLite, and now that I have 
>> moved to postgres it is failing:
>>
>> auth.login_bare(request.vars.email, request.vars.password)
>>
>> I have the passwords for the time being in plaintext, both in postgres 
>> and SQLite. I have imported the data to postgres like this:
>>
>> # PRAGMA and AUTOINCREMENT are not supported in postgres
>> # sqlite_sequence is specific to sqlite
>> sqlite3 storage.sqlite .dump | sed -e 
>> '/^PRAGMA/d;/sqlite_sequence/d;s/AUTOINCREMENT//' > /tmp/from_sqlite.sql
>> sudo -u postgres PGPASSWORD=mypass psql -h localhost -U myuser -d 
>> web2py_wavportal < /tmp/from_sqlite.sql
>>
>> I have verified that the data in postgres looks fine:
>>
>> web2py_wavportal=# \dt
>>   List of relations
>>  Schema |  Name   | Type  |   Owner   
>> +-+---+---
>>  public | auth_cas| table | wavportal
>>  public | auth_event  | table | wavportal
>>  public | auth_group  | table | wavportal
>>  public | auth_membership | table | wavportal
>>  public | auth_permission | table | wavportal
>>  public | auth_user   | table | wavportal
>>  public | fulluser| table | wavportal
>> (7 rows)
>>
>> The credentials in auth_user are as expected, but auth.login_bare is 
>> failing. Why could that be?
>>
>> Thanks,
>> Daniel
>>
>

-- 





[web2py] Re: Triggering imports during web2py startup

2013-01-17 Thread Niphlod
I'm not very well versed in all the intricacies, but if the "layer" calls 
os.fork() (if you're on linux, that's probably what the underlying server 
does) your import will happen only on the first request. 
All the subsequent should not import anything because they will "acquire" 
the current status of the process when they are forked. 
There are some options in most of the "layers" (being apache, uwsgi, and so 
on) to tell the interpreter to completely restart the process after a 
while, but if you have those issues you'll be better off never forcing a 
restart of the interpreter.

On Wednesday, January 16, 2013 5:47:18 PM UTC+1, Daniel Gonzalez wrote:
>
> That would work, and is what I am planning to do, but: how can I guarantee 
> that all processes (threads?) have been targetted?.
> I guess this is not possible, unless I start at least N parallel requests, 
> N being the number of processes ...
>
> On Wednesday, January 16, 2013 5:37:24 PM UTC+1, Niphlod wrote:
>>
>> do an "outside" request as soon as you reload apache with curl ?
>>
>> Il giorno mercoledì 16 gennaio 2013 12:06:14 UTC+1, Daniel Gonzalez ha 
>> scritto:
>>>
>>> Hi,
>>>
>>> In my models I am importing third party libraries. Importing those 
>>> libraries takes time (3s) which means the first requests (one per process) 
>>> take long time to be served.
>>>
>>> Do you have any suggestion on how to trigger the importing before the 
>>> first requests arrive? I am running web2py via apache / mod_wsgi.
>>>
>>> Thanks,
>>> Daniel
>>>
>>

-- 





[web2py] Re: can't install v 2.3

2013-01-17 Thread Niphlod
don't know if Roberto will dig that, but the script I was referring to is 
https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh
 
.  

On Thursday, January 17, 2013 9:11:02 AM UTC+1, Lewis wrote:
>
> Which script?  I used Bruno's from slices, which was pretty recent.  His 
> script installs from maintainer (ubuntu) packages.  Thanks. 
> I am going to rely on script based installs from now on.  Even if a pain 
> to diagnose, once right you have something repeatable.
>
> On Wednesday, January 16, 2013 8:43:12 AM UTC-8, Niphlod wrote:
>>
>> That's why now the script installs uwsgi from pip and relies on the 
>> easier-than-a-drink-to-maintain emperor mode of uwsgi.
>>
>> Il giorno mercoledì 16 gennaio 2013 03:00:40 UTC+1, Lewis ha scritto:
>>>
>>> Back in business.
>>>
>>> There was detritus from previous installs interfering with new installs.
>>>
>>> So, the culprit is not uwsgi:  unjustly accused.  Apologies.
>>>
>>> File based config is inherently fragile.
>>>
>>> Uninstalling with apt-get --purge remove uwsgi, etc. was the only way to 
>>> really start fresh.
>>>
>>> I think the scripts need to be more robust to deal with upgrade in place 
>>> scenarios, not just new "from-scratch" installation.
>>>
>>

-- 





[web2py] Re: Edit an article

2013-01-17 Thread Alan Etkin

>
> well I didn't try to give them excess but sounds logical. nevertheless I 
> didn't want to give them access to that. But I don't want to access each 
> article by myself just because someone did a spelling mistake or wants to 
> add a little content.
>

A very simple rights restriction example for editing Articles:

def owns_article(arg=None):
return db((db.Article.owner_id==auth.user_id)&\
  (db.Article.id==request.args(1))).count() > 0

@auth.requires(owns_article)
def edit_article():
form = SQLFORM(db.Article, request.args(1))
return dict(form=form)

You must point users to the edit page with urls like

URL(f="edit_article", args=["Article", ])

And add a Field("owner_id", "reference auth_user", default=auth.user_id, 
writable=False) to the Article table definition

web2py also provides an API for fine-grained access control, covered here: 
http://www.web2py.com/books/default/chapter/29/09

-- 





[web2py] Re: Insert on multiple tables with SQLFORM.grid

2013-01-17 Thread Anthony
The "create" action of the grid results in a URL that ends with args 
/new/tablename, so you can do:

if request.args and request.args[-2] == 'new':
tablename = request.args[-1]
[custom create code]

Anthony

On Thursday, January 17, 2013 11:32:08 AM UTC-5, AngeloC wrote:
>
> Hi guys,
>
> I'm trying to insert something into related tables with SQLFORM.grid.
>
> I want the user can see only one form with mixed fields for the various 
> tables. Tables are related, so I have to insert a record contemporary on 
> multiple tables. However I want to stick to SQLFORM.grid for the maximum 
> extent.
>
> As far I can understand, there is no way to make it with the 
> stock SQLFORM.grid, so I should opt for SQLFORM.factory.
>
> Is there an easy way to intercept the "create" (insertion) of SQLFORM.grid 
> and replace it with an SQLFORM.factory?
>
> Thank you!
>
> -- 
> Profile: http://it.linkedin.com/in/compagnucciangelo 
>

-- 





[web2py] aµzing...

2013-01-17 Thread Bill Thayer
Been searching a while now for the magic decoder ring that solves the UTF-8 
encoding issue.

If I enter a mu (µ) by typing alt+0181 into my form field it looks fine. 
Then looking at the data in SQLDeveloper (Oracle) the data is 2 little 
boxes. NP I think the client encoding is wrong so I set my preferences to 
UTF-8 but µ is still 2 boxes. Still not worried yet but then I refresh  or 
re-edit the field with the µ in it then it is returned from the database as 
two question marks. Same behavior occurs with the squared (²) sign...two 
boxes in db, two question marks in returned value on page.

Anyone solve this yet?

Thank you,
Bill

-- 





Re: [web2py] should re remove crud from the book?

2013-01-17 Thread Alan Etkin

>
> ... But if we want to keep it longer term we need a better reason.


A recent post has reminded me about a really cool crud feature:

crud.settings.

What would be the replacements for SQLFORM?, I don't think that SQLFORM 
supports this kind of options.

-- 





[web2py] Get the Local time

2013-01-17 Thread Andrew Evans
Hello web2py group! I am trying to find a way to get the local time say PST
or EST so I can display a video based on that time.

Any suggestions? I was able to convert it to UTC but this doesn't really
help the situation


{{project_date = db(db.schedule).select(orderby=~db.schedule.date_in,
limitby=(0,1))}}
{{for project in project_date:}}
{{start = project.date_in}}
{{end = project.date_out}}
{{dt_utc = datetime.datetime.utcnow()}}
{{current_time = dt_utc - datetime.timedelta(seconds=time.altzone)}}
{{if current_time >= start and current_time <= end:}}


*cheers

and thank you

-- 





[web2py] Re: Get the Local time

2013-01-17 Thread Andrew Evans
I was able to solve my problem with this if anyone is interested

import pytz

{{current_time =
datetime.datetime.now(pytz.timezone('America/Vancouver')).replace(tzinfo=None)}}

*cheers

On Thu, Jan 17, 2013 at 8:25 AM, Andrew Evans wrote:

> Hello web2py group! I am trying to find a way to get the local time say
> PST or EST so I can display a video based on that time.
>
> Any suggestions? I was able to convert it to UTC but this doesn't really
> help the situation
>
>
> {{project_date = db(db.schedule).select(orderby=~db.schedule.date_in,
> limitby=(0,1))}}
> {{for project in project_date:}}
> {{start = project.date_in}}
> {{end = project.date_out}}
> {{dt_utc = datetime.datetime.utcnow()}}
> {{current_time = dt_utc - datetime.timedelta(seconds=time.altzone)}}
> {{if current_time >= start and current_time <= end:}}
>
>
> *cheers
>
> and thank you
>
>

-- 





[web2py] Re: Query not returning correct data

2013-01-17 Thread Alan Etkin
I'd suggest a couple of changes:

- Change CamelCase (used in Python class definitions) with 
the_more_appropiate_convention for object attributes.
- Those foreign keys you have declared as ThingId should be renamed as 
thing_id (for a more web2py like naming style)
- Reference keys (links to other tables) are easily handled if declared as 
type "reference " (i.e. it adds widgets automatically to 
sqlforms)

The empty query results you are getting (in case you actually inserted and 
commited changes to tables) are probably related to unexpected values (i.e. 
None, empty strings passed in the query expression)

Again, using the methods covered in the book for building forms (i.e. 
SQLFORM) will do things really easier.

If you still need to implement the code you posted as is, I'd suggest you 
log/inspect the output of the values submitted in the form, for detecting 
incompatible data used in the controller for building the query.

-- 





Re: [web2py] Having some strange occurence with label printing and FPDF

2013-01-17 Thread Paul Rykiel
mine worked by copying to gluon/contrib/fpdf

and then in code:

from gluon.contrib.fpdf import PDFLabel



On Thu, Jan 17, 2013 at 10:42 AM, António Ramos wrote:

> I still cannot import it in web2py shell by just copying pdflabels.py to
> gluon/contrib/pypdf
>
> can someone post a stupid example app?
>
> Thank you
> António
>
> 2013/1/17 Paul Rykiel 
>
>> I just want to say a big Thank you!
>> this works perfectly!!
>> I am so happy!
>> Best Regards,
>>
>> On Thu, Jan 17, 2013 at 1:49 AM, Mariano Reingart wrote:
>>
>>> Sorry, the correct url for PDFLabels is currently:
>>>
>>> https://code.google.com/p/pyfpdf/source/browse/tools/pdflabels.py
>>>
>>> We did some cleanups and reorganization of the project folders
>>> structure to be more compatible with pep8, distutils, etc.
>>> For the next release, if you can confirm that PDFLabels is working
>>> with the new structure, it could be moved to fpdf folder (currently in
>>> tools) so it would be packaged with web2py.
>>>
>>> BTW, there has been some other enhancements and bugfixes to PyFPDF
>>> thanks to several contributors, if you find an issue, please grab a
>>> latest copy and take a look on the project site:
>>>
>>> https://code.google.com/p/pyfpdf/source/browse/
>>>
>>> (look for the download zip link)
>>>
>>> https://code.google.com/p/pyfpdf/issues/list
>>>
>>> ASAP we close a few more pending tickets, surely a new version of FPDF
>>> will be published.
>>>
>>> Best regards,
>>>
>>> Mariano Reingart
>>> http://www.sistemasagiles.com.ar
>>> http://reingart.blogspot.com
>>>
>>>
>>> On Thu, Jan 17, 2013 at 4:13 AM, José Luis Redrejo 
>>> wrote:
>>> > I've just checked pdflabel is not included in fpdf in web2py. I ignore
>>> > the reason because I uploaded it to pyfpdf 18 months ago. I thought
>>> > web2py automatically included pyfpdf updates. You can download it from
>>> > http://code.google.com/p/pyfpdf/source/browse/pdflabels.py and copy it
>>> > at gluon/contrib/fpdf directory so you can use:
>>> >
>>> > from gluon.contrib.fpdf.pdflabels import PDFLabel
>>> >
>>> > PDFLabel accepts "\n" , if you use cell, it doesn't understand "\n"
>>> >
>>> > Regards.
>>> >
>>> > 2013/1/16 Paul Rykiel :
>>> >> Hi Jose,
>>> >>
>>> >> I tried what you suggested, I was getting errors on the line
>>> >> from glon.contrib.pyfpdf.pdflabels import PDFLabel ... it does not
>>> seem to
>>> >> exist, and cannot find how to load this
>>> >>
>>> >> so, my other option seems to be to get all of the text inside of one
>>> cell,
>>> >> so I used your "more_text" from below, it works ('sort of") ... it
>>> lists all
>>> >> of the text inside the one cell, but
>>> >> the program is ignoring the "\n" page breaks, if I can get those to
>>> work, I
>>> >> am almost done
>>> >>
>>> >> then I have to figure out how to create the pages side by side, but I
>>> want
>>> >> to tackle one thing at a time.
>>> >>
>>> >> I am sure when I get to my next issue of printing the labels where
>>> there are
>>> >> 3 labels across and 10 down, maybe I will have to figure out
>>> >> how to use the PDFLabel, but for right now I just want to get this to
>>> work.
>>> >>
>>> >> thanks for all of your help!!
>>> >> Regards,
>>> >>
>>> >>
>>> >> On Wednesday, January 16, 2013 12:46:34 PM UTC-6, José L. wrote:
>>> >>>
>>> >>> Some time ago, we include PDFLabel too, so you can simplify your code
>>> >>> if you are using an avery-compatible format ( the sys stuff is only
>>> >>> needed if you're using a non-english language):
>>> >>>
>>> >>> def label_bikes():
>>> >>> from gluon.contrib.pyfpdf.pdflabels import PDFLabel
>>> >>> import sys
>>> >>> reload(sys)
>>> >>> sys.setdefaultencoding( "latin-1" )
>>> >>>
>>> >>> pdf = PDFLabel('Apli-01277')
>>> >>> pdf.add_page()
>>> >>> rows = db(db.bike.id.belongs(bikeIds)).select()
>>> >>> # Print labels
>>> >>> for row in rows:
>>> >>> idString = row.destination + str(row.id)
>>> >>> more_text = idString
>>> >>> more_text += "Make:  " + row.make + "\n" if row.make else ""
>>> >>> more_text += "Model:  " + row.model + "\n" if row.model else
>>> ""
>>> >>> more_text += "Size:  " + row.size + "\n" if row.size else ""
>>> >>> pdf.add_label(more_text)
>>> >>>
>>> >>> response.headers['Content-Type'] = 'application/pdf'
>>> >>> response.headers['Content-Disposition']='attachment.filename =
>>> >>> sample.pdf'
>>> >>> return pdf.output(dest='S')
>>> >>>
>>> >>>
>>> >>> Regards
>>> >>> José L.
>>> >>>
>>> >>> 2013/1/16 Paul Rykiel :
>>> >>> > Hi Mariano,
>>> >>> > thank you for the response. Let me look into the margin issue,
>>> maybe you
>>> >>> > have given me enough to figure this out.
>>> >>> > thanks so much for the response. you know, Massimo was my
>>> professor last
>>> >>> > term.
>>> >>> >
>>> >>> > On Wednesday, January 16, 2013 12:39:06 AM UTC-6, Mariano Reingart
>>> >>> > wrote:
>>> >>> >>
>>> >>> >> Hello Paul:
>>> >>> >>
>>> >>> >> Could you send a sample without actu

Re: [web2py] Having some strange occurence with label printing and FPDF

2013-01-17 Thread António Ramos
I still cannot import it in web2py shell by just copying pdflabels.py to
gluon/contrib/pypdf

can someone post a stupid example app?

Thank you
António

2013/1/17 Paul Rykiel 

> I just want to say a big Thank you!
> this works perfectly!!
> I am so happy!
> Best Regards,
>
> On Thu, Jan 17, 2013 at 1:49 AM, Mariano Reingart wrote:
>
>> Sorry, the correct url for PDFLabels is currently:
>>
>> https://code.google.com/p/pyfpdf/source/browse/tools/pdflabels.py
>>
>> We did some cleanups and reorganization of the project folders
>> structure to be more compatible with pep8, distutils, etc.
>> For the next release, if you can confirm that PDFLabels is working
>> with the new structure, it could be moved to fpdf folder (currently in
>> tools) so it would be packaged with web2py.
>>
>> BTW, there has been some other enhancements and bugfixes to PyFPDF
>> thanks to several contributors, if you find an issue, please grab a
>> latest copy and take a look on the project site:
>>
>> https://code.google.com/p/pyfpdf/source/browse/
>>
>> (look for the download zip link)
>>
>> https://code.google.com/p/pyfpdf/issues/list
>>
>> ASAP we close a few more pending tickets, surely a new version of FPDF
>> will be published.
>>
>> Best regards,
>>
>> Mariano Reingart
>> http://www.sistemasagiles.com.ar
>> http://reingart.blogspot.com
>>
>>
>> On Thu, Jan 17, 2013 at 4:13 AM, José Luis Redrejo 
>> wrote:
>> > I've just checked pdflabel is not included in fpdf in web2py. I ignore
>> > the reason because I uploaded it to pyfpdf 18 months ago. I thought
>> > web2py automatically included pyfpdf updates. You can download it from
>> > http://code.google.com/p/pyfpdf/source/browse/pdflabels.py and copy it
>> > at gluon/contrib/fpdf directory so you can use:
>> >
>> > from gluon.contrib.fpdf.pdflabels import PDFLabel
>> >
>> > PDFLabel accepts "\n" , if you use cell, it doesn't understand "\n"
>> >
>> > Regards.
>> >
>> > 2013/1/16 Paul Rykiel :
>> >> Hi Jose,
>> >>
>> >> I tried what you suggested, I was getting errors on the line
>> >> from glon.contrib.pyfpdf.pdflabels import PDFLabel ... it does not
>> seem to
>> >> exist, and cannot find how to load this
>> >>
>> >> so, my other option seems to be to get all of the text inside of one
>> cell,
>> >> so I used your "more_text" from below, it works ('sort of") ... it
>> lists all
>> >> of the text inside the one cell, but
>> >> the program is ignoring the "\n" page breaks, if I can get those to
>> work, I
>> >> am almost done
>> >>
>> >> then I have to figure out how to create the pages side by side, but I
>> want
>> >> to tackle one thing at a time.
>> >>
>> >> I am sure when I get to my next issue of printing the labels where
>> there are
>> >> 3 labels across and 10 down, maybe I will have to figure out
>> >> how to use the PDFLabel, but for right now I just want to get this to
>> work.
>> >>
>> >> thanks for all of your help!!
>> >> Regards,
>> >>
>> >>
>> >> On Wednesday, January 16, 2013 12:46:34 PM UTC-6, José L. wrote:
>> >>>
>> >>> Some time ago, we include PDFLabel too, so you can simplify your code
>> >>> if you are using an avery-compatible format ( the sys stuff is only
>> >>> needed if you're using a non-english language):
>> >>>
>> >>> def label_bikes():
>> >>> from gluon.contrib.pyfpdf.pdflabels import PDFLabel
>> >>> import sys
>> >>> reload(sys)
>> >>> sys.setdefaultencoding( "latin-1" )
>> >>>
>> >>> pdf = PDFLabel('Apli-01277')
>> >>> pdf.add_page()
>> >>> rows = db(db.bike.id.belongs(bikeIds)).select()
>> >>> # Print labels
>> >>> for row in rows:
>> >>> idString = row.destination + str(row.id)
>> >>> more_text = idString
>> >>> more_text += "Make:  " + row.make + "\n" if row.make else ""
>> >>> more_text += "Model:  " + row.model + "\n" if row.model else
>> ""
>> >>> more_text += "Size:  " + row.size + "\n" if row.size else ""
>> >>> pdf.add_label(more_text)
>> >>>
>> >>> response.headers['Content-Type'] = 'application/pdf'
>> >>> response.headers['Content-Disposition']='attachment.filename =
>> >>> sample.pdf'
>> >>> return pdf.output(dest='S')
>> >>>
>> >>>
>> >>> Regards
>> >>> José L.
>> >>>
>> >>> 2013/1/16 Paul Rykiel :
>> >>> > Hi Mariano,
>> >>> > thank you for the response. Let me look into the margin issue,
>> maybe you
>> >>> > have given me enough to figure this out.
>> >>> > thanks so much for the response. you know, Massimo was my professor
>> last
>> >>> > term.
>> >>> >
>> >>> > On Wednesday, January 16, 2013 12:39:06 AM UTC-6, Mariano Reingart
>> >>> > wrote:
>> >>> >>
>> >>> >> Hello Paul:
>> >>> >>
>> >>> >> Could you send a sample without actual data?
>> >>> >> (without the db query, so it can be reproduced)
>> >>> >>
>> >>> >> fpdf.cell will jump to the next page if no more room available,
>> maybe
>> >>> >> there is a sizing or rounding issue.
>> >>> >> Also, you have to take a look at page margins.
>> >>> >>
>> >>> >> Best regards,
>> >>> >>
>> 

[web2py] Insert on multiple tables with SQLFORM.grid

2013-01-17 Thread Angelo Compagnucci
Hi guys,

I'm trying to insert something into related tables with SQLFORM.grid.

I want the user can see only one form with mixed fields for the various
tables. Tables are related, so I have to insert a record contemporary on
multiple tables. However I want to stick to SQLFORM.grid for the maximum
extent.

As far I can understand, there is no way to make it with the
stock SQLFORM.grid, so I should opt for SQLFORM.factory.

Is there an easy way to intercept the "create" (insertion) of SQLFORM.grid
and replace it with an SQLFORM.factory?

Thank you!

-- 
Profile: http://it.linkedin.com/in/compagnucciangelo

-- 





Re: [web2py] Having some strange occurence with label printing and FPDF

2013-01-17 Thread Paul Rykiel
I just want to say a big Thank you!
this works perfectly!!
I am so happy!
Best Regards,

On Thu, Jan 17, 2013 at 1:49 AM, Mariano Reingart wrote:

> Sorry, the correct url for PDFLabels is currently:
>
> https://code.google.com/p/pyfpdf/source/browse/tools/pdflabels.py
>
> We did some cleanups and reorganization of the project folders
> structure to be more compatible with pep8, distutils, etc.
> For the next release, if you can confirm that PDFLabels is working
> with the new structure, it could be moved to fpdf folder (currently in
> tools) so it would be packaged with web2py.
>
> BTW, there has been some other enhancements and bugfixes to PyFPDF
> thanks to several contributors, if you find an issue, please grab a
> latest copy and take a look on the project site:
>
> https://code.google.com/p/pyfpdf/source/browse/
>
> (look for the download zip link)
>
> https://code.google.com/p/pyfpdf/issues/list
>
> ASAP we close a few more pending tickets, surely a new version of FPDF
> will be published.
>
> Best regards,
>
> Mariano Reingart
> http://www.sistemasagiles.com.ar
> http://reingart.blogspot.com
>
>
> On Thu, Jan 17, 2013 at 4:13 AM, José Luis Redrejo 
> wrote:
> > I've just checked pdflabel is not included in fpdf in web2py. I ignore
> > the reason because I uploaded it to pyfpdf 18 months ago. I thought
> > web2py automatically included pyfpdf updates. You can download it from
> > http://code.google.com/p/pyfpdf/source/browse/pdflabels.py and copy it
> > at gluon/contrib/fpdf directory so you can use:
> >
> > from gluon.contrib.fpdf.pdflabels import PDFLabel
> >
> > PDFLabel accepts "\n" , if you use cell, it doesn't understand "\n"
> >
> > Regards.
> >
> > 2013/1/16 Paul Rykiel :
> >> Hi Jose,
> >>
> >> I tried what you suggested, I was getting errors on the line
> >> from glon.contrib.pyfpdf.pdflabels import PDFLabel ... it does not seem
> to
> >> exist, and cannot find how to load this
> >>
> >> so, my other option seems to be to get all of the text inside of one
> cell,
> >> so I used your "more_text" from below, it works ('sort of") ... it
> lists all
> >> of the text inside the one cell, but
> >> the program is ignoring the "\n" page breaks, if I can get those to
> work, I
> >> am almost done
> >>
> >> then I have to figure out how to create the pages side by side, but I
> want
> >> to tackle one thing at a time.
> >>
> >> I am sure when I get to my next issue of printing the labels where
> there are
> >> 3 labels across and 10 down, maybe I will have to figure out
> >> how to use the PDFLabel, but for right now I just want to get this to
> work.
> >>
> >> thanks for all of your help!!
> >> Regards,
> >>
> >>
> >> On Wednesday, January 16, 2013 12:46:34 PM UTC-6, José L. wrote:
> >>>
> >>> Some time ago, we include PDFLabel too, so you can simplify your code
> >>> if you are using an avery-compatible format ( the sys stuff is only
> >>> needed if you're using a non-english language):
> >>>
> >>> def label_bikes():
> >>> from gluon.contrib.pyfpdf.pdflabels import PDFLabel
> >>> import sys
> >>> reload(sys)
> >>> sys.setdefaultencoding( "latin-1" )
> >>>
> >>> pdf = PDFLabel('Apli-01277')
> >>> pdf.add_page()
> >>> rows = db(db.bike.id.belongs(bikeIds)).select()
> >>> # Print labels
> >>> for row in rows:
> >>> idString = row.destination + str(row.id)
> >>> more_text = idString
> >>> more_text += "Make:  " + row.make + "\n" if row.make else ""
> >>> more_text += "Model:  " + row.model + "\n" if row.model else ""
> >>> more_text += "Size:  " + row.size + "\n" if row.size else ""
> >>> pdf.add_label(more_text)
> >>>
> >>> response.headers['Content-Type'] = 'application/pdf'
> >>> response.headers['Content-Disposition']='attachment.filename =
> >>> sample.pdf'
> >>> return pdf.output(dest='S')
> >>>
> >>>
> >>> Regards
> >>> José L.
> >>>
> >>> 2013/1/16 Paul Rykiel :
> >>> > Hi Mariano,
> >>> > thank you for the response. Let me look into the margin issue, maybe
> you
> >>> > have given me enough to figure this out.
> >>> > thanks so much for the response. you know, Massimo was my professor
> last
> >>> > term.
> >>> >
> >>> > On Wednesday, January 16, 2013 12:39:06 AM UTC-6, Mariano Reingart
> >>> > wrote:
> >>> >>
> >>> >> Hello Paul:
> >>> >>
> >>> >> Could you send a sample without actual data?
> >>> >> (without the db query, so it can be reproduced)
> >>> >>
> >>> >> fpdf.cell will jump to the next page if no more room available,
> maybe
> >>> >> there is a sizing or rounding issue.
> >>> >> Also, you have to take a look at page margins.
> >>> >>
> >>> >> Best regards,
> >>> >>
> >>> >> Mariano Reingart
> >>> >> http://www.sistemasagiles.com.ar
> >>> >> http://reingart.blogspot.com
> >>> >>
> >>> >>
> >>> >> On Tue, Jan 15, 2013 at 8:02 PM, Paul Rykiel 
> wrote:
> >>> >> > Greetings this is my code:
> >>> >> >
> >>> >> > def triagePrintTags(bikeIds):
> >>> >> > assert(bikeIds != None)
> >>> >> >

[web2py] Re: How to avoid Not authorized?

2013-01-17 Thread Sverre
Never mind. I worked too much. This posting can be ignored.

On Thursday, January 17, 2013 4:47:45 PM UTC+1, Sverre wrote:
>
> I defined a custom auth.user table like
>
> db.define_table(
>
> auth.settings.table_user_name,
> Field('username', length=20, default=''),
> Field('first_name', length=128, default=''),
> Field('last_name', length=128, default=''),
> Field('email', length=128, default='', unique=True), # required
> Field('password', 'password', length=512,# required
>   readable=False, label='Password'),
> Field('description','text',label='Comment'),
> Field('registration_key', length=512,# required
>   writable=False, readable=False, default=''),
> Field('reset_password_key', length=512,  # required
>   writable=False, readable=False, default=''),
> Field('registration_id', length=512, # required
>   writable=False, readable=False, default=''))
>
>
> ## do not forget validators
> custom_auth_table = db[auth.settings.table_user_name] # get the 
> custom_auth_table
> custom_auth_table.username.requires =   IS_NOT_EMPTY(error_message=auth.
> messages.is_empty)
> custom_auth_table.first_name.requires =   IS_NOT_EMPTY(error_message=auth.
> messages.is_empty)
> custom_auth_table.last_name.requires =   IS_NOT_EMPTY(error_message=auth.
> messages.is_empty)
> #custom_auth_table.password.requires = [IS_STRONG(), CRYPT()]
> custom_auth_table.email.requires = [
>   IS_EMAIL(error_message=auth.messages.invalid_email),
>   IS_NOT_IN_DB(db, custom_auth_table.email)]
>
>
> auth.settings.table_user = custom_auth_table # tell auth to use 
> custom_auth_table
>
>
> Then I defined a view index.html just including a link with the class btn. 
> When I'm accessing the destination page I'm getting "Not authorized". This 
> was working before until I added a login rule for the destination 
> controller: 
>
> # coding: utf8
> # try something like
> #@auth.requires_login()
> def index(): 
> return dict()
> 
> #@auth.requires_login()
> def organisations():
> table = db.organisations
> query = (table.id>0)
> return dict(grid=SQLFORM.grid(query))
>
> So I'm logged in with a user and this user has no access rights even when 
> I commented the access roles. 
>
>
>

-- 





[web2py] How to avoid Not authorized?

2013-01-17 Thread Sverre
I defined a custom auth.user table like

db.define_table(

auth.settings.table_user_name,
Field('username', length=20, default=''),
Field('first_name', length=128, default=''),
Field('last_name', length=128, default=''),
Field('email', length=128, default='', unique=True), # required
Field('password', 'password', length=512,# required
  readable=False, label='Password'),
Field('description','text',label='Comment'),
Field('registration_key', length=512,# required
  writable=False, readable=False, default=''),
Field('reset_password_key', length=512,  # required
  writable=False, readable=False, default=''),
Field('registration_id', length=512, # required
  writable=False, readable=False, default=''))


## do not forget validators
custom_auth_table = db[auth.settings.table_user_name] # get the 
custom_auth_table
custom_auth_table.username.requires =   IS_NOT_EMPTY(error_message=auth.
messages.is_empty)
custom_auth_table.first_name.requires =   IS_NOT_EMPTY(error_message=auth.
messages.is_empty)
custom_auth_table.last_name.requires =   IS_NOT_EMPTY(error_message=auth.
messages.is_empty)
#custom_auth_table.password.requires = [IS_STRONG(), CRYPT()]
custom_auth_table.email.requires = [
  IS_EMAIL(error_message=auth.messages.invalid_email),
  IS_NOT_IN_DB(db, custom_auth_table.email)]


auth.settings.table_user = custom_auth_table # tell auth to use 
custom_auth_table


Then I defined a view index.html just including a link with the class btn. 
When I'm accessing the destination page I'm getting "Not authorized". This 
was working before until I added a login rule for the destination 
controller: 

# coding: utf8
# try something like
#@auth.requires_login()
def index(): 
return dict()

#@auth.requires_login()
def organisations():
table = db.organisations
query = (table.id>0)
return dict(grid=SQLFORM.grid(query))

So I'm logged in with a user and this user has no access rights even when I 
commented the access roles. 


-- 





Re: [web2py] how to create a counter button...

2013-01-17 Thread sasogeek
I did read the book, but only the chapters I needed information from to get 
my app started :) thanks anyway
please look up my app here though if you'd be interested in using it 
http://newupp.tk
what  it's about is briefed here 
https://sasogeek.pythonanywhere.com/newup/default/about (temporary url 
though)

thanks again for your help :)

On Thursday, 17 January 2013 14:42:06 UTC, rochacbruno wrote:
>
>
> Did you read the book?  I recommend chapters 3, 4 and 6
>
> Plus the Ajax one: http://web2py.com/books/default/chapter/29/11
>

-- 





Re: [web2py] editing database entry

2013-01-17 Thread Bruno Rocha
controllers/article.py

#http://./article/add
def add():
form = SQLFORM(db.article).process()
return dict(form=form)

#http:///article/edit/1
def edit():
article_id = request.args(0) or redirect(URL('index'))
form = SQLFORM(db.article, article_id).process()
return dict(form=form)

#http:///article/show/1
def show():
article_id = request.args(0) or redirect(URL('index'))
article = db.article[article_id]
return dict(article=article)

def index():
   articles = db(db.article).select()
   return dict(articles=articles)



On Thu, Jan 17, 2013 at 12:49 PM, BlueShadow  wrote:

> Hi,
> I got a table for articles me and other people write(authors) I want all
> the authors to be able to edit those articles. I currently got no clue
> where I'm going to start this project. Any help is greatly appreciated.
>
> --
>
>
>
>

-- 





[web2py] Re: crud to SQLFORM

2013-01-17 Thread Annet
Hi Anthony,

Thanks for your reply. Problem solved!

Best regards,

Annet

-- 





[web2py] editing database entry

2013-01-17 Thread BlueShadow
Hi,
I got a table for articles me and other people write(authors) I want all 
the authors to be able to edit those articles. I currently got no clue 
where I'm going to start this project. Any help is greatly appreciated.

-- 





Re: [web2py] how to create a counter button...

2013-01-17 Thread Bruno Rocha
Did you read the book?  I recommend chapters 3, 4 and 6

Plus the Ajax one: http://web2py.com/books/default/chapter/29/11

-- 





Re: [web2py] Trying to do a new database as a field in web2py,

2013-01-17 Thread Bruno Rocha
Wow, Now I see my example completely wrong..

should be


db.define_table('post',
  # more fields here
 Field('thoughts', "reference Thoughts")

)

db.define_table('Thoughts',
 Field('Editedby', db.auth_user, default=None, readable=True,
writable=True),
Field('TitleOfPost',requires=IS_NOT_EMPTY()),
Field('ContentOfPost','text',requires=IS_NOT_EMPTY()),
Field('DatePosted','date'),
Field('DP_Large', 'upload', uploadfield='picture_file'),
Field('picture_file', 'blob'),
)

-- 





Re: [web2py] Trying to do a new database as a field in web2py,

2013-01-17 Thread Bruno Rocha
On Thu, Jan 17, 2013 at 5:39 AM, damien rompapas  wrote:

> I am sorry if the question is not clear enough.


Yes it is not clear :)

are you trying to create a table inside a table? it is not permitted on
relational dbms. (are you using NOSQL)?

I think you want to create separate tables and create relations?


*BTW: you dont need the trailing ; in Python


db.define_table('post',
 # fields here!
)

db.define_table('Thoughts',
 Field('Editedby', db.auth_user, default=None, readable=True,
writable=True),
Field('TitleOfPost',requires=IS_NOT_EMPTY()),
Field('ContentOfPost','text',requires=IS_NOT_EMPTY()),
Field('DatePosted','date'),
Field('DP_Large', 'upload', uploadfield='picture_file'),
Field('picture_file', 'blob'),
Field('comments', "reference post")
)

try to use all lowercase names for table and fields.

-- 





[web2py] Re: sqlform onvalidation changes upload image file to txt file

2013-01-17 Thread Anthony
Didn't Massimo already solve this for 
you: https://groups.google.com/d/msg/web2py/YlGv7Ap1HVA/AkEyDkUr-FAJ

First, your onvalidation function stores the file using the field's 
.store() method. Then it assigns the resulting filename to form.vars.photo, 
which presumably is an upload field. Subsequently, the .accepts() method 
attempts to store the contents of form.vars.photo in a file as well (it is 
expecting form.vars.photo to be the uploaded file at that point, not a 
filename) -- hence the second file, which contains the name of the first 
file.

Anthony

On Thursday, January 17, 2013 8:50:25 AM UTC-5, Ramos wrote:
>
> hello
> i have a strange behaviour in my sqlform
>
> def attach_image_to_record(form):
>
> if form.vars.delete_this_record not in ['on']:
>
> response=requests.get(form.vars.fp_url)
> img=Image.open(StringIO(response.content))
> img.save('foto1231.jpg','JPEG')
> temp=open('foto1231.jpg','rb')
> foto=db.trabalhador.foto.store(temp,'foto.jpg')
> print "print new foto",foto   # this prints something like 
> trabalhador.foto.123o817.asdasdaid.jpg
> form.vars.foto=foto
>
>
> if trabalhador_form.process(onvalidation=attach_image_to_record).accepted:
> print "trab foto",trabalhador_form.vars.foto  
> # this prints something like 
> trabalhador.foto.987398734982734.12312o319832789.txt
>
> in my upload folder i see the 2 files.
> The txt inside has writen the name of the image file above
>
> Why?
>
> Thank you
>
>
>

-- 





[web2py] Re: sqlform onvalidation changes upload image file to txt file

2013-01-17 Thread António Ramos
I´m helping myself.
I need to add fiels=['f1','f2','f3'] excluding the field foto! in sqlform

Thank you me!
:)

2013/1/17 António Ramos 

> hello
> i have a strange behaviour in my sqlform
>
> def attach_image_to_record(form):
>
> if form.vars.delete_this_record not in ['on']:
>
> response=requests.get(form.vars.fp_url)
> img=Image.open(StringIO(response.content))
> img.save('foto1231.jpg','JPEG')
> temp=open('foto1231.jpg','rb')
> foto=db.trabalhador.foto.store(temp,'foto.jpg')
> print "print new foto",foto   # this prints something like
> trabalhador.foto.123o817.asdasdaid.jpg
> form.vars.foto=foto
>
>
> if trabalhador_form.process(onvalidation=attach_image_to_record).accepted:
> print "trab foto",trabalhador_form.vars.foto
> # this prints something like
> trabalhador.foto.987398734982734.12312o319832789.txt
>
> in my upload folder i see the 2 files.
> The txt inside has writen the name of the image file above
>
> Why?
>
> Thank you
>
>
>

-- 





[web2py] Re: View not displaying the pictures

2013-01-17 Thread Mihir Lade
Actually got this to work however the issue now is its iterating thorugh 
the table and printing out the information twice.. so for example.. 

if i have one picture there is information next to that picture.. and the 
next picture should have another bit of info.. how do i get that to work?

-- 





[web2py] sqlform onvalidation changes upload image file to txt file

2013-01-17 Thread António Ramos
hello
i have a strange behaviour in my sqlform

def attach_image_to_record(form):

if form.vars.delete_this_record not in ['on']:

response=requests.get(form.vars.fp_url)
img=Image.open(StringIO(response.content))
img.save('foto1231.jpg','JPEG')
temp=open('foto1231.jpg','rb')
foto=db.trabalhador.foto.store(temp,'foto.jpg')
print "print new foto",foto   # this prints something like
trabalhador.foto.123o817.asdasdaid.jpg
form.vars.foto=foto


if trabalhador_form.process(onvalidation=attach_image_to_record).accepted:
print "trab foto",trabalhador_form.vars.foto
# this prints something like
trabalhador.foto.987398734982734.12312o319832789.txt

in my upload folder i see the 2 files.
The txt inside has writen the name of the image file above

Why?

Thank you

-- 





[web2py] View not displaying the pictures

2013-01-17 Thread Mihir Lade
Can't get my view to display the pictures in the database..

{{for xxx in records:}}





{{pass}}
  

Encounter error:

Error traceback 

1.
2.
3.
4.
5.
6.

Traceback (most recent call last):
  File "I:\wdd-softw\web2py\gluon\restricted.py", line 184, in restricted
  File 
"K:\wdd-softw\web2py\applications\Assignment/views/default/getMeOut.html", line 
72, in 
  File "I:\wdd-softw\web2py\gluon\sql.py", line 621, in __getattr__
KeyError: 'Picture'

Controller:

def addCarrier():
form=SQLFORM(db.Carrier)

if form.accepts(request.vars, session):
response.flash="Carrier added to the database"

records=SQLTABLE(db().select(db.Carrier.ALL))
return dict(form=form, records=records)

-- 





[web2py] Re: Unable to UNinstall application

2013-01-17 Thread JediLuke
Yes, that sounds like what happened. I could see them from the admin 
interface. I only went to the folder after I had uninstalled most of the 
folders using the 'remove' button in the interface. The 'ABOUT' application 
is the only one that wouldn't install. When I checked the actual folder it 
was a single file so I deleted it and now it's gone.

It's all fixed now, possibly I did something very weird, but I would love 
to know what actually happened. I should have taken screenshots.

On Thursday, January 17, 2013 8:48:30 PM UTC+8, Anthony wrote:
>
> When you create an application, there should be a single folder with the 
> application name inside the /web2py/applications folder. Then, inside the 
> application folder, you should see folders such as cron, databases, views, 
> etc. Like this:
>
> /web2py
>   /applications
> /myapp
>   /cache
>   /controllers
>
> Are you saying that instead you had these folders directly within the 
> /applications folder, rather than within a specific application folder -- 
> like this:
>
> /web2py
>   /applications
> /cache
> /controllers
>
> Anthony
>
> On Thursday, January 17, 2013 5:41:45 AM UTC-5, JediLuke wrote:
>>
>> Hi,
>>
>> I am new to web2py so probably I am doing something wrong. I used the 
>> wizard and (I think it was the wizard that did it) it created a bunch of 
>> applications - called cron, database, view, there was about 8 or 10 of 
>> them. I didn't make them and it was confusing me so I uninstalled most of 
>> them, but one called 'ABOUT' when I click uninstall it tried to do it but 
>> then has an error and says 'unable to uninstall "ABOUT" '. Why were these 
>> applications created, and why can't I uninstall this one?
>>
>> I used the wizard again and it only created one application which is what 
>> I expected in the first place, so I'm very confused.
>>
>> Update:
>> I went into my web2py folder with the idea that I will delete files and 
>> get a clean install. There was a file "ABOUT" - not a folder - which I 
>> deleted and now the project is gone. That's fixed my problem (which was 
>> really just an annoyance) however I would still like to know why these 
>> things happened.
>>
>> Thanks for your help
>>
>

-- 





[web2py] Re: crud to SQLFORM

2013-01-17 Thread Anthony

>
> if form.process(onsuccess=lambda form: onaccept_about_text(form),
> next=session.crud_next).accepted:
>
session.flash='Form accepted'
>

By specifying the "next" argument, you are telling it to do a redirect 
after processing -- so, it will redirect when the .process() method is 
called and therefore never get to your session.flash assignment. Instead, 
you either have to make the session.flash assignment before calling 
.process() or within your onsuccess function (which will get called before 
the redirect). Also, if you already have a function defined for onsuccess 
with the appropriate signature (i.e., the first and only required argument 
is the form), there is no need to wrap it in a lambda -- just specify the 
function directly.

def onaccept_about_text(form):
del session.name
del session.aboutID
session.flash = 'Form accepted'

def generic_about():
...
form.process(onsuccess=onaccept_about_text, next=session.crud_next)
if form.errors:
...

Anthony

-- 





[web2py] Re: Query not returning correct data

2013-01-17 Thread Mihir Lade
Hi Alan,

Sorry for the late reply.. 

Table Definition:


##Customer table.
db.define_table('Customer',
Field('CustID', type = 'string', length = 10, notnull = True, unique = 
True),
Field('Surname', type = 'string', length = 15, notnull = True),
Field('FirstName', type = 'string', length = 15, notnull = True),
Field('Address', length = 50, notnull = True),
Field('EmailID', type = 'string', length = 30, notnull = True, unique = 
True),
Field('Phone', type = 'string', length = 10, unique = True),
Field('Password', type='password'))

##Booking Table.
db.define_table('Booking',
Field('BookingID', type = 'string', length = 10, notnull = True, unique 
= True),
Field('CustID', type = 'string', length = 10, notnull = True),
Field('FlightNum', type = 'string', length = 10, notnull = True),
Field('DepartureLocation', type = 'string', length = 20, notnull = 
True),
Field('ArrivalLocation', type = 'string', length = 20, notnull = True),
Field('DepartureDate', type='date'),
Field('ArrivalDate', type='date'),
Field('DepartureTime', type = 'time'),
Field('ArrivalTime', type = 'time'))

##Flight Table
db.define_table('Flight',
Field('FlightNum', type = 'string', length = 10, notnull = True),
Field('PlaneID', type = 'string', length = 10, notnull = True),
Field('DepartureLocation', type = 'string', length = 20, notnull = 
True),
Field('ArrivalLocation', type = 'string', length = 20, notnull = True),
Field('DepartureDate', type='date'),
Field('ArrivalDate', type='date'),
Field('DepartureTime', type = 'time'),
Field('ArrivalTime', type = 'time'))  

##Plane table
db.define_table('Plane',
Field('PlaneID', type = 'string', length = 10, notnull = True, unique = 
True),
Field('CarrierID', type = 'string', length = 10, notnull = True),
Field('Model', type = 'string', length = 15, notnull = True),
Field('Make', type = 'string', length = 15, notnull = True),
Field('FirstClassCapacity', type = 'integer', notnull = True),
Field('BusClassCapacity', type = 'integer', notnull = True),
Field('EcoClassCapacity', type = 'integer', notnull = True),
Field('FirstClassPrice', type = 'integer', notnull = True),
Field('BusClassPrice', type = 'integer', notnull = True),
Field('EcoClassPrice', type = 'integer', notnull = True))

## Carrier table.
db.define_table('Carrier', 
Field('CarrierID', type = 'string', length = 10, notnull = True, unique 
= True),
Field('Name', type = 'string', length = 30, notnull = True, unique = 
True),
Field('Picture', type = 'upload'))


##Below is the code for changing the dateform for the date type in the code.
db.Flight.DepartureDate.requires = IS_DATE(format='%m/%d/%Y')
db.Flight.ArrivalDate.requires= IS_DATE(format='%m/%d/%Y')

##Below is code the drop down menu which is mapped to the STATE module in 
modules.
db.Flight.DepartureLocation.requires = IS_IN_SET(states)
db.Flight.ArrivalLocation.requires = IS_IN_SET(states)

##Validators for fields:
db.Customer.EmailID.requires = IS_EMAIL(error_message='Please check your 
email address!')
db.Customer.Phone.requires = IS_NOT_EMPTY()
db.Customer.Surname.requires = IS_NOT_EMPTY()
db.Customer.FirstName.requires = IS_NOT_EMPTY()

##Below are the conditions where the foreign key is referencing primary key 
in the above tables.
db.Booking.CustID.requires = [IS_IN_DB(db, db.Customer.CustID)]
db.Booking.FlightNum.requires = [IS_IN_DB(db, db.Flight.FlightNum)]
db.Flight.PlaneID.requires = [IS_IN_DB(db, db.Plane.PlaneID)]
db.Plane.CarrierID.requires = [IS_IN_DB(db, db.Carrier.CarrierID)]

We aren't allowed to use CRUD..

On Thursday, January 17, 2013 10:13:26 PM UTC+10:30, Alan Etkin wrote:
>
> I've tried that however when I hit search flight button it returns an 
>> empty page with no data from the database... 
>>
>
> Please post your model also (the table definitions). And consider using 
> SQLFORM , as 
> Anthony suggested, or 
> CRUD, 
> for an easier way of handling user input.
>
>

-- 





[web2py] Re: Unable to UNinstall application

2013-01-17 Thread Anthony
When you create an application, there should be a single folder with the 
application name inside the /web2py/applications folder. Then, inside the 
application folder, you should see folders such as cron, databases, views, 
etc. Like this:

/web2py
  /applications
/myapp
  /cache
  /controllers

Are you saying that instead you had these folders directly within the 
/applications folder, rather than within a specific application folder -- 
like this:

/web2py
  /applications
/cache
/controllers

Anthony

On Thursday, January 17, 2013 5:41:45 AM UTC-5, JediLuke wrote:
>
> Hi,
>
> I am new to web2py so probably I am doing something wrong. I used the 
> wizard and (I think it was the wizard that did it) it created a bunch of 
> applications - called cron, database, view, there was about 8 or 10 of 
> them. I didn't make them and it was confusing me so I uninstalled most of 
> them, but one called 'ABOUT' when I click uninstall it tried to do it but 
> then has an error and says 'unable to uninstall "ABOUT" '. Why were these 
> applications created, and why can't I uninstall this one?
>
> I used the wizard again and it only created one application which is what 
> I expected in the first place, so I'm very confused.
>
> Update:
> I went into my web2py folder with the idea that I will delete files and 
> get a clean install. There was a file "ABOUT" - not a folder - which I 
> deleted and now the project is gone. That's fixed my problem (which was 
> really just an annoyance) however I would still like to know why these 
> things happened.
>
> Thanks for your help
>

-- 





Re: [web2py] Unable to UNinstall application

2013-01-17 Thread Marco Mansilla
Apps are created in the /path/to/web2py/applications folder, and are
folders too, so you can delete them from that path.

Marco.

> Hi,
> 
> I am new to web2py so probably I am doing something wrong. I used the 
> wizard and (I think it was the wizard that did it) it created a bunch
> of applications - called cron, database, view, there was about 8 or
> 10 of them. I didn't make them and it was confusing me so I
> uninstalled most of them, but one called 'ABOUT' when I click
> uninstall it tried to do it but then has an error and says 'unable to
> uninstall "ABOUT" '. Why were these applications created, and why
> can't I uninstall this one?
> 
> I used the wizard again and it only created one application which is
> what I expected in the first place, so I'm very confused.
> 
> Update:
> I went into my web2py folder with the idea that I will delete files
> and get a clean install. There was a file "ABOUT" - not a folder -
> which I deleted and now the project is gone. That's fixed my problem
> (which was really just an annoyance) however I would still like to
> know why these things happened.
> 
> Thanks for your help
> 

-- 





Re: [web2py] Having some strange occurence with label printing and FPDF

2013-01-17 Thread Paul Rykiel
Thank you so much Jose... you are so helpful.
I am going to try this. this is a requirement to launch this system I wrote 
with another programmer
there is more work to do, but this needs to work.
Thank you again!!
Regards,
On Thursday, January 17, 2013 1:13:21 AM UTC-6, José L. wrote:

> I've just checked pdflabel is not included in fpdf in web2py. I ignore 
> the reason because I uploaded it to pyfpdf 18 months ago. I thought 
> web2py automatically included pyfpdf updates. You can download it from 
> http://code.google.com/p/pyfpdf/source/browse/pdflabels.py and copy it 
> at gluon/contrib/fpdf directory so you can use: 
>
> from gluon.contrib.fpdf.pdflabels import PDFLabel 
>
> PDFLabel accepts "\n" , if you use cell, it doesn't understand "\n" 
>
> Regards. 
>
> 2013/1/16 Paul Rykiel >: 
> > Hi Jose, 
> > 
> > I tried what you suggested, I was getting errors on the line 
> > from glon.contrib.pyfpdf.pdflabels import PDFLabel ... it does not seem 
> to 
> > exist, and cannot find how to load this 
> > 
> > so, my other option seems to be to get all of the text inside of one 
> cell, 
> > so I used your "more_text" from below, it works ('sort of") ... it lists 
> all 
> > of the text inside the one cell, but 
> > the program is ignoring the "\n" page breaks, if I can get those to 
> work, I 
> > am almost done 
> > 
> > then I have to figure out how to create the pages side by side, but I 
> want 
> > to tackle one thing at a time. 
> > 
> > I am sure when I get to my next issue of printing the labels where there 
> are 
> > 3 labels across and 10 down, maybe I will have to figure out 
> > how to use the PDFLabel, but for right now I just want to get this to 
> work. 
> > 
> > thanks for all of your help!! 
> > Regards, 
> > 
> > 
> > On Wednesday, January 16, 2013 12:46:34 PM UTC-6, José L. wrote: 
> >> 
> >> Some time ago, we include PDFLabel too, so you can simplify your code 
> >> if you are using an avery-compatible format ( the sys stuff is only 
> >> needed if you're using a non-english language): 
> >> 
> >> def label_bikes(): 
> >> from gluon.contrib.pyfpdf.pdflabels import PDFLabel 
> >> import sys 
> >> reload(sys) 
> >> sys.setdefaultencoding( "latin-1" ) 
> >> 
> >> pdf = PDFLabel('Apli-01277') 
> >> pdf.add_page() 
> >> rows = db(db.bike.id.belongs(bikeIds)).select() 
> >> # Print labels 
> >> for row in rows: 
> >> idString = row.destination + str(row.id) 
> >> more_text = idString 
> >> more_text += "Make:  " + row.make + "\n" if row.make else "" 
> >> more_text += "Model:  " + row.model + "\n" if row.model else "" 
> >> more_text += "Size:  " + row.size + "\n" if row.size else "" 
> >> pdf.add_label(more_text) 
> >> 
> >> response.headers['Content-Type'] = 'application/pdf' 
> >> response.headers['Content-Disposition']='attachment.filename = 
> >> sample.pdf' 
> >> return pdf.output(dest='S') 
> >> 
> >> 
> >> Regards 
> >> José L. 
> >> 
> >> 2013/1/16 Paul Rykiel : 
> >> > Hi Mariano, 
> >> > thank you for the response. Let me look into the margin issue, maybe 
> you 
> >> > have given me enough to figure this out. 
> >> > thanks so much for the response. you know, Massimo was my professor 
> last 
> >> > term. 
> >> > 
> >> > On Wednesday, January 16, 2013 12:39:06 AM UTC-6, Mariano Reingart 
> >> > wrote: 
> >> >> 
> >> >> Hello Paul: 
> >> >> 
> >> >> Could you send a sample without actual data? 
> >> >> (without the db query, so it can be reproduced) 
> >> >> 
> >> >> fpdf.cell will jump to the next page if no more room available, 
> maybe 
> >> >> there is a sizing or rounding issue. 
> >> >> Also, you have to take a look at page margins. 
> >> >> 
> >> >> Best regards, 
> >> >> 
> >> >> Mariano Reingart 
> >> >> http://www.sistemasagiles.com.ar 
> >> >> http://reingart.blogspot.com 
> >> >> 
> >> >> 
> >> >> On Tue, Jan 15, 2013 at 8:02 PM, Paul Rykiel  
> wrote: 
> >> >> > Greetings this is my code: 
> >> >> > 
> >> >> > def triagePrintTags(bikeIds): 
> >> >> > assert(bikeIds != None) 
> >> >> > assert(isinstance(bikeIds, list) or isinstance(bikeIds, 
> tuple)) 
> >> >> > pdf = FPDF('P', 'mm', (66.548, 25.4)) 
> >> >> > # get all the r(ows 
> >> >> > rows = db(db.bike.id.belongs(bikeIds)).select() 
> >> >> > for row in rows: 
> >> >> > pdf.add_page() 
> >> >> > pdf.set_font('Times', 'B', 8) 
> >> >> > idString = row.destination + str(row.id) 
> >> >> > pdf.cell(0, 2, idString, 0, 1) 
> >> >> > if row.make != None: 
> >> >> > pdf.cell(0, 2, "Make:  " + row.make,0,1) 
> >> >> > if row.model != None: 
> >> >> > pdf.cell(0, 2, "Model:  " + row.model,0,1) 
> >> >> > if row.size != 0: 
> >> >> > sz = "Size:  " + str(row.size) 
> >> >> > pdf.cell(0, 2, sz,0,1) 
> >> >> > if row.color != None: 
> >> >> > pdf.cell(0, 2, "Color:  " + row.color,0,1)

[web2py] Re: Query not returning correct data

2013-01-17 Thread Alan Etkin

>
> I've tried that however when I hit search flight button it returns an 
> empty page with no data from the database... 
>

Please post your model also (the table definitions). And consider using 
SQLFORM , as 
Anthony suggested, or 
CRUD, 
for an easier way of handling user input.

-- 





[web2py] Unable to UNinstall application

2013-01-17 Thread JediLuke
Hi,

I am new to web2py so probably I am doing something wrong. I used the 
wizard and (I think it was the wizard that did it) it created a bunch of 
applications - called cron, database, view, there was about 8 or 10 of 
them. I didn't make them and it was confusing me so I uninstalled most of 
them, but one called 'ABOUT' when I click uninstall it tried to do it but 
then has an error and says 'unable to uninstall "ABOUT" '. Why were these 
applications created, and why can't I uninstall this one?

I used the wizard again and it only created one application which is what I 
expected in the first place, so I'm very confused.

Update:
I went into my web2py folder with the idea that I will delete files and get 
a clean install. There was a file "ABOUT" - not a folder - which I deleted 
and now the project is gone. That's fixed my problem (which was really just 
an annoyance) however I would still like to know why these things happened.

Thanks for your help

-- 





[web2py] Trying to do a new database as a field in web2py,

2013-01-17 Thread damien rompapas
Hi everyone,


Been using web2py for university, and i'm trying to add a feature within my 
"websites" forum posting which will allow me to have each row with a field 
of a new database,


basically when a user creates a post, it also creates a new database table 
that matches this specific post which stores any comments made,


Can anyone help me with this?
the code for the posts table is as follows
db.define_table('Thoughts',
 Field('Editedby', db.auth_user, default=None, readable=True, 
writable=True),
Field('TitleOfPost',requires=IS_NOT_EMPTY()),
Field('ContentOfPost','text',requires=IS_NOT_EMPTY()),
Field('DatePosted','date'),
Field('DP_Large', 'upload', uploadfield='picture_file'),
Field('picture_file', 'blob'),
//here is where I want to create the table something like
Field('comments',db.define_table('post'))
);

I am sorry if the question is not clear enough. thanks for any help!

-- 





Re: [web2py] Re: Postgres : created new database, but tables not being create when I access the app

2013-01-17 Thread Johann Spies
On 16 January 2013 17:28, Massimo Di Pierro wrote:

> Can you suggest how to make the advice better?
>
> On Wednesday, 16 January 2013 01:05:14 UTC-6, Johann Spies wrote:
>
>> On 6 January 2013 22:00, Anthony  wrote:
>>
>>> See 
>>> http://web2py.com/books/**default/chapter/29/06#**Migrations
>>> :
>>>
>>> The value of migrate is the filename (in the "databases" folder for the
>>> application) where web2py stores internal migration information for this
>>> table. These files are very important and should never be removed
>>> except when the entire database is dropped. In this case, the ".table"
>>> files have to be removed manually.
>>>
>>>
>> I regularly have situations where I have to delete a file for one table
>> in the "databases" folder on my development system.  In my view this advice
>> in the documentation is not practical.
>>
>>
Maybe something like

*These files are very important and should never be removed while the
corresponding tables exist.  In cases where a table has been dropped and
the corresponding file still exist, it can be removed manually.
*

Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 





[web2py] Re: How "experimental" is postgis?

2013-01-17 Thread Paolo valleri
Hi, I've tried few examples in last weeks. Gis support is getting better, I 
don't think is far from being stable but right now I don't have the 
possibility to say it is stable, i.e., a few functions are available only 
for postgis (i.e., st_x, st_y). Moreover the errors I found have been 
fixed, I suggest you to read more 
here: https://groups.google.com/d/topic/web2py/6DDLVv4jt0w/discussion

right now it is not clear if web2py is going to support only gis 2d or more 
( I like 3d). I need 3d, not only to define 3d points (which somehow can be 
defined as 2d more an other field for the elevation) but also to define 3d 
polylines.
The 2d doesn't work with 3d, the 3d works well with 3d and 2d. The only 
problem is that the 3d is not backward compatible with existing 2d objects.
@Massimo, how would you go with that?

Paolo

On Thursday, January 17, 2013 10:47:59 AM UTC+1, encompass wrote:
>
> I am hoping to use it in an upcoming application.  Does anyone here have 
> issues with this that still need to be resolved?
> BR,
> Jason
>
>

-- 





[web2py] Book in epub format?

2013-01-17 Thread Johann Spies
Is there any chance to get the book in epub-format?

I think it should be possible using markmin -> xhtml > epub (via calibre)?

Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

-- 





Re: [web2py] Re: Project: pydev extension for web2py in Eclipse

2013-01-17 Thread Angelo Compagnucci
Any news on this?


2013/1/13 Álvaro José Iradier 

> Hi, I get back to this thread again as I recently got a notification from
> the feature request on Sourceforge.I had it nearly forgotten, but I think
> it is still interesting and it looks like the author of Pydev is thinking
> about including the web2py support.
>
> You can see my original proposal and the Pydev author comments here on
> Sourceforge:
>
>
> http://sourceforge.net/tracker/?func=detail&atid=577332&aid=3294887&group_id=85796
>
> I do not know if the same approach applies after the changes commented by
> Bruno, but I think it would be worth to try.
>
> Greets.
>
>
> On Monday, June 13, 2011 8:40:47 PM UTC+2, Álvaro José Iradier wrote:
>
>> No, I wasn't aware... sorry, I can't follow the current web2py
>> development at that detail. Could you point me to the information or
>> make a small brief? It sounds like it could be quite useful.
>>
>> Greets.
>>
>> On 10 jun, 04:52, Bruno Rocha  wrote:
>> > Are you aware about the changes included in the latest web2py version?
>> >
>> > I am talking specially about the new importer, the 'current' object and
>> the
>> > models subfolders.
>> >
>> > Is that being considerated?
>> >
>> > On Thu, Jun 9, 2011 at 6:11 PM, Álvaro J. Iradier 
>> > wrote:
>>
>> >
>> > > Talking to the pydev author in the pydev mailing list, he might
>> > > consider including support for web2py if we manage to get it working
>> > > fine, and we are quite there.
>> >
>>
>>  --
>
>
>
>



-- 
Profile: http://it.linkedin.com/in/compagnucciangelo

-- 





[web2py] crud to SQLFORM

2013-01-17 Thread Annet
I am replacing:

form=crud.update(table=db.aboutText,hidden=dict(nodeID=id,aboutID=aboutID),record=row,next=session.crud_next,onaccept=onaccept_about_text,deletable=True)

crud.messages.record_updated=session.record_updated
crud.messages.record_deleted=session.record_deleted
crud.messages.record_created=session.record_updated

With functions using SQLFORM:

def onaccept_about_text(form):
del session.name
del session.aboutID

def generic_about():
name=session.name
aboutID=session.aboutID

record=db((db.aboutText.nodeID==id)&(db.aboutText.aboutID==aboutID)).select(db.aboutText.ALL).first()

form=SQLFORM(table=db.aboutText,record=record,deletable=True,showid=False,separator='',hidden=dict(nodeID=id,aboutID=aboutID))
if form.process(onsuccess=lambda form: 
onaccept_about_text(form),next=session.crud_next).accepted:
session.flash='Form accepted'
elif form.errors:
response.flash='Form has errors'
else:
response.flash='Please fill out the form'
return dict(form=form)

I am struggling with the flash messages. When I display the form the flash 
is correctly set to: 'Please fill out the form', also when the form 
contains errors the message is set to: 'Form has errors'. However, when the 
form is accepted, no flash message is being displayed. When I remove the 
onsuccess= lambda form: onaccept_about_text(form) from process() the flash 
message does display not 'Form accepted' but 'Success!'

How do I set the flash message correctly. Furthermore, I'd like the flash 
messages to distinguish between inserting/updating/deleting a record, is 
that possible?


Since web2py sets the flash message to 'Success!' and 'Errors in form, 
please check it out' I only need to set 'Please fill out the form', 
however, 

form=SQLFORM(...)
if form.process(..).accepted:

cannot be empty, I could move the redirect from process() to the if, but 
that would be a workaround. What's the correct way to use SQLFORM here?

Kind regards,

Annet

-- 





[web2py] How "experimental" is postgis?

2013-01-17 Thread Jason Brower
I am hoping to use it in an upcoming application.  Does anyone here have issues 
with this that still need to be resolved?
BR,
Jason

-- 





[web2py] Re: Why does the login expire when doing periodic jsonrpc requests?

2013-01-17 Thread Daniel Gonzalez
Here: http://code.google.com/p/web2py/issues/detail?id=1287

On Thursday, January 17, 2013 4:50:08 AM UTC+1, Massimo Di Pierro wrote:
>
> Please open a ticket about this... :-)
>
> On Wednesday, 16 January 2013 17:28:59 UTC-6, Daniel Gonzalez wrote:
>>
>> This is the relevant section in Auth.__init__ for the login expiration:
>>
>> if auth and auth.last_visit and auth.last_visit + \
>> datetime.timedelta(days=0, seconds=auth.expiration) >request
>> .now:
>> self.user = auth.user
>> # this is a trick to speed up sessions
>> if (request.now - auth.last_visit).seconds > (auth.expiration 
>> / 10):
>> auth.last_visit = request.now
>> else:
>> self.user = None
>> if session.auth:
>> del session.auth
>>
>> I have verified that jsonrpc requests will update the last_visit. BUT the 
>> login will expire anyway (after "expiration", since the original login), 
>> which I can not understand from the code above.
>>
>> This does not happen when doing normal accesses: doing periodic requests 
>> will keep an active login forever, which is expected I think.
>>
>> Am I missing something here?
>>
>> Thanks,
>> Daniel
>>
>

-- 





[web2py] Re: db().select(db.table.all) does not return all fields

2013-01-17 Thread raphael . benedet
Hello,

I noticed that a legacy model (with a different table definition) was 
imported, overriding db in my module. Everything works now.

Sorry for the noise...
Raphael

Le jeudi 17 janvier 2013 04:37:16 UTC+1, Massimo Di Pierro a écrit :
>
> What is you print print str(schedulings) instead? Any change?
>
> On Wednesday, 16 January 2013 07:48:18 UTC-6, raphael...@netaxis.be wrote:
>>
>> Hello,
>>
>> I have a table defined like this in my model:
>> db.define_table('schedulings',
>>   Field('name'),
>>   Field('description'),
>>   Field('connectorId', db.connectors),
>>   Field('scenarioId', db.scenarios),
>>   Field('parametersSetId', db.parametersSets),
>>   Field('minInterval', 'integer', default=10),
>>   Field('maxDuration', 'integer', default=0),
>>   Field('scenarioInstanceId', default=''),
>>   Field('nextRun', 'double'),
>> )
>>
>> db.schedulings.name.requires = [IS_NOT_IN_DB(db, 'schedulings.name'), 
>> IS_NOT_EMPTY()]
>> db.schedulings.connectorId.requires = IS_IN_DB(db, db.connectors.id)
>> db.schedulings.scenarioId.requires = IS_IN_DB(db, db.scenarios.id)
>> db.schedulings.parametersSetId.requires = IS_IN_DB(db, 
>> db.parametersSets.id)
>> db.schedulings.minInterval.requires = IS_INT_IN_RANGE(0, 86401)
>> db.schedulings.maxDuration.requires = IS_INT_IN_RANGE(0, 86400*7+1)
>>
>> When I use appadmin, I can verify that all the fields are populated:
>> schedulings.id schedulings.name schedulings.description 
>> schedulings.connectorId schedulings.scenarioId 
>> schedulings.parametersSetId schedulings.minInterval 
>> schedulings.maxDuration schedulings.scenarioInstanceId 
>> schedulings.nextRun
>> 1 test 1 1 8 10 0 None
>>
>> But when I do a simple select with all fields, I don't get all the 
>> fields. This code (launched as an homemade task queue):
>> schedulings = db().select(db.schedulings.ALL)
>> print schedulings.as_list()
>> outputs:
>> [{'minInterval': 10, 'description': '', 'scenarioId': 1, 'connectorId': 
>> 1, 'id': 1, 'maxDuration': 0, 'name': 'test'}]
>>
>> For instance, parametersSetId, set to 8 is not present in the row 
>> retrieved.
>>
>> Any idea why?
>>
>> Thanks in advance.
>>
>> Best Regards,
>> Raphael
>>
>

-- 





[web2py] Re: Possible bug? session.auth is None in some requests

2013-01-17 Thread Daniel Gonzalez
Yes Anthony, pretty sure. The little hash that you see in the logs *is* the 
cookie. Otherwise I can not grep for the relevant log messages (lots of 
activity going on with 10 parallel requests). This is the code that I have 
at the very top of my db.py:

try:
cookie_value = request.cookies[response.session_id_name].value
except:
cookie_value = None

from gluon.tools import tools_tracer
tools_tracer.setid(cookie_value)

(tools_tracer is part of my instrumentation) And that setid call with 
compute a cookie hash for my logs.

On Thursday, January 17, 2013 5:32:22 AM UTC+1, Anthony wrote:
>
> You're sure the client is sending the session cookie each time?
>
> On Wednesday, January 16, 2013 10:19:01 PM UTC-5, Daniel Gonzalez wrote:
>>
>> Hi,
>>
>> I am doing stress testing of my web2py application. The way I am doing 
>> this is:
>>
>>- 10 parallel clients
>>- the clients log-in automatically, and obtain the session cookie
>>- the clients log-in only *once* at the start of testing.
>>- I use the session cookie to tag log messages in order to look for 
>>mý problem: this way I can relate the log messages to a specific client.
>>- I am looking for problems in the web2py code, specifically in 
>>tools.py, Auth.__init__, where the auth.user is defined
>>
>> This is my instrumented code (in tools.py, Auth.__init__):
>>
>> if auth is None:
>> tools_tracer.show('session.auth is None')
>> if auth and auth.last_visit and auth.last_visit + \
>> datetime.timedelta(days=0, seconds=auth.expiration) >request
>> .now:
>> tools_tracer.show('session.auth active, last_visit=%s', auth.
>> last_visit)
>> self.user = auth.user
>> # this is a trick to speed up sessions
>> if (request.now - auth.last_visit).seconds > (auth.expiration 
>> / 10):
>> auth.last_visit = request.now
>> else:
>> self.user = None
>> if session.auth:
>> del session.auth
>> tools_tracer.show('session.auth expired')
>>
>> And (in tools.py, Auth.login_user):
>>
>> current.session.auth = Storage(
>> user = user,
>> last_visit=current.request.now,
>> expiration=self.settings.expiration,
>> hmac_key=web2py_uuid())
>> tools_tracer.show('session.auth created')
>>
>> This is my current log:
>>
>> 2013-01-17 04:00:41,816 - Thread-5  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:00:41,861 - Thread-5  - c2d769 session.auth 
>> created
>> 2013-01-17 04:00:41,984 - Thread-6  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:00:41.791030
>> 2013-01-17 04:00:48,923 - Thread-7  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:01:51,131 - Thread-10 - c2d769 session.auth 
>> is None
>> 2013-01-17 04:01:51,214 - Thread-9  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:02:42,506 - Thread-6  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:04:42,791 - Thread-9  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:04:07.717197
>> 2013-01-17 04:04:42,816 - Thread-4  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:04:48,862 - Thread-10 - c2d769 session.auth 
>> is None
>> 2013-01-17 04:04:49,251 - Thread-6  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:05:35,713 - Thread-7  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:06:39,764 - Thread-8  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:06:10.853567
>> 2013-01-17 04:06:39,803 - Thread-2  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:07:35,154 - Thread-8  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:07:00.261709
>> 2013-01-17 04:07:40,860 - Thread-9  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:07:46,176 - Thread-8  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:07:46,266 - Thread-5  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:08:27,416 - Thread-9  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:08:03.492030
>> 2013-01-17 04:08:27,436 - Thread-2  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:09:31,485 - Thread-10 - c2d769 session.auth 
>> is None
>> 2013-01-17 04:11:21,903 - Thread-7  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:12:20,207 - Thread-10 - c2d769 session.auth 
>> is None
>>
>> (the c2d769 is a hash of the cookie, and identifies the client)
>>
>> As you can see, very often (for this specific client, other clients have 
>> fewer problems), the session.auth  is not there. But then suddenly, in the 
>> following request, it is there again.
>>
>> What can be causing this strange problem?

[web2py] Re: Possible bug? session.auth is None in some requests

2013-01-17 Thread Daniel Gonzalez
I was having a problem with session.auth.user, and my investigation has 
narrowed down the problem to web2py code. Instrumenting the code has 
allowed me to see the problem directly in the logs, but the problem is 
there no matter whether I modify Auth code or not.

Sure, for me Sessions and session.auth work well ... except when I am doing 
stress testing. With 10 parallel clients, I start to have problems. Strange 
problems as you see in the logs: around 30% of the requests overall do not 
have a properly initialized auth. Some clients have nearly no problems, 
other clients have lots of problems.

My question is: is nobody else seeing this? Not even when running several 
clients in parallel? I am fairly confident on my client code ...

I am running:
Version 2.4.1-alpha.2+timestamp.2013.01.13.13.14.47
commit 4bbe6ed, 4 days ago, "minor fix in parse_as_rest"

On Thursday, January 17, 2013 4:56:00 AM UTC+1, Massimo Di Pierro wrote:
>
> You are modifying Auth code. What problem are you trying to solve? 
> Sessions and session.auth work well with both stable and trunk version, do 
> they not?
>
> On Wednesday, 16 January 2013 21:19:01 UTC-6, Daniel Gonzalez wrote:
>>
>> Hi,
>>
>> I am doing stress testing of my web2py application. The way I am doing 
>> this is:
>>
>>- 10 parallel clients
>>- the clients log-in automatically, and obtain the session cookie
>>- the clients log-in only *once* at the start of testing.
>>- I use the session cookie to tag log messages in order to look for 
>>mý problem: this way I can relate the log messages to a specific client.
>>- I am looking for problems in the web2py code, specifically in 
>>tools.py, Auth.__init__, where the auth.user is defined
>>
>> This is my instrumented code (in tools.py, Auth.__init__):
>>
>> if auth is None:
>> tools_tracer.show('session.auth is None')
>> if auth and auth.last_visit and auth.last_visit + \
>> datetime.timedelta(days=0, seconds=auth.expiration) >request
>> .now:
>> tools_tracer.show('session.auth active, last_visit=%s', auth.
>> last_visit)
>> self.user = auth.user
>> # this is a trick to speed up sessions
>> if (request.now - auth.last_visit).seconds > (auth.expiration 
>> / 10):
>> auth.last_visit = request.now
>> else:
>> self.user = None
>> if session.auth:
>> del session.auth
>> tools_tracer.show('session.auth expired')
>>
>> And (in tools.py, Auth.login_user):
>>
>> current.session.auth = Storage(
>> user = user,
>> last_visit=current.request.now,
>> expiration=self.settings.expiration,
>> hmac_key=web2py_uuid())
>> tools_tracer.show('session.auth created')
>>
>> This is my current log:
>>
>> 2013-01-17 04:00:41,816 - Thread-5  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:00:41,861 - Thread-5  - c2d769 session.auth 
>> created
>> 2013-01-17 04:00:41,984 - Thread-6  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:00:41.791030
>> 2013-01-17 04:00:48,923 - Thread-7  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:01:51,131 - Thread-10 - c2d769 session.auth 
>> is None
>> 2013-01-17 04:01:51,214 - Thread-9  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:02:42,506 - Thread-6  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:04:42,791 - Thread-9  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:04:07.717197
>> 2013-01-17 04:04:42,816 - Thread-4  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:04:48,862 - Thread-10 - c2d769 session.auth 
>> is None
>> 2013-01-17 04:04:49,251 - Thread-6  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:05:35,713 - Thread-7  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:06:39,764 - Thread-8  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:06:10.853567
>> 2013-01-17 04:06:39,803 - Thread-2  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:07:35,154 - Thread-8  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:07:00.261709
>> 2013-01-17 04:07:40,860 - Thread-9  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:07:46,176 - Thread-8  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:07:46,266 - Thread-5  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:08:27,416 - Thread-9  - c2d769 session.auth 
>> active, last_visit=2013-01-17 04:08:03.492030
>> 2013-01-17 04:08:27,436 - Thread-2  - c2d769 session.auth 
>> is None
>> 2013-01-17 04:09:31,485 - Thread-10 - c2d769 session.auth 
>> is None
>> 2013-01-17 04:11:21,903 - Thread-7  - c2d76

[web2py] Re: can't install v 2.3

2013-01-17 Thread Lewis
Which script?  I used Bruno's from slices, which was pretty recent.  His 
script installs from maintainer (ubuntu) packages.  Thanks. 
I am going to rely on script based installs from now on.  Even if a pain to 
diagnose, once right you have something repeatable.

On Wednesday, January 16, 2013 8:43:12 AM UTC-8, Niphlod wrote:
>
> That's why now the script installs uwsgi from pip and relies on the 
> easier-than-a-drink-to-maintain emperor mode of uwsgi.
>
> Il giorno mercoledì 16 gennaio 2013 03:00:40 UTC+1, Lewis ha scritto:
>>
>> Back in business.
>>
>> There was detritus from previous installs interfering with new installs.
>>
>> So, the culprit is not uwsgi:  unjustly accused.  Apologies.
>>
>> File based config is inherently fragile.
>>
>> Uninstalling with apt-get --purge remove uwsgi, etc. was the only way to 
>> really start fresh.
>>
>> I think the scripts need to be more robust to deal with upgrade in place 
>> scenarios, not just new "from-scratch" installation.
>>
>

-- 





Re: [web2py] how to create a counter button...

2013-01-17 Thread sasogeek
what is an ajax callback and how do i use it? what is it for?

On Thursday, 17 January 2013 03:16:38 UTC, rochacbruno wrote:
>
> models/foo.py
>
> # the thing table
> db.define_table("thing", Field("name"))
>
> # you may want to store likes on another table so you never allow a user 
> to like the same thing twice
> db.define_table("thing_likes",
> Field("user", "reference auth_user", notnull=True),
> Field("thing", "reference thing", notnull=True),
> Field("unikey", unique=True, notnull=True)
> )
>
> # this ensure that user cannot like a thing twice
> db.thing_likes.unikey.compute = lambda row: "%(user)s-%(thing)s" % row
>
>
> controllers/default.py
>
> def show_thing():
>  thing_id = request.args(0)
>  thing = db.thing[thing_id]
>  thing_likes = db(db.thing_likes.id == thing.id).count()
>  return dict(thing=thing. thing_likes=thing_likes)
>
> def like_thing():
> thing_id = request.args(0)
> user_id = auth.user_id
> try:
> db.thing_likes.validate_and_insert(
> thing=int(thing_id),
> user=int(user_id)
> )
> redirect(URL('show_thing', args=thing_id))
> except:
> return "thing cannot be liked twice"
> 
>
> views/default/show_thing.html
>
> {{=thing.name}}
>  Like this thing 
>
>
> 
>
> To a better implementation you should use an ajax callback to the "like" 
> button, and also you should check if user already likes to show a different 
> button, maybe unlike.
>

--