Re: [web2py] Re: Uwsgi-error: ImportError: No module named 'globals'
Hi, I had a problem along the same lines, it turned out that uwsgi was compile with python 3.3 support. This was Ubuntu 13.04 and I installed it via apt-get , check the entire uwsgi logs for the python version. regards, Nils On Fri, Sep 13, 2013 at 10:48 AM, Johann Spies johann.sp...@gmail.comwrote: On 12 September 2013 03:52, Massimo Di Pierro massimo.dipie...@gmail.comwrote: In both cases print the sys.path. On 'spyker' where the problem is: $ python web2py.py -M -S alterit web2py Web Framework Created by Massimo Di Pierro, Copyright 2007-2013 Version 2.5.1-stable+timestamp.2013.06.06.15.39.19 Database drivers available: SQLite(sqlite3), MySQL(pymysql), PostgreSQL(pg8000), MSSQL(pyodbc), DB2(pyodbc), Teradata(pyodbc), Ingres(pyodbc), IMAP(imaplib) Python 2.7.5+ (default, Jun 2 2013, 13:26:34) Type copyright, credits or license for more information. IPython 0.13.2 -- An enhanced Interactive Python. ? - Introduction and overview of IPython's features. %quickref - Quick reference. help - Python's own help system. object? - Details about 'object', use 'object??' for extra details. In [1]: import sys In [2]: print sys.path ['', '/home/www-data/web2py/gluon', '/home/www-data/web2py/site-packages', '/home/www-data/web2py', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode', '/usr/lib/python2.7/dist-packages/IPython/extensions'] On the other one: $ python web2py.py -M -S alterit web2py Web Framework Created by Massimo Di Pierro, Copyright 2007-2013 Version 2.5.1-stable+timestamp.2013.06.06.15.39.19 Database drivers available: SQLite(sqlite3), MySQL(pymysql), PostgreSQL(pg8000), MSSQL(pyodbc), DB2(pyodbc), Teradata(pyodbc), Ingres(pyodbc), IMAP(imaplib) Python 2.7.5+ (default, Jun 13 2013, 13:26:49) Type copyright, credits or license for more information. IPython 0.13.2 -- An enhanced Interactive Python. ? - Introduction and overview of IPython's features. %quickref - Quick reference. help - Python's own help system. object? - Details about 'object', use 'object??' for extra details. In [1]: import sys In [2]: print sys.path ['', '/home/www-data/web2py/gluon', '/home/www-data/web2py/site-packages', '/home/www-data/web2py', '/usr/local/lib/python2.7/dist-packages/tiffany-0.6-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode', '/usr/lib/python2.7/dist-packages/IPython/extensions'] When I add the lines used in uwsgihandler.py I get: In [11]: import sys In [12]: import os In [13]: In [13]: path = os.path.dirname(os.path.abspath(__file__)) In [14]: os.chdir(path) In [15]: sys.path = [path] + [p for p in sys.path if not p == path] In [16]: print sys.path ['/home/www-data/web2py/applications/alterit/models', '', '/home/www-data/web2py/gluon', '/home/www-data/web2py/site-packages', '/home/www-data/web2py', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode', '/usr/lib/python2.7/dist-packages/IPython/extensions'] This does not really show me the root of the problem. Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code
Re: [web2py] puppet for web2py
Hi, You should take a look a http://docs.saltstack.com/ref/python-api.html This is like fabric and puppet all in one and its really easy to use. Regards, Nils On Wed, Aug 28, 2013 at 3:28 PM, Francisco Barretto kikobarre...@gmail.comwrote: Hi there! Did Anyone already made some puppet module to manage/install web2py and web2py's app management(install/update) through Puppet? I was thinking about hosting my app in a git repository and use a puppet module to keep web2py updated (by applying both web2py and app changes to client machines). 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. -- --- 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] pyfilesystem support (store uploads in S3)
Hi, I use s3 for storing images, I was looking a creating something like this ages ago but my python Fu and web2py Fu were not up to scratch... I will test this, just wondering if I can change my DB model over,currently I have s3 mounted as a filesystem, so web2py is just writing to a directory. Nils On May 31, 2012 6:56 p.m., Massimo Di Pierro massimo.dipie...@gmail.com wrote: Here is an example: easy_install pyfilesystem import fs.s3fs myfs = fs.s3fs.S3FS(bucket, prefix, aws_access_ke, aws_secret_key) db.define_table('test',Field('file','upload',uploadfs = myfs)) Now all your uploaded files will go on S3. Here is a list of supported filesystems: http://packages.python.org/fs/filesystems.html WARNINGS: - needs testing. I have tested with OSFS and I am confident it works - I do not think with will work on GAE, should be tested - uploadfolder and uploadseparate are ignored when uploadfs is specified (this should be changed, any takers?) Should be possible to wrap myfs into an encryption layer but I have not done it yet. We may want a more comprehensive strategy and allow every web2py file (including apps, sessions, tickets, etc) to go into a pyfilesystem. Is this necessary? On linux one can mount filesystems in a folder anyway. Is this more trouble than it is worth? Massimo
Re: [web2py] Re: storing more than 1 millions uploaded files
Amazon's S3 is ideal for this, I use it I mount s3 using fuse interface. Works pretty well for me. Nils On May 12, 2012 7:53 PM, Sebastian E. Ovide sebastian.ov...@gmail.com wrote: just wondering... (I know that it is not a normal application)... where would you store a couple of millions pictures of less than 60K each ? On Sat, May 12, 2012 at 2:04 AM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Oops. Sorry. I read it in a hurry. I would not use the file system for something like this. Anyway, upload separate creates up to 1296 subfolder per table.field. This number can be increased. On Friday, 11 May 2012 18:33:22 UTC-5, Anthony wrote: On Friday, May 11, 2012 7:25:21 PM UTC-4, Massimo Di Pierro wrote: yes. Field('name','upload',**uploadseparate=True) He's aware of that but seems to think that one level of sub-folders won't be enough (he's expecting millions of files, so still more than 1000 files per sub-folder, even with uploadseparate=True). I don't think web2py includes any out-of-the-box solution for generating deeper levels of sub-folders for uploaded files. Maybe subclass Field for that upload field and roll your own .store() and .retrieve() methods. Anthony -- Sebastian E. Ovide
Re: [web2py] Re: db manipulation
Hi, Do you not need to specify a type='string' etc ? Regards, nils On Wed, Feb 22, 2012 at 7:35 PM, Anthony abasta...@gmail.com wrote: Did you turn off migrations via DAL(..., migrate=False) or DAL(..., migrate_enabled=False)? Is this in a web2py app, or an external script or shell? On Wednesday, February 22, 2012 2:16:17 PM UTC-5, davidjensen wrote: In db.py, I created a db 'contacts' with a table 'mytable'. I later added a field 'date' to mytable. db.define_table('mytable', Field('date',requires=IS_NOT_EMPTY()), Field('name',requires=IS_NOT_EMPTY()), Field('organization'), Field('notes','text', requires=IS_NOT_EMPTY()) ) The new field did not show. Is it necessary to use db.executesql with an alter statement or is there a way to do this in web2py? I can also use sqlite3 command line. Thanks,
Re: [web2py] db manipulation
Hi, Do you not need to specify a type='string' etc ? Regards, nils On Wed, Feb 22, 2012 at 7:16 PM, davidjensen davidjensen...@gmail.com wrote: In db.py, I created a db 'contacts' with a table 'mytable'. I later added a field 'date' to mytable. db.define_table('mytable', Field('date',requires=IS_NOT_EMPTY()), Field('name',requires=IS_NOT_EMPTY()), Field('organization'), Field('notes','text', requires=IS_NOT_EMPTY()) ) The new field did not show. Is it necessary to use db.executesql with an alter statement or is there a way to do this in web2py? I can also use sqlite3 command line. Thanks,
Re: [web2py] Re: ssh tunnel to admin panel with lighttpd= ERROR:web2py.cache:corrupted file
Hi, . Lighty runs under the user of www-data and so folders or files that need to be written too, have to have the ownership changed to www-data other wise you will get this error, same goes for a download/upload folder if you are uploading content via your application. Regards, Nils On Sun, Jan 29, 2012 at 9:50 AM, Benjamin benjamin.aguet...@gmail.com wrote: Hello, Just to let you know ISSUE SOLVED. For an unknown reason sessions folder was not chown to www-data, so simply : chown -R www-data:www-data sessions solved the issue. I am not sure it's the way it should be but at least it works now. Thanks, Cheers, On 29 jan, 09:41, Benjamin benjamin.aguet...@gmail.com wrote: Hello Massimo, Unfortunately it doesn't solve it. There is from time to time only 2 files in this cache folder : cache.lock cache.shelve And deleting it doesn't change the behavior, i.e.: the web2py welcome page is displayed correctly using an SSH tunnel but the admin panel displays Internal error Ticket issued: admin/ __1.2012-01-29.13-25-47.643f7d62-256c-4151-b2e3-fd1ef2fc332a Here is what I have found at the end of the ticket : *** SStorage {'_user_agent': {'os': {'name': 'Macint...owser': {'version': '5.1.1', 'name': 'Safari'}}} p3726 sg60 SStorage {'body': cStringIO.StringO object at 0..._vars': Storage {}, 'post_vars': Storage {}} p3727 sg2782 SStorage {'status': 200, 'body': cStringIO.Stri.../css/ styles.css'], 'view': 'default/index.html'} p3728 sS'session_folder' p3729 S'/home/www-data/web2py/applications/ admin/sessions' p3730 sssS'traceback' p3731 S'Traceback (most recent call last):\n File /home/www-data/web2py/ gluon/main.py, line 523, in wsgibase\n session._try_store_on_disk(request, response)\n File /home/www-data/ web2py/gluon/globals.py, line 586, in _try_store_on_disk\n response.session_file = open(response.session_filename, \'wb\')\nIOError: [Errno 13] Permission denied: \'/home/www-data/web2py/applications/admin/sessions/.. 1-055bbcfa-3236-4328-b1ff-0dc2d70a32b9\'\n' p3732 s. *** By looking at my admin folder it seems like EVERYTHING has rights : drwxr-xr-x www-data www-data, EXCEPT only the sessions folder which has drwxr-xr-x root root. Any reason why is it so ? Isn't the session folder supposed to also be drwxr-xr-x www-data www- data ? It's really weird it happened as i've chown chown -R www-data:www- data web2py during web2py installation... Thanks for your help, Cheers, On 28 jan, 20:53, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Can you try delete applications/admin/cache/*? it is possible that there is a cache file created using a different python version and web2py cannot open it. For permission issues it may be unable to remove it and re-create it. On Jan 28, 12:25 pm, Benjamin benjamin.aguet...@gmail.com wrote: Hello guys, Attracted by web2py dev possibilities I couldn't resist ;-) But unfortunately deployment is a whole other story and I'm having major difficulties. So after a struggle I got web2py to run on lighttpd, then discovered that, as I didn't set any SSL, I couldn't access the admin interface. So I'm trying to use an ssh tunnel : ssh -L 9090:localhost:80 r...@192.168.1.101 After that I can see the demo app at localhost:9090 but every single click on the Admin interface button on the right of the demo app end up with : on the browser side : Internal error Ticket issued: admin/__1.2012-01-28.23-18-18.cf854d0b-a8f7-4ef8-bd28- a24debe031a8 on the terminal side (the terminal which started a bash script starting the fcgihandler.fcgi ) I got this : ERROR:web2py.cache:corrupted file /home/www-data/web2py/applications/ admin/cache/cache.shelve, will try delete it! Interesting fact : each time I try to click on the admin panel button from the browser, a new ERROR:web2py.cache:corrupted file / home/www-data/web2py/applications/admin/cache/cache.shelve, will try delete it! is displayed on the terminal. What am I doing wrong ? Thanks a lot, cheers, PS : the file got deleted automatically each time but I still can't access the admin panel
Re: [web2py] Initial db setup using csv import for relational tables?
Hi, I had a similar problem, my solution was somthing like this: import csv dr = csv.DictReader(open('csvfile.csv'), delimiter=',') for data in dr: if data['team'] =='text': team = 1 or (the team id in your table) elif data['team'] =='more text': team = 2 or (the team id in your table) db.teams.insert(name=team) On Wed, Jan 25, 2012 at 1:57 PM, vtgorilla bradley.allmendin...@gmail.com wrote: Hi, first post so go easy on me! I have two tables setup as shown below. I have a lot of data (thousands of lines) that I'd like to import, but I can't seem to figure out an easy way to relate the players.team field back to a team in the teams table without modifying thousands of lines in excel, one by one, to have the matching ID for a team rather than the matching text (both csv files contain teams.name). db.define_table('teams', Field('name', unique=True),...) db.define_table('players', Field('team', 'reference teams'),...) db.players.team.requires = IS_IN_DB(db, db.teams.id, '%(name)s') So my question is...is there a way to csv import my players and have w2p or sql recognize the matching team name and assign the corresponding teams.id in the table? It seems to work this way if I add one at a time from the interface, but obviously that would be impractical with such a large number of items. Thanks for you help and let me know if that wasn't clear enough! Brad
Re: [web2py] string not recognized
Hi, Could you not use {{=XML(string...)}} Regards, Nils On Jan 18, 2012 9:43 a.m., davidjensen davidjensen...@gmail.com wrote: This is not recognized asa string: {{this is a string}} in: {{=PRE({{this is a string}}))}in a web page but it works on the command line: PRE({{this is a string}}).xml()
Re: [web2py] Re: ssl certificate?
Hi, Ive used go daddy, works perfect for me and they are cheap Regards, Nils On Dec 23, 2011 4:49 a.m., guruyaya guruy...@gmail.com wrote: I've used it myself, but note this certificate is not insured in any way, and it allows a pretty weak protection, in the free edition. It also fails to work with wget (you can add some extra params to make it work with wget, but most people don't want this hussle). The quiestion is, what is this certificate for? The free edition was good eanogth to prevent errors, when being transfered to google, when I wanted to retrieve contacts for google. I guess it's good for the admin, or to allow secured logins. But I wouldn't use to for web services (as I cannot trust it to work with command line clients), and avoid it for web payments (it's not insured at all). I have no idea if the none free edition of startssl. On Dec 22, 6:04 pm, Angelo Compagnucci angelo.compagnu...@gmail.com wrote: This on is free and it works well http://www.startssl.com/?app=1 They make simple validation, the certificate is ready in minutes and the certificate is a fully featured one! I use it! 2011/12/22 Massimo Di Pierro massimo.dipie...@gmail.com Any advice on where to buy a chap ssl certificate? Please advice ONLY about services you have personally used already. Massimo -- Profile:http://www.gild.com/compagnucciangelo Register on Gild:http://www.gild.com/referral/compagnucciangelo
Re: [web2py] web2py sitting behind load balancer showing lb IP not client IP
Hi, what load balancer are you using? Regards, Nils On Dec 23, 2011 5:17 a.m., Dave dave.st...@gmail.com wrote: Since I've moved my installation behind a load balancer all my session IP addresses show as the back-side IP of the load balancer, not the real client IP. Have any of you figured out a way to pull the {X-Forwarded-For} entry from the HTTP environment for the remote_addr instead?
Re: [web2py] problem with mod_wsgi deployment
Hi, What is the contents of your httpd.conf file. can you post it ? Regards, Nils On Mon, Dec 19, 2011 at 6:23 AM, Johann Spies johann.sp...@gmail.com wrote: Dear Hassan, On 15 December 2011 12:32, Web2Py Freak halna...@gardeniatelco.com wrote: Dear All, i am trying to use mod_wsgi with apache on fedora i installed web2py in var/www/ and i unzipped it , and i edited the httpd.conf and added the virtual host script but it keeps giving me this error with i do $ service httpd start the error is : bad user name : root@linux Try using the script setup-web2py-fedora.sh in web2py/scripts. Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3)
Re: [web2py] Make an image Thumb
Hi, Do you have PIL library installed ? I have something similar but def THUMB(image,nx=100,ny=100): try: from PIL import Image import os basefolder=os.path.join(request.folder, 'uploads') img = Image.open(os.path.join(basefolder, image)) img.thumbnail((nx,ny), Image.ANTIALIAS) root, ext = os.path.splitext(image) thumb ='%s_thumb%s' % (root, ext) img.save(os.path.join(basefolder, thumb)) return thumb except: return Database Model: Field('thumbnail','upload', compute=lambda r: THUMB(r['image'])) Regards, Nils On Thu, Nov 17, 2011 at 3:27 PM, Web2Py Freak halna...@gardeniatelco.com wrote: Dear All, i am trying to make a Thumb and i used this code here : Model: db.define_table('uploads', Field('name','string'), Field('mainfile','upload'), Field('thumb','upload',writable=False,readable=False), ) Controller: def makeThumbnail(dbtable,ImageID,size=(150,150)): try: thisImage=db(dbtable.id==ImageID).select()[0] import os, uuid from PIL import Image except: return im=Image.open(request.folder + 'uploads/' + thisImage.mainfile) im.thumbnail(size,Image.ANTIALIAS) thumbName='uploads.thumb.%s.jpg' % (uuid.uuid4()) im.save(request.folder + 'uploads/' + thumbName,'jpeg') thisImage.update_record(thumb=thumbName) return def uploadimage(): dbtable = db.uploads #uploads table name if len(request.args): records = db(dbtable.id==request.args[0]).select() if len(request.args) and len(records): form = SQLFORM(dbtable, records[0], deletable=True) else: form = SQLFORM(dbtable) if form.accepts(request.vars, session): response.flash = 'form accepted' makeThumbnail(dbtable,form.vars.id,(175,175)) elif form.errors: response.flash = 'form has errors' ## Quick list just to demonstrate... list = crud.select(dbtable) return dict(form=form,list=list) But after i upload an image i don't get a thumb i don't know why just the original image and the thumb Field in the database stays empty , i don't know why so help me guys ... Best regards,
[web2py] Authentication
Hi, Just wondering if this is possible, I think it should be... I have a 2 web2py application, but i want them to have a common authentication db. I was thinking of doing this in the model DB for both. authdb = DAL('mysql database') Then auth = Auth(globals(),authdb) I have now tested this but would this work ? Nils
Re: [web2py] Authentication
Hi, Ok this sound good, I figured i could, I was thinking of storing session in database, but I don't think user will be logged into the 2 apps at the same time, and I don't really want a complicated CAS setup. Regards, Nils On Tue, Nov 8, 2011 at 12:55 PM, Anthony abasta...@gmail.com wrote: On Tuesday, November 8, 2011 7:08:08 AM UTC-5, rochacbruno wrote: Yes it works well. You can also use cas to share authentication between applications. But the approach using same db for both applications is better, but note that both applications should have the same hmac_key for auth instance. Also, make sure all applications but one turn off migrations for the Auth tables. If the db connection is exclusively for accessing the Auth tables, you can disable migrations for the whole connection via: authdb = DAL('mysql database', migrate_enabled=False) Alternatively, you can disable migrations for the individual Auth tables (but not other tables accessed by the connection via: auth.define_tables(migrate=False) I could be wrong, but I think simply sharing the db for Auth tables would still require separate logins for each app, whereas I think using CAS, a single login would keep you logged into both apps at once. Anthony
Re: [web2py] Re: Has anyone configured web2py on the Basic Amazon Linux AMI?
Hi Chris, I do this ssh -i key.pem -L 8000:localhost:8000 root@amazon-Ec2-VPS I then run on the amazon instance ./web2py -a password You can then access web2py via http://localhost:8000 Regards, Nils On Sat, Aug 27, 2011 at 4:40 PM, Chris ch...@spitfireinnovation.com wrote: I could, but the problem I'm experiencing may not be related to that ... I think have permissions wide-open on my test instance. On Aug 26, 7:20 pm, pbreit pbreitenb...@gmail.com wrote: The Amazon AMI is pretty locked down by default. I presume you've reviewed all the docs?http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?... Would you be able to go with Ubuntu or some other AMI?
Re: [web2py] Any LDAP auth users out there?
Hi, Have your tried wireshark or tcpdump ? Regards, Nils On Thu, Jul 28, 2011 at 4:06 AM, Ismael Serratos ialejandr...@gmail.com wrote: So how do you know it's not working? Do you get any error? or just you can't login? On Wed, Jul 27, 2011 at 8:39 PM, Brian M bmere...@gmail.com wrote: Hmm not certain server is on 10.0.0.x ldap_auth works from 10.0.1.x but not from 10.0.0.x Unfortunately I'm not an expert on ActiveDirectory/LDAP so I don't know for sure how ours is setup.
Re: [web2py] Re: upload - S3 storage
Hi, I forgot about Mounting S3 as partition, I'm already using the boto interface. The computer field sounds like an Idea, but now to come up with the code :) Thanks for the tips. Regards, Nils On Tue, Jul 26, 2011 at 6:32 AM, howesc how...@umich.edu wrote: pbreit might be right - you would still end up uploading the file to your server, and then saving to s3. (though if your server was ec2 there might be a way to mount an s3 bucket, not sure though). i also agree on looking at the boto interface: http://code.google.com/p/boto/ i'm using an older version of the library (just cause i have been too lazy to disturb running code) quite successfully. cfh
[web2py] upload - S3 storage
Hi all, Before I go off and make an attempt at creating a S3 upload function, I was just wondering if anyone has a working version ? I read the discussion on this and for me I need a way of storing uploaded images on S3 to share between a few VPS on Amazon's EC2. The only other way to accomplish the same thing would be to use rsync, which is not ideal. I want to stay within the functionality of web2py SQLforms, maybe by having the field type 'uploadS3' so web2py would know that the file is going to be uploaded to amazons S3 service. Is this a good approach ? So far I've only used the functionality of web2py, I never had to change or customize it, so any help or pointer would be appreciated. Regards, Nils
Re: [web2py] upload - S3 storage
HI, Just looking at dal.py and there is a SQLCustomType, I was wondering if the functionality i would require could be added via this class?, Would this be the way to go ? Nils On Mon, Jul 25, 2011 at 1:04 PM, Nils Olofsson nils.olofs...@gmail.com wrote: Hi all, Before I go off and make an attempt at creating a S3 upload function, I was just wondering if anyone has a working version ? I read the discussion on this and for me I need a way of storing uploaded images on S3 to share between a few VPS on Amazon's EC2. The only other way to accomplish the same thing would be to use rsync, which is not ideal. I want to stay within the functionality of web2py SQLforms, maybe by having the field type 'uploadS3' so web2py would know that the file is going to be uploaded to amazons S3 service. Is this a good approach ? So far I've only used the functionality of web2py, I never had to change or customize it, so any help or pointer would be appreciated. Regards, Nils
[web2py] Re: upload - S3 storage
Hi, This is what I have done so far, really rough. I have extended the Field class and added some extra functions. I called the class s3upload and I created function within the class called s3_store and s3_retrieve. I was just wondering if upon creating these classes. I.E creating the same functionality as the default store/retrieve will this work out of the box if i replace in the Field ('photo','s3upload') or is there other things i need to be looking at ? This is assuming that all the bugs of uploading and retrieving will be sorted :) Regards, Nils On Jul 25, 2:10 pm, nils nils.olofs...@gmail.com wrote: HI, Just looking at dal.py and there is a SQLCustomType, I was wondering if the functionality i would require could be added via this class?, Would this be the way to go ? Nils On Mon, Jul 25, 2011 at 1:04 PM, Nils Olofsson nils.olofs...@gmail.com wrote: Hi all, Before I go off and make an attempt at creating a S3 upload function, I was just wondering if anyone has a working version ? I read the discussion on this and for me I need a way of storing uploaded images on S3 to share between a few VPS on Amazon's EC2. The only other way to accomplish the same thing would be to use rsync, which is not ideal. I want to stay within the functionality of web2py SQLforms, maybe by having the field type 'uploadS3' so web2py would know that the file is going to be uploaded to amazons S3 service. Is this a good approach ? So far I've only used the functionality of web2py, I never had to change or customize it, so any help or pointer would be appreciated. Regards, Nils
[web2py] Re: database replication
Hi, I'm still not sure as to how to go about using this. Say, I have a controller with the function list: and a function called write: if the function is list then read from slaves, if the function is write, write to master. So the correct code should be: if request.function in read_only_action: db =... ... else db = and this is in the model/db.py file. I just don't understand where to define read_only_action or it is used ? Regards, Nils On Jul 21, 9:16 pm, Anthony abasta...@gmail.com wrote: That's just some (incomplete) example code. You have to define 'read_only_actions' yourself. In that example, it would be a list functions that only need to read (but not write) the database and can therefore be given access to one of the slave databases. Actually, it looks like the code has an error -- it should say request.function, not request.action -- I'll make the change. Anthony On Thursday, July 21, 2011 3:54:20 PM UTC-4, Nils Olofsson wrote: Hi, I did this but i got : Traceback (most recent call last): File /var/www/web2py/gluon/restricted.py, line 192, in restricted exec ccode in environment File /var/www/web2py/applications/Event/models/db.py, line 18, in module if request.action in read_only_actions: NameError: name 'read_only_actions' is not defined type 'exceptions.NameError'(name 'read_only_actions' is not defined) This error is the reason i asked where it should go. Maybe some one could shed some light on it ? Regards, Nils On Jul 21, 7:44 pm, Anthony abas...@gmail.com wrote: It would go in your model file -- the same place where you would normally define the db connection. Anthony On Thursday, July 21, 2011 2:29:45 PM UTC-4, Nils Olofsson wrote: Hi Massimo, I'm testing amazon's RDS and EC2 , 1 master many slaves. I could not find out where exactly I am suppose to be putting this code. Regards, Nils On Jul 21, 6:48 pm, Massimo Di Pierro massi...@gmail.com wrote: You would only use this if you have a replicated database. I.e. you are running many database servers synced with each other. For example: http://en.wikipedia.org/wiki/Multi-master_replication On Jul 21, 12:44 pm, Nils Olofsson nils...@gmail.com wrote: Hi, I see this in the Documentation: if request.action in read_only_actions: db = DAL(shuffle(['mysql://...1','mysql://...2','mysql://...3'])) else: db = DAL(shuffle(['mysql://...3','mysql://...4','mysql://...5'])) I'm not sure where exactly I should be using this ? And does anyone have some sample code as to how it should be used ? Nils
[web2py] Re: database replication
Hi, I did something similar, if add in request.function: db = DAL(['mysql://Database connection string']) else: print Using Slave Database db = DAL(shuffle(['database connection string']) That would and uses the slave database (readonly) but, I get this error message. InternalError: (1290, u'The MySQL server is running with the --read- only option so it cannot execute this statement') bar this function add and auth all other functions read data. I looked around at the DAL code and could not find a way to tell the DAL that mysql is read only. any ideas ? Regards, Nils On Jul 22, 1:58 pm, Anthony abasta...@gmail.com wrote: You could define 'read_only_actions' anywhere it makes sense, for example: read_only_actions = ['list','another_read_action','yet_another_read_action'] if request.function in read_only_actions: db =... ... else db = Of course, if that one 'if' statement is the only place you refer to 'read_only_actions', then there's no need to define it as a separate variable -- you could just put the list right in the 'if' statement. I think 'read_only_actions' was used in the book example just to indicate the idea that you would use the slave databases for actions that don't need to write to the db -- it's just a stand-in for an actual list of such actions. Anthony On Friday, July 22, 2011 6:50:31 AM UTC-4, Nils Olofsson wrote: Hi, I'm still not sure as to how to go about using this. Say, I have a controller with the function list: and a function called write: if the function is list then read from slaves, if the function is write, write to master. So the correct code should be: if request.function in read_only_action: db =... ... else db = and this is in the model/db.py file. I just don't understand where to define read_only_action or it is used ? Regards, Nils On Jul 21, 9:16 pm, Anthony abas...@gmail.com wrote: That's just some (incomplete) example code. You have to define 'read_only_actions' yourself. In that example, it would be a list functions that only need to read (but not write) the database and can therefore be given access to one of the slave databases. Actually, it looks like the code has an error -- it should say request.function, not request.action -- I'll make the change. Anthony On Thursday, July 21, 2011 3:54:20 PM UTC-4, Nils Olofsson wrote: Hi, I did this but i got : Traceback (most recent call last): File /var/www/web2py/gluon/restricted.py, line 192, in restricted exec ccode in environment File /var/www/web2py/applications/Event/models/db.py, line 18, in module if request.action in read_only_actions: NameError: name 'read_only_actions' is not defined type 'exceptions.NameError'(name 'read_only_actions' is not defined) This error is the reason i asked where it should go. Maybe some one could shed some light on it ? Regards, Nils On Jul 21, 7:44 pm, Anthony aba...@gmail.com wrote: It would go in your model file -- the same place where you would normally define the db connection. Anthony On Thursday, July 21, 2011 2:29:45 PM UTC-4, Nils Olofsson wrote: Hi Massimo, I'm testing amazon's RDS and EC2 , 1 master many slaves. I could not find out where exactly I am suppose to be putting this code. Regards, Nils On Jul 21, 6:48 pm, Massimo Di Pierro mass...@gmail.com wrote: You would only use this if you have a replicated database. I.e. you are running many database servers synced with each other. For example: http://en.wikipedia.org/wiki/Multi-master_replication On Jul 21, 12:44 pm, Nils Olofsson nil...@gmail.com wrote: Hi, I see this in the Documentation: if request.action in read_only_actions: db = DAL(shuffle(['mysql://...1','mysql://...2','mysql://...3'])) else: db = DAL(shuffle(['mysql://...3','mysql://...4','mysql://...5'])) I'm not sure where exactly I should be using this ? And does anyone have some sample code as to how it should be used ? Nils
Re: [web2py] Re: database replication
Hi Anthony, That worked, maybe the docs should be updated. I did try migrate=False, thought they were both the same thing. Regards, Nils On Fri, Jul 22, 2011 at 3:05 PM, Anthony abasta...@gmail.com wrote: Have all the tables already been created in the slave databases (web2py may be trying to create tables or run migrations)? What happens if you do: db = DAL(shuffle(['connection string']), migrate_enabled=False) Anthony On Friday, July 22, 2011 9:28:40 AM UTC-4, Nils Olofsson wrote: Hi, I did something similar, if add in request.function: db = DAL(['mysql://Database connection string']) else: print Using Slave Database db = DAL(shuffle(['database connection string']) That would and uses the slave database (readonly) but, I get this error message. InternalError: (1290, u'The MySQL server is running with the --read- only option so it cannot execute this statement') bar this function add and auth all other functions read data. I looked around at the DAL code and could not find a way to tell the DAL that mysql is read only. any ideas ? Regards, Nils On Jul 22, 1:58 pm, Anthony abas...@gmail.com wrote: You could define 'read_only_actions' anywhere it makes sense, for example: read_only_actions = ['list','another_read_action','yet_another_read_action'] if request.function in read_only_actions: db =... ... else db = Of course, if that one 'if' statement is the only place you refer to 'read_only_actions', then there's no need to define it as a separate variable -- you could just put the list right in the 'if' statement. I think 'read_only_actions' was used in the book example just to indicate the idea that you would use the slave databases for actions that don't need to write to the db -- it's just a stand-in for an actual list of such actions. Anthony On Friday, July 22, 2011 6:50:31 AM UTC-4, Nils Olofsson wrote: Hi, I'm still not sure as to how to go about using this. Say, I have a controller with the function list: and a function called write: if the function is list then read from slaves, if the function is write, write to master. So the correct code should be: if request.function in read_only_action: db =... ... else db = and this is in the model/db.py file. I just don't understand where to define read_only_action or it is used ? Regards, Nils On Jul 21, 9:16 pm, Anthony aba...@gmail.com wrote: That's just some (incomplete) example code. You have to define 'read_only_actions' yourself. In that example, it would be a list functions that only need to read (but not write) the database and can therefore be given access to one of the slave databases. Actually, it looks like the code has an error -- it should say request.function, not request.action -- I'll make the change. Anthony On Thursday, July 21, 2011 3:54:20 PM UTC-4, Nils Olofsson wrote: Hi, I did this but i got : Traceback (most recent call last): File /var/www/web2py/gluon/restricted.py, line 192, in restricted exec ccode in environment File /var/www/web2py/applications/Event/models/db.py, line 18, in module if request.action in read_only_actions: NameError: name 'read_only_actions' is not defined type 'exceptions.NameError'(name 'read_only_actions' is not defined) This error is the reason i asked where it should go. Maybe some one could shed some light on it ? Regards, Nils On Jul 21, 7:44 pm, Anthony aba...@gmail.com wrote: It would go in your model file -- the same place where you would normally define the db connection. Anthony On Thursday, July 21, 2011 2:29:45 PM UTC-4, Nils Olofsson wrote: Hi Massimo, I'm testing amazon's RDS and EC2 , 1 master many slaves. I could not find out where exactly I am suppose to be putting this code. Regards, Nils On Jul 21, 6:48 pm, Massimo Di Pierro mas...@gmail.com wrote: You would only use this if you have a replicated database. I.e. you are running many database servers synced with each other. For example: http://en.wikipedia.org/wiki/Multi-master_replication On Jul 21, 12:44 pm, Nils Olofsson nil...@gmail.com wrote: Hi, I see this in the Documentation: if request.action in read_only_actions: db = DAL(shuffle(['mysql://...1','mysql://...2','mysql://...3'])) else: db = DAL(shuffle(['mysql://...3','mysql://...4','mysql://...5'])) I'm not sure where exactly I should be using this ? And does anyone have some sample code as to how it should be used ? Nils
Re: [web2py] Re: database replication
Hi Anthony, yes, migrate is set for fields in the aut table. Also another note, shuffle did not work for me I have to, from random import sample. then change DAL(sample(['mysql connection string','mysql connection string'],1),migrate_enabled=False) Regards, Nils On Fri, Jul 22, 2011 at 4:02 PM, Anthony abasta...@gmail.com wrote: On Friday, July 22, 2011 10:12:01 AM UTC-4, nils wrote: Hi Anthony, That worked, maybe the docs should be updated. Indeed. I did try migrate=False, thought they were both the same thing. migrate=False (as an argument to DAL) doesn't turn off migrations -- it merely determines the default value of migrate for define_table() when it is not explicitly specified. So, DAL(..., migrate=False) should have the same effect as DAL(..., migrate_enabled=False) as long as none of your db.define_table() calls explicilty sets their 'migrate' argument. Do you have an explicit migrate=True in at least one of your db.define_table() calls? Anthony
[web2py] database replication
Hi, I see this in the Documentation: if request.action in read_only_actions: db = DAL(shuffle(['mysql://...1','mysql://...2','mysql://...3'])) else: db = DAL(shuffle(['mysql://...3','mysql://...4','mysql://...5'])) I'm not sure where exactly I should be using this ? And does anyone have some sample code as to how it should be used ? Nils
[web2py] Re: database replication
Hi Massimo, I'm testing amazon's RDS and EC2 , 1 master many slaves. I could not find out where exactly I am suppose to be putting this code. Regards, Nils On Jul 21, 6:48 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: You would only use this if you have a replicated database. I.e. you are running many database servers synced with each other. For example:http://en.wikipedia.org/wiki/Multi-master_replication On Jul 21, 12:44 pm, Nils Olofsson nils.olofs...@gmail.com wrote: Hi, I see this in the Documentation: if request.action in read_only_actions: db = DAL(shuffle(['mysql://...1','mysql://...2','mysql://...3'])) else: db = DAL(shuffle(['mysql://...3','mysql://...4','mysql://...5'])) I'm not sure where exactly I should be using this ? And does anyone have some sample code as to how it should be used ? Nils
[web2py] Re: database replication
Hi, I did this but i got : Traceback (most recent call last): File /var/www/web2py/gluon/restricted.py, line 192, in restricted exec ccode in environment File /var/www/web2py/applications/Event/models/db.py, line 18, in module if request.action in read_only_actions: NameError: name 'read_only_actions' is not defined type 'exceptions.NameError'(name 'read_only_actions' is not defined) This error is the reason i asked where it should go. Maybe some one could shed some light on it ? Regards, Nils On Jul 21, 7:44 pm, Anthony abasta...@gmail.com wrote: It would go in your model file -- the same place where you would normally define the db connection. Anthony On Thursday, July 21, 2011 2:29:45 PM UTC-4, Nils Olofsson wrote: Hi Massimo, I'm testing amazon's RDS and EC2 , 1 master many slaves. I could not find out where exactly I am suppose to be putting this code. Regards, Nils On Jul 21, 6:48 pm, Massimo Di Pierro massimo@gmail.com wrote: You would only use this if you have a replicated database. I.e. you are running many database servers synced with each other. For example: http://en.wikipedia.org/wiki/Multi-master_replication On Jul 21, 12:44 pm, Nils Olofsson nils.o...@gmail.com wrote: Hi, I see this in the Documentation: if request.action in read_only_actions: db = DAL(shuffle(['mysql://...1','mysql://...2','mysql://...3'])) else: db = DAL(shuffle(['mysql://...3','mysql://...4','mysql://...5'])) I'm not sure where exactly I should be using this ? And does anyone have some sample code as to how it should be used ? Nils
[web2py] double insert.
Hi, I'm having a problem: web2py: Version 1.96.4 (2011-06-07 21:08:15) Running on Rocket 1.2.2 Database is mysql. I have this code: form =SQLFORM(db.events,fields=['title','venue','starttime','startdate','endtime','enddate','location','image','cost','website','booking','latlng','information']) my_extra_element = TR(,INPUT(_id='Lookup',_value=Check Map,_type='submit')) form[0].insert(6,my_extra_element) my_extra_element = TR(Add Tags,SELECT(_name='tags',_multiple='multiple',*[OPTION(tags[i].name,_value=str(tags[i].id)) for i in range(len(tags))])) form[0].insert(-1,my_extra_element) if form.accepts(request.vars, session,keepvalues=True): db.events.insert(**db.events._filter_fields(form.vars)) cache.ram.clear() response.flash = 'form accepted' redirect(URL('index')) print form accepted elif form.errors: response.flash = 'form has errors' print form has errors else: print fill out form return dict(form=form) Every time I add a record it gets inserted twice. There is a slight difference in records, 1st has no tags added while the 2nd has the tags correctly added. Any idea why this is happening ? Regards, Nils
[web2py] Re: double insert.
Hi, Yes, that was me, sorry, I never got an email stating that it was posted :( or a response. Thanks for the quick response. BTW, web2py is great, only learning at the moment:) Nils
[web2py] SQL forms
Hi, I have this: tags=db().select(db.event_tags.ALL) form =SQLFORM(db.events,fields=['title','venue','starttime','endtime','location','image','cost','website','booking','latlng','information']) #form = SQLFORM(db.events) my_extra_element = TR(,INPUT(_id='Lookup',_value=Check Map,_type='submit')) form[0].insert(5,my_extra_element) my_extra_element = TR(Add Tags,SELECT(_name='tags',_multiple='multiple',*[OPTION(tags[i].name,_value=str(tags[i].id)) for i in range(len(tags))])) form[0].insert(-1,my_extra_element) if form.accepts(request.vars, session,keepvalues=True): db.events.insert(**db.events._filter_fields(form.vars)) cache.ram.clear() response.flash = 'form accepted' redirect(URL('index')) print form accepted elif form.errors: response.flash = 'form has errors' print form has errors else: response.flash = 'please fill out the form' print fill out form return dict(form=form) this is part of the database model is this: Field('image', 'upload',label=T('Profile Image')), Field('userid',db.auth_user,default = auth.user and auth.user.id), Field('tags','list:reference event_tags') Whenever I submit the form, 2 records get added. I'm not sure as to why this is happening. Could anyone shed some light on this problem ? Nils