Re: [web2py] Re: Help with db query
Assuming that request.args contains the right values, this should work: category = request.args[1].replace('_', ' ') query = (db.Supplements.Category == category) & ((db.Supplements.Users == request.args[0]) | (db.Supplements.Users == "Both")) records = db(query).select() Notes: - "contains" does not work as it's intended only for fields defined as list types, - the alternative is to use "belongs" as Niphlod suggested yesterday. --
[web2py] Re: How to create long running tasks?
Use the scheduler. It runs as an *independent* process. If the web server is running or not have no influence on the scheduler. Read more here: http://web2py.com/books/default/chapter/29/04?search=scheduler#Scheduler-%28experimental%29 --
Re: [web2py] Re: Routes - simple requirement, but how??
You right, the prefix is what makes possible to use the same plugin code across many apps. Setting the "alias" for the plugin manager sounds like a good solution to me. from gluon.tools import PluginManager plugins = PluginManager() plugins.wiki.path = "wiki"
[web2py] Re: A page served by two different backends
Your description is very confusing. Static content are the files that are not dynamically generated but simply served over the network, e.g. images, javascript, css. If you generate an HTML page using a view (template) and filling it with data from DB, that is a dynamic page generation. Now, you want to use tornado + javascript to have a user side generated page. And you want access to DB from the javascript? If so, try the REST approach and expose the data as JSON. See this book chapter for details: http://web2py.com/books/default/chapter/29/10#HTML,-XML,-and-JSON But then the question is, what is the benefit of using tornado in the first place if at the end your requests go to web2py anyway?
[web2py] Re: Routes - simple requirement, but how??
I might be missing something but it looks to me that there is a very simple solution to your problem. Rename the controller from "plugin_wiki" to "pretty_url". Then use the following routes.py: routers = dict( app1 = dict( domain = "domain1.com", default_controller = "default", default_function = "myfunc1" ), app2 = dict( domain = "domain2.com", default_controller = "default", default_function = "myfunc2" ) )
[web2py] Re: Routing help
OK, so you want /myapp/args to be mapped to /myapp/default_controller/default_function/args. By default args would be interpreted as a function name and will be mapped to /myapp/default_controller/args. To change that you need to define a list of functions for the default controller. Then if args is not in that list it would be mapped to /myapp/default_controller/default_function/args. routers = dict( myapp = dict( default_controller = "default", default_function = "index", functions = ["fun1", "fun2", "fun3"] ) )
[web2py] Re: GAE datastore: how to unindex a field?
This is really a GAE question, not related to web2py. By default the indexes are set automatically when you run your app in dev environment depending on what queries you use. But you can do it manually to by editing the index.yaml (above the #AUTOGENERATED line). On the next deploy the indexes will be updated. To disable the autogenerated indexes and test your index definitions, you can run your app locally with: dev_appserver.py --require_indexes Read this article for more details: https://developers.google.com/appengine/articles/indexselection
[web2py] Re: External lib import issue ( opencv )
Where is the opencv installed in your system? When you check python interpreters in PyDev options is that path on the list? If you still struggling with it, a workaround could be to add the installation folder to the system path by hand: import sys sys.path.append("opencv")
[web2py] Re: How to intervene in web2py's upload process(store/retrieve/stream...) to do something with uploaded file?
I think you need to customize the functions for storing/retrieving the uploaded file. In you model add: Field("myfile", "upload", custom_store=store_myfile, custom_retrieve=retrieve_myfile) Then implement the functions: def store_myfile(uploaded_file, filename=None, path=None): buffer = uploaded_file.read() filename = put_to_storage(buffer) return filename def retrieve_myfile(filename, path=None): buffer = get_from_storage(filename) return (filename, buffer)
[web2py] Re: scheduler "advanced" question
You can set the desired logging level in the logging.conf: [logger_scheduler] level=DEBUG handlers=consoleHandler qualname=scheduler propagate=0 If that doesn't help, you could try to play with the -D and -l options of web2py.py, To instantiate the object once, you could implement the class as a singleton. Or simply create the object inside the module: modules/mymodule.py - x = SomeClass(db) models/tasks.py - from mymodule import x This should work as long as db is accessible inside the module code (not sure if this is the case). If not, use singleton pattern.
[web2py] Re: how can one replace an element in html?
So you have an HTML code as input and would like to change some tags to some others ones. But why? You should never had the need to build the HTML page from another HTML page in web2py. You should rather simply combine the data and a view. In your example, the view could be this: pages.css --- .page { page-break-after: always; } pages.html {{ for page in pages: }} {{=DIV(page.content, _class="page")}} And if you really need to process the HTML, you should use an HTML parser e.g. lxml or html5lib.
Re: [web2py] Re: routes.py
OK, so if I define the list of function, the situation is clear. If I don't and I want to pass arguments to the default function I need to use the default function name (/default_function/arg). Arguments alone (/arg) in that case would be treated as if it is a function name (even if it does not exist in the controller) and /app/ctrl/arg would be called instead of /app/ctrl/default_function/arg. Thanks for clarifying this.
Re: [web2py] Re: Web2py + Python 2.7 on GAE: Can I use PIL and resize an image when uploading to datastore?
I would just queue the image processing task (using GAE queue) to have the work done in the background. Doing it right when the form is submitted is possible too but will cause delays to the user. You could insert a logo by converting the image into uncompressed format (e.g. bmp), modifying the pixel array directly and converting the image string again to png or jpg. Using PIL is only possible with python2.7. You just do "import PIL" as usual and read images from the blob as strings.
[web2py] Re: web2py doesn't seem to be picking up posted json
How do you post it? I'm guessing this is the part that needs fixing.
[web2py] Re: CRON tasks in Google App Engine
Not directly. You can't execute scripts on GAE, so you would have to move the checking/sending code into a controller function and set up the GAE cron to call it periodically. However, it might be easier to use the GAE queues and to delegate e-mail sending to a background task: https://developers.google.com/appengine/docs/python/taskqueue/overview
Re: [web2py] Re: routes.py
Hmmm... So how does the router know if /abc is (1) function - /default_app/default_controller/abc or (2) argument - /default_app/default_controller/default_function/abc?
[web2py] Re: Web2py + Python 2.7 on GAE: Can I use PIL and resize an image when uploading to datastore?
For simple things such as thumbnails, you can use the GAE images API (which internally uses PIL): https://developers.google.com/appengine/docs/python/images/imageclass from google.appengine.api import images blob = db.marcas(id).logotipo_marca_blob image = images.Image(blob) image.resize(32, 32) data = image.execute_transforms()
[web2py] Re: Memory leak in standalone DAL (issue #731), can you please help test?
I've tested in on Ubuntu 11.04, with web2py 1.99.2 and trunk and in both cases after 35s the memory use is 1GB and growing. Same results with DAL("sqlite://storage.db").
Re: [web2py] Re: routes.py
Oh, so the default for functions is ALL_FUNCTIONS? In the comments it says: "list of valid functions in the default controller (default None)". From that I concluded (without testing I admit) that by default no function name will be mapped unless explicitly specified. It make sense to map all functions by default, but then the docs should be altered: http://code.google.com/p/web2py/source/browse/router.example.py
[web2py] Re: routes.py
For this type of routing where you don't use complex regular expressions, it is better to use the simple router. It could make selected functions of the default controller in the default application available directly, i.e. /f1 == /my_app/default_controller/f1 To have "/rules" mapped to "/aggat/default/rules", you only need this in your routes.py: routers = dict( BASE = dict( default_application = "aggat", functions = ["rules"] ) )
[web2py] Re: Questions on the scheduler
If all what you need is to report th task progress, you could periodically write the amount of work done to db from within the task. Then query db asynchronously with ajax to show it to the user. This could be done by extending the "scheduler_run" table. I'm not sure if there is a way to stop a running task. I guess you would have to kill the worker process to do that. Pause/resume would be even more difficult as the state of a task have to be stored. Probably it would be easier to do using a task queue framework such as Celery [1] or implementing your own queue using e.g. RabbitMQ [2]. [1] http://celeryproject.org/ [2] http://www.rabbitmq.com/tutorials/tutorial-two-python.html
[web2py] Re: Python Negative Popularity
I don't agree that multiprocessing is difficult in Python. Threading is difficult, multiprocessing is easy. Together with asynchronous I/O this brings the scalability. You think node.js is multithreading? No, it's single thread with event loop and non-blocking callbacks based I/O. And so is Twisted or Eventlet and they perform equally well. If you need to scale you add another instance of the event loop running on a separate core and route your traffic through a load balancer. I also disagree that python 3.x is a problem. It is a better language than 2.x. It's a shame that the transition of many projects is happening so slow. If the life of 2.x is extended it will only cause further delays in transition to 3.x. Also, in all this discussion on how tragic it is that Python has been surpassed by the Javascript, we need to remember that TIOBE index is calculated by counting hits on the top 9 search engines using a query of " programming". And as Derek has already spotted the query for Javascript has been extended and includes "JS programming" too [1]. I think it is much more reasonable to count the number of commits in a given programming language like ohloh is doing [2]. Then Python is not so much behind Java/C/C++ and is recovering from a drop in activity in 2011. [1] http://www.tiobe.com/index.php/content/paperinfo/tpci/tpci_definition.htm [2] http://goo.gl/suOH6
Re: [web2py] Re: sqlite to postgres
Upgrade. Python 2.7 is backward compatible with 2.6. Pip install is also a good option.
[web2py] Re: DAL Challenge
First you need to change your model. In relation database you would have: db.define_table("articles", db.Field("title"), ...) db.define_table("comments", db.Field("article_id", db.articles), db.Field("author"), ...) But with datastore you want to do the reverse, keep the comment ids in the article table: db.define_table("comments", db.Field("author"), ...) db.define_table("articles", db.Field("title"), db.Field("comments", "list:reference comments"), ...) or maybe even simply: db.define_table("articles", db.Field("title"), db.Field("comments", "list:integer"), ...) Then you read all the articles as usual: articles = db().select(db.articles.ALL) You go over all articles and store keys for all comments: from google.appengine.ext import db as gdb keys = [] for a in articles: keys.extend([gdb.Key.from_path("comments", id) for id in a.comments]) And finally you fetch all comments in a single query: comments = gdb.get(keys) You will get the comments in a fixed order so it shouldn't be difficult to map them to articles in the view. Simply for the first article where len(articles[0].comments) = 3, it would be comments[:3], for the second article where len(articles[1].comments) = 5, it would be comments[3:8]. A dictionary with article ids as you proposed would also work.
[web2py] Re: @auth.requires(lambda: auth.has_membership(VCARD))
You need web2py >= 1.99.3 for the lambda to work.
[web2py] Re: difference between
You *have to* set the response.files first, then include web2py_ajax.html. Look how this is done in the example app: http://code.google.com/p/web2py/source/browse/applications/welcome/views/layout.html Also notice that web2py_ajax.html already includes jquery and web2py.js: http://code.google.com/p/web2py/source/browse/applications/welcome/views/web2py_ajax.html Check the generated HTML to see exactly what scripts you include and in what order and post it here if you still have problems.
[web2py] Re: Using single instance of LibreOffice to convert documents - is this safe?
If this processing is done after the form submission you can delegate that to a background task. Having a queue of tasks end executing them one by one should solve the concurrent access problem. Check out the book section on scheduler: http://web2py.com/books/default/chapter/29/4#Scheduler-%28experimental%29
[web2py] Re: DAL Challenge
When working with GAE datastore you want to execute minimum number of queries necessary to avoid delays and limit the use of DB API calls. Fetching comments one by one is not the best option then (even if done with ajax). Probably the most efficient way would be to store the list of comment ids as an attribute of each article entity. Then you could get all comment ids with a single query. Having the ids you could build a list of GAE keys, and fetch all needed comment entities at once. We discussed that recently here: https://groups.google.com/d/topic/web2py/7dvo_jqIR38/discussion I'm also guessing that this might be quite common GAE use case and you might find a better solution already optimised for this on GAE forum. The other option is to show comments only on the article individual page (not on the list of articles). If you use the wrapper for caching, then you could memorize the entire response, so this is very efficient as the views are not rendered but read straight from cache. If you need some extra parametrisation inside the controller you could either move some of the code to a separate function which output is cached or simply cache only the queries: http://web2py.com/books/default/chapter/29/6#Caching-selects
[web2py] Re: Is it a way to query data from GAE and then save to the upload feild as a sqlite databasefile file
Make a simple model for storing files: db.define_table("files", db.Field("name"), db.Field("content", "text")) Then use a function similar to the one below to download the file: def download(): file = db.files(request.args[0]) if not file: raise HTTP(404, "File not found.") response.headers["Content-Type"] = "text/plain" response.headers["Content-Disposition"] = "attachment; filename=%s.txt" % file.name response.headers["Content-Title"] = file.name+".txt" response.headers['Content-Length'] = len(file.content) return file.content For binary content use db.Field("content", "blob"). If it is a large file, use the blobstore API instead: http://code.google.com/appengine/docs/python/blobstore/overview.html
[web2py] Re: 'tuple' object has no attribute 'items'
What do you mean by "I've made skills and items unnecessary"? What about these references? Field('Skills','list:reference SkillUser',default=None) Field('Items','list:reference Item',default=None) And at which point in your code the error occurs? Why you didn't include full error message? >From the message alone I'm guessing a tuple is used where a dictionary was expected.
[web2py] Re: web2py integration with python applications
So you want a web server on a local machine with a TCP backend to control the remote device. You also want some API to be able to access the server problematically. If this is correct, you will need: - a web2py application with functions decorated as services http://web2py.com/books/default/chapter/29/10#Remote-procedure-calls - background tasks for communication with the remote device http://web2py.com/books/default/chapter/29/4#Scheduler-%28experimental%29 How you implement the TCP communication is up to you. It could be C++ or Python or whatever you like. It has nothing to do with the apache httpd server. It would just be a part of the backend, executed outside of the user request to the http server. It could be an external command called from a task.
[web2py] Re: Getting started in Web2py
Don't use the web admin. It's for kids :P Copy welcome or example app and change the files directly. For me the selling point of web2py was the simplicity of the syntax. See this comparison: http://www.web2py.com/examples/static/web2py_vs_others.pdf
[web2py] Re: missing FROM-clause entry
Just a blind guess but does this work any better? query = (comment.id > 0) & (webpage.title == 'FAQ') & (comment.page_id == webpage.id) & (comment.id == comment_tags.comment_id) & (tag.id == comment_tags.tag_id) & (tag.label == 'Agree') db(query).select()
[web2py] Re: efficient DB queries
This is not the best way. It will run a separate query for each board id. On GAE you want to do as much as you can in a single query. So the best way is to construct a list of GAE keys and get all entities together. Unfortunately, AFAIK, there is no support for GAE batch queries in DAL. You can, however, try to refer to the GAE datastore directly. from google.appengine.ext import db as gdb articles = db().select(db.articles.ALL) keys = [gdb.Key.from_path("boards", a.board_id) for a in articles] boards = gdb.get(keys) But I'm afraid this is not an elegant solution as it probably won't work without a gdb.Model defined for the board entity, and that would go against DRY [1]. Anyway, if you want to do it, see the GAE docs [2] for details on model definition. Depending on how often are you going to perform this query a better solution might be redesigning your database. Forget about 3NF and add the board attributes to each article entity so that you can fetch everything together in a single query. [1] https://en.wikipedia.org/wiki/Don%27t_repeat_yourself [2] http://code.google.com/appengine/docs/python/datastore/entities.html
[web2py] Re: Conditional Fields
There are two separated things here. One is presentation of required attributes only, the other is validation of the from. The first one could be solved with the "conditional field" approach described in the book. If you are not sure what are the ids for generated form elements, simply view the generated HTML code in your browser. To implement the validation you need to use your own function in the controller: def validate_survey(form): if "M" == form.vars.sex: if not form.vars.fav_car: form.errors.fav_car = "favorite car is required" if not form.vars.fav_sport: form.errors.fav_sport = "favorite sport is required" elif "F" == form.vars.sex: if not form.vars.fav_soapie: form.errors.fav_soapie = "favorite soap opera is required" if not form.vars.fav_perfume: form.errors.fav_perfume = "favorite perfume is required" And the use it with the grid: grid = SQLFORM.grid(db.survey, onvalidation=validate_survey)
[web2py] Re: SQLForm.grid : how to change the way column are rendered
You can use a format string to define the data representation, read this: http://web2py.com/books/default/chapter/29/6#Record-representation To get the icons, instead of a format string, pass a function that generates the required HTML code.
[web2py] Re: How do I group the list by value and make it table in HTML?
You can simply loop over a sorted list (first by the state, then by name): city_list = [('Huntsville', 'AL'), ('Decatur', 'AL'), ('Anchorage', 'NV'), ('Nome', 'AK'),('Selma', 'AL'), ('Flagstaff', 'AZ'), ('Phoenix', 'AZ'), ('Tucson', 'AZ')] sorted_list = sorted(city_list, key=lambda x: (x[1],[0])) last = None for city, state in sorted_list: if state != last: print(state) last = state print(city)
Re: [web2py] Re: Is there any way to calculate distance between two points(lat and long) inside of sqlite?
You wrote you know how to do it with mysql. DAL doesn't care what db you use. Trigonometric functions are not supported by DAL anyway. So I recommend you to apply your mysql solution using raw sql queries, suggested already by Alan: http://web2py.com/books/default/chapter/29/6#Raw-sql
[web2py] Re: subdomain routes for websites
> > I'm trying to use a single controller for all my functions, including the > "web/site" controller/function. OK, but why? While it might be possible to achieve what you want to do this way too, it is definitely not going to be easier.
[web2py] Re: bug in unicode decoding/encoding upload file?
The decoder detection seems to focus on 2-4 byte encoding. Many times you will get a text in iso-8859-1 or cp-1250 or other 1 byte encoding and none of this is covered there. I might not make sense to extend the decoder if it is not meant for 1 byte encoding. In that case adding the alternative decoder to contrib would be a better idea. BTW, you the best way to do the conversion is probably customization of the file store method. In your model you do: Field("my_file", "upload", autodelete=True, custom_store=store_my_file) And then implement store_my_file based on the original Field.store method: http://code.google.com/p/web2py/source/browse/gluon/dal.py#7334
[web2py] Re: Download file dialog to local PC when running from PythonAnywhere
It looks to me that when you say "download" you mean "upload". If a user sends a file to a server, she uploads it. I recommend you to read about upload field in the book: http://web2py.com/books/default/chapter/29/7#SQLFORM-and-uploads
Re: [web2py] Re: {{pass}} problems
So you are saying the problem is now solved? Can you share with us what was the cause of this strange "missing pass in view" error?
[web2py] Re: Is there any way to calculate distance between two points(lat and long) inside of sqlite?
You can use mysql with web2py: http://web2py.com/books/default/chapter/29/6#Connection-strings
[web2py] Re: call function in template layout
In a view you can only call functions defined in this view or a one being extended/included: http://web2py.com/books/default/chapter/29/5#Functions-in-views More complex data processing should be done in the controller. Views should just present the data. Make the form transformation in the controller and pass the result to the view along with the form. def index(): form = SQLFORM(...) something = encadrement(form) return dict(form=form, something=something)
[web2py] Re: subdomain routes for websites
What is the purpose of the "demo" version there? Wouldn't it be easier to have a separate "demo" controller? You could then simply define the default for the domains as: routers = dict( BASE = dict( domains = {"domain.com":"app", "demo.domain.com":"app/demo/index"}, default_application = 'app', default_controller = 'org', default_function = 'index' ) )
Re: [web2py] Re: Upgrading web2py in Linux
I assume that you have only one application and you keep it separate from web2py: $HOME/workspace/my-project/src <-- your application folder $HOME/workspace/my-project/web2py <-- web2py folder To upgrade web2py to a desired version you can run then the following script. It pulls the changes from the repository and applies them to web2py folder. The it copies the global configuration files (which has been overwritten during update) from the application src folder (yaml files are only needed for GAE apps). Finally, it creates symbolic link to your application from within the web2py folder. #!/bin/bash TAG="R-1.99.7" cd $HOME/workspace/my-project # update files from repo cd web2py hg pull hg update -C $TAG cd .. # copy config files cp -p src/private/*.yaml web2py/. cp -p src/private/routes.py web2py/. # link to my application if [ ! -d "web2py/applications/init" ] then cd web2py/applications/ ln -s ../../src init fi Notice that your application will be linked as init. If you have more than one application per web2py instance, adjust the script to link all applications. Also, you will need mercurial installed to run the script (sudo apt-get install mercurial). And one more thing, this is perfectly normal that you need to mange the changes carefully. So there is no need to be bitter. BTW, there was an attempt by Jose to package web2py for Debian. It's pretty good but stays a bit behind the upstream: http://packages.debian.org/sid/python-web2py
[web2py] Re: custom css
Does the example app that comes with web2py show flash/errors correctly on Firefox 10 + Windows? If so, it would mean you didn't copy all the required CSS rules or you are missing a class/id/tag in your layout.
[web2py] Re: Can I change DAL encoding for strings?
You could inherit from DAL and overwrite the methods with wrappers that do the decoding/encoding where needed. I guess typically only insert, update, select and the constructor have to be wrapped. There is also the "db_codec" keyword argument for DAL constructor defaulted to "utf-8". But I'm guessing this only affects encoding on database level, not the queries.
[web2py] Re: need help with unicode decoding/encoding upload file
To convert a string to utf-8 you need to do two operations: - decode the string to unicode (using the original file codec) - encode the unicode string using utf-8 codec This is what decoder.decoder function is doing but it is guessing the original codec. You need to either provide the right codec for decoding (if you know it is always the same) or guess it better (e.g. by catching exception and trying different codecs in order). input_codec = "iso-8592-1" output = text.decode(input_codec).encode("utf-8")
[web2py] Re:
What exactly are you trying to do? Why you don't use the URL function?
[web2py] Re: web2py site and disabling browser right clicks
It looks like you don't understand how the world wide web works. There is nothing you can do to stop me from seeing the HTML code of your website. Blocking right click gets you nowhere as I can still use the browser menu, numerous plugins or simply download the page code directly without even using the browser. Even if you would javascript to generate the HTML dynamically, I can still access that generated code. So don't waste your time.
[web2py] Re: Many to Many?
What pbreit suggested assumes that all the company servers are at the same location as the company, which I guess is not what you wanted. It think it should rather be: db.define_table('company', Field('name'), Field('location', db.location)) db.define_table('server', Field('name'), Field('company', db.company), Field('location', db.location)) db.define_table('location', Field('name'))
[web2py] Re: Using SQLFORM.grid()
The args keywords is used to pass extra parameters to grid URLs. It is only useful if you implement your own ondelete, onupdate or oncreate functions and need to get this extra arguments from a request.
[web2py] Re: Validating data in a CRUD form before entering into the databse
I think the easiest is to add your validation code in the controller and then process the data after successful validation. I don't know how your data looks like but here is a simple example of a controller code with custom validation and db insert: def validate_add(form): pattern = re.compile("[0-9a-z]+") for line in form.vars.data: if not pattern.match(line): form.errors.data = "only alphanumeric characters are accepted" def add(): form = SQLFORM.factory( Field("data", "text", label="names", comment="list of names (1 per line)"), submit_button="Add to library") if form.process(session=None, onvalidation=validate_add).accepted: for name in form.vars.data.split(): id = db.my_table.insert(name=name) redirect(URL("status")) return {"form":form}
[web2py] Re: web2py resources
Except of websites with very small user base, the use of sqlite is not recommended as it doesn't provide concurrent writes. Mysql or postgresql is usually a good first choice, but web2py supports about 10 different DBs, so you can choose something else too. The application code (including instant press) is using DAL, so it is not bounded to sqlite or any other any specific DB. It will work the same. By default it is sqlite and to switch to a different DB you need to modify the variable DB_CONNECT_URI at the top of the config file: http://code.google.com/p/instant-press/source/browse/models/_aconfig.py Read the book chapter on deployment: http://www.web2py.com/books/default/chapter/29/13 There are many options. It's hard to recommend one without knowing what your host constraints are.
[web2py] Re: Passing variables from form to function to be classified and matched against DB
If I understand you correctly, you simply want to use the matched scenario on the next stage of the form. So, after validation you need to pass the id of the matched scenario either by: a) storing it in a session (1) and reading it later in the "next" function (2) 1) session.scenario = scenario_id 2) scenario = db.scenarios(session.scenario) b) adding it as an argument of the "next" URL and reading it in the "next" function (2) 1) redirect(URL("next", args=[scenario_id])) 2) scenario = db.scenarios(request.args[0]) The same applies to the form data. You can (a) store them all in session object or (b) store them in DB and just pass the form.vars.id as an argument of the "next" URL.
[web2py] Re: Capture the system shut down and browser close event
You could simply assume x minutes (eg. 15) without any user action equals to logout. Then all you need is just a small script that runs periodically by cron and does a DB update when inactivity is detected.
[web2py] Re: GAE - Rendering uploaded Blob as jpeg image rather than as a string?
You kind of do :) There is no way to embed streams in HTML directly. You need a separate function showing a single image by id (e.g. /show_image/id) and build a list with links to that function in the list_image view. {{for img in images:}} {{= TD(img.title) }} {{= TD(IMG(_src=URL("show_image", args=img.id), _alt=img.title)) }} {{pass}}
[web2py] Re: using existing DB connection inside module/class
The code in controllers is wrapped in web2py with a try except clause that automatically commits or rolls back the changes to db. I believe this is not the case for modules and an explicit commit is needed there. Try to add "db.commit" to your module code.
[web2py] Re: dynamic keywords on database update
You can pass a dictionary to a function as if you are passing keyword arguments. kwargs = {"a":1, "b":2} f(**kwargs) # this call is equal to f(a=1, b=3) There is similar mechanism for positional arguments in Python: args = [1, 2] f(*args) # this call is equal to f(1, 2)
[web2py] Re: in my IE 6.0 the layout is wrong.
I'm sorry, but I think you are on your own on this one :) Anyone who was ever involved in coding CSS workarounds for IE6 remembers this nightmare very strongly and would not go back to it even if paid lots of money :) If you need your app to work perfectly on IE6, I suggest starting the nightmare, I mean reading, here: http://www.positioniseverything.net/ie-primer.html
[web2py] Re: GAE and Web2Py - Current Issues and some thoughts on Best Practices?
Goggle bigtable support in DAL is already GAE specific. You can also access entities by id (which is returned after insert) or key using DAL. Mixing in native API is possible if needed too, as app portability is lost anyway with GAE. And the non web2py specific things such as N:N relations, debugging or profiling are already described in GAE documentation. However, adding some extra information to the book would be useful. There is already section on GAE there, I see no reason why not to extend it. As you just started playing with it and you see the problems much better, maybe you should join the documentation team and add information as you go?
[web2py] Re: concurrency, web2py, and GAE
You're probably right, access to global variables in mulithreading environment requires extra care. You might find reading this helpful: http://blog.notdot.net/2011/10/Migrating-to-Python-2-7-part-1-Threadsafe
[web2py] Re: $.ajax : how to parse data sent to the controller
if "students" in request.vars: students = json.loads(request.vars.students) print students[0]["student_id"] For python 2.5 you might need to import the simplejson from contrib (I'm not sure if this is done automatically): import gluon.contrib.simplejson as json
[web2py] Re: How to optimize the output typography of blocks in web2py views?
You can do tricks like that, but it does not have the best readability: {{ for i in range(10): }} text {{=i}} text {{ pass }}
[web2py] Re: Validate the Checkbox
The easiest way to do that is rely on web2py model -> form transformation and use a validator (instead of the custom form). model -- MY_OPTIONS = ["a","b","c"] db.define_table("my_table", db.Field("my_options", "list:string", default=MY_OPTIONS)) db.my_table.my_options.widget = SQLFORM.widgets.checkboxes.widget db.my_table.my_options.requires = [IS_IN_SET(MY_OPTIONS, multiple=True), IS_NOT_EMPTY()] controller -- def my_function(): if len(request.args): form=SQLFORM(db.my_table, request.args[0]) else: form=SQLFORM(db.my_table) if form.accepts(request.vars): redirect(URL(r=request, f='my_next_function', args=[form.vars.id])) return {"form":form}
[web2py] Re: crontab sytax
I say the book works just fine: http://web2py.com/book/default/chapter/04#Cron The syntax you want to use is: @reboot * * * * root *applications/test/controllers/private.py Set that in your app/cron/crontab and make sure your controller does db.commit() at the end. Also you need SOFTCRON = True in the wsgihandler (if you run it as WSGI script).
[web2py] Re: deployment
The /var/www folder is just an example. You can put the wsgi.py in your home folder as well. You can also simply use wsgihandler.py that comes with web2py. One or the other has to be set as the WSGI script in the http server configuration. To learn more on deploying web2py applications read this: http://www.web2py.com/books/default/chapter/29/13
[web2py] Re: rendering a view
Right, my bad, I missed the "args" keyword in the URL call. It should be: URL("articles", "show", args=article.id). For more details see the examples given by Anthony.
[web2py] Re: Why admin|examples|welcome in hgignore?
The intention is not to track changes in user made applications (different than the default ones). ?! is the negative lookahead operator, so the first part of the expression will match "applications/" only if it is not followed with any of the strings in the brackets. The the second part (.*) matches everything, so as long as the first part match, the entire sting will match too.
[web2py] Re: deployment
The directory does not exist. Run "mkdir /var/www" first.
[web2py] Re: rendering a view
If all what you want to do is to link to individual items from the main page, you don't need to use redirect at all. Simply add HTML code to your view that would link to /arcticles/show/[id] or /bussiness/show/[id] as needed. {{ for article in articles: }} {{=LI(A(article.title, _href=URL("articles", "show", article.id)))} {{ pass }} Then implement show function in both controllers starting with: def show(): id = request.args[0]
Re: [web2py] Re: [w2py-dev] Re: Movuca - Social CMS beta 0.1
Sorry, I was not precise. I was describing a case in which there is a dependency on a code under a license which is GPL compatible and not compatible with LGPL. So I meant "simpler" in that context. I agree that for projects with no such dependency there would be no difference in "difficulty". I'm looking at the flexibility from a developer point of view. My point is that GPL is compatible with more licenses than LGPL. So under GPL more code can be used. There is always an option to change LGPL to GPL to use that extra code. But as long as you stay with LGPL, some code remains unaccessible to you. So with respect to what code can be included, and if I understood you correctly this is what we were talking about, the GPL is more flexible. Looking from the user point of view, however, it would be different. The LGPL might be seen as giving more choices to the user as it is not copy-left. And when I mentioned abusive tactics, I meant abusive in the sense of the free software philosophy. The goal of free software movement is to replace all proprietary code with free code. If I let people take advantage of my code without sharing back, I would work against that goal, just making the proprietary world stronger. So even if the tactic is not breaking the terms of a license, I still see it as abusive to the free software.
Re: [web2py] Re: [w2py-dev] Re: Movuca - Social CMS beta 0.1
You're right, if you careful enough, you can separate the changes to the CMS code required by your application and release just them. But this is just one of the abusive tactics which GPL protects against. Because how useful would that changes be to others? I believe it would make more sense if others could see how the application code uses the new API or test the app themselves before deciding to include the changes. It is not possible to release a code that depends on GPL components under LGPL. You have to use GPL as an umbrella license. It's simpler to use GPL from the start in such a case. Unless you do that, you want be able to use code under many licenses compatible with GPL but not with LGPL, so there is more flexibility in what code you can include. And as long as you include such code, there is no longer option for LGPL release of the combined work and the original "flexibility" of LGPL does no longer apply. Anyway, it is not flexibilty we should care about, but the preservation of the software freedom.
[web2py] Re: Implementing task queue using web2py
If it worked with different controller my guess is still that the URL you are passing is wrong. Try to simplify it to: taskqueue.add(url=URL('hello'))
Re: [web2py] Re: [w2py-dev] Re: Movuca - Social CMS beta 0.1
LGPL is designed for libraries. Static or dynamic linking to LGPL code is allowed without enforcing copy-left. That means that the derivative work can even be a proprietary software. However, if you change the library code itself, you modification has to be released under LGPL. Since version 3 LGPL is compatible with GPL, which means that the modifications could be released under GPLv3 too. In case of CMS, all these doesn't matter in practice. CMS is not a self-contained isolated library and except of very simple projects, a web application build on top of it will require changes in the CMS code. So commonly, there would be the same copy-left enforcement in place as in case of the GPL. There is also no difference between GPL and LGPL with respect to the server deployment. Both licenses do not see that as distribution, so the deployed code, whatever type of changes it contains, can remain secret. That's why my recommendation was GPLv3, as in this case there is no way to get anything extra from LGPL anyway. I guess the key difference is in the licenses compatibility. Under LGPLv3 you can include all non copy-left free software (BSD, MIT, MPL 2.0, Apache 2.0) but not the code under the GPL (you would have to release the combination under GPLv3, for details see the compatibility matrix [1]). With GPLv3 it's simpler as more licenses are compatible (see the full list [2]), including GPLv2 as long as the phrase "either version 2 of the License, or (at your option) any later version" is present in the copyright notice. For more arguments in the GPL vs LGPL case see [3]. [1] http://www.gnu.org/licenses/gpl-faq.html#AllCompatibility [2] http://www.gnu.org/licenses/license-list.html#GPLCompatibleLicenses [3] http://www.gnu.org/licenses/why-not-lgpl.html
[web2py] Re: Implementing task queue using web2py
Check the app engine requests log to make sure the right task URL is being used.
Re: [web2py] Re: [w2py-dev] Re: Movuca - Social CMS beta 0.1
With web2py being licensed under LGPL it is possible to build applications which are proprietary software. To some degree it is even possible to build another web framework that uses unchanged web2py code as back-end. In practice, however, the latter is too complicated on a technical level. The most common case, direct modification to the framework, have to be covered by LGPL or GPL, so you cannot make a proprietary fork. However, it is possible to create a a proprietary fork in the software as service model. So you can imagine web applications running on a fine tuned version of web2py while this tuning remains secret. Same thing may happen to Movuca if it is not licensed under AGPL. Somebody can take the code, make improvements and run it on a server without offering either binaries or code to her clients. Just the service. Free software movement sees that as unethical. You benefit from the community code, but your code is not shared back with community. With a rise of the cloud platforms this becomes more and more relevant problem and pose a risk to the free software. It is yet another way of circumventing the GPL and changing the free code into a proprietary one (there were others in the past that have been stopped by GPLv3 e.g. tivoization). As Mariano already pointed out, in case of web applications, the LGPL does have much sense as it is equivalent in this context to the GPL. And is always best to minimize confusion and use one of well known licenses rather than creating your own. So as long as you do not see proprietary forks behind server deployments as a problem, the best choice for Movuca is GPLv3.
[web2py] Re: [w2py-dev] Re: Movuca - Social CMS beta 0.1
What I see you are trying to say is that by keeping the code secret one gains a temporary advantage over the competition. That might be true. But this is the way of thinking coming from the proprietary software philosophy. How much will I loose by making the software free? If this is your line of thinking, then maybe writing free software is not what you want to do. Because at the core of the free software movement is a believe, that sharing the code would make the world better. Free software is not here to make us rich. Is not here to make our software easy to (ab)use by business. It is here to preserve out freedoms. It represent an ethical view that sharing knowledge is more important than making money. If you don't agree with that, then the free software is probably not for you. Everyone writing free software should understand that the old business models of proprietary software based on secrecy doesn't apply here. The value is in the collaborative effort to improve the shared code. It shouldn't bother you when somebody else builds on your code and gets ahead of you in terms of features, because this is what you wanted when you decided to write the free software! Instead of complaining that this puts you out of the business you should rather seek for opportunities to collaborate and write more code together which would be good for the business too. And if you want to compete, compete in solving new problems (not the ones that have been already solved, there is no need to duplicate the works of others) and charge your customers for doing that. Now, don't get me wrong. I admit it is not as easy to build a business around the free software as it is in case of proprietary software. But it is not impossible or even especially hard. And is much more fun. This is why we shouldn't give up trying new ways just because they are different to what we know from the proprietary world. On the rise of cloud platforms I see future for the AGPL too.
[web2py] Re: how to deploy web2py not in the apache root (help with url rewriting)
If you have just one application all you need to do is set the web2py WSGI script alias and serve files from the web2py folder excluding admin parts. WSGIDaemonProcess web2py display-name=%{GROUP} WSGIProcessGroup web2py WSGIScriptAlias /prefix /var/www/web2py/wsgihandler.py Options +FollowSymLinks AllowOverride None Order Allow,Deny Deny from all Allow from all AliasMatch ^/prefix/([^/]+)/static/(.*) /var/www/web2py/applications/$1/static/$2 Order Allow,Deny Allow from all Deny from all Deny from all Then set path prefix and the default application in your web2py/routes.py file: routers = dict( # base router BASE = dict( default_application = "app", path_prefix = "prefix", ), ) As a result you will get "domain/prefix" pointing to the default application "app".
[web2py] Re: [w2py-dev] Re: Movuca - Social CMS beta 0.1
I'm not sure if looking at the problem of license from the business point of view is reasonable. If Bruno's goal was to make the business people happy, he would put his software into the public domain. But I'm guessing he is more interested in getting some help from others and maybe building a small community around the project. In my opinion this works best when code is collectively own and protected from abuse (e.g. proprietary forks). The assumed connection between the number of users and a scale of contributions does not sound right to me. Depending on the chosen license there would be different number and type of contributions. Non-copyleft license doesn't encourage contribution, it encourages the use. The code can be taken by everyone who will leave an attribution note for exchange, but usually not more than that. Unless the rate of development of the project is very high, the business would always prefer to fork a project and maintain proprietary changes on their own, over a struggle with upstream integration. Copyleft license encourages the contribution, as it protects the code from being abused, so no risk of being taken advantage of and more likely that some developers will join you. On the users side, however, it scares of "the integrators", people who have a number of different pieces of code that they don't want to or can't release as a free software. The question that remains is if the copyleft licenses can be used by business at all? Let's limit the discussion to the most common case of "customizers", people who adapt software to the needs of their clients (e.g. making extensions or plugins) or use it to build custom products (e.g. websites). Now, we need to remember that when the work is being released, the license is between the business and its client. Not between the business and the entire world. So the freedoms of the software are granted to the client only and it is up to him to decide if he wants to distribute the software any further. If he does, only then he will be bounded by the copyleft clause to do it on the same terms. It doesn't matter if it is AGPL, GPL, LGPL or BSD, the effect here is the same. The only difference is the case of deploying the software on a server, which according to AGPL is a form of distribution and would require making the source code available upon request. However, in practice it is not always a concern, e.g. when the target deployment happens in the intranet. Saying that legal department avoids GPL or AGPL and not saying *why* is not very convincing. Argument from authority is not enough. I could agree, that AGPL might be not very convincing as it seems to give away for what the customer has paid to everyone. However, you have to remember that potential competition is still bounded by the same license. They could copy your customer's website and to distinguish themselves add some extra features, but at the end they will have to release those changes on AGPL too. Now, nothing stops your customer from using what they did on his website. I dare to say, this would create a fast progressing market with lots of competition. Fair competition, without any artificial market barriers. So does it make sense to demonise it as bad for bussiness?
[web2py] Re: [w2py-dev] Re: Movuca - Social CMS beta 0.1
Bruno's work is given for free, and if you don't share your changes back, keep it secret behind the server, it doesn't help the Movuca project. So for Bruno the GPL or even AGPL is a good option, as it keeps the code free (as in freedom). CMS is very different to a framework like web2py, which is only a base for application development and could be seen as similar to a system library. CMS is an application itself. It's not a component used to build bigger projects. The FSF discourage use of LGPL in such cases, because they goal is to spread and increase adoption of the free software. So they favor a scenario in which your software is released under the GPL, as all work derived from it would have to become free software too (which is not the case for LGPL). Also, I don't see any contradiction between GPL or AGPL and "commercial intentions". Your client is paying for a customised solution and is getting one no matter if the license is LGPL, GPL or AGPL. The only difference here is for Bruno and the community of people working with him on the CMS. They might ask for the source code and benefit from changes made by others. The same way as those others benefited in the first place from Bruno's CMS as they didn't have to write it from scratch. It's a win win situation. Where do you guys see problems with adoption and commercial use? GPL will prevent anyone from making a proprietary system that includes your code (LGPL allows that). However, it would be still possible to do it without code distribution, for example in a software as service model. Only AGPL will prevent that, as it requires to make the source available whenever the code is deployed on a server.
[web2py] Re: Too many redirects when trying to use interactive demo
The problem seems to be a redirection loop between this two addresses: 1) http://web2py.com/demo_admin/default/site 2) http://web2py.com/demo_admin/default/index?send=%2Fdemo_admin%2Fdefault%2Fsite Both return 303 and redirect 1 -> 2, and 2 -> 1 until the browser gives up with a message: "Firefox has detected that the server is redirecting the request for this address in a way that will never complete". See attached headers log for details. http://web2py.com/demo_admin GET /demo_admin HTTP/1.1 Host: web2py.com User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.7,pl;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: UTF-8,* DNT: 1 Proxy-Connection: keep-alive Cookie: __utma_a2a=1688569230.1329956564.1298399638.1298400133.1298400137.10; session_id_books=123.123.123.123-411d0ab0-e05f-402d-aad5-32a0fc3c745d; session_id_poweredby=123.123.123.123-6f3c9acc-0ebf-4fe1-aaff-e1e3244f7364; session_id_pdfbuy=123.123.123.123-d28a483d-e1a5-4978-86bc-032867d3846b HTTP/1.0 303 See Other Date: Fri, 03 Feb 2012 13:39:05 GMT Server: Apache/2.2.8 (Ubuntu) mod_wsgi/3.2-BRANCH Python/2.5.2 mod_ssl/2.2.8 OpenSSL/0.9.8g Set-Cookie: session_id_demo_admin=123.123.123.123-9e14f731-c4c8-4cd8-856f-c1c8fc08b313; Path=/; secure Location: /demo_admin/default/site Content-Type: text/html; charset=UTF-8 X-Cache: MISS from proxy.example.com X-Cache-Lookup: MISS from proxy.example.com:3128 Via: 1.0 proxy.example.com:3128 (squid/2.6.STABLE6) Proxy-Connection: close -- http://web2py.com/demo_admin/default/site GET /demo_admin/default/site HTTP/1.1 Host: web2py.com User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.7,pl;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: UTF-8,* DNT: 1 Proxy-Connection: keep-alive Cookie: __utma_a2a=1688569230.1329956564.1298399638.1298400133.1298400137.10; session_id_books=123.123.123.123-411d0ab0-e05f-402d-aad5-32a0fc3c745d; session_id_poweredby=123.123.123.123-6f3c9acc-0ebf-4fe1-aaff-e1e3244f7364; session_id_pdfbuy=123.123.123.123-d28a483d-e1a5-4978-86bc-032867d3846b HTTP/1.0 303 See Other Date: Fri, 03 Feb 2012 13:39:06 GMT Server: Apache/2.2.8 (Ubuntu) mod_wsgi/3.2-BRANCH Python/2.5.2 mod_ssl/2.2.8 OpenSSL/0.9.8g Set-Cookie: session_id_demo_admin=123.123.123.123-21eeb408-fd78-48f0-90d1-2a3039698189; Path=/; secure Location: /demo_admin/default/index?send=%2Fdemo_admin%2Fdefault%2Fsite Content-Length: 105 Content-Type: text/html; charset=UTF-8 X-Cache: MISS from proxy.example.com X-Cache-Lookup: MISS from proxy.example.com:3128 Via: 1.0 proxy.example.com:3128 (squid/2.6.STABLE6) Proxy-Connection: keep-alive -- http://web2py.com/demo_admin/default/index?send=%2Fdemo_admin%2Fdefault%2Fsite GET /demo_admin/default/index?send=%2Fdemo_admin%2Fdefault%2Fsite HTTP/1.1 Host: web2py.com User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.7,pl;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: UTF-8,* DNT: 1 Proxy-Connection: keep-alive Cookie: __utma_a2a=1688569230.1329956564.1298399638.1298400133.1298400137.10; session_id_books=123.123.123.123-411d0ab0-e05f-402d-aad5-32a0fc3c745d; session_id_poweredby=123.123.123.123-6f3c9acc-0ebf-4fe1-aaff-e1e3244f7364; session_id_pdfbuy=123.123.123.123-d28a483d-e1a5-4978-86bc-032867d3846b HTTP/1.0 303 See Other Date: Fri, 03 Feb 2012 13:39:06 GMT Server: Apache/2.2.8 (Ubuntu) mod_wsgi/3.2-BRANCH Python/2.5.2 mod_ssl/2.2.8 OpenSSL/0.9.8g Set-Cookie: session_id_demo_admin=123.123.123.123-5c8046bd-8d1b-49cb-bef8-2ec581ddd334; Path=/; secure Location: /demo_admin/default/site Content-Length: 68 Content-Type: text/html; charset=UTF-8 X-Cache: MISS from proxy.example.com X-Cache-Lookup: MISS from proxy.example.com:3128 Via: 1.0 proxy.example.com:3128 (squid/2.6.STABLE6) Proxy-Connection: keep-alive -- http://web2py.com/demo_admin/default/site GET /demo_admin/default/site HTTP/1.1 Host: web2py.com User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.7,pl;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: UTF-8,* DNT: 1 Proxy-Connection: keep-alive Cookie: __utma_a2a=1688569230.1329956564.1298399638.1298400133.1298400137.10; session_id_books=123.123.123.123-411d0ab0-e05f-402d-aad5-32a0fc3c745d; session_id_poweredby=123.123.123.123-6f3c9acc-0ebf-4fe1-aaff-e1e3244f7364; session_id_pdfbuy=123.123.123.123-d28a483d-e1a5-4978-86bc-0
[web2py] Re: upload field value reset on form failure of another field
So how does it work for other form elements? I'm guessing they are stored in session. So the way to go would be to store the uploaded file in session too and then on form resubmission check what to display. If file is in session the input field should look as on update of an existing object (i.e. having a link to a file next to it). So having a controller as below, we would need to store file on error but also read it to form.vars on validation: def validate(form): # read file from session if form.vars.file is None and session.file: form.vars.file = session.file def test(): form = SQLFORM.factory( Field('file', 'upload'), Field('name', requires=IS_NOT_EMPTY())) if form.process(onvalidation=validate).accepted: response.flash = 'OK' # delete session object session.forget(response) elif form.errors: response.flash = 'errors' # store file in session session.file = form.vars.file return dict(form=form) Unfortunately this doesn't work as file objects cannot be pickled. Any other ideas? Maybe mocking the CGI file with StringIO?
[web2py] Re: DAL level access to GAE entities by named key
Thanks! It works with the query using the "long" syntax: *db(db.table_name.id == key).select().first()* The short version *db.table_name(key)* does returns *None* as it performs a check if key is an integer first. However, using a query instead of a key also works: *db.table_name(db.table_name.id == key)* The other shortcut *db.table_name[key]* could work if the DAL Table code is altered to detect app engine Key instance. See the patch below (also includes your changes). diff -r 3070c65f3e19 gluon/dal.py --- a/gluon/dal.pyMon Oct 17 08:20:27 2011 -0500 +++ b/gluon/dal.pyMon Oct 17 18:01:14 2011 +0100 @@ -3381,10 +3350,10 @@ def select(self,query,fields,attributes): (items, tablename, fields) = self.select_raw(query,fields,attributes) # self.db['_lastsql'] = self._select(query,fields,attributes) -rows = [ -[t=='id' and (int(item.key().id()) if item.key().id() else - item.key().name()) or getattr(item, t) for t in fields] -for item in items] +rows = [] +for item in items: +row = [t=='id' and item.key().id_or_name() or getattr(item, t) for t in fields] +rows.append(row) colnames = ['%s.%s' % (tablename, t) for t in fields] return self.parse(rows, colnames, False) @@ -4913,13 +4860,13 @@ if rows: return rows[0] return None -elif str(key).isdigit(): +elif str(key).isdigit() or isinstance(key, Key): return self._db(self._id == key).select(limitby=(0,1)).first() elif key: return dict.__getitem__(self, str(key))
[web2py] Re: DAL level access to GAE entities by named key
I'm getting nothing (None). If the intention was to having it work this way (by passing key as id) I'll have a look at the DAL code more closely. Maybe something affects the key outside of the select_raw function. Have this ever worked for you?
Re: [web2py] Re: checkbox input default value
Try to define default values for your fields: name = Field("name", "boolean", default=False)
[web2py] Re: checkbox input default value
Are you using "list:string"? Can you post the relevant parts of your model and controller?
[web2py] DAL level access to GAE entities by named key
Is there a way to use DAL to make a GAE query by entity name (not just numeric id)? I remember a discussion on the list about GAE keys with parents and a proposed patch for DAL to be able to pass GAE Key instead of if id. I see this implemented in the DAL code: http://code.google.com/p/web2py/source/browse/gluon/dal.py#3349 So, I was expecting something as simple as this to work: id = request.args[0] key = Key.from_path("data", "label:"+id) entity = db.data[key] But it doesn't. Neither do other variants of a DAL query: entity = db(db.data.id == key).select().first() entity = db.data(key) Only the direct reference to GAE worked: from google.appengine.ext import db as gae entity = gae.get(key) Do I expect too much and the access by GAE Key is not possible with DAL or this should work and can be fixed?
Re: [web2py] App-specific routes using the new router syntax
Hmmm... So this means that app-specific routes are not so useful as I thought. I thought I would be able to get away without the "web2py/routes.py" having all rules defined per application. In other words, I was expecting the default_router to be the default when there is no "web2py/routes.py". But I guess this could break backward compatibility and that's why it was decided against it. It's a pity because with the default router it would be trivial to demonstrate the app-specific routes in examples or welcome app without altering the user defined routes for other apps on version upgrade. Without the default router turned on, defining routes inside application folders makes little sense. It doesn't bring much of the portability as the "global" file is still needed. It is actually easier do to what you suggest, that is define everything in "web2py/routes.py". And that's quite disappointing as I really liked the elegance of self-contained apps. I understand, however, that backward compatibility is more important. Thanks for the explanation.
[web2py] App-specific routes using the new router syntax
I want to use app-specific routes to make my application more portable. Let's assume that there is no "web2py/routes.py" file and my application name is "init". Now I created the "routes.py" file in "web2py/applications/init/" directory and defined my simple router there: my_router = dict( controllers = "DEFAULT", functions = ["about", "privacy", "api"], map_static = True, ) My intention here was to make some URLs shorter: /init/default/about <-> /about /init/static/css/print.css <-> /static/css/print.css After reading the code of rewrite.py:load() I got an impression that I need to define this app-specific router inside a "routers" dictionary. It doesn't make much sense for me, but so be it, I added: routers = {"init":my_router} However this doesn't work for the app-specific routes in "web2py/applications/init/routes.py". On the other hand, it works when put in "web2py/routes.py" so I believe I didn't define the router correctly. As this is not documented precisely and the welcome or example apps have no app-level routes defined either could you please share some more information/examples on this? I've tried to figure out the mechanism from the code but the routes loading procedure is not the easiest one to follow :)
Re: [web2py] Re: How to debug HTTP 500 error on GAE?
I've deleted the logging.conf file.
Re: [web2py] Re: How to debug HTTP 500 error on GAE?
I think you mean the default logging level set to DEBUG as we once discussed here: https://groups.google.com/forum/#!msg/web2py/N2O7WrPJdAE/trGuTFU9cssJ But here we have quite opposite problem, it's not that too much goes to the log but rather that errors were not logged.
[web2py] Re: web2py GAE and memory usage
The exact behaviour of this instance memory control mechanism was not revealed (see http://code.google.com/p/googleappengine/issues/detail?id=1646 ). From your log message it looks like it was the first request that triggered the limit so the garbage collection can hardly be blamed here. And from what I've read, the soft limit exception (in contrast to a hard one) means that a request was allowed to complete before the instance was shut down.
Re: [web2py] Re: How to debug HTTP 500 error on GAE?
Yes. There is no call to session.connect(). As I'm running the app on GAE I wanted to avoid the default file system based session. If this is not default any more and there is no session at all until explicitly created I can safely remove it. The bigger problem here are the logs though. Why would example logging.conf silence the errors like this? I thought it redirects everything >= warning level to the console handler which passes it to stdout. Am I missing something here?
[web2py] Re: web2py GAE and memory usage
The thing is that when you read from datastore you always read all properties of an entity. Each entity can take up to 1MB, so I can imagine reading 500 of them could hit the instance limit. The solution would be to use GAE cursor and cycle your task. In pseudo code: def request_handler(): max_size = 400 # start from the position stored in a cursor if (request.cursor): entities = query(max_size, cursor) else: entities = query(max_size) process(entities) # if not all processing done if entities.size() == max_size: # read cursor cursor = entities.get_cursor() # start new task, pass cursor as parameter queue.add("/request_handler", {"cursor":cursor}) I don't think DAL has a GAE cursor support implemented so the disadvantage of this approach is that you would have to use the GAE API directly.
[web2py] Re: routes for crud
Why not simply use /sr/action/id without any url remapping? What is the advantage of having an argument and function name order reversed? For viewing the record you still need to call a specific function, e.g. /sr/view/1. Anyway, if you want it your way, try this: routes_in = ( ("/sr/(\d+)/(.+)", r"/init/sr/\2/\1"), ("/sr/(\d+)", r"/init/sr/view/\1"), ("/sr", "/init/sr"), )
[web2py] Re: confused on routes.py
Yes, if host.domain.tld/meetings/2011/ points to the MYAPP already, you don't need routes_in. Probably your outgoing routes mapping should look like this: routes_out = ( ("/MYAPP/(.*)", r"/meetings/2011/MYAPP/\1"), )
[web2py] Re: How to debug HTTP 500 error on GAE?
Thanks for the hint! It was the logging indeed. Apparently the logging.conf that comes with web2py was hiding the error: ERROR2011-07-26 18:44:54,452 restricted.py:156] Traceback (most recent call last): File "/home/momat/workspace/pm-cmp-python/web2py/gluon/main.py", line 531, in wsgibase del response.cookies[response.session_id_name] KeyError: 'session_id_init' I find out this was cause by the session.forget() in my db.py. It looks like this way of disabling the session is no longer supported (I guess it is disabled by default now).
[web2py] How to debug HTTP 500 error on GAE?
I'm using the latest GAE 1.5.2 and web2py 1.96.4. When I run the application with: python2.5 /opt/gae-python-sdk/dev_appserver.py --port 8001 ./web2py and open http://localhost:8001 in a browser I get the HTTP 500 internal server error. There is no message in the appserver console output, there is also no error file in web2py/applications/init/errors. I've also deployed the app to GAE as test version to check if there would be some info in the log, but there was none. How can I debug this? There must be a reason why web2py is generating the error but I don't know where to look for clues.