[web2py] Thread with own db connection

2016-05-11 Thread Alfonso Serra
Im using a thread to import some rows from a csvfile into the database (MySQL). The problem is that the request closes the connection while the thread is inserting records and i have to restart the server in order to clean up the hanged thread. So is there anyway to use DAL with an independen

[web2py] Re: Thread with own db connection

2016-05-11 Thread Alfonso Serra
Thanks for your interest Dave. Yes the files are big, the last one was 8mb with about 44k records About the scheduler. i start it manually at the control panel launching the script below ("python scheduler.py" from a pythonanywhere console). After a few days it becomes unresponsive and i have t

[web2py] Re: Scheduler - limit on how large the result can be?

2016-05-12 Thread Alfonso Serra
A Task's run_output and run_result fields types are mapped to LONGTEXT if you are using mysql, this is 4gb storage capacity. Python strings should be around 3Gb depending on your system's ram amount. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.co

Re: [web2py] Highcharts in web2py

2016-05-12 Thread Alfonso Serra
Actually is quite easy. Prepare some data on your controller: import json def index(): ... #get some rows from any source countries = XML(json.dumps([[r.country_name, r.population] for r in rows ])) At your view: //declare the libraries here, jquery hc, etc

[web2py] Re: Thread with own db connection

2016-05-12 Thread Alfonso Serra
I kinda have it but its very bad. i have to declare the connection as: class customthread(Thread): def __init__ self.db = DAL(cnnstring, migrate=False) self.db['dontclose'] = True At gluon/packages/pydal/connection.py wich handles the ConnectionPool modify the line 56

[web2py] Problem with routes

2016-05-14 Thread Alfonso Serra
Hi. Im trying to map some routes using patterns but i cant get it right. I want to get rid of the app name and index actions so: http://mydom.com/anycontr/123 maps to http://mydom.com/myapp/anycontr/index/123 and be able to use numeric parameters on the default controller as http://mydom.com/

[web2py] Re: I tried learning scheduler but got messed up. Can someone help me with this?

2016-05-14 Thread Alfonso Serra
On Saturday, 14 May 2016 08:38:57 UTC-1, Steve Joe wrote: > > how to write a scheduler function that will send me an email with subject > "hello" every night at 12 am? > Yep, 1-Launch the scheduler on a command prompt run cmd.exe or any terminal on your computer and type python web2py.py -K myapp

[web2py] Re: What is the difference between these two in relation with working of script?

2016-05-14 Thread Alfonso Serra
This is not web2py related but geolocation is disabled on all browsers by default. You have to enable it. -- 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) ---

[web2py] Re: Problem with routes

2016-05-14 Thread Alfonso Serra
No problem i got it. I dont need to type the app name or the index action at the url and numeric params works. routes.py default_application = "myapp" default_controller = "default" #no need to declare the default action routes_in = ( #... include the same routes as the example file , ('/(\d

[web2py] Re: Thread with own db connection

2016-05-14 Thread Alfonso Serra
Thanks for your answer massimo. The problem is that the thread im creating "use to" last longer than the request dispatch, and it needs its own connection opened until is done (importing bulk data into the database). Thats why i cannot .join the thread, i let the request finish, and the importa

[web2py] Re: IDX (internet data exchange) plugin in web2py

2016-05-14 Thread Alfonso Serra
What is IDX? a php wordpress plugin? -- 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 Gr

[web2py] Re: Problem with routes

2016-05-14 Thread Alfonso Serra
Another problem. Since i want to get rid of the app name and index actions in the url i have added these to routes_in routes_in ... , ('/myapp/default/user/$anything', '/user/$anything') routes_out ... , ('/myapp/default/user/$anything', '/user/$anything') It works but redirecting to the login

[web2py] Re: db.import_from_csv_file

2016-05-14 Thread Alfonso Serra
I dont think its the constraints but it looks you are trying to import that csv to the user's table, and the user's table doesnt have a field called created_by. if thats what you want remove the columns its asking like created_by from the file If its not the user's table you are trying to update

[web2py] Re: Problem with routes

2016-05-14 Thread Alfonso Serra
Thanks Anthony ill give it a try but i dont quite understand how it works. Anyway the pattern routes are working but Auth doesnt realise the routes are mapped resulting in wrong _next and logout redirections. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://gi

[web2py] Re: unknown ticket on server for all sites

2016-05-14 Thread Alfonso Serra
Hmm looks bad, ransomware on your server? Do you have a copy of your database? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Repo

[web2py] Re: I tried learning scheduler but got messed up. Can someone help me with this?

2016-05-14 Thread Alfonso Serra
Its just doing what you told it. Inserting a record each time it runs. So ye, its working. Just make sure to tell it how long it should pass between executions. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://c

[web2py] Re: I tried learning scheduler but got messed up. Can someone help me with this?

2016-05-14 Thread Alfonso Serra
Making the scheduler work wasnt easy for me either. You said earlier the db was being flooded which is a good sign, the scheduler is working. As for the parameters take a look here: http://web2py.com/books/default/chapter/29/04#Complete-Scheduler-signature And here: http://web2py.com/books/default

[web2py] Re: Problem with routes

2016-05-14 Thread Alfonso Serra
Finally i got it right. Its so cool, ive corrected something that happens when you are logged in, if you visit /myapp/default/user it takes you to the login page, i was able to redirect to the profile page. If the url ends with numbers it converts them into args regardless the url you are in. s

[web2py] Is there any way to inherit from Row?

2016-05-14 Thread Alfonso Serra
I would like to subclass a Row object but cant get it right. What would be the way? from pydal.objects import Row class Hotel(Row): _room_types = None _regimen_types = None _agencies = None _countries = None def __init__(self, db, id): super(Hotel, self).__init__()

[web2py] Re: Is there any way to inherit from Row?

2016-05-14 Thread Alfonso Serra
Sry i got it. super(Hotel, self).__init__(db.hotels[id]) -- 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 subsc

[web2py] Re: Is there any way to inherit from Row?

2016-05-14 Thread Alfonso Serra
Thanks for the advise. Yes you are right i didnt need the join, was just following the same pattern as other queries which does need them, not this case. Also right with virtual fields, they are easy to use but i dont think i should write tens lines of code within a lambda. My webapp is getting

[web2py] Re: unknown ticket on server for all sites

2016-05-14 Thread Alfonso Serra
Still, what operating system are you running? Does it have bitlocker or similar enabled? I dont know how bitlocker works but you could be uploading an encrypted file to your server. Easy to check If you try any other text file and it works. -- Resources: - http://web2py.com - http://web2py.com

[web2py] Re: Is there any way to inherit from Row?

2016-05-15 Thread Alfonso Serra
> > Why not? That's how ORMs do it -- everything related to a given model > lives in a single class. After all, the logic in question does pertain to > the associated model. > You don't need classes to organize code. > All the tables/models are connected somehow by reference fields. I dont k

[web2py] Re: unknown ticket on server for all sites

2016-05-15 Thread Alfonso Serra
Bit locker is a windows feature that encrypts your harddrive so no one can read your files. It might be this, you can read your files but the uploaded ones are encrypted, readable only by your windows machine. You can try this https://technet.microsoft.com/en-us/library/ee424315%28v=ws.10%29.aspx

[web2py] Re: Thread with own db connection

2016-05-16 Thread Alfonso Serra
The difference is, from my modest knowledge about the scheduler, the following. The scenario is: - Users have to be able to import a csv to one of the tables. csv's may be big 8mb, 40k rows. (worst case) - Users may do this whenever they want, so concurrency would occur. Implementation problems

[web2py] Re: Thread with own db connection

2016-05-16 Thread Alfonso Serra
Well, the sceduler starts with an error because im mapping booleans to tinyint in 01_db.py. But it doesnt fail inserting booleans. db = DAL("mysql://cnnstring", pool_size = 10, check_reserved=None, migrate= True) db._adapter.types['boolean']='TINYINT(1)' db._adapter.TRUE = 1 db._adapter.FALSE =

[web2py] Re: Is there any way to inherit from Row?

2016-05-17 Thread Alfonso Serra
Yep it isnt working well inheriting from Row. The instance looks like a row, but all the db methods doesnt work. update_record, and such. Following your advise and going back to web2py recursive selects i have this problem: Given this schema: - A company has groups and groups has subgroups I n

[web2py] Re: Redirect after profile update

2016-05-17 Thread Alfonso Serra
Instead on relying on callbacks you could implement the user() controller in default.py login, logout, register, profile, and so on are passed as request.args in default.py, something like: def user(): if auth.user: if request.args == "profile": if user.type == "seller": red

[web2py] Re: Is there any way to inherit from Row?

2016-05-17 Thread Alfonso Serra
Thanks Anthony it works. I get the result but the sql is not quite right. Inspecting db._lastsql i see this: SELECT subgroupfields... FROM groups, subgroups WHERE ((groups.hotel = 1) AND (groups.id = groups.id));' Performancewise im not sure if thats the same as declaring Joins. Its good to se

[web2py] how to handle boolean's tri states?

2016-07-07 Thread Alfonso Serra
If i define a boolean field as: Field("mybool", "boolean", required = False, notnull = False, default = None ) Its stored as False if its not present in request.post_vars. The proper behaviour would be to store a null value in this case, which allows to handle boolean's tri-states. To achieve

[web2py] Re: how to handle boolean's tri states?

2016-07-07 Thread Alfonso Serra
MySQL with TINYINT as booleans: db = DAL("mysql://", pool_size = 10, check_reserved=None, migrate=True) db._adapter.types['boolean']='TINYINT(1)' db._adapter.TRUE = 1 db._adapter.FALSE = 0 -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py

[web2py] Re: how to handle boolean's tri states?

2016-07-07 Thread Alfonso Serra
> > Thanks Richard, Anthony, very good answers. > The use case is simple: For example, query articles with a field of uncatalogued, you can either select catalogued, uncatalogued or all (doesnt matter if its uncatalogued). To store such filter i can make use of a boolean tri state, True, False

[web2py] Re: how to handle boolean's tri states?

2016-07-08 Thread Alfonso Serra
Just to post the right solution. filter_in didnt work out since im not saving the form when its posted, just using the form to generate a query. So the right solution would be something like: form = SQLFORM(db.myfilters).process(dbio=False, keepvalues=True, onvalidation=enable_bool_tri_state)

[web2py] Re: how to handle boolean's tri states?

2016-07-08 Thread Alfonso Serra
You are right. The real scenario is: Im using a table to store filters that are used to retrieve data from another table. This other table are bookings, and i need a filter to retrieve either all of them, or with kids, or without them. The form of such filters has 3 kind of submits "Execute fi

[web2py] Re: how to handle boolean's tri states?

2016-07-08 Thread Alfonso Serra
Absolutetly right, i just realised that. @Richard Rather than a string field, i tried your approach using an integer and IS_IN_SET() but the problem is that bool conversion happens after that is executed. Hmm, actually this might work since as integer the bool conversion wont take place, right?

[web2py] Re: how to handle boolean's tri states?

2016-07-08 Thread Alfonso Serra
This should do it: Field("with_kids", "integer", length = 1, notnull = False, default=None, required = False, requires=IS_NULL_OR(IS_INT_IN_RANGE(0,2)) ) Ive tested it and it converts correctly, and accepts the tri state. Thanks again. -- Resources: - http://web2py.com - http://web2py.com/bo

[web2py] Re: Do not show None

2016-07-08 Thread Alfonso Serra
Declare your field as: Field("price", "double", represent = lambda f, r: r.price if r.price != None else " ") Here represent is a function that will format the field's value and takes the field itself and the row as arguments. To display the table. def index(): table = SQLTABLE(db(db.myt

[web2py] Re: how to handle boolean's tri states?

2016-07-08 Thread Alfonso Serra
Sorry, to finish up some considerations... Ive been investigating how web2py assigns default validators to field types. If im not wrong this is done by SQLFORM which imports a function from gluon.dal called _default_validators. In this function the relationship between web2py field types and

[web2py] Re: how to handle boolean's tri states?

2016-07-09 Thread Alfonso Serra
> > Actually, the API for creating a custom field type is > http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Custom-Field-types--experimental-. > > Note, it isn't documented, but SQLCustomType also takes "validator", > "represent", "widget", and "_class" arguments,

[web2py] Re: web2py resources

2016-09-12 Thread Alfonso Serra
Another tool for Firefox that may help to develop your applications. This AutoHotKey script reloads your browser and removes the repost Confirmation dialog whenever you press Ctrl + S. So if you save your code in any editor Firefox will show the changes. Havent tested for Chrome but it may work

[web2py] Difference between migrate = False or migrate_enabled = False

2016-10-15 Thread Alfonso Serra
Yes what's the difference between migrate = False and migrate_enabled = False on a DAL declaration? Since all my mysql tables are defined and they need some extra UNIQUE indexes (that are removed automatically if migrate = True). What would be the way to disable migrations in general and only e

[web2py] Re: Difference between migrate = False or migrate_enabled = False

2016-10-15 Thread Alfonso Serra
Yes Stifan, but isnt the same thing? migrate = False disables migration for all tables migrate_enabled = False disables all migrations? Are there migrations not meant for tables? Thats the question. If they are the same thing why the need of 2 parameters? Is a legacy feature? Thanks -- Res

[web2py] Re: conditional use of None

2016-11-16 Thread Alfonso Serra
Have you tried?: if request.get_vars.specificAddressID == "None": Whatever you put in the url is not python, so specificAddressID=None is translated as a string. To translate it into python's None i think the url should be something like: http://127.0.0.1:8000/ES3/default/add_new_meeting_segmen

[web2py] How to Fail silently if ip is blacklisted

2015-12-05 Thread Alfonso Serra
Hi, im working on a blacklist and i was wondering if can make web2py to fail silently on an early stage if the client is blacklisted. I have something like this in my models. #blacklist an ip def blacklist(ip): if ip: db.blacklist.insert(ip=ip) #hidden ips are considered black def i

[web2py] Re: How to Fail silently if ip is blacklisted

2015-12-05 Thread Alfonso Serra
Thanks Anthony. Ill read more about how the ticket system behaves if the request is not local. I guess that an empty response is acceptable by now. Ill post if i make any progress. By the way i was able to fix the problem at my other post

[web2py] Re: web2py resources

2015-12-05 Thread Alfonso Serra
web2py Best Practices by martin Mulone translated to english by me. Download "web2py Best Practices.pdf" -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - h

[web2py] Re: web2py resources

2015-12-06 Thread Alfonso Serra
: > > Nice, when did Martin write the original version? I do not remember seeing > this before. > > On Saturday, 5 December 2015 23:07:44 UTC-6, Alfonso Serra wrote: >> >> web2py Best Practices by martin Mulone translated to english by me. >> >> Download

[web2py] Bug on checkboxes

2015-12-13 Thread Alfonso Serra
Hey i was creating a custom widget for a checkbox and i wanted to keep the value when the form doesnt validate. This is the declaration for the input: chk = request.post_vars[field.name] != None if chk: _input = INPUT(_type="checkbox", _name=field.name, _class="checkbox", _checked=

[web2py] Re: Bug on checkboxes

2015-12-14 Thread Alfonso Serra
Hi Anthony, Thanks again but it isnt working on postback. chk = True if chk: _input = INPUT(_type="checkbox", _name=field.name, _class="checkbox", _value="on", _checked="on") else: _input = INPUT(_type="checkbox", _name=field.name, _class="checkbox", _value="on", _checked="on") Still r

[web2py] Re: Bug on checkboxes

2015-12-14 Thread Alfonso Serra
Hi Anthony, Thanks again but it isnt working on postback. chk = True if chk: _input = INPUT(_type="checkbox", _name=field.name, _class="checkbox", _value="on", _checked="on") else: _input = INPUT(_type="checkbox", _name=field.name, _class="checkbox", _value="on", _checked="on") Still r

Re: [web2py] Re: Bug on checkboxes

2015-12-14 Thread Alfonso Serra
Wow thanks. that was unintuitive since all attributes are prefixed but ye it does work, indeed. Its documented tho, my bad. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (

[web2py] The Almighty Form

2015-12-16 Thread Alfonso Serra
Im trying to create a formstyle, when the form is submitted without introducing any value it skips any kind of validation and, without being accepted, tries to perform db changes. Eventually i get an error ticket like: pymysql.err.InternalError'> (1048, u"Column 'salida' cannot be null") This

[web2py] Re: The Almighty Form

2015-12-16 Thread Alfonso Serra
Ive found a workaround but the question still remains. Why cant we define formstyles like the example above? the workaround is by creating the formstyle like this: def mystyle(form): container = CAT() for fld in form.fields: container += INPUT(_name=fld) container += INPUT(_t

[web2py] Re: The Almighty Form

2015-12-16 Thread Alfonso Serra
Thanks Niphlod and Anthony for your help. Niphlod i didnt want to use the tuple fields, was using form.fields to build everything from scratch as Anthony said. I like to have some kind of freedom to create html, without breaking internals whenever is posible. I thought requires was performed i

[web2py] Re: The Almighty Form

2015-12-17 Thread Alfonso Serra
Makes sense, but now i have automatic markup in my view when the form has errors, which is something that im trying to avoid. Any advise on how to disable that, so i can implement my own markup when that happens? Thanks -- Resources: - http://web2py.com - http://web2py.com/book (Documentation

[web2py] Re: The Almighty Form

2015-12-17 Thread Alfonso Serra
I thought about it but it has a disadvantage. The SQLFORM is perfect to render complex queries without having to hardcode the html. If the models changes i dont have to worry about the view. And this is where the bootstrap decouple comes in place. Everything is easy if you use the welcome app

[web2py] Re: The Almighty Form

2015-12-18 Thread Alfonso Serra
> > you should instead hide the errors, and then you could add your own via > server-side DOM manipulation. > But how do i do that if i dont know when errors has happened?. Currently the form gets automatic markup when is instantiated and later on its modified when process is called. But this

[web2py] Help with deployment

2015-12-23 Thread Alfonso Serra
Im trying to mount a fresh web2py in a hosting with mod_python, i dont have shell access, only ftp and htaccess editing. Steps ive done: 1. Unzip web2py in my hard drive and execute rocket server to create deposit, logs folders and parameters_80.py (password and port 80) 2. Delete all

[web2py] Re: Help with deployment

2015-12-23 Thread Alfonso Serra
Ive removed the hardcoded message and this is the real error: RuntimeError: No module named copy -- 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 rec

[web2py] Support for BIT(1) as boolean?

2016-01-11 Thread Alfonso Serra
I need to do some rawsql calculations involving booleans and I would like to add boolean support to web2py using 0 or 1 BIT(1) in the database, so i dont have to convert "T" or "F" every time. My question are: Where can i find the code that does the conversion from CHAR() "T" to boolean and mys

[web2py] Re: Support for BIT(1) as boolean?

2016-01-11 Thread Alfonso Serra
Im sorry i just seen Massimo's answer at the post: https://groups.google.com/forum/#!searchin/web2py/boolean$20values/web2py/IukqqZF_PPE/Dehg9dKUT58J import copy db =DAL() db._adapter.types = copy.copy(db._adapter.types) db._adapter.types['boolean']='TINYINT(1)' db._adapter.TRUE = 1 db._adapter.FA

Re: [web2py] Re: Support for BIT(1) as boolean?

2016-01-11 Thread Alfonso Serra
Its weird the application seems to work fine but cant create a select() at the console. The queries in the controllers doesnt fail. This is the db definition: if not request.env.web2py_runtime_gae: db = DAL("mysql://root:@localhost/mydb", pool_size = 10, check_reserved= None, migrate=True)

Re: [web2py] Re: Support for BIT(1) as boolean?

2016-01-12 Thread Alfonso Serra
Excuse me, one last question. Is it really necesary? import copy db._adapter.types = copy.copy(db._adapter.types) or modify the adapter right away will work? It looks like it does, but i dont know if theres any implication by skiping copy. Thanks -- Resources: - http://web2py.com - http://we

[web2py] How can we help with the documentation?

2016-01-12 Thread Alfonso Serra
Ive spent 6 hours wondering why i couldnt update or insert a record with the interactive console. After changing mysql user passwords, drop tables, remigrate everything, mounting a fresh new web2py installation, tried to disable caching, i wasnt able to update or insert a record even tho the do

[web2py] Re: DAL calls fail after first stored procedure call

2016-01-20 Thread Alfonso Serra
I have exactly the same issue. Call a procedure once and works. Call another procedure again, returns None and from this point on, simple db(..).select() are broken. Its definetly a DAL issue since using mysql connector does works well. This is an example: Download mysql connectors

[web2py] Re: DAL calls fail after first stored procedure call

2016-01-20 Thread Alfonso Serra
Ive solved it by creating a function as: def callproc(name, args): cur = db._adapter.cursor cur.callproc(name, args) if hasattr(cur, "stored_results"): for r in cur.stored_results(): return r.fetchall() else: return cur.fetchall() Im not sure if its wor

[web2py] Re: web2py resources

2016-01-23 Thread Alfonso Serra
web2py video bookmarks Massimo's 4 web2py videos are 11 hours long so its hard to find specifics subjects. With this tool you can create VLC Player bookmarks which helps to quickly find any subject. demo video vlclist.zip

[web2py] Nested queries

2016-01-31 Thread Alfonso Serra
Given the following model: A company has departments and each department has subdepartments. How would i query all subdepartments from a company? Thanks. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.g

[web2py] Re: Nested queries

2016-02-01 Thread Alfonso Serra
Ok took me a while but here it is: rows = db(db.company.id==1).select(db.subdepartments.ALL, join=[db. departments.on(db.departments.id == db.subdepartments.department), db. companies.on(db.company.id == db.departments.company)]) -- Resources: - http://web2py.com - http://web2py.com/book (Docu

[web2py] Re: one select form multiple table

2016-02-01 Thread Alfonso Serra
> > I want to make a form which can search in multiple db tables. The tables > has a same structure. the form is only one since your inputs are a single search field isnt it? so what you would do is: form = SQLFORM.factory(Field("search", "string", notnull=True)).process() results = [] if fo

[web2py] Re: Nested queries

2016-02-02 Thread Alfonso Serra
Yep thats right, i edited the post. that was just an example, they arent real tables in my project. I like plurals for tables since they are collections of records and singular for field names. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web

[web2py] Is there any reason to auto include an id field in a SQLFORM.factory?

2016-02-10 Thread Alfonso Serra
Its not big deal but yep, thats the question. The auto id field is messing around with custom forms since i have to calculate the amount of "defined" fields to create the proper html output (html rows or columns). This is the solution im taking but i dont know if theres gonna be a problem dow

[web2py] Problems with Upload files

2016-02-11 Thread Alfonso Serra
Hey everyone. Im having a hard time to import and process a csv file. I would like to: - upload the file, - let the user do some kind of preprocess, (map columns, and such). - insert records. - dispose the uploaded file. Its a double post i gotta do, one to submit the file, and another for the

[web2py] Re: Problems with Upload files

2016-02-11 Thread Alfonso Serra
Ok the first mistake ive made file.seek(0) returns None so file.seek(0).read() doesnt make sense. -- 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 rece

[web2py] Re: Problems with Upload files

2016-02-11 Thread Alfonso Serra
Hi val thanks for your answer. Althought as you said, an absolute path is safer, a relative path as i have in the field form, looks like it works. I got that part covered with: filename = form1.vars.csvfile file = request.post_vars.csvfile.file file.seek(0) #something is consuming the file so i

[web2py] Re: Rows not releasing all the memory back

2016-02-11 Thread Alfonso Serra
You can try "del rows" to remove the reference from memory before collecting del a single row raises a TypeError but del rows doesnt. It may help. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com

[web2py] Re: Problems with Upload files

2016-02-11 Thread Alfonso Serra
Thats not the issue. Sry i didnt post the whole declaration but yes im calling process. This is the declaration form = SQLFORM.factory( fields...).process(formname = "form1") The problem was the IS_BINARY validator which was consuming the file before it got saved. If i remove it the file is sto

[web2py] Re: Rows not releasing all the memory back

2016-02-12 Thread Alfonso Serra
pass > > > On Friday, February 12, 2016 at 5:49:38 AM UTC+5:30, Alfonso Serra wrote: >> >> You can try "del rows" to remove the reference from memory before >> collecting >> del a single row raises a TypeError but del rows doesnt. It may help. >&

[web2py] Re: one select form multiple table

2016-02-16 Thread Alfonso Serra
executesql always return tuples and thats ok unless you need to to hide columns, remove elements, edit or add data and such. To turn a tuple into a list is just result = list(result) To return a table web2py has many "magic" methods like SQLFORM.grid or SQLFORM.smartgrid that will only work if

[web2py] Progress bars and session

2016-02-16 Thread Alfonso Serra
Im trying to make a progress bar by reading and writing a session variable: There are 2 controllers: Get session.progress def getprogress(): print "getprogress:", session.progress return session.progress This one takes 5 seconds to perform and changes session.progress each one. def progre

[web2py] Re: Progress bars and session

2016-02-16 Thread Alfonso Serra
Thanks Anthony, it does work. The hack is easy to implement, but to represent the insertion of 30k records into the database, writing the session file and connecting 30k times might not be optimal. Theres a chapter about the Scheduler that may work for this. Ill read about it, it has something

Re: [web2py] Re: Progress bars and session

2016-02-17 Thread Alfonso Serra
> > > Perhaps you should update a field in some db table and use it instead of > session. > Please note that the end of this, is to create an ajax progress bar that indicates the numbers of records being inserted on a request. Although that might work as well, still it isnt good to read and w

Re: [web2py] Re: Progress bars and session

2016-02-17 Thread Alfonso Serra
Ive adapted the code to use cache.ram, but the docs about this mechanism is quite confusing, and i can't get it to work. There are several questions like, how to store simple values instead callables? what happens if i access a cache value after expiration? This is the code: def getprogress()

Re: [web2py] Re: Progress bars and session

2016-02-17 Thread Alfonso Serra
Omg it did work!. Thanks you very much Anthony, i owe you one. Console log: progress -1 progress -1 main: 0 progress 0 main: 1 progress 1 main: 2 progress 2 main: 3 progress 3 main: 4 progress 4 -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web

[web2py] How to know if the scheduler is running?

2016-03-08 Thread Alfonso Serra
In order to run a scheduler task, the scheduler must be running using web2py.py -K myapp Its all good but sometimes servers are stopped for mantainance or they kill processes if they are running for too long. So if i have a controller that assigns a task, how do i detect if the scheduler is ru

[web2py] Re: How to know if the scheduler is running?

2016-03-09 Thread Alfonso Serra
Thanks Nico ill give it a try. On Wednesday, 9 March 2016 09:46:55 UTC, Nico de Groot wrote: > > Or use something like Monit (on Linux) to check if scheduler is still > running, restarting it if it's not. > > Nico de Groot > -- Resources: - http://web2py.com - http://web2py.com/book (Documentat

[web2py] Re: How to know if the scheduler is running?

2016-03-09 Thread Alfonso Serra
Thanks Niphlod. So i can inspect for workers with a last_heartbeat less than 4 seconds ago (default interval is 3 i think). Is that right? It might work, thanks. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https:/

[web2py] Re: How to know if the scheduler is running?

2016-03-09 Thread Alfonso Serra
This would be the funcion: from gluon.scheduler import Scheduler sched = Scheduler(db) def sched_running(): from datetime import datetime workers = sched.get_workers() for key, worker in workers.items(): last = (datetime.now() - worker.last_heartbeat).seconds if last

[web2py] Re: How to know if the scheduler is running?

2016-03-09 Thread Alfonso Serra
> > Ok this should do it. > def sched_running(): workers = sched.get_workers() for key, worker in workers.items(): last = (request.now - worker.last_heartbeat).seconds if last < 4: return True return False One last thing, any idea on how to start

[web2py] Re: How to know if the scheduler is running?

2016-03-09 Thread Alfonso Serra
This looks like it works. import subprocess ret = subprocess.Popen(["python","D:/web2py/web2py.py", "-K", "myapp"], shell=True) print ret.pid I have the stdout in the same console as the server but both, the sched and the server, are working. This whole scheduler thing looks very messy but it

[web2py] Re: How to know if the scheduler is running?

2016-03-09 Thread Alfonso Serra
Yes you are right, the connection resets often and even if it works its not worthy. -- 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 m

[web2py] Scheduler mysql error

2016-03-09 Thread Alfonso Serra
The scheduler is working on localhost but on pythonanywhere i get following error: starting single-scheduler for "myapp"... /home/aleonserra/web2py/gluon/packages/dal/pydal/adapters/base.py:1379: Warning: Incorrect integer value: 'F' for column 'is_ticker' at row 1 ret = self.get_cursor().ex

[web2py] Re: Scheduler mysql error

2016-03-10 Thread Alfonso Serra
Ive tried on a paid account and it works even with that error. It might be the amount of processes limitation on free accounts. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/li

[web2py] Re: How to know if the scheduler is running?

2016-03-11 Thread Alfonso Serra
Excuse me Niphlod, i can't find any docs about running the scheduler programatically. Do you have any advise on how to do it? Thanks. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/i

[web2py] Is there any way to control the view representation of python types?

2016-03-22 Thread Alfonso Serra
Yes, is there a way to control how to render builtin python types (int, float, NoneType, ...)? Instead of: None: a = None renders as "None", render as " " Integer: b = 1234 render as "1.234" Float: c = 1234.265 render as "1.234,27" Boolean d = True render as "ok" And so on... We cant change buil

[web2py] Re: Is there any way to control the view representation of python types?

2016-03-22 Thread Alfonso Serra
Thanks to point me to filter_in, filter_out functions they are helpful indeed. The problem is that not all the view data comes from a database, form.vars for example or any custom variable from a controller or a model. Wrapping everything in all the views is not mantainable. All this data, sh

Re: [web2py] Re: Progress bars and session

2016-03-23 Thread Alfonso Serra
Ill try to explain it here but this is gonna require a video tutorial: First there are several ways to achieve it. Although Anthony's suggestion (cache.ram) is optimal it didnt work on production, I dont know why cache.ram doesnt work on pythonanywhere. I got the progress bar working on product

[web2py] row.as_json confussion

2016-03-27 Thread Alfonso Serra
On an interactive console running: rows = db(mytable).select() rows[0].as_json() I get the expected result, an unicode string containing the row representation with the right values. On a controller or view i get a complete different thing: The result is a dictionary with a single ['_extra'] k

[web2py] Re: row.as_json confussion

2016-03-27 Thread Alfonso Serra
Sorted out with: rows = db(db.mytable).select(*[db.mytable[f] for f in db.mytable.fields[0:5]) -- 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 receiv

[web2py] Rawsql to DAL Rows

2016-03-29 Thread Alfonso Serra
Im trying to adapt an executesql query to a dal object to make use of features like export to csv. So ive tried something like: #create a dummy table with the same structure as the results db.define_table("results", Field("field1", "string") , Field("field2", "string") , migrate = Fal

  1   2   >