[web2py] Re: JQUERY as response in Ajax call?

2013-05-09 Thread Niphlod
if you're using components, use response.js .
http://web2py.com/books/default/chapter/29/12?search=response.js

On Friday, May 10, 2013 7:10:31 AM UTC+2, Mika Sjöman wrote:
>
> Hi
>
> I am trying to close a window title dialog with JQUERY after sucessuflly 
> updating a clients phone number. The problem is that after I successfully 
> update the data I send this as a response to the browser: 
>
> 
> message = "jQuery('#windowTitleDialog').toggle('slow');"
> return message
>
>
> But the script just loads it as text in a DIV instead of executing the 
> Jquery :( 
>
> The way I call it is like this from the webbrowser:
>
> 
> jQuery('#update_phone_number').submit(function() {
>   ajax('{{=URL('update_phone_number')}}', ['phone',], 
> 'phone_updated_div');
>   return false;
> });
>  
>
> Anyone has an idea on how to run the JQUERY instead of just loding it as 
> text inside the phone_updated_div ?
>
> cheerio
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: Migrations Problem: two fields added, two not added

2013-05-09 Thread Manuele Pesenti
Hi!
I got quite the same problem with postgresql. I tried to add a field to
an already defined table but I fot this error:

ProgrammingError: ERRORE:  la colonna
plugin_lookout_fields.table_meta_data non esiste
LINE 1: ...s.field_comment, plugin_lookout_fields.is_active, plugin_loo...

(it says that column plugin_lookout_fields.table_meta_data do not exists
which is the one I've added)

the solution hereunder suggested did not solved... is there a way to
solve this problem?

Thank you very mutch

cheers

Manuele

Il 08/04/11 22:04, Massimo Di Pierro ha scritto:
> 1) get trunk
> 2) comment the missing fields
> 3) run with DAL(...,fake_migrate_all=True)
> 4) visit appadmin
> 5) uncomment the missing fields
> 6) remove fake_migrate_all=True from DAL(...)
> 7) visit appadmin
>
> did it fix it?
>
>
>
> On Apr 8, 2:21 pm, Lennon  wrote:
>> I added the follow fields to my table:
>>
>> Field('rooming_requests','string', length=500, label='Do you have any
>> rooming requests?', widget=SQLFORM.widgets.text.widget,
>> requires=[IS_LENGTH(500)]),
>>
>> Field('misc_info','string', length=500, label='Anything else you would
>> like us to know?', widget=SQLFORM.widgets.text.widget,
>> requires=[IS_LENGTH(500)]),
>>
>> Field('us_citizen','boolean', label='Are you a US citizen?',
>> requires=IS_IN_SET(['T', 'F'],zero='Choose One')),
>>
>> Field('dietary_restrict','string', length=500, label='Do you have any
>> dietary restrictions?', widget=SQLFORM.widgets.text.widget,
>> requires=[IS_LENGTH(500)]),
>>
>> When I did a migrate, the "rooming_requests" field and the "misc_info"
>> fields were added to the table file and to the MySQL database but the
>> "us_citizen" field and the "dietary_restrict" field was not.
>>
>> Subsequent migration attempts have had no effect.
>>
>> Please advise,
>>
>> ~Lennon

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] JQUERY as response in Ajax call?

2013-05-09 Thread Mika Sjöman
Hi

I am trying to close a window title dialog with JQUERY after sucessuflly 
updating a clients phone number. The problem is that after I successfully 
update the data I send this as a response to the browser: 


message = "jQuery('#windowTitleDialog').toggle('slow');"
return message


But the script just loads it as text in a DIV instead of executing the 
Jquery :( 

The way I call it is like this from the webbrowser:


jQuery('#update_phone_number').submit(function() {
  ajax('{{=URL('update_phone_number')}}', ['phone',], 
'phone_updated_div');
  return false;
});
 

Anyone has an idea on how to run the JQUERY instead of just loding it as 
text inside the phone_updated_div ?

cheerio

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Does layout.html have a corresponding controller?

2013-05-09 Thread Anthony
You've got it somewhat backwards -- views don't have controller functions 
-- controller functions have views. In other words, URLs that come into 
web2py do not specify a particular view being requested but instead specify 
a particular controller and function. Typically the function will then have 
an associated view, and that view itself may then extend or include other 
views. The extended and included views are typically not associated with 
other functions but are there specifically to be extended or included. A 
layout.html view, therefore, is not associated with any controller function 
-- it is just used by other views to fill out common parts of the page so 
those views don't have to repeat the same template code over and over.

If you want to have a search box in the layout, you'll have to create a 
search function in a controller. Then in the form HTML in the layout, 
specify the URL of the search function as the "action" attribute of the 
form. When the form is submitted, it will request the search function URL, 
and the search results page will load in the browser.

In the layout:



In the default.py controller:

def search():
[process the search request]
return dict(...)

Anthony

On Thursday, May 9, 2013 7:52:07 PM UTC-4, Bob Babby wrote:
>
> I want to add a search bar to my all my pages. I think the best way to do 
> this is by adding it to the layout.html from which all my other html views 
> extend from.
>
> The problem I can't figure out is where to put the corresponding 
> controller function. For all the other views, the controller functions are 
> in default.py. Where would I put the controller logic for layout.html so 
> that I can begin building the form using the htmlhelpers?
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Does layout.html have a corresponding controller?

2013-05-09 Thread Bob Babby
I want to add a search bar to my all my pages. I think the best way to do 
this is by adding it to the layout.html from which all my other html views 
extend from.

The problem I can't figure out is where to put the corresponding controller 
function. For all the other views, the controller functions are in 
default.py. Where would I put the controller logic for layout.html so that 
I can begin building the form using the htmlhelpers?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Controller for layout.html?

2013-05-09 Thread Bob Babby
Sorry if this is a repost. My last post wasn't showing up for some reason.

I want to add a search bar to all my pages. To do this I plan on adding an 
input text to layout.html (all my pages extend layout.html).

But where is the controller for layout.html so that I can build the 
htmlhelpers and then do {{=form}} in layout.html?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: superfish.css overridden : menu sent to back of jqgrid

2013-05-09 Thread Patrick Patel
Wow, that was extraordinarily helpful!  Thanks so much...

On Saturday, July 16, 2011 6:59:33 AM UTC-7, Vineet wrote:
>
> Hello List ! 
> I am trying to facelift my app by completely overriding the 
> superfish.css. 
> In most of the forms, the new-look menu is working superbly. 
> But only in those forms containing "jqgrid" or "dataTable" controls, 
> the menu is sent to back to the table control. 
> Tried by setting "z-index:" property of  containing the menu at 
> higher value. But no success. 
> I am wondering why this behaviour (only in case of jqgrid & 
> dataTable). 
>
> Anybody got any idea? 
>
> (If the problem description is too short, pl. tell me sothat I can 
> post the code in this thread). 
>
> Thanks. 
> :-)

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] German TranslationFile für admin

2013-05-09 Thread Klaus Kappel
hi there,

here is a german language file the admin-app.

If someone could share some helper scripts, for example to get rid of 
obsolete strings, i would appreciate that.

cu,

Klaus Kappel

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


# coding: utf8
# Translation by: Klaus Kappel 
{
'!langcode!': 'de',
'!langname!': 'Deutsch',
'"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN': '"Update" ist ein optionaler Ausdruck wie "Feld1 = \'newvalue". JOIN Ergebnisse k?nnen nicht aktualisiert oder gel?scht werden',
'%s %%{row} deleted': '%s %%{row} Zeilen gel?scht',
'%s %%{row} updated': '%s %%{row} Zeilen aktualisiert',
'%Y-%m-%d': '%d.%m.%Y',
'%Y-%m-%d %H:%M:%S': '%d.%m.%Y %H:%M:%S',
'(requires internet access)': '(Internet Zugang wir ben?tigt)',
'(requires internet access, experimental)': '(ben?tigt Internet Zugang)',
'(something like "it-it")': '(so etwas wie "it-it")',
'@markmin\x01Searching: **%s** %%{file}': '@markmin\x01Suche: **%s** Dateien',
'A new version of web2py is available': 'Eine neue Version von web2py ist verf?gbar',
'A new version of web2py is available: %s': 'Eine neue Version von web2py ist verf?gbar: %s',
'Abort': 'Abbrechen',
'About': '?ber',
'About application': '?ber die Anwendung',
'Additional code for your application': 'zus?tzlicher Code f?r Ihre Anwendung',
'admin disabled because no admin password': 'admin ist deaktiviert, weil kein Admin-Passwort gesetzt ist',
'admin disabled because not supported on google apps engine': 'admin ist deaktiviert, es existiert daf?r keine Unterst?tzung auf der google apps engine',
'admin disabled because unable to access password file': 'admin ist deaktiviert, weil kein Zugriff auf die Passwortdatei besteht',
'Admin is disabled because insecure channel': 'Appadmin ist deaktiviert, wegen der Benutzung eines unsicheren Kanals',
'Admin is disabled because unsecure channel': 'Appadmin ist deaktiviert, wegen der Benutzung eines unsicheren Kanals',
'Admin language': 'Admin-Sprache',
'administrative interface': 'Administrative Schnittstelle',
'Administrator Password:': 'Administrator Passwort:',
'An error occured, please %s the page': 'Ein Fehler ist aufgetereten, bitte %s die Seite',
'and rename it (required):': 'und benenne sie um (erforderlich):',
'and rename it:': ' und benenne sie um:',
'appadmin': 'appadmin',
'appadmin is disabled because insecure channel': 'Appadmin ist deaktiviert, wegen der Benutzung eines unsicheren Kanals',
'Application': 'Anwendung',
'application "%s" uninstalled': 'Anwendung "%s" deinstalliert',
'application compiled': 'Anwendung kompiliert',
'application is compiled and cannot be designed': 'Die Anwendung ist kompiliert kann deswegen nicht mehr ge?ndert werden',
'Application name:': 'Name der Applikation:',
'Are you sure you want to delete file "%s"?': 'Sind Sie sich sicher, dass Sie diese Datei l?schen wollen "%s"?',
'Are you sure you want to delete this object?': 'Are you sure you want to delete this object?',
'Are you sure you want to uninstall application "%s"': 'Sind Sie sich sicher, dass Sie diese Anwendung deinstallieren wollen "%s"',
'Are you sure you want to uninstall application "%s"?': 'Sind Sie sich sicher, dass Sie diese Anwendung deinstallieren wollen "%s"?',
'Are you sure you want to upgrade web2py now?': 'Sind Sie sich sicher, dass Sie web2py jetzt upgraden m?chten?',
'arguments': 'arguments',
'ATTENTION: Login requires a secure (HTTPS) connection or running on localhost.': 'ACHTUNG: Die Einwahl ben?tigt eine sichere (HTTPS) Verbindung. Es sei denn sie l?uft Lokal(localhost).',
'ATTENTION: TESTING IS NOT THREAD SAFE SO DO NOT PERFORM MULTIPLE TESTS CONCURRENTLY.': 'ACHTUNG: Testen ist nicht threadsicher. F?hren sie also nicht mehrere Tests gleichzeitig aus.',
'ATTENTION: This is an experimental feature and it needs more testing.': 'ACHTUNG: Dies ist eine experimentelle Funktion und ben?tigt noch weitere Tests.',
'ATTENTION: you cannot edit the running application!': 'ACHTUNG: Eine laufende Anwendung kann nicht editiert werden!',
'Authentication': 'Authentifizierung',
'Available databases and tables': 'Verf?gbare Datenbanken und Tabellen',
'back': 'zur?ck',
'beautify': 'versch?nern',
'cache': 'Pufferspeicher',
'cache, errors and sessions cleaned': 'Zwischenspeicher (cache), Fehler und Sitzungen (sessions) gel?scht',
'call': 'Aufruf',
'can be a git repo': 'kann ein git Repository sein',
'Cannot be empty': 'Darf nicht leer sein',
'Cannot compile: there are errors in your app.Debug it, correct errors and try again.': 'Nicht Kompilierbar:Es sind Fehler in der Anwendung. Beseitigen Sie die Fehler und versuchen Sie es erneut.',
'cannot create file': 'Kann Datei nicht erstellen',
'cannot upload file "%(fi

[web2py] Re: In openshift: Need help on why my web2py website is being constantly accessed by openshift itself

2013-05-09 Thread smoggy
I've checked ./haproxy-1.4/conf/haproxy.cfg

and I indeed had 

listen express 127.9.181.130:8080
option httpchk GET /

i commented that in order to get only tcp based checks instead of http ones 
to keep the logs cleaner. After restarting the cartridge 
with "rhc cartridge reload haproxy-1.4 --namespace my_namespace --app 
my_app " the log file still shows a hit or health check every 3 seconds :/ .

Andrew do your logs also show these events ? have you had any configuration 
changes to prevent this from happening ?


On Thursday, May 9, 2013 9:06:13 PM UTC+1, Andrew Replogle wrote:
>
> If you're using haproxy are you sure it's not the heartbeat check?
>
> On Wednesday, May 8, 2013 5:10:51 AM UTC-5, smoggy wrote:
>>
>> Hi folks,
>>
>> So in openshift in a python 2.6 cartridge + haproxy i'm having lots of 
>> accesses from openshift ip itself, like one every 3 seconds. I do not have 
>> any cron jobs. Is there a way to figure where these access are coming from 
>> : wsgi, web2py, openshift ?
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: How can Web2py prevent web scraping?

2013-05-09 Thread Derek
I've read an idea about using a 'ticket' system... each session gets X # of 
tickets. Tickets regenerate at a fixed rate. Normal users would never run 
out of tickets.
Each query operation would have a fixed cost of tickets. Inserts would cost 
double selects... 
You don't have to calculate regeneration - just when an operation is about 
to be performed, you check the last time a request was made, and the last 
number of tickets. calculate regeneration and then if they have enough 
tickets, you do the request. If not, you return a 503 error, or perhaps a 
friendly message saying "swiper no swiping" (to quote Dora)

On Thursday, May 9, 2013 11:58:43 AM UTC-7, Alex Glaros wrote:
>
> What techniques can be used in a Web2py site to prevent data mining by 
> harvester bots?
>
> In my day job, if the Oracle database slows down, I go to the Unix OS, see 
> if the same IP address is doing a-lot-faster-than-a-human-could-type 
> queries, and then block that IP address in the firewall.
>
> Are there any ideas that that I could use with a Web2py website?
>
> Thanks,
>
> Alex Glaros
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: (1/2 OT) Bug in production? [nginx + uwsgi]

2013-05-09 Thread Jose


El jueves, 9 de mayo de 2013 19:52:47 UTC-3, Jose escribió:
>
> Hello,
>
> The normal behavior is: The user presses the Test button, then  id="sql"> show "ABCD". (The code is shown below)
>
> In development mode running rocket, works well, but in production ajax 
> call is not executed.
>
>
> Environment:
>
> Web2py 2.4.6 (Version 2.4.6-stable+timestamp.2013.05.08.16.52.12)
> FreeBSD 9.1
> Nginx-1.4.0
> Uwsgi-1.4.9
>
> uwsgi.conf:
>
> 
>   127.0.0.1:9001
>   /home/web2py/
>   wsgihandler
>   4
>   8192
> 
>
> nginx.conf
> ...
> location ~ /myapp{
> uwsgi_pass  127.0.0.1:9001;
> include uwsgi_params;
> }
>
> ...
>
>
> default.py:
>
> def index():   
>return dict()
>
>
> def bg_test():
> id = request.vars.id
> return id
>
>
>
>
> default/index.html:
>
>
>
> {{extend 'layout.html'}}
>
> 
>
>
> function test(){
> $('#id').val('ABCD');
> ajax('bg_test', ['id'], 'sql');
> }
> 
> 
> 
> 
>
>
> Test
>
>
> 
>
>
> I think the problem is not web2py, I tested with version 1.99.4 and also 
> works bad.
>
> Something that can be changed or added in nginx.conf or uwsgi.conf?
> Any idea?
>
> Best Regards
> Jose
>

I think the problem is the url of the call

ajax('bg_test', ['id'], 'sql');

must be well:

url = "{{=URL('default', 'bg_test')}}"
ajax(url, ['id'], 'sql');

José

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] (1/2 OT) Bug in production? [nginx + uwsgi]

2013-05-09 Thread Jose
Hello,

The normal behavior is: The user presses the Test button, then  show "ABCD". (The code is shown below)

In development mode running rocket, works well, but in production ajax call 
is not executed.


Environment:

Web2py 2.4.6 (Version 2.4.6-stable+timestamp.2013.05.08.16.52.12)
FreeBSD 9.1
Nginx-1.4.0
Uwsgi-1.4.9

uwsgi.conf:


  127.0.0.1:9001
  /home/web2py/
  wsgihandler
  4
  8192


nginx.conf
...
location ~ /myapp{
uwsgi_pass  127.0.0.1:9001;
include uwsgi_params;
}

...


default.py:

def index():   
   return dict()


def bg_test():
id = request.vars.id
return id




default/index.html:



{{extend 'layout.html'}}




function test(){
$('#id').val('ABCD');
ajax('bg_test', ['id'], 'sql');
}






Test





I think the problem is not web2py, I tested with version 1.99.4 and also 
works bad.

Something that can be changed or added in nginx.conf or uwsgi.conf?
Any idea?

Best Regards
Jose

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: How can Web2py prevent web scraping?

2013-05-09 Thread Niphlod
for "kind" agents a robots.txt suffice. 
for inconsiderate harvester, usually that kind of work is addressed by 
either the firewall or the webserver.

in web2py either you evaluate the user agent for every request and cut it 
to a "HTTP(500)" in models or you implement your own rate-limiting, that 
needs to be as fast as possible. 

On Thursday, May 9, 2013 8:58:43 PM UTC+2, Alex Glaros wrote:
>
> What techniques can be used in a Web2py site to prevent data mining by 
> harvester bots?
>
> In my day job, if the Oracle database slows down, I go to the Unix OS, see 
> if the same IP address is doing a-lot-faster-than-a-human-could-type 
> queries, and then block that IP address in the firewall.
>
> Are there any ideas that that I could use with a Web2py website?
>
> Thanks,
>
> Alex Glaros
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: In openshift: Need help on why my web2py website is being constantly accessed by openshift itself

2013-05-09 Thread Andrew Replogle
If you're using haproxy are you sure it's not the heartbeat check?

On Wednesday, May 8, 2013 5:10:51 AM UTC-5, smoggy wrote:
>
> Hi folks,
>
> So in openshift in a python 2.6 cartridge + haproxy i'm having lots of 
> accesses from openshift ip itself, like one every 3 seconds. I do not have 
> any cron jobs. Is there a way to figure where these access are coming from 
> : wsgi, web2py, openshift ?
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Possible problem with cron using python 2.7.3 and Ubuntu 12.04

2013-05-09 Thread goome
I got the same error with the same python and ubuntu. did you solve in some 
manner?
Thanks

Il giorno lunedì 7 maggio 2012 05:40:11 UTC+2, Nick Noel ha scritto:
>
> Hello,
> I find that I get the following error on startup:
>
> Starting hardcron...
> please visit:
> http://127.0.0.1:8000
> starting browser...
> Exception AttributeError: AttributeError("'_DummyThread' object has no 
> attribute '_Thread__block'",) in  '/usr/lib/python2.7/threading.pyc'> ignored
>
> Furthermore, 
> I find that each time a cronjob is scheduled to kick off I get the same 
> error.  This seems to prevent the job from starting up.
>
> A little research led me to the following Python bug report:
> http://bugs.python.org/issue14308
>
> Has anyone else experienced this?
>
> Thanks,
> --Nick
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Dynamically change highlighted class for response.menu

2013-05-09 Thread Omi Chiba
>Niphlod 
Thank you !! It's perfect now.

>Paolo
Thank you for the reference that's look easier too especially for someone 
like me who's not javascript gulu.


On Thursday, May 9, 2013 1:55:00 PM UTC-5, Niphlod wrote:
>
>   
> jQuery(function() {
>   var path = location.pathname.substring(1);
> if ( path ) {
> var els = jQuery('ul.nav a[href$="'+path+'"]').filter(
> "[rel!=nofollow]");
> if (els.length != 0) {
> els.find('span').addClass('highlighted');
> } else {
> jQuery('#default_highlighted').find('span').addClass(
> 'highlighted');
> }
> }
> })
> 
>
>
>
> is the one. the previous was for the one with the additional "fiddles" 
> with the css.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] How can Web2py prevent web scraping?

2013-05-09 Thread Alex Glaros


What techniques can be used in a Web2py site to prevent data mining by 
harvester bots?

In my day job, if the Oracle database slows down, I go to the Unix OS, see 
if the same IP address is doing a-lot-faster-than-a-human-could-type 
queries, and then block that IP address in the firewall.


Are there any ideas that that I could use with a Web2py website?

Thanks,

Alex Glaros

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Dynamically change highlighted class for response.menu

2013-05-09 Thread Niphlod
  
jQuery(function() {
  var path = location.pathname.substring(1);
if ( path ) {
var els = jQuery('ul.nav a[href$="'+path+'"]').filter(
"[rel!=nofollow]");
if (els.length != 0) {
els.find('span').addClass('highlighted');
} else {
jQuery('#default_highlighted').find('span').addClass(
'highlighted');
}
}
})




is the one. the previous was for the one with the additional "fiddles" with 
the css.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] dealing with legacy tables with strange names

2013-05-09 Thread Massimo Di Pierro
Many of you have complained about the pain of having to deal with table 
with strange names for example table names containing a ".".
There is a quick solution in trunk:

# assuming
db =DAL()
db.define_table('owner',Field('name'))
db.define_table('thing',Field('name'),Field('owner','reference owner'))
i=db.owner.insert(name='max')
db.thing.insert(name='Chair',owner=i)

# you can do
db =DAL(enable_migrations=False)
db.define_table('o',Field('name'),actual_name='owner')
db.define_table('t',Field('name'),Field('owner','reference o'), 
actual_name='thing')
print db(db.t.owner==db.o.id).select()
print db(db.t).select(db.t.ALL,db.o.ALL,left=[db.o.on(db.t.owner==db.o.id)])

The key here is in the second part. You can do actual_name="thing" and db.t 
will be the same as db.thing and actual_name can contain "." or it can be 
an escaped name like actual_name="[domain].[thing]".

This only works in reading, not in writing the tables. It passes my test 
but please help me test it. It should be easy to make it work in writing 
too.

Massimo 





-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Dynamically change highlighted class for response.menu

2013-05-09 Thread Paolo Caruccio
for a pyhon solution (not involving javascript) you could check this 
argument https://groups.google.com/d/topic/web2py/8AHYqV_EKy0/discussion 




Il giorno martedì 7 maggio 2013 17:56:10 UTC+2, Omi Chiba ha scritto:
>
> I have a following response.menu in my menu.py. By default Home is 
> highlighted but I want to highlight the menu clicked by the user. For 
> example, when user click contact, 'highlighted' class should be added to 
> contact and removed from home.
>
> response.menu = [
> (SPAN('Home', _class='highlighted'), False, URL('default', 'index'), 
> []),
> (T('Order Status'), False, URL('default', 'orderstatus'), []),
> (T('Q&A'), False, URL('default', 'qa'), []),
> (T('Contact'), False, URL('default', 'contact'), [])
> ]
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] upgrade web2py

2013-05-09 Thread Richard Vézina
Hello,

I don't think it a good idea to use the upgrade feature. Last version of
web2py is 2.4.6 and 1.99.4 is pretty old and the upgrade feature may be
buggy. Also consider that you may or may not need to update python
interpreter in order to use web2py 2.4.6 to access new feature in this
version.

At least I hope you have make a backup...

What I usually do to upgrade is to download new web2py and copy my app in
the new version web2py beside the older web2py in developpement
environnement... Patch my app to make it works under the new version when
needed and then deploy on prod system the whole thing (new web2py and
refactor app), you may have to install new dependencies on you prod server.

Before update prod, I create a archive recursively on web2py folder that is
generally in /home/www-data/web2py...

Hope it helps.

Richard




On Thu, May 9, 2013 at 11:01 AM, George Hellman wrote:

> I am trying to upgrade web2py automatically
>
> I am running
> "Version 1.99.4"  " Running on Apache/2.2.20 (Ubuntu)"
>  (ubuntu server) with full root access.
>
> It says: "Checking for upgrades..." or, if there is an upgrade button, it
> does not upgrade.
>
> This may have to do with "file locking" as on post said.
> How do I get Ubuntu to allow an upgrade?
>
>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] upgrade web2py

2013-05-09 Thread George Hellman
I am trying to upgrade web2py automatically

I am running  
"Version 1.99.4"  " Running on Apache/2.2.20 (Ubuntu)"
 (ubuntu server) with full root access.

It says: "Checking for upgrades..." or, if there is an upgrade button, it 
does not upgrade.

This may have to do with "file locking" as on post said.
How do I get Ubuntu to allow an upgrade?


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Dynamically change highlighted class for response.menu

2013-05-09 Thread Niphlod
I will but you have to wait a few hours for me to get back home :(

Il giorno giovedì 9 maggio 2013 15:34:10 UTC+2, Omi Chiba ha scritto:
>
> Oh, actually it's not working for me
> It was working fine with the previous code except default home but now it 
> doesn't highlight the menu at all.
>
> Can you quickly check my attached app?
>
>
> On Thursday, May 9, 2013 8:19:31 AM UTC-5, Omi Chiba wrote:
>>
>> Worked! Thank you~!
>>
>> On Thursday, May 9, 2013 3:38:41 AM UTC-5, Niphlod wrote:
>>>
>>> it's exactly working as expected with the latest snippet.
>>>
>>> Il giorno giovedì 9 maggio 2013 00:15:38 UTC+2, Omi Chiba ha scritto:

 Thank you for the additional explanation.

 I just want to highlight the home by defaut only first time user access 
 the page. It should be removed when user click menu1 or menu2. The home 
 will be highlighted again when user click home.

 By default.
 --
 Home highlihgted
 Menu1
 Menu2

 User click menu1...
 
 Home 
 Menu1 highlihgted
 Menu2

 User click Home again...
 
 Home highlihgted
 Menu1
 Menu2





 On Wednesday, May 8, 2013 4:34:07 PM UTC-5, Niphlod wrote:
>
> ps: if you are on the case where you need to have home highlighted by 
> default no matter what, use this javascript snippet (pretty 
> straightforward)
> Added also a filter() to exclude the registration/login/etc links from 
> being highlighted
>
> jQuery(function() {
>   var path = location.pathname.substring(1);
> if ( path ) {
> var els = jQuery('ul.nav a[href$="'+path+'"]').filter(
> "[rel!=nofollow]");
> if (els.length != 0) {
> els.closest('li').addClass('highlighted');
> } else {
> jQuery('ul.nav a[href$="/highlight/default/index"]').
> closest('li').addClass('highlighted');
> }
> }
> })
>
> PS: maybe to make it more clearer, use a Home link with an id, such as 
>
> (SPAN('Home', _id='default_highlighted'), False, URL('default', 
> 'index'), []),
>
> so you can switch the last line from
>
> jQuery('ul.nav a[href$="/highlight/default/index"]').closest('li').
> addClass('highlighted');
>
>
> to
>
>
> jQuery('#default_highlighted').closest('li').addClass('highlighted');
>
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Dynamically change highlighted class for response.menu

2013-05-09 Thread Omi Chiba
Worked! Thank you~!

On Thursday, May 9, 2013 3:38:41 AM UTC-5, Niphlod wrote:
>
> it's exactly working as expected with the latest snippet.
>
> Il giorno giovedì 9 maggio 2013 00:15:38 UTC+2, Omi Chiba ha scritto:
>>
>> Thank you for the additional explanation.
>>
>> I just want to highlight the home by defaut only first time user access 
>> the page. It should be removed when user click menu1 or menu2. The home 
>> will be highlighted again when user click home.
>>
>> By default.
>> --
>> Home highlihgted
>> Menu1
>> Menu2
>>
>> User click menu1...
>> 
>> Home 
>> Menu1 highlihgted
>> Menu2
>>
>> User click Home again...
>> 
>> Home highlihgted
>> Menu1
>> Menu2
>>
>>
>>
>>
>>
>> On Wednesday, May 8, 2013 4:34:07 PM UTC-5, Niphlod wrote:
>>>
>>> ps: if you are on the case where you need to have home highlighted by 
>>> default no matter what, use this javascript snippet (pretty straightforward)
>>> Added also a filter() to exclude the registration/login/etc links from 
>>> being highlighted
>>>
>>> jQuery(function() {
>>>   var path = location.pathname.substring(1);
>>> if ( path ) {
>>> var els = jQuery('ul.nav a[href$="'+path+'"]').filter(
>>> "[rel!=nofollow]");
>>> if (els.length != 0) {
>>> els.closest('li').addClass('highlighted');
>>> } else {
>>> jQuery('ul.nav a[href$="/highlight/default/index"]').closest
>>> ('li').addClass('highlighted');
>>> }
>>> }
>>> })
>>>
>>> PS: maybe to make it more clearer, use a Home link with an id, such as 
>>>
>>> (SPAN('Home', _id='default_highlighted'), False, URL('default', 
>>> 'index'), []),
>>>
>>> so you can switch the last line from
>>>
>>> jQuery('ul.nav a[href$="/highlight/default/index"]').closest('li').
>>> addClass('highlighted');
>>>
>>>
>>> to
>>>
>>>
>>> jQuery('#default_highlighted').closest('li').addClass('highlighted');
>>>
>>>
>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: Web Frameworks Performance

2013-05-09 Thread Alexei Vinidiktov
I run a small website in a Linux VM on Azure with WSGI. Seems to work fine.
It's just a VM as any other.


On Thu, May 9, 2013 at 2:56 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> Just some comments about 4. Web2py was not meat as a teacher tool. Web2py
> was meant to enforce good practice and this made it a good teaching tool.
> Not quite the same. In fact web2py is based on WSGI and it does run on
> Heroku. There is a session in the manual about that. I never tried Iron.io
> or Azure but I am sure it runs there as any other WSGI server does.
>
>
>
> On Wednesday, 8 May 2013 11:54:43 UTC-5, Derek wrote:
>>
>> Well, if you look at the benchmarks, several things stand out.
>>
>> 1. All the WSGI servers are pre-loaded. That means the code is already
>> pre-compiled and loaded in ram, ready to run. Web2py doesn't quite work
>> that way, because each request loads the database, does migrations if
>> necessary, and inserts a lot of objects into the scope.
>>
>> 2. They are all using gunicorn, which spawns about 4 workers on startup.
>> We could certainly run Web2py in WSGI mode with gunicorn, but it wouldn't
>> make much a difference. I believe if we are going to support sessions, they
>> should be off by default and use a decorator @session_enabled or something
>> like that. However, that may go against Web2py principles.
>>
>> 3. Those benchmarks are not development type setups. If we are going to
>> compare benchmarks, we'll need to make sure that our configuration matches
>> theirs.
>>
>> 4. Web2py was meant to be a teaching tool. However, as it is now, what
>> it's teaching is years old. Now everything needs to be WSGI so you can run
>> it on a PAAS such as Heroku, Iron.io, Azure, etc.
>>
>> It's good to know how we compare with performance, but at the same time,
>> I think we need to be realistic. Web2py needs to be re-architectured if
>> we're going to see wider adoption in the future.
>>
>>
>>
>> On Wednesday, May 8, 2013 5:31:19 AM UTC-7, Alfonso de la Guarda Reyes
>> wrote:
>>>
>>> Hi,
>>>
>>> How we can improve web2py to match the fastest python web frameworks
>>> performance?
>>>
>>> http://www.techempower.com/**benchmarks/#section=intro
>>>
>>> Surely, with many brains we can offer some method to improve that!
>>>
>>> Saludos,
>>>
>>> --**--
>>> Alfonso de la Guarda
>>> Twitter: @alfonsodg
>>> Redes sociales: alfonsodg
>>>Telef. 991935157
>>> 1024D/B23B24A4
>>> 5469 ED92 75A3 BBDB FD6B  58A5 54A1 851D B23B 24A4
>>>
>>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Alexei Vinidiktov

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] In openshift: Need help on why my web2py website is being constantly accessed by openshift itself

2013-05-09 Thread smoggy
here is what tail_all gives me and i guess that can be relevant. How can i 
get the user agent or more info ?

==> python-2.6/logs/error_log-20130508-00-EST <==
[Wed May 08 13:15:26 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30569): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Wed May 08 13:15:26 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Wed May 08 14:01:11 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30568): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Wed May 08 14:01:11 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Wed May 08 14:04:27 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30568): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Wed May 08 14:04:27 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Wed May 08 14:30:36 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30569): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Wed May 08 14:30:36 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Wed May 08 19:30:25 2013] [crit] (70007)The timeout specified has expired: 
mod_wsgi (pid=30568): Unable to read WSGI request.
[Wed May 08 19:30:29 2013] [error] [client 127.9.181.129] (32)Broken pipe: 
mod_wsgi (pid=8717): Unable to send request details to WSGI daemon process 
'516332d0e0b8cd9f14000160' on 
'/var/lib/openshift/516332d0e0b8cd9f14000160/python-2.6/logs/wsgi.20595.1.1.sock'.

==> python-2.6/logs/error_log-20130509-00-EST <==
[Thu May 09 00:10:17 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30568): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Thu May 09 00:10:18 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Thu May 09 00:55:28 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30568): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Thu May 09 00:55:28 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Thu May 09 01:30:33 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30569): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Thu May 09 01:30:33 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Thu May 09 02:10:32 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30569): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Thu May 09 02:10:32 2013] [error] [client 127.9.181.129] IOError: failed 
to write data
[Thu May 09 03:12:21 2013] [error] [client 127.9.181.129] mod_wsgi 
(pid=30568): Exception occurred processing WSGI script 
'/var/lib/openshift/516332d0e0b8cd9f14000160/app-root/runtime/repo/wsgi/application'.
[Thu May 09 03:12:21 2013] [error] [client 127.9.181.129] IOError: failed 
to write data

==> python-2.6/logs/web2py.log <==
127.9.181.129, 2013-05-09 04:53:55, GET, /, HTTP/1.0, 200, 0.273601
127.9.181.129, 2013-05-09 04:53:58, GET, /, HTTP/1.0, 200, 0.205469
127.9.181.129, 2013-05-09 04:54:00, GET, /, HTTP/1.0, 200, 0.273682
127.9.181.129, 2013-05-09 04:54:03, GET, /, HTTP/1.0, 200, 0.450868
127.9.181.129, 2013-05-09 04:54:12, GET, /, HTTP/1.0, 200, 7.086337
127.9.181.129, 2013-05-09 04:54:21, GET, /, HTTP/1.0, 200, 6.137373
127.9.181.129, 2013-05-09 04:54:24, GET, /, HTTP/1.0, 200, 1.335112
127.9.181.129, 2013-05-09 04:54:27, GET, /, HTTP/1.0, 200, 1.107582
127.9.181.129, 2013-05-09 04:54:30, GET, /, HTTP/1.0, 200, 0.272535
127.9.181.129, 2013-05-09 04:54:32, GET, /, HTTP/1.0, 200, 0.454832
/usr/bin/tail: cannot open `python-2.6/logs/wsgi.20595.1.1.sock' for 
reading: No such device or address

==> python-2.6/logs/access_log-20130509-00-EST <==
- - - [09/May/2013:04:54:32 -0400] "GET / HTTP/1.0" 200 22647 "-" "-"

==> python-2.6/logs/web2py.log <==
127.9.181.129, 2013-05-09 04:54:35, GET, /, HTTP/1.0, 200, 0.292673

==> python-2.6/logs/access_log-20130509-00-EST <==
- - - [09/May/2013:04:54:34 -0400] "GET / HTTP/1.0" 200 22647 "-" "-"

==> python-2.6/logs/web2py.log <==
127.9.181.129, 2013-05-09 04:54:37, GET, /, HTTP/1.0, 200, 0.405507

==> python-2.6/logs/access_log-20130509-00-EST <==
- - - [09/May/2013:04:54:37 -0400] "GET / HTTP/1.0" 200 22647 "-" "-"


Quarta-feira, 8 de Maio de 201

[web2py] Re: What would be the best way to optimize/resize images after upload

2013-05-09 Thread Niphlod
there's also a /contrib/imageutils.py ready to use.

Il giorno giovedì 9 maggio 2013 07:22:06 UTC+2, weheh ha scritto:
>
> There are numerous ways to resize uploaded images. Some are done via the 
> web server. Others are done within the app. For a couple of my apps I use 
> the python PIL package to resize uploaded images to thumbnails and the 
> like. Here's a code fragment that shows how to do it:
>
> def resize_image(img_file, indx):
> from PIL import Image
> im = Image.open(img_file)
> im.thumbnail((w, h), Image.ANTIALIAS)
> return im
>
> You then have to use im.save('path', 'jpeg') to get a jpeg out. You also 
> have to do a little extra work to save it to db or do some file management 
> to discard the original, if  you so desire.
>
>
>
> On Thursday, May 9, 2013 5:43:45 AM UTC+8, Dragan Matic wrote:
>>
>> Is there a way to automatically optimize and convert images after users 
>> upload it on my web app? I am pretty sure lots of users will upload 
>> uncompressed .bmp pictures or extra large pictures directly from camera. I 
>> think it would be best if I could resize and compress them immediately 
>> after upload. What would be the best way to do it? 
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Dynamically change highlighted class for response.menu

2013-05-09 Thread Niphlod
it's exactly working as expected with the latest snippet.

Il giorno giovedì 9 maggio 2013 00:15:38 UTC+2, Omi Chiba ha scritto:
>
> Thank you for the additional explanation.
>
> I just want to highlight the home by defaut only first time user access 
> the page. It should be removed when user click menu1 or menu2. The home 
> will be highlighted again when user click home.
>
> By default.
> --
> Home highlihgted
> Menu1
> Menu2
>
> User click menu1...
> 
> Home 
> Menu1 highlihgted
> Menu2
>
> User click Home again...
> 
> Home highlihgted
> Menu1
> Menu2
>
>
>
>
>
> On Wednesday, May 8, 2013 4:34:07 PM UTC-5, Niphlod wrote:
>>
>> ps: if you are on the case where you need to have home highlighted by 
>> default no matter what, use this javascript snippet (pretty straightforward)
>> Added also a filter() to exclude the registration/login/etc links from 
>> being highlighted
>>
>> jQuery(function() {
>>   var path = location.pathname.substring(1);
>> if ( path ) {
>> var els = jQuery('ul.nav a[href$="'+path+'"]').filter(
>> "[rel!=nofollow]");
>> if (els.length != 0) {
>> els.closest('li').addClass('highlighted');
>> } else {
>> jQuery('ul.nav a[href$="/highlight/default/index"]').closest(
>> 'li').addClass('highlighted');
>> }
>> }
>> })
>>
>> PS: maybe to make it more clearer, use a Home link with an id, such as 
>>
>> (SPAN('Home', _id='default_highlighted'), False, URL('default', 'index'), 
>> []),
>>
>> so you can switch the last line from
>>
>> jQuery('ul.nav a[href$="/highlight/default/index"]').closest('li').
>> addClass('highlighted');
>>
>>
>> to
>>
>>
>> jQuery('#default_highlighted').closest('li').addClass('highlighted');
>>
>>
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: _after_delete callback - how to access info of deleted Set?

2013-05-09 Thread Niphlod
uhm. please take into consideration that you can't hook to the 
"after_delete" callback if you still want to access the record that has 
been deleted.. use before_delete for that case.

Il giorno giovedì 9 maggio 2013 01:40:49 UTC+2, Jurgis Pralgauskis ha 
scritto:
>
> Thanks, 
>
> hm, ok, my usecase is more problematic, 
>
>
> db.define_table('Product',
> Field('name',),
> Field('price', 'decimal(10,2)'),
> Field('quantity', 'integer'),
> Field('*quantity_sold*', 'integer'), # this could be virtual - but 
> then it does not play with queries...
> )
>
> I want to refresh *quantity_sold* after each Purchase 
> (insert/update/delete)
> but after delete I'd like to still access which product it has been?
> if I do it before delete, the purchace is still there - and my aggregate 
> function sums it (though I need it gone) ...
>
> db.define_table('Purchase',
> Field('product', db.Product),
> Field('quantity', 'integer'),
> )
>
> def update_Product_quantity_from_Purchase( purchase ):
> q_sum = db.Purchase.quantity.sum()
> quantity_sold = 
> db(db.Purchase.product== purchase.product ).select(q_sum).first()[q_sum] or 
> 0
>db.Product[purchase.product].update_record( *quantity_sold*
> =quantity_sold )
> 
>
> db.Pardavimai._after_insert.append( lambda 
> f,id: update_Product_quantity_from_Purchase(f) )
> db.Pardavimai._after_update.append( lambda 
> s,f: update_Product_quantity_from_Purchase(s.select()[0]) )
> db.Pardavimai._after_delete.append( lambda 
> s: update_Product_quantity_from_Purchase(s.select()[0]) ) #ERR
>
> ***
> Ha, while writing I came up with workaround -  _before_delete
> I add extra parameter to my update_Product... function, which tells that 
> purchase stuff should be subtracted in advance (as it will be detelted)
>
> def update_Product_quantity_from_Purchase( purchase, deleting=False ):
>...
>if deleting: 
> quantity_sold -= purchace.quantity
>db.Product[purchase.product].update_record( *quantity_sold*=quantity_sold 
>  )
>
> db.Pardavimai._before_delete.append( lambda 
> s: update_Product_quantity_from_Purchase(s.select()[0], True) ) #OK
>
> ***
> ps.: Maybe similar functionality could be extended for "compute'd" field?
> If it knew what foreign tables&fields it depends on, the 
> triggers/callbacks could be added automatically?
>
>
>
>
> On Thu, May 9, 2013 at 2:06 AM, Anthony  >wrote:
>
>> If the query only has that one condition, then you can do:
>>
>> s.query.second
>>
>> A Set object has a "query" attribute, which is a Query object, and a 
>> Query object has "op", "first", and "second" attributes. So, s.query gets 
>> the Query object of the Set, and s.query.second gets the second operand of 
>> the "==" operator. If instead you have multiple conditions in the query, 
>> keep in mind that the operands of the "&" operator are themselves Query 
>> objects. So, if you have:
>>
>> set = db((db.person.id > 10) & (db.person.name.startswith('A')))
>>
>> you can extract the 10 from the first part of the query via:
>>
>> set.query.first.second
>>
>> In that case, set.query.first itself returns a Query (i.e., db.person.id> 
>> 10), so set.query.first.second gives you the 10.
>>
>> Keep in mind that these properties of Set and Query are internal and not 
>> part of the API, so this isn't guaranteed to remain backward compatible.
>>
>> Another option is to pass the Set to the str() function, which generates 
>> a string that contains the SQL produced by the query. You could then do 
>> some parsing of that string to get what you want. For example, in this case 
>> you get:
>>
>> >>> str(db(db.person.id == 1))
>> ''
>>
>> You can use a regex to get the 1 from that string.
>>
>> Anthony
>>
>>
>> On Wednesday, May 8, 2013 6:10:05 PM UTC-4, Jurgis Pralgauskis wrote:
>>>
>>> Hi, 
>>>
>>> I look at example:
>>> http://www.web2py.com/book/**default/chapter/06#before-and-**
>>> after-callbacks
>>>
>>> how can I find out what is the value of person.id from the set without 
>>> select?
>>> (,)
>>>
>>> as I tried:
>>> s.select(..)[0]   # it worked for update
>>> but got 
>>>
>>> Traceback (most recent call last):
>>>   File "/home/nijole/Downloads/**EasyVet/web2py/gluon/**restricted.py", 
>>> line 212, in restricted
>>>
>>> exec ccode in environment
>>>   File 
>>> "/home/nijole/Downloads/**EasyVet/web2py/applications/**apskaitele/controllers/**appadmin.py"
>>>  
>>> ,
>>>  line 569, in 
>>>
>>>   File "/home/nijole/Downloads/**EasyVet/web2py/gluon/globals.**py", line 
>>> 194, in 
>>>
>>> self._caller = lambda f: f()
>>>
>>>   File 
>>> "/home/nijole/Downloads/**EasyVet/web2py/applications/**apskaitele/controllers/**appadmin.py"
>>>  
>>> ,
>>>  line 304, in update
>>>
>>> if form.accepts(request.vars, session)