[web2py] how to implement database tables with one level of indirection?

2011-07-02 Thread Luis Goncalves
Hello!

How do I make a database table where the fields are defined by another 
table?

For example, suppose some users of my system are event organizers, and they 
can define what fields would belong in a person's profile.

Then, attendees of that event have to fill out a profile with those specific 
fields. 

What is the best way to represent this information (the fields relevant for 
an event's profile,  and the event profiles of users) in a database?

What I have been thinking of so far is to define a table that holds the 
definitions of profile fields:

db.define_table('event_profile_field',
Field('event', db.event),
Field('display_title','text'),
Field('data_type', 
requires=IS_IN_SET('string','text','checkbox','list')),
Field('display_order', 'int'))

and then each user's profile is built up of multiple entries of the 
following:

db.define_table('event_profile_entry',
Field('person', db.person),
Field('event', db.event),
Field('event_profile_field', db.event_profile_field),
Field('data') # XXX we need data to be of different types

However, as indicated above by the comment, I'm not sure if it is possible 
to store different data types in the event_profile_entry.data field.
(I suppose I could just make it be 'text' type and have the code know that a 
checkbox can only be True or False, for example).

Is there a more efficient/smarter way to do this?

Thanks,
Luis.


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

2011-07-02 Thread Massimo Di Pierro
Do this instead

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

or better

 row = db.web_page(url=url)
 urlID = row and row.id or db.web_page.insert(url=url)

If  db.web_page(url=url) fails with an OperationalError (database
error) you should not catch it without rollback.

Massimo

On Jul 2, 5:05 pm, Nick Arnett  wrote:
> 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] 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] Re: Unexpected 404s

2011-07-02 Thread pbreit
False alarm. Missing view. Have missing views always generated 404s? I know 
the generics changed so missing views used to be rare.

[web2py] Unexpected 404s

2011-07-02 Thread pbreit
I'm getting some unexpected 404s. Is there any way to make sure any route 
caching is flushed? Any other ideas what might cause the problem? Nginx + 
uWSGI on Ubuntu.

[web2py] Re: Dropdown field not being accepted

2011-07-02 Thread Happy Rob
Thanks for the ideas, I'm looking at the source code now.

On Jul 1, 6:15 pm, Bruno Rocha  wrote:
> Here is a modified versionhttps://bitbucket.org/rochacbruno/surveycloud
>
> Bug fixes
> Auth included
> No more cpuckle
> Powertables
> Smart reports
>
> http://zerp.ly/rochacbruno
> Em 30/06/2011 23:59, "pbreit"  escreveu:
>
> > Everything above the "if form.accepts()" is run each time the submit
> button
> > is pressed.
>
> > I can't think of the best way to implement this off-hand. It does seem
> like
> > you could do it all in one controller.
>
> > There's a pretty old survey app which might give you some ideas:
> >http://www.web2py.com/appliances/default/show/66
>
>


[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread pbreit
I also use LOAD(ajax=False) in emails and am not sure how well ajax=True 
would work in various email clients.

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

2011-07-02 Thread Anthony
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.
 
Anthony

On Saturday, July 2, 2011 6:05:46 PM UTC-4, Nick Arnett wrote:

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


[web2py] improvement of a multiselect update design

2011-07-02 Thread Nicolas Palumbo
At this moment I am doing this for a multiselect form page:

db.py:

db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
r: '%s %s' %
(db.application[r.app].name,db.server[r.server].hostname))
#table constraints:
db.instance.app.requires = IS_IN_DB(db, db.application.id, 'application.name')
db.instance.server.requires = IS_IN_DB(db, db.server.id, '%(hostname)s')

db.define_table('audienceInstances', Field('instances','list:reference
instance'),Field('user',db.auth_user,writable=False, readable=False))

default.py:
   monitoredInstances =
db.audienceInstances(db.audienceInstances.user == auth.user.id)
   #If the result of this query is None means that the user has just registered
   if (monitoredInstances == None):
   #and we insert a record with an empty list of monitored instances
   db.audienceInstances.insert(user=auth.user.id)
   #we recover the record that has just been inserted
   monitoredInstances =
db.audienceInstances(db.audienceInstances.user == auth.user.id)
   #response.flash = 'new user row inserted'

   #Generates a form for the updation of the list of monitored instances
   instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
submit_button='Update', showid=False)
   if instancesForm.accepts(request.vars, session):
   response.flash = 'list updated'
   elif instancesForm.errors:
   response.flash = 'form has errors'

in index.html:
{{=instancesForm}}

And the result is a multiselect list having as content the list of
instances. The user can edit the selection and update which are the
instances that like to have monitored.

I'd like to redesign the use case.

having an autocompletion box with a +/Add button next to it, that
allow the to add the instance visualized in the textbox after clicking
the +/Add button  to the instances field of the audienceInstances
table, instead of presenting the whole list of instances which are
more than 100 in general to the user.

When the user clicks the add button the instance selected is saved
into the database and the content of the list below should be updated.
At the same time, i'd like to add a -/remove button next to each
instance in the bottom list, to remove the instance from instances
field of audienceInstances table and remove the item from the bottom
list.

this would be a sketch up:

Select the instance to add:

|  the instance is fetched as you type with autocomplete
 |   | +/Add button|

List of monitored instances aka bottom list:
 the content of the instances list of audienceInstancesTable
---
| instance1  |   |- / remove|
| instance 20   |   |- / remove|
||
|--|

Is it feasible to implement this keeping the same database structure
as the existing multiselect?
Any ideas?

Thanks in advance,
Nico


[web2py] customizing instant press layout

2011-07-02 Thread Andrew Thompson

Greetings,

I just installed Instant Press and am trying to figure out how to skin 
it. The views/layout.html says you should create views/layouts/xxx, but 
it's not real specific on what to name those files. I've tried 
views/layouts/layout.html and views/layouts/index.html, but neither seem 
to have affected it.


How should I go about skinning it?

--
Andrew Thompson
http://aktzero.com/



[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] Re: BUG: I think.

2011-07-02 Thread Jonathan Lundell
On Jul 2, 2011, at 10:52 AM, cjrh wrote:
>  The point regarding backwards compatibility is well-taken, I wouldn't want 
> to mess with that at all.  However, cognitive dissonance in code is a 
> particular bugbear of mine.  I am especially nervous (in general) of 
> situations where one thing is used to *sematically* represent a different 
> kind of thing.  "=None" and "=False" behaving differently in this case makes 
> me uncomfortable.  Imagine that the argument was called something like 
> "extension_override" and then you should be able to see my concern more 
> clearly.   Still, it isn't a big deal.  I can live with the current 
> behaviour.  As JL says, "=None" is almost idiomatic in Python to represent 
> "default" behaviour, not necessarily the value "None".  Perhaps my gripe is 
> with the idiom rather than web2py specifically.

Perhaps so, and in part with Python's choice of 'None' as the name of the nil 
singleton; it carries more semantic baggage than 'Nil' or 'Null' would have 
done.

And elaborating a little on the default-argument convention, None is the 
conventional default when a dynamic default is required, as it is in this case. 
If the default really were 'html', then it could be so specified. But since the 
default is request.extension (and only 'html' if *that* isn't defined), we use 
None. (Argument defaults are fixed when the function is defined, so you can't 
say something like extension=r.extension.)

Yet another approach would be to have yet another singleton object to be used 
for dynamic default arguments (called, perhaps, Default), but the use of None 
for that purpose is pretty deeply embedded in Python practice, and changing it 
would be confusing.



[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread Anthony
I believe templates that you include will have access to the current 
request.vars. You should even be able to call functions from views (though 
they would have to return HTML or some objects your view can then handle).

On Saturday, July 2, 2011 2:59:44 PM UTC-4, LightOfMooN wrote:

> Yes, I can include templates with {{include}}, but I can't process 
> vars by that way. 
>
> On 2 июл, 23:38, pbreit  wrote: 
> > I don't know if this would work for you but you can compartmentalize view 
>
> > snippets and {{include}} them: 
> > {{include './html/item-box.html'}} 
> > 
> > I have zero desire to for JavaScript-less support.



[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread LightOfMooN
Yes, I can include templates with {{include}}, but I can't process
vars by that way.

On 2 июл, 23:38, pbreit  wrote:
> I don't know if this would work for you but you can compartmentalize view
> snippets and {{include}} them:
> {{include './html/item-box.html'}}
>
> I have zero desire to for JavaScript-less support.


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] Re: BUG: I think.

2011-07-02 Thread cjrh
(In reply to both JL and AB)

 The point regarding backwards compatibility is well-taken, I wouldn't want 
to mess with that at all.  However, cognitive dissonance in code is a 
particular bugbear of mine.  I am especially nervous (in general) of 
situations where one thing is used to *sematically* represent a different 
kind of thing.  "=None" and "=False" behaving differently in this case makes 
me uncomfortable.  Imagine that the argument was called something like 
"extension_override" and then you should be able to see my concern more 
clearly.   Still, it isn't a big deal.  I can live with the current 
behaviour.  As JL says, "=None" is almost idiomatic in Python to represent 
"default" behaviour, not necessarily the value "None".  Perhaps my gripe is 
with the idiom rather than web2py specifically.


[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread pbreit
I don't know if this would work for you but you can compartmentalize view 
snippets and {{include}} them:
{{include './html/item-box.html'}}

I have zero desire to for JavaScript-less support.


Re: [web2py] Re: BUG: I think.

2011-07-02 Thread Anthony
Defaulting to 'html' is not what we want. In general, we don't want to see 
explict 'html' extensions in our urls. Instead, web2py is set up to 
interpret urls without extensions as 'html' view requests. If you explicitly 
pass 'html' to URL() as the extension, it will add it to the URL -- 
otherwise, we don't want URL() to propagate the .html extension of the 
current request. However, we do want it to progagate the extension of the 
current request when (a) no explicit extension has been provided, (b) the 
current request extension is anything but 'html', and (c) there is an 
indication that propagation is desired, which is currently done via None 
(which is the default). I think you're taking issue with the fact that None 
is used to acheive (c). Perhaps that could have been indicated differently, 
and None could have been treated the same as False, but alas, backward 
compatibility prevents a change at this point.
 
Anthony

On Saturday, July 2, 2011 12:37:34 PM UTC-4, cjrh wrote:

> On Saturday, 2 July 2011 16:57:11 UTC+2, Jonathan Lundell wrote: 
>>
>> On Jul 2, 2011, at 7:41 AM, Anthony wrote:
>> > On Saturday, July 2, 2011 6:22:15 AM UTC-4, cjrh wrote:
>>
>> So, extension=None is saying that we're going to stick with the same 
>> extension as the current request, and if it happens to be 'html', we'll 
>> preserve that as well, but leave it implicit.
>>
>> extension=False (or anything that evaluates to False) is saying 
>> explicitly: no extension at all.
>>
>
> Wouldn't it be a lot better if the default argument was 
> "extension='.html'"?  I don't see why None should mean "use .html", when a 
> default arg of ".html" could do the job even better.  I should think that 
> None and False should be synonymous in this case, and IMO None is better 
> than False.
>


Re: [web2py] Re: BUG: I think.

2011-07-02 Thread Jonathan Lundell
On Jul 2, 2011, at 9:37 AM, cjrh wrote:
> On Saturday, 2 July 2011 16:57:11 UTC+2, Jonathan Lundell wrote:
> On Jul 2, 2011, at 7:41 AM, Anthony wrote:
> > On Saturday, July 2, 2011 6:22:15 AM UTC-4, cjrh wrote:
> So, extension=None is saying that we're going to stick with the same 
> extension as the current request, and if it happens to be 'html', we'll 
> preserve that as well, but leave it implicit.
> 
> extension=False (or anything that evaluates to False) is saying explicitly: 
> no extension at all.
> 
> 
> Wouldn't it be a lot better if the default argument was "extension='.html'"?  
> I don't see why None should mean "use .html", when a default arg of ".html" 
> could do the job even better.  I should think that None and False should be 
> synonymous in this case, and IMO None is better than False.

Regardless, it's not possible to change it now, since it would break all kinds 
of code.

But None is pretty conventional in Python to indicate a default value, and 
that's what's used for most of the other arguments to URL. The question is 
whether the default ought to be explicitly 'html' or the extension of the 
current request. For a lot of applications that's the same thing--everything is 
html. Where it's not html, it seems natural that if the request is for 
something.rss (say) that the default response have an extension of .rss, and 
that's what URL is doing now (with a provision to override that default if 
necessary).

Re: [web2py] How to create a new record in database without submit buttons

2011-07-02 Thread portable dora
You were right Anthony.
And I found what I exactly needed was 'Components' .
I didn't want to refresh the entire page.
But anyways, the fact that there is the insert method and it doesn't give me
much to create a record from input forms, was new knowledge for me, so it
was good to know about it.
Thank you always helps me.

Dora

2011/7/2 Anthony 

> Note, in that case, you won't be taking advantage of any of the built-in
> form processing, such as input validation and return/display of form errors.
> To get the validation, you could use the .validate_and_insert() method, but
> you'd still have to manually process and deal with the potential validation
> errors returned.
>
> If you want a regular form submission and the usual form processing but
> simply want to submit without a submit button, maybe just use something like
> jQuery .submit(): http://api.jquery.com/submit/
>
> Anthony
>
> On Saturday, July 2, 2011 6:44:04 AM UTC-4, dorasan wrote:
>
>> 'Insert' method. That is what I wanted to know.
>> Thank you so much!!
>>
>> 2011/7/2 cjrh 
>>
>> In the method called by the AJAX event, you don't need the form at all.
>>> You can just do a straight insert. You must pass the data to be inserted as
>>> part of the AJAX call, either via args, or post data or some other method on
>>> the URL. Then, inside writing(), just do a direct DB insert as documented
>>> here: 
>>> http://web2py.com/book/**default/chapter/06#insert
>>
>>
>>


Re: [web2py] Re: BUG: I think.

2011-07-02 Thread cjrh
On Saturday, 2 July 2011 16:57:11 UTC+2, Jonathan Lundell wrote:
>
> On Jul 2, 2011, at 7:41 AM, Anthony wrote:
> > On Saturday, July 2, 2011 6:22:15 AM UTC-4, cjrh wrote:
>
> So, extension=None is saying that we're going to stick with the same 
> extension as the current request, and if it happens to be 'html', we'll 
> preserve that as well, but leave it implicit.
>
> extension=False (or anything that evaluates to False) is saying explicitly: 
> no extension at all.
>

Wouldn't it be a lot better if the default argument was "extension='.html'"? 
 I don't see why None should mean "use .html", when a default arg of ".html" 
could do the job even better.  I should think that None and False should be 
synonymous in this case, and IMO None is better than False.


[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread LightOfMooN
I pasted some code to better explain my approach:
http://pastebin.com/MS3y6sNQ

Advantages of ajax=false for me is passing vars of current request to
all LOADed components.

On 2 июл, 20:21, Massimo Di Pierro  wrote:
> Can you explain to me why you prefer ajax=False to ajax=True? What
> advantages do you expect?
>
> On Jul 2, 1:28 am, LightOfMooN  wrote:
>
>
>
>
>
>
>
> > ajax=False is very important for me, so, I like 1.96 more than 1.97 :)
> > I use it at most interactive components, that can be displayed on the
> > all pages of site.
>
> > Just one example:
>
> > def voting_viewlet():
> >     if not session.has_key('finished_votings'):
> >         session.finished_votings = {}
> >     if request.vars.get('vote', None):
> >         active_voting =
> > db((db.voting.id==session['active_voting'])&(db.voting.status=='opened')).s 
> > elect().first()
> >         if active_voting and active_voting.id not in
> > session.get('finished_votings', []):
> >             answers =
> > db(db.voting_answers.voting_id==active_voting.id).select()
> >             show_results = False
> >             if active_voting.multi:
> >                 answerlist = []
> >                 tmp = makelist(request.vars.answer)
> >                 for i in tmp:
> >                     answerlist.append(int(i))
> >                 valide_answers = list(set(get_ids(answers)) &
> > set(answerlist))
> >                 if valide_answers:
>
> > db(db.voting_answers.id.belongs(valide_answers)).update(count=db.voting_ans 
> > wers.count
> > +1)
> >                     try:
>
> > session['finished_votings'].append(active_voting.id)
> >                     except:
> >                         session['finished_votings']=[active_voting.id]
> >                     show_results = True
> >             else:
> >                 if request.vars.answer:
> >                     answer = int(request.vars.answer)
> >                     if answer in get_ids(answers):
>
> > db(db.voting_answers.id==answer).update(count=db.voting_answers.count
> > +1)
> >                         try:
>
> > session['finished_votings'].append(active_voting.id)
> >                         except:
>
> > session['finished_votings']=[active_voting.id]
> >                         show_results = True
> >             if show_results:
> >                 voting =
> > db(db.voting.id==active_voting.id).select().first() or
> > redirect(URL('default','index'))
> >                 answers =
> > db(db.voting_answers.voting_id==voting.id).select(orderby=~db.voting_answer 
> > s.count)
> >                 count = 0
> >                 if answers:
> >                     max = answers.first().count
> >                     for answer in answers:
> >                         count += answer.count
> >                     for answer in answers:
> >                         if count > 0:
> >                             answer.percent =
> > int(float(answer.count)*100/count)
> >                             answer.width = int(float(answer.count)*100/
> > max)
> >                             answer.color = getColor()
> >                         else:
> >                             answer.percent = 0
> >                             answer.width = 0
> >                             answer.color = getColor()
> >                 return response.render('voting/
> > voting_viewlet_results.html', dict(voting=voting, answers=answers,
> > count=count))
>
> >     votings = db(db.voting.status=='opened').select()
> >     finished_votings = session.get('finished_votings',[])
> >     unfinished_votings = []
> >     for voting in votings:
> >         if voting.id not in finished_votings:
> >             unfinished_votings.append(voting)
> >     if unfinished_votings:
> >         active_voting = unfinished_votings[random.randint(0,
> > len(unfinished_votings)-1)]
> >         session['active_voting'] = active_voting.id
> >     else:
> >         active_voting = None
> >         session['active_voting'] = None
>
> >     if active_voting:
> >         answers =
> > db(db.voting_answers.voting_id==active_voting.id).select(orderby=db.voting_ 
> > answers.id)
> >     else:
> >         answers = []
>
> >     return dict(active_voting=active_voting, answers=answers)
>
> > On 2 июл, 04:51, Massimo Di Pierro  wrote:
>
> > > There are logic problems with ajax=False. Just use ajax=True. I am not
> > > sure ajax=False should be an option al all.
>
> > > On Jul 1, 11:45 am, LightOfMooN  wrote:
>
> > > > Thx, but I just disabled some components until the new stable version
> > > > of webpy :)
>
> > > > On 1 июл, 21:29, Anthony  wrote:
>
> > > > > That problem has been fixed in trunk, but looks like another problem 
> > > > > may
> > > > > have been introduced. Try downloading trunk revision d4c2d8d15bb1 -- 
> > > > > that
> > > > > fixes the request.vars problem, but comes before the 
> > > > > copy.copy(request)
> > > > > problem was introduced. Actually, maybe you could try the latest 
> > > > > revision in
> > > > > trunk and see 

[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread pbreit
I've just been using it as a way to compartmentalize code but without the extra 
request. For some things, the discrete load doesn't seem appropriate. If I lost 
Ajax=false, I would probably bring the code back into the calling 
view/controller. Which is not a huge deal for me. I'm also looking into making 
more use of view blocks.


[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread LightOfMooN
With ajax=False I don't need some javascripts on every page.
I can just add {{=LOAD('voting', 'voting_viewlet', ajax=False)[0][0]}}
in layout.html, and on every page users can vote (for example),
because ajax=False passed vars of current request to LOAD. And I liked
it, because I can write some components, like voting, feedback,
some_switchers, and all of them would work without javascript and on
any of my new sites.

Now I have 1.97.1. I replaced lines 124 and 125 with
other_request.vars = Storage(vars)
other_request.get_vars = Storage(vars)
to avoid error. But all of my components doesn't work, because I
think, now vars of current request doesn't pass to LOAD with
ajax=False. So, I need to write some javascripts to make it work
again. But what about backward compatibility?

thx


On 2 июл, 20:21, Massimo Di Pierro  wrote:
> Can you explain to me why you prefer ajax=False to ajax=True? What
> advantages do you expect?
>
> On Jul 2, 1:28 am, LightOfMooN  wrote:
>
>
>
>
>
>
>
> > ajax=False is very important for me, so, I like 1.96 more than 1.97 :)
> > I use it at most interactive components, that can be displayed on the
> > all pages of site.
>
> > Just one example:
>
> > def voting_viewlet():
> >     if not session.has_key('finished_votings'):
> >         session.finished_votings = {}
> >     if request.vars.get('vote', None):
> >         active_voting =
> > db((db.voting.id==session['active_voting'])&(db.voting.status=='opened')).s 
> > elect().first()
> >         if active_voting and active_voting.id not in
> > session.get('finished_votings', []):
> >             answers =
> > db(db.voting_answers.voting_id==active_voting.id).select()
> >             show_results = False
> >             if active_voting.multi:
> >                 answerlist = []
> >                 tmp = makelist(request.vars.answer)
> >                 for i in tmp:
> >                     answerlist.append(int(i))
> >                 valide_answers = list(set(get_ids(answers)) &
> > set(answerlist))
> >                 if valide_answers:
>
> > db(db.voting_answers.id.belongs(valide_answers)).update(count=db.voting_ans 
> > wers.count
> > +1)
> >                     try:
>
> > session['finished_votings'].append(active_voting.id)
> >                     except:
> >                         session['finished_votings']=[active_voting.id]
> >                     show_results = True
> >             else:
> >                 if request.vars.answer:
> >                     answer = int(request.vars.answer)
> >                     if answer in get_ids(answers):
>
> > db(db.voting_answers.id==answer).update(count=db.voting_answers.count
> > +1)
> >                         try:
>
> > session['finished_votings'].append(active_voting.id)
> >                         except:
>
> > session['finished_votings']=[active_voting.id]
> >                         show_results = True
> >             if show_results:
> >                 voting =
> > db(db.voting.id==active_voting.id).select().first() or
> > redirect(URL('default','index'))
> >                 answers =
> > db(db.voting_answers.voting_id==voting.id).select(orderby=~db.voting_answer 
> > s.count)
> >                 count = 0
> >                 if answers:
> >                     max = answers.first().count
> >                     for answer in answers:
> >                         count += answer.count
> >                     for answer in answers:
> >                         if count > 0:
> >                             answer.percent =
> > int(float(answer.count)*100/count)
> >                             answer.width = int(float(answer.count)*100/
> > max)
> >                             answer.color = getColor()
> >                         else:
> >                             answer.percent = 0
> >                             answer.width = 0
> >                             answer.color = getColor()
> >                 return response.render('voting/
> > voting_viewlet_results.html', dict(voting=voting, answers=answers,
> > count=count))
>
> >     votings = db(db.voting.status=='opened').select()
> >     finished_votings = session.get('finished_votings',[])
> >     unfinished_votings = []
> >     for voting in votings:
> >         if voting.id not in finished_votings:
> >             unfinished_votings.append(voting)
> >     if unfinished_votings:
> >         active_voting = unfinished_votings[random.randint(0,
> > len(unfinished_votings)-1)]
> >         session['active_voting'] = active_voting.id
> >     else:
> >         active_voting = None
> >         session['active_voting'] = None
>
> >     if active_voting:
> >         answers =
> > db(db.voting_answers.voting_id==active_voting.id).select(orderby=db.voting_ 
> > answers.id)
> >     else:
> >         answers = []
>
> >     return dict(active_voting=active_voting, answers=answers)
>
> > On 2 июл, 04:51, Massimo Di Pierro  wrote:
>
> > > There are logic problems with ajax=False. Just use ajax=True. I am not
> > > sure ajax=Fals

Re: [web2py] Re: BUG: I think.

2011-07-02 Thread Jonathan Lundell
On Jul 2, 2011, at 7:41 AM, Anthony wrote:
> On Saturday, July 2, 2011 6:22:15 AM UTC-4, cjrh wrote:
> On Jul 1, 8:34 pm, pbreit  wrote: 
> > I usually do extension='' 
> 
> What would extension=None do?  It seems to make the most semantic 
> sense, to me at least.
>  
> The code for URL does this:
>  
> if extension is None and r.extension != 'html':
> extension = r.extension
>  
>  
> So, extension=None results in the extension being set to request.extension 
> (unless that is already set to 'html'). If extension is set to anything that 
> evaluates to False (other than None), no extension will be added, as per this 
> code, which appears later:
>  
> if extension:
> function += '.' + extension
>  
>  
> So, None is a way of getting URL to propogate the current extension, and 
> anything else that evaluates to False ensures there is no extension.
> 

Exactly (and extension=None) is the function's default). Notice also that this:

> if extension is None and r.extension != 'html':
> extension = r.extension

make a special case of 'html' only because it's web2py's convention that 
incoming URLs *without* an extension are treated as 'html', so we suppress 
'html' here in the interest of a "cleaner" URL.

So, extension=None is saying that we're going to stick with the same extension 
as the current request, and if it happens to be 'html', we'll preserve that as 
well, but leave it implicit.

extension=False (or anything that evaluates to False) is saying explicitly: no 
extension at all. Of course, the function that ends up handling the URL can 
make its own decision about what to return,

Re: [web2py] How to create a new record in database without submit buttons

2011-07-02 Thread Anthony
Note, in that case, you won't be taking advantage of any of the built-in 
form processing, such as input validation and return/display of form errors. 
To get the validation, you could use the .validate_and_insert() method, but 
you'd still have to manually process and deal with the potential validation 
errors returned.
 
If you want a regular form submission and the usual form processing but 
simply want to submit without a submit button, maybe just use something like 
jQuery .submit(): http://api.jquery.com/submit/
 
Anthony
 
On Saturday, July 2, 2011 6:44:04 AM UTC-4, dorasan wrote:

> 'Insert' method. That is what I wanted to know. 
> Thank you so much!!
>
> 2011/7/2 cjrh 
>
>> In the method called by the AJAX event, you don't need the form at all. 
>> You can just do a straight insert. You must pass the data to be inserted as 
>> part of the AJAX call, either via args, or post data or some other method on 
>> the URL. Then, inside writing(), just do a direct DB insert as documented 
>> here: http://web2py.com/book/default/chapter/06#insert
>
>
>

[web2py] Re: BUG: I think.

2011-07-02 Thread Anthony
On Saturday, July 2, 2011 6:22:15 AM UTC-4, cjrh wrote: 
>
> On Jul 1, 8:34 pm, pbreit  wrote: 
> > I usually do extension='' 
>
> What would extension=None do?  It seems to make the most semantic 
> sense, to me at least.

 
The code for URL does this:
 
if extension is None and r.extension != 'html':
extension = r.extension
 
 
So, extension=None results in the extension being set to request.extension 
(unless that is already set to 'html'). If extension is set to anything that 
evaluates to False (other than None), no extension will be added, as per 
this code, which appears later:
 
if extension:
function += '.' + extension
 
 
So, None is a way of getting URL to propogate the current extension, and 
anything else that evaluates to False ensures there is no extension.
 
Anthony
 


[web2py] Re: regarding "http://mdp.cti.depaul.edu/"

2011-07-02 Thread Massimo Di Pierro
Where is that link? That was replaced by http://web2py.com more than 3
years ago.

On Jul 2, 7:56 am, Vineet  wrote:
> I was trying to see this link--http://mdp.cti.depaul.edu/
> Is this link broken?
> I could not access it.


[web2py] Re: Error on LOAD() in trunk

2011-07-02 Thread Massimo Di Pierro
Can you explain to me why you prefer ajax=False to ajax=True? What
advantages do you expect?

On Jul 2, 1:28 am, LightOfMooN  wrote:
> ajax=False is very important for me, so, I like 1.96 more than 1.97 :)
> I use it at most interactive components, that can be displayed on the
> all pages of site.
>
> Just one example:
>
> def voting_viewlet():
>     if not session.has_key('finished_votings'):
>         session.finished_votings = {}
>     if request.vars.get('vote', None):
>         active_voting =
> db((db.voting.id==session['active_voting'])&(db.voting.status=='opened')).s 
> elect().first()
>         if active_voting and active_voting.id not in
> session.get('finished_votings', []):
>             answers =
> db(db.voting_answers.voting_id==active_voting.id).select()
>             show_results = False
>             if active_voting.multi:
>                 answerlist = []
>                 tmp = makelist(request.vars.answer)
>                 for i in tmp:
>                     answerlist.append(int(i))
>                 valide_answers = list(set(get_ids(answers)) &
> set(answerlist))
>                 if valide_answers:
>
> db(db.voting_answers.id.belongs(valide_answers)).update(count=db.voting_ans 
> wers.count
> +1)
>                     try:
>
> session['finished_votings'].append(active_voting.id)
>                     except:
>                         session['finished_votings']=[active_voting.id]
>                     show_results = True
>             else:
>                 if request.vars.answer:
>                     answer = int(request.vars.answer)
>                     if answer in get_ids(answers):
>
> db(db.voting_answers.id==answer).update(count=db.voting_answers.count
> +1)
>                         try:
>
> session['finished_votings'].append(active_voting.id)
>                         except:
>
> session['finished_votings']=[active_voting.id]
>                         show_results = True
>             if show_results:
>                 voting =
> db(db.voting.id==active_voting.id).select().first() or
> redirect(URL('default','index'))
>                 answers =
> db(db.voting_answers.voting_id==voting.id).select(orderby=~db.voting_answer 
> s.count)
>                 count = 0
>                 if answers:
>                     max = answers.first().count
>                     for answer in answers:
>                         count += answer.count
>                     for answer in answers:
>                         if count > 0:
>                             answer.percent =
> int(float(answer.count)*100/count)
>                             answer.width = int(float(answer.count)*100/
> max)
>                             answer.color = getColor()
>                         else:
>                             answer.percent = 0
>                             answer.width = 0
>                             answer.color = getColor()
>                 return response.render('voting/
> voting_viewlet_results.html', dict(voting=voting, answers=answers,
> count=count))
>
>     votings = db(db.voting.status=='opened').select()
>     finished_votings = session.get('finished_votings',[])
>     unfinished_votings = []
>     for voting in votings:
>         if voting.id not in finished_votings:
>             unfinished_votings.append(voting)
>     if unfinished_votings:
>         active_voting = unfinished_votings[random.randint(0,
> len(unfinished_votings)-1)]
>         session['active_voting'] = active_voting.id
>     else:
>         active_voting = None
>         session['active_voting'] = None
>
>     if active_voting:
>         answers =
> db(db.voting_answers.voting_id==active_voting.id).select(orderby=db.voting_ 
> answers.id)
>     else:
>         answers = []
>
>     return dict(active_voting=active_voting, answers=answers)
>
> On 2 июл, 04:51, Massimo Di Pierro  wrote:
>
>
>
>
>
>
>
> > There are logic problems with ajax=False. Just use ajax=True. I am not
> > sure ajax=False should be an option al all.
>
> > On Jul 1, 11:45 am, LightOfMooN  wrote:
>
> > > Thx, but I just disabled some components until the new stable version
> > > of webpy :)
>
> > > On 1 июл, 21:29, Anthony  wrote:
>
> > > > That problem has been fixed in trunk, but looks like another problem may
> > > > have been introduced. Try downloading trunk revision d4c2d8d15bb1 -- 
> > > > that
> > > > fixes the request.vars problem, but comes before the copy.copy(request)
> > > > problem was introduced. Actually, maybe you could try the latest 
> > > > revision in
> > > > trunk and see if the copy.copy(request) causes the same problem for you 
> > > > as
> > > > it has for pbreit -- that might help diagnose the problem.
>
> > > > Anthony
>
> > > > On Friday, July 1, 2011 10:57:13 AM UTC-4, LightOfMooN wrote:
> > > > > so, request has no vars storage
>
> > > > > On 1 июл, 20:53, LightOfMooN  wrote:
> > > > > > def voting_viewlet():
> > > > > >     return dict()
>
> > > > > > works fine
>
> > > > > > But if I try to check request.var

Re: [web2py] Insert "One to many" related tables in GAE

2011-07-02 Thread José Luis Redrejo Rodríguez
2011/7/2 Vasile Ermicioi :
> GAE is a NoSQL database http://en.wikipedia.org/wiki/NoSQL
> but you can use a field where you can store a list of ids (one to many
> relation denormalized)
> http://web2py.com/book/default/chapter/06#Many-to-Many,-list:,-and-contains
>


I know, but using dal I can use "one to many" relationship in gae. My
problem is not how to use it, but how to fill two related datatables
to use it later.


[web2py] regarding "http://mdp.cti.depaul.edu/"

2011-07-02 Thread Vineet
I was trying to see this link--
http://mdp.cti.depaul.edu/
Is this link broken?
I could not access it.


Re: [web2py] Insert "One to many" related tables in GAE

2011-07-02 Thread Vasile Ermicioi
GAE is a NoSQL database http://en.wikipedia.org/wiki/NoSQL

but you can use a field where you can store a list of ids (one to many
relation denormalized)

http://web2py.com/book/default/chapter/06#Many-to-Many,-list:,-and-contains


[web2py] Insert "One to many" related tables in GAE

2011-07-02 Thread José L .
Hi, I have a very simple case use that I'm not able to solve using GAE:
I have a file with the content of two tables (cities and provinces). Cities 
have a db.provinces field, and when I start a new aplicacation I use to 
populate these tables using data from a module with this structure:
Provinces=(
(1, 'Álava', 'alava', 'ALV','01'),
(2, 'Castellón', 'castellon', 'CAS','12'),
...)

where the first field is the id of the province

Cities=(
(1,1,'Alegría-Dulantzi', 'alegria-dulantzi', '01240', '42.841171', 
'-2.512608'),
(2,1,'Amurr...)

(first field is the id of the city and second field is the province_id 
field) 

So I do a bulk insert in the provinces table, and using the province_id I do 
a bulk insert in the cities tables.
So far, so good using mysql, or sqlite.

But using GAE I can not fill it using the province_id (the id is ignored and 
gae puts another one) and I have no clue on how to associate both data.

Can anybody lend me a hand?

Regards
José L.


[web2py] Re: Forcing SSL/HTTPS

2011-07-02 Thread cjrh
I have found that only the *new *Google Groups is working reliably.  Using 
the old system has become very unreliable.

Re: [web2py] Forcing SSL/HTTPS

2011-07-02 Thread cjrh
Added here:

http://web2py.com/book/default/chapter/04#Cron

Please verify that I got the details correct.  Also, in future if you want 
something fixed in the book just email me directly and I'll get it done 
ASAP.  My ability to follow the groups closely waxes and wanes relative to 
how busy I am with other things.


[web2py] Re: Multiple Domains, Subdomains, and Applications with SSL. Single web2py Instance on Apache

2011-07-02 Thread cjrh
If you format this post in markmin and email it to me, I'll add it to the 
book as an additional subsection after Apache setup.

Re: [web2py] How to create a new record in database without submit buttons

2011-07-02 Thread portable dora
'Insert' method. That is what I wanted to know.
Thank you so much!!

2011/7/2 cjrh 

> In the method called by the AJAX event, you don't need the form at all.
>  You can just do a straight insert.  You must pass the data to be inserted
> as part of the AJAX call, either via args, or post data or some other method
> on the URL.  Then, inside writing(), just do a direct DB insert as
> documented here: http://web2py.com/book/default/chapter/06#insert


Re: [web2py] How to create a new record in database without submit buttons

2011-07-02 Thread cjrh
In the method called by the AJAX event, you don't need the form at all.  You 
can just do a straight insert.  You must pass the data to be inserted as 
part of the AJAX call, either via args, or post data or some other method on 
the URL.  Then, inside writing(), just do a direct DB insert as documented 
here: http://web2py.com/book/default/chapter/06#insert

[web2py] Re: BUG: I think.

2011-07-02 Thread cjrh
On Jul 1, 8:34 pm, pbreit  wrote:
> I usually do extension=''

What would extension=None do?  It seems to make the most semantic
sense, to me at least.


[web2py] How to create a new record in database without submit buttons

2011-07-02 Thread dorasan
Hello everyone.

Could you tell me how to create a new record in database without
submit buttons?
I actually would like to do it by the onclick event.
I know that I can call the ajax function like this.

  

But I don"t know what I have to write in the 'def:writing'.
My code implemented by a submit button is this.


db.define_table('article',
   Field('title'),
   Field('text')
   )


def writing():
  form = SQLFORM(db.article)
  if form.accepts(request.vars, session, formname='article_works'):
  response.flash = 'Done'
  elif form.errors:
  response.flash = 'Error'
  else:
  response.flash = 'Write something'
  return dict(formkeyvalue=form.formkey, message=response.flash)


{{include 'web2py_ajax.html'}}

Title
Text




{{=message}}