Re: [web2py] Re: talks

2011-07-04 Thread Nick Arnett
On Mon, Jul 4, 2011 at 7:13 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> It is somewhere in San Francisco. I only have 20minutes and I am told
> to expect a tough crowd (mostly Django people). I will be driving to
> SF from Lake Tahoe just for that. What should I cover?


I should be able to get there, too, and can offer my impression from having
just moved from Django to Web2Py!

However, I can't figure out what group this is, either.

Nick


Re: [web2py] Re: Best practice for inserting possible duplicates?

2011-07-02 Thread Nick Arnett
On Sat, Jul 2, 2011 at 7:39 PM, Anthony  wrote:

> Be careful about using an 'except' without specifying specific exception
> types -- that code will attempt an insert regardless of the reason for the
> failure in the 'try' clause.
>

I was wondering if someone would mention that... was just shortcutting!

Nick


[web2py] Best practice for inserting possible duplicates?

2011-07-02 Thread Nick Arnett
Getting more comfortable with Web2Py and there sure is a lot to like about
it.

I'm wondering what is considered best practice for inserting records that
might already exist, when I also want to get the id of the record if it does
exist.  I haven't come across a shortcut for this.

For now, I'm using a try statement, as below, for a table that stores web
page data:

try:
 urlID = db.web_page(url=url).id
except:
 urlID = db.web_page.insert(url=url)

I notice that early last year there was a discussion of how to create the
equivalent of Django's get_or_create(), which does this.  I don't see that
that even made its way into Web2Py.

NIck


Re: [web2py] SQL UNIQUE IN WEB2PY : CONSTRAINT unique_test UNIQUE (num_part1, num_part2, num_part3, title)

2011-07-02 Thread Nick Arnett
On Fri, Jul 1, 2011 at 1:20 AM, Bruno Rocha  wrote:

> Db.define_table('foo',Field('a'),Field('b'), Field('ab',unique=True,
> compute=lambda r: r.a + r.b))
>
This failed for me with sqlite and I see from other discussions that the
same is true with Django - sqlite throws an error that it cannot create a
unique field.

However, it seems to work fine with MySQL; it did create a unique index on
the column.  I wasn't really planning to use sqlite, anyway, just thought
I'd keep things simpler at first.  I just switched to MySQL now and it's
working fine.

Thanks for the help.

Nick


Re: [web2py] SQL UNIQUE IN WEB2PY : CONSTRAINT unique_test UNIQUE (num_part1, num_part2, num_part3, title)

2011-06-30 Thread Nick Arnett
On Thu, Jun 30, 2011 at 7:00 PM, Anthony  wrote:
>
>
> I don't think web2py automatically creates any indexes -- see
> http://web2py.com/book/default/chapter/06#Indexes.
>
>

It has to!  Can't have primary keys without them.  But I see what you mean,
looking at the docs.

I guess I will just use that approach to create a multi-column unique
index but at this point I was really hoping to avoid raw SQL.

Nick


Re: [web2py] SQL UNIQUE IN WEB2PY : CONSTRAINT unique_test UNIQUE (num_part1, num_part2, num_part3, title)

2011-06-30 Thread Nick Arnett
On Thu, Jun 30, 2011 at 6:43 PM, Nick Arnett  wrote:

>
>
> On Thu, Jun 30, 2011 at 4:15 PM, Anthony  wrote:
>
>> IS_NOT_IN_DB does take a DAL Set object as the first argument, so you can
>> limit the records checked to a particular set within the table (see
>> http://web2py.com/book/default/chapter/07#Database-Validators). However,
>> I'm not quite sure what you're trying to do here.
>>
>> I think what he wants is the equivalent of Django's "unique together",
> which I'm also trying to figure out.  IS_NOT_IN_DB seems to accomplish it,
> but is that going to create a unique index on the combined fields?
>  Otherwise, it will be expensive to do inserts.
>

Actually, I don't see how NOT_IN_DB can accomplish this, since it is
associated with a single field.  Do I have to create an extra concatenated
field and make it unique?  Seems silly, given that's what a database unique
index is.

In other words, for table foo, if I want fields A, B and C to be unique
together, do I have to do this?

db.define_table('foo', Field('A'), Field('B'), Field('C'),
Field('ABC_unique', unique=True))

And remember to concat A, B, and C into that last field every time I do an
insert?

I'm missing something here, since this is so simple elsewhere.

Nick


Re: [web2py] SQL UNIQUE IN WEB2PY : CONSTRAINT unique_test UNIQUE (num_part1, num_part2, num_part3, title)

2011-06-30 Thread Nick Arnett
On Thu, Jun 30, 2011 at 4:15 PM, Anthony  wrote:

> IS_NOT_IN_DB does take a DAL Set object as the first argument, so you can
> limit the records checked to a particular set within the table (see
> http://web2py.com/book/default/chapter/07#Database-Validators). However,
> I'm not quite sure what you're trying to do here.
>
> I think what he wants is the equivalent of Django's "unique together",
which I'm also trying to figure out.  IS_NOT_IN_DB seems to accomplish it,
but is that going to create a unique index on the combined fields?
 Otherwise, it will be expensive to do inserts.

Nick


[web2py] Use the ORM for a robot?

2011-06-29 Thread Nick Arnett
I'm just getting to know Web2Py after working with Django a fair bit.  I
have robots that gather data that I would like to insert using the Web2Py
ORM, but I can't quite figure out the right way to do that.  If I put the
bot scripts in the modules directory, I don't seem to have access to the
ORM.  When I run a module in the controllers directory, I can import from
the modules directory with a simple import even though the documentation
seems to say that I should use local_import... which doesn't work.  And
running a module in the controllers directory doesn't seem to give it access
to the ORM, either.

So... I'm lost and not finding the answer in the docs.  In Django, I would
just put the appropriate imports in the robot scripts, but I get that that's
not the Web2Py way!

Can anybody point me to an example of this sort of thing - inserting data
that isn't coming from a request - or give me an idea of the right way to
organize it into the Web2Py structure?

Thanks in advance.

Nick