[web2py] How do I do complex validation?
Is there a way in the model file to set a bit more complex set-ups? It is in the book? For examples I have: user_role.id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.id user_role.user_id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.user_id user_role.role_id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.role_id user_role.conference_id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.conference_id user_role.checked_in http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.checked_in and I want to make sure that there is no user_id and conference_id duplicatants. --- Best Regards, Jason Brower
[web2py] Type of computed fields.
Hi, I'm using Version 1.91.6 (2011-01-03 17:55:14) and I'm find this behaviour with computed fields. Is correct, is the type of a computed field always a string? Example: *Define a table with a computed field:* db.define_table('entries', Field http://127.0.0.1:8080/examples/global/vars/Field('f1', 'integer'), Field http://127.0.0.1:8080/examples/global/vars/Field('f2', 'integer'), Field http://127.0.0.1:8080/examples/global/vars/Field('f3', 'integer', compute=lambda r: r['f1'] * r['f2'])) *Insert some data:* db.entries.insert(f1=9, f2=8) *Show data and type:* for r in db(db.entries).select(): ... print r.f1, type(r.f1) ... print r.f2, type(r.f2) ... print r.f3, type(r.f3) ... 9 type 'int' 8 type 'int' 72 type 'str' Thanks - Ian
[web2py] Recaptcha (....,, comment='')
Again... Maybe there should be an additional formal parameter in /gluon/tools.py for Recaptcha.__init__ def __init__ (... comment = '' ): and line 619 should be self.comment = comment Regard, Martin
[web2py] Translation of error_messages for IS_INT_IN_RANGE and similar classes
Some weeks ago there has been a discussion about this problem, but I did not find any solution in the new version 1.93.2 Therefore: may I repeat a proposal? From the description of /gluon/validators.py: Built-in validators have constructors that take the optional argument error message which allows you to change the default error message. Here is an example of a validator on a database table:: db.person.name.requires=IS_NOT_EMPTY(error_message=T('fill this')) where we have used the translation operator T to allow for internationalization. Notice that default error messages are not translated. This solution is not very beautiful, because I have to repeat the string 'fill this', but it works. *It does not work for classes like IS_INT_IN_RANGE,* because there is a lot of error messages, depending on the values: if minimum is None: if maximum is None: self.error_message = error_message or 'enter an integer' else: self.maximum = int(maximum) if error_message is None: error_message = 'enter an integer less than or equal to %(max)g' self.error_message = error_message % dict(max=self.maximum-1) elif maximum is None: self.minimum = int(minimum) if error_message is None: error_message = 'enter an integer greater than or equal to %(min)g' self.error_message = error_message % dict(min=self.minimum) else: self.minimum = int(minimum) self.maximum = int(maximum) if error_message is None: error_message = 'enter an integer between %(min)g and %(max)g' self.error_message = error_message % dict(min=self.minimum, max=self.maximum-1) Using the T-operator there is no way to translate these error message for example to German. And I think it looks very unprofessional to have mixes English and German messages. My proposal: I have changed the following lines (file validators.py, class IS_INT_IN_RANGE) def __init__( self, minimum=None, maximum=None, error_message=None, *T=lambda x:x, # One additional parameter with a default value* ): self.minimum = self.maximum = None if minimum is None: if maximum is None: self.error_message = error_message or *T('enter an integer') * else: self.maximum = int(maximum) if error_message is None: error_message = *T('enter an integer less than or equal to %(max)g')* self.error_message = error_message % dict(max=self.maximum-1) elif maximum is None: self.minimum = int(minimum) if error_message is None: error_message = *T('enter an integer greater than or equal to %(min)g')* self.error_message = error_message % dict(min=self.minimum) else: self.minimum = int(minimum) self.maximum = int(maximum) if error_message is None: error_message = *T('enter an integer between %(min)g and %(max)g')* self.error_message = error_message % dict(min=self.minimum, max=self.maximum-1) And I have used it in the following way: Field('number', type='integer', requires=IS_INT_IN_RANGE(2,5,*T=T*), label=T('number')), Now every error message can be translated using the usual way. Advantages: - It is not necessary to repeat error messages as in IS_NOT_EMPTY(error_message=T('fill this')) (remember: Dont repeat yourself) - It's full compatible with current programs. - Every nested error message could be translated. Disadvantage: - To use this feature there has to be an additional parameter on calling the constructor, e.g. requires=IS_INT_IN_RANGE(2,5,*T=T*) But without this parameter it works like the current version. Are there any other disadvantages in my solution? Or is there any other solution? Of course, every class in validators.py should be changed in this way. Maybe this solution would be useful for the file tools.py too? Regards, Martin
[web2py] Re: Error in templating system
I thought that after the = I could only write one string/variable/ function with string output which is wrapped in write... Anything else I could put in non-python block... Never mind. I can live with what you choose as solution :) Just I say it was working before :-o I will stay with web2py anyway :-D On márc. 5, 03:22, Jonathan Lundell jlund...@pobox.com wrote: On Mar 4, 2011, at 6:03 PM, villas wrote: On Mar 4, 10:22 pm, Thadeus Burgess thade...@thadeusb.com wrote: I don't think you should have code included in a {{= block. +1 Explicit is better {{if abc:}} {{=xyz}} {{pass}} Yes, there are extra brackets, but no one's going to have a problem with that. That would continue to work regardless. Right now we have two rules, and it's hard to explain why. {{=abc abc = 123}} ...fails. But {{abc = 123 =abc}} ... is fine. And so is {{abc = 123 =abc abc = 456}} {{pass =abc pass}} is fine. But {{=abc pass}} ...is not. That's a strange set of rules, if you ask me. And confusing, as we've already seen, especially since the error message is not helpful.
[web2py] customize error messages
Hello I can customize some error messages like this: IS_NOT_IN_DB(db, custom_auth_table.email, error_message=T('email already used'))] But how can I customise error messages if there are more than 1 error message? For example: IS_STRONG(min=8,max=None,upper=None,lower=None,special=None,number=None, error_message=T('just one message for too much variants???'))
[web2py] Vertical superfish menu doesn't work well, how about yours?
Hi there, I stayed with web2py 1.79 for quite some time, and am now keeping up with 1.92, oh, and latest 1.93. Lots of improvements. Wow. One minor, minor problem so far. When I try to use the new superfish menu system to produce a vertical menu, I found the menu can show up BUT, the first level of sub-menu fully overlaps with the main menu. That is not the same effect as in superfish official website http://users.tpg.com.au/j_birch/plugins/superfish/#sample3 I examined 3 superfish css files but did not find any suspect. Anyone who is interested to investigate please put following code into your controller to see it in action. Thanks in advance! Regards, Iceberg Luo def test(): response.files.append(URL(request.application,'static','css/ superfish-vertical.css')) return {'':MENU( [ (T('Item 1'), False, URL('default','test/1'), [ (T('Item 1-1'), False, URL('default','test/11'), []), (T('Item 1-2'), False, URL('default','test/12'), []), (T('Item 1-3'), False, URL('default','test/13'), []), ]), (T('Item 2'), False, URL('default','test/2'), []), (T('Item 3'), False, URL('default','test/3'), []), ], _class='sf-menu sf-vertical')}
[web2py] Re: mssql, login problems
As it doesn't seem possible to change self._uri in SQLDB, I solved the problem by adding an extra keyword argument (which travels to SQLDB): Database_Name = r'mssql://NKCV2 *MSSQL_Login = ';UID=MY_SQL_LOGIN;PWD=MY_PASSWORD' *My_DB = DAL ( Database_Name, folder = folder, *MSSQL_Login = MSSQL_Login* ) cheers, Stef On 05-03-2011 00:34, Stef Mientki wrote: hello, With the DAL I created tables in an MSSQL database, which I can access as long as I login as the same user. I created the table with a windows login on my own machine, like this Database_Name = r'mssql://NKCV2' My_DB = DAL ( Database_Name, folder = folder ) Now I'm on anther machine, I can not use the windows login, so I use a MSSQL login ( I found the syntax by trial and error) *Database_Name = r'mssql://NKCV2;UID=MY_SQL_LOGIN;PWD=MY_PASSWORD' *My_DB = DAL ( Database_Name, folder = folder ) The login works, I can contact de database, with the DAL is trying to create new tables (which I'm not allowed, and as far as know, I don't need to because they are already there) File P:\Python26\lib\site-packages\gluon\sql.py, line 1100, in lambda self._execute = lambda *a, **b: self._cursor.execute(*a, **b) ProgrammingError: ('42000', [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]CREATE TABLE permission denied in database 'NKCV2'. (262) (SQLExecDirectW)) Could this be caused, by the DAL creating other filenames to store the table information ? Any suggestions to solve this problem ? thanks, Stef Mientki
Re: [web2py] Re: DAL new syntax RFC
Field(':name') and Field('.name') Is very hard to read. Especially : Field('.name') . When writing large applications with many lines of codes , . is very very hard to read. On 3/5/11, Luther Goh Lu Feng elf...@yahoo.com wrote: I too like the 'default' syntax much better than the new one. It feels more readable. If the following is feasible, will it be a better solution? Field('name', r=F,w=F) Field('name', d='value') On Mar 5, 7:50 am, Massimo Di Pierro massimo.dipie...@gmail.com wrote: think of a dot a False. Two does r and w are false, one dot and only w is false. On Mar 4, 4:43 pm, pbreit pbreitenb...@gmail.com wrote: I like the default functionality since it's still really easy to understand. I'm not sold on the : and . shortcuts.
[web2py] Re: Weird self submitting forms all checkbox is checked after submit
With the new 1.93.2 there is no issue... :) On márc. 4, 15:29, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Which web2py version? I cannnot reproduce it? If latest, can you post some code to reproduce it? On Mar 4, 6:12 am, szimszon szims...@gmail.com wrote: If I Submit form data which contains checkbox (boolean) field I got back the form with all checkbox selected... The database operation is ok. Just the returning form is displayed with all checkbox checked...
[web2py] is there a function to increase a sql field
Hi, I want to know is there a function to add 1 to a sql field, or else I have to select to get the value of the field and then add 1 to the value, then update the field. Thanks.
[web2py] Little bug in admin/.../edit.html
Symptom: when you save controller content, then disapears list of available views in gray box. 1.1 --- a/applications/admin/views/default/edit.html Fri Mar 04 17:46:21 2011 -0600 1.2 +++ b/applications/admin/views/default/edit.html Sat Mar 05 16:09:19 2011 +0100 1.3 @@ -24,15 +24,15 @@ 1.4 h2{{=T('Editing file %s',filename)}}/h2 1.5 1.6 {{if functions:}} 1.7 -div style=text-align:left; id=exposed 1.8 - p class=formfield{{=B(T('exposes:'))}} 1.9 - {{=XML(', '.join([A(f,_href=URL(a=app,c=controller,f=f)).xml() for f in functions]))}} 1.10 + p class=formfield 1.11 +span style=text-align:left; id=exposed 1.12 + {{=B(T('exposes:'))}}{{=XML(', '.join([A(f,_href=URL(a=app,c=controller,f=f)).xml() for f in functions]))}} 1.13 +/span 1.14{{if editviewlinks:}}br/ 1.15{{=B(T('edit views:'))}} 1.16{{=XML(', '.join([v.xml() for v in editviewlinks]))}} 1.17{{pass}} 1.18/p 1.19 -/div 1.20 {{pass}} 1.21 1.22 p class=right controls Best regards Milan Melena
Re: [web2py] Translation of error_messages for IS_INT_IN_RANGE and similar classes
On Mar 5, 2011, at 4:01 AM, Martin Weissenboeck wrote: This solution is not very beautiful, because I have to repeat the string 'fill this', but it works. It does not work for classes like IS_INT_IN_RANGE, because there is a lot of error messages, depending on the values: if minimum is None: if maximum is None: self.error_message = error_message or 'enter an integer' else: self.maximum = int(maximum) if error_message is None: error_message = 'enter an integer less than or equal to %(max)g' self.error_message = error_message % dict(max=self.maximum-1) elif maximum is None: self.minimum = int(minimum) if error_message is None: error_message = 'enter an integer greater than or equal to %(min)g' self.error_message = error_message % dict(min=self.minimum) else: self.minimum = int(minimum) self.maximum = int(maximum) if error_message is None: error_message = 'enter an integer between %(min)g and %(max)g' self.error_message = error_message % dict(min=self.minimum, max=self.maximum-1) Using the T-operator there is no way to translate these error message for example to German. And I think it looks very unprofessional to have mixes English and German messages. 1.93 was intended as a stable release without big changes, so that it can serve as the ongoing release for legacy support of Python 2.4. We'll have general support for translation in gluon fairly soon. In the meantime, using T in the constructor for IS_INT_IN_RANGE should work just fine. Is there some specific case that isn't working for you?
Re: [web2py] customize error messages
On Mar 5, 2011, at 4:18 AM, LightOfMooN wrote: I can customize some error messages like this: IS_NOT_IN_DB(db, custom_auth_table.email, error_message=T('email already used'))] But how can I customise error messages if there are more than 1 error message? For example: IS_STRONG(min=8,max=None,upper=None,lower=None,special=None,number=None, error_message=T('just one message for too much variants???')) You only need to customize it for the combination of requirements that you're specifying in that particular case. In your example, T('password must be at least 8 characters')
Re: [web2py] How do I do complex validation?
I´d say you have to create your own validator so achive that. Kenneth Is there a way in the model file to set a bit more complex set-ups? It is in the book? For examples I have: user_role.id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.id user_role.user_id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.user_id user_role.role_id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.role_id user_role.conference_id http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.conference_id user_role.checked_in http://127.0.0.1:8000/InterestID3/appadmin/select/db?orderby=user_role.checked_in and I want to make sure that there is no user_id and conference_id duplicatants. --- Best Regards, Jason Brower
[web2py] Re: One form for multiple tables
Hi Denes, I believe you want something like this: That's exactly what I wanted, thanks! Kind regards, Annet.
[web2py] Re: Multiple form flash problem.
Denes and Jonathan, Thank you both for your replies, now I do understand the logic of the function. @Denes, So, in Python you can only simulate a CASE statement using if's? Could you provide me with an example? Kind regards, Annet
Re: [web2py] Re: Multiple form flash problem.
On Mar 5, 2011, at 8:44 AM, annet wrote: So, in Python you can only simulate a CASE statement using if's? Could you provide me with an example? The first reply here is useful: http://stackoverflow.com/questions/594442/choosing-between-different-switch-case-replacements-in-python-dictionary-or-if
Re: [web2py] is there a function to increase a sql field
update tabl1 set field1=field1+1 where your_condition db(some dal condtion like: db.table1.id0).update(field1=db.table1.field1+1)
Re: [web2py] is there a function to increase a sql field
Thanks a lot. It works. On Sun, Mar 6, 2011 at 1:13 AM, Vasile Ermicioi elff...@gmail.com wrote: update tabl1 set field1=field1+1 where your_condition db(some dal condtion like: db.table1.id0).update(field1=db.table1.field1+1)
Re: [web2py] How do I do complex validation?
Check here: http://web2py.com/book/default/chapter/07#Custom-Validators
Re: [web2py] Re: DAL new syntax RFC
Obviously those of us who don't like it don't have to use it but I fear it going into documentation and leading to confusion. This is where I like one of the zens: There should be one-- and preferably only one --obvious way to do it.
[web2py] Re: Error in templating system
There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident?
[web2py] Re: DAL new syntax RFC
think of a dot a False. Two does r and w are false, one dot and only w is false. IMHO: It's very short to write, but nearly impossible to guess its meaning. Wouldn't Field('readonly:name') and Field('invisible:name') be more readable ?
Re: [web2py] Re: Error in templating system
On Mar 5, 2011, at 11:18 AM, pbreit wrote: There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident? Leading spaces get stripped (between {{ and =), so that wasn't relevant (in this case).
[web2py] Re: web2py still unable to create application on WebFaction
Dear Christopher and All, Something like you, Christopher, suggested was also suggested by the Webfaction Support folks. This suggestion worked for me, after I had investigated some other possibilities. You can read my blog post on this subject, Fixing my my web2py is unable to create a new application on WebFaction problem, which references THIS web2py-users thread for a full discussion of the problem. Here is the link http://joecodeswell.blogspot.com/2011/02/fixing-my-my-web2py-is-unable-to-create.html Thanks for the help. Love and peace, Joe On Mar 1, 3:54 pm, Christopher Steel chris.st...@gmail.com wrote: If you really want to do this you shodl be able to but first you need to ssh in and manually start Web2py from webapps/yourapp/web2py with something like the following: python2.5 web2py.py -p 80 Then shut it down and try again from the web interface Let me know how it goes... On 1 mar, 07:48, Saf Hulou saf.hu...@gmail.com wrote: I have the same problem. Installed today. Admin allows me to edit current apps such as the examples app - can create new views etc. No new apps though. Help would be much appreciated... Thanks, Saf On Feb 22, 4:15 pm,JoeCodeswelljoecodesw...@gmail.com wrote: Dear Webfacton Support and web2py-users Google Group, ref: web2py-users Google Group thread Unable to create application on WebFaction the link is in the text below. I just made a flurry of webfaction tickets about memory usage and upgrading my account. Actually doing an upgrade. This was because i had just used the web2py Custom Installation Script from the WebFaction Control Panel to install a new web2py instance. When i went to add a new app to the new web2py, up came a message saying unable to create application home (it may exist already). I tried every name in the book but to no avail. I googled the problem, and one entry showed there could be a memory issue. That is the cause of the flurry of tickets. Now i have found out that the memory issue is NOT the problem. I have plenty of memory, having upgraded, but i still get the bad behaviour. I have done more research on the problem in the web2py-users Google Group. There is a recent [Dec 15, 2010] thread on this subject which seems to imply that running the web2py Custom Installation Script from the Control Panel causes a critical directory [deposit] to be left off the installation. Here is the link to that thread:http://groups.google.com/group/web2py/browse_thread/thread/98d3d1d2de... I have looked at both of my web2py installations and they both have a deposit directory, but i still cannot create an app in my w2p_mobyjoe installation. I can easily create a new app on the old instance. Here is the output: new application justforkicks created. Does anyone have any ideas? I am cross posting this on both the web2py-users Google Group and WebFaction Ticket System. All of the folks in both of these groups are very supportive. Thanks in advance. Love and peace, Joe
[web2py] Re: Vertical superfish menu doesn't work well, how about yours?
On Mar 6, 3:11 am, pbreit pbreitenb...@gmail.com wrote: That might be tricky to troubleshoot. It may have to do with a conflicting CSS style. Have you used the Inspect Element in Google Chrome? Is Item 1 the problem? Can you see anything unusual in the style list on the right? I included a screen shot of mine. These can unfortunately be tricky to resolve. Screen shot 2011-03-05 at 11.10.38 AM.png 256KViewDownload Thanks for the clue. I'll check it later. Cause it's after midnight in my timezone now. -_- Besides, you screen shot is NOT relevent to the problem. The default horizontal menu bar works fine I believe. Only the vertical menu does not show good. If you try my source code, I guess you can reproduce the issue on your environment.
Re: [web2py] Re: web2py still unable to create application on WebFaction
On Mar 5, 2011, at 11:35 AM, JoeCodeswell wrote: Something like you, Christopher, suggested was also suggested by the Webfaction Support folks. This suggestion worked for me, after I had investigated some other possibilities. You can read my blog post on this subject, Fixing my my web2py is unable to create a new application on WebFaction problem, which references THIS web2py-users thread for a full discussion of the problem. Here is the link http://joecodeswell.blogspot.com/2011/02/fixing-my-my-web2py-is-unable-to-create.html Do we know what's going on here? I'm guessing that it's the initialization of the admin password.
[web2py] Re: Bugfix for CheckboxesWidget
On Jan 31, 7:58 am, Bernd Rothert roth...@googlemail.com wrote: This patch fixes the CheckboxesWidget as a replacement for the MultipleOptionsWidget in list:reference fields. list:reference fields use the IS_IN_DB(...,multiple=True) validator. Its options() method returns possible choices a list of string tuples (key, label) to be used in HTML option tags and checkboxes. So the widget has to convert the current values of the reference field to strings as well before comparing them to the string keys returned by options() - see value=(k in values). Without the conversion the checkboxes won't show the current values - there won't be any check marks. diff -r 6e655c2a202d gluon/sqlhtml.py --- a/gluon/sqlhtml.py Sat Jan 29 22:49:21 2011 -0600 +++ b/gluon/sqlhtml.py Sun Jan 30 22:53:07 2011 +0100 @@ -328,7 +328,10 @@ # was values = re.compile('[\w\-:]+').findall(str(value)) - values = not isinstance(value,(list,tuple)) and [value] or value + if isinstance(value, (list, tuple)): + values = [str(v) for v in value] + else: + values = [str(value)] attr = OptionsWidget._attributes(field, {}, **attributes) Cheers Bernd Hi Bernd Massimo, Does the above patch ever go into trunk? I see no change in latest source code, perhaps that's why the problem still exists in latest web2py 1.93.2. Background: The web2py book suggests that the default SQLFORM.widgets.multiple.widget can be replaced with SQLFORM.widgets.checkboxes.widget for list:reference fields. I tried it but the checkboxes did not show any check marks (because of the int/ string mismatch according to Bernd). Regards, Iceberg Luo
[web2py] Re: Error in templating system
It was on purbose. On márc. 5, 20:18, pbreit pbreitenb...@gmail.com wrote: There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident?
Re: [web2py] Re: Error in templating system
On Mar 5, 2011, at 12:16 PM, szimszon wrote: It was on purbose. If so, it has only a cosmetic effect; the parser strips the spaces. On márc. 5, 20:18, pbreit pbreitenb...@gmail.com wrote: There was also a suggestion that the space before the = might have been an issue: {{ =XML(msg)}} Is that space in there on purpose or by accident?
[web2py] Re: DAL new syntax RFC
I agree with Stefaan. However the ':' before a variable name notation looks like the Ruby symbols whose only purpose was improved performance (lightweight strings) but lead inevitably to confusion (IMHO). On Mar 4, 5:55 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: There are some new features in trunk: 1) I got tired of writing default='value',readable=False,writable=False etc. So: Field(':name') is the same as Field('name',readable=False,writable=False) Field('.name') is the same as Field('name',readable=True,writable=False) Field('name=value') is the same as Field('name',default='value') and combinations: Field(':name=value') is the same as Field('name',default='value',readable=True,writable=False) notice Field('name=') is the same as Field('name',default='') 2) db(db.table).select((db.table.field.length()+5).sum()) note operators length(), +5, sum() can be combined in more ways than before.
[web2py] Just a typo in change log.
In the change log page http://www.web2py.com/examples/default/changelog the version should be 1.93.1-2 instead 1.63.1-2 i guess. btw I think the last changes should be shown first so I dont have to scrolldown all the page :P
Re: [web2py] Re: web2py still unable to create application on WebFaction
On Mar 5, 2011, at 12:07 PM, Jonathan Lundell wrote: On Mar 5, 2011, at 11:35 AM, JoeCodeswell wrote: Something like you, Christopher, suggested was also suggested by the Webfaction Support folks. This suggestion worked for me, after I had investigated some other possibilities. You can read my blog post on this subject, Fixing my my web2py is unable to create a new application on WebFaction problem, which references THIS web2py-users thread for a full discussion of the problem. Here is the link http://joecodeswell.blogspot.com/2011/02/fixing-my-my-web2py-is-unable-to-create.html Do we know what's going on here? I'm guessing that it's the initialization of the admin password. On second thought, that's not it. It'd be good to track it down and fix it, though.
[web2py] Re: Vertical superfish menu doesn't work well, how about yours?
Hello Iceberg,I had the same issue just few hours ago, the problem is that superfish-vertical.css is applied before superfish.css when you use response.files.append() and overwrites some css styles. One solution could be editing the /view/layout.html adding the superfish-vertical.css after. In 43 line {{#-- require CSS and JS files for this page (read info in base.css) --}} {{response.files.append(URL('static','css/base.css'))}} {{response.files.append(URL('static','css/superfish.css'))}} {{response.files.append(URL('static','css/superfish- vertical.css'))}} {{response.files.append(URL('static','js/superfish.js'))}} {{#-- include web2py specific js code (jquery, calendar, form stuff) --}} Remember delete response.files.append(URL(request.application,'static','css/ superfish-vertical.css')) from your controller. Tested and works fine.
[web2py] Hiding default error messages, Part 2
Hi all, I recently had to deal with a very similar situation to: http://groups.google.com/group/web2py/browse_thread/thread/ad5a9494c4bb06fb/f88a913ee7514197?lnk=gstq=custom+forms#f88a913ee7514197 -- The original message: I still seem to be missing something. Must be obvious but I can't see it. I use the example code you showed, and the errors dict shows the values and form.errors is now an empty dict, but the error messages still get displayed in the old manner without me doing anything. It's as if the error messages are displayed from somewhere else, but I can't see where. I put this line of code towards the top of my view:-- {{(errors,form.errors)=(form.errors,dict())}} Then I display errors and form.errors to make sure they have what I expect. Form.errors is empty. Now I would expect not to see any errror messages unless I place them myself. Unfortunately, they still appear in the old position as though I had made no changes. What have I overlooked. John Aherne -- After some poking around, I found the bit of code that renders the error message, even on custom controls. You can disable the error message attached to individual controls by writing the following code: {{form.custom.widget.name_of_widget['hideerror'] = True}} If you want to remove all the error messages without prejudice, you can do the following: for widget in form.custom.widget: try: form.custom.widget[widget]['hideerror'] = True except: pass I believe there's a setting to do this globally (crud.hide_errors or something?) but I haven't needed it yet. If someone needs it I'd be happy to point them in the right direction. Unfortunately I'm a year past the original message, but perhaps this will be useful to someone.
[web2py] Re: Multiple form flash problem.
Hi Annet, It wasn't obvious to me why you needed two forms. Why not use one and test to see what has been filled in? Just another idea. Regards, David On Mar 5, 4:44 pm, annet annet.verm...@gmail.com wrote: Denes and Jonathan, Thank you both for your replies, now I do understand the logic of the function. @Denes, So, in Python you can only simulate a CASE statement using if's? Could you provide me with an example? Kind regards, Annet
Re: [web2py] Re: DAL new syntax RFC
Explicit is better than implicit. Typing is cheap. Design is the hardest part of development. -- Thadeus On Sat, Mar 5, 2011 at 2:52 PM, Vidul Petrov vidul.r...@gmail.com wrote: I agree with Stefaan. However the ':' before a variable name notation looks like the Ruby symbols whose only purpose was improved performance (lightweight strings) but lead inevitably to confusion (IMHO). On Mar 4, 5:55 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: There are some new features in trunk: 1) I got tired of writing default='value',readable=False,writable=False etc. So: Field(':name') is the same as Field('name',readable=False,writable=False) Field('.name') is the same as Field('name',readable=True,writable=False) Field('name=value') is the same as Field('name',default='value') and combinations: Field(':name=value') is the same as Field('name',default='value',readable=True,writable=False) notice Field('name=') is the same as Field('name',default='') 2) db(db.table).select((db.table.field.length()+5).sum()) note operators length(), +5, sum() can be combined in more ways than before.
Re: [web2py] Re: Error in templating system
Ok, when put into this context I agree, it should be fixed. It should all behave the same. -- Thadeus On Fri, Mar 4, 2011 at 8:22 PM, Jonathan Lundell jlund...@pobox.com wrote: s a strange set of rules, if you ask me. And confusing, as we've already seen, especially since the error message is not hel
Re: [web2py] Re: DAL new syntax RFC
+1 2011/3/6 Thadeus Burgess thade...@thadeusb.com: Explicit is better than implicit. Typing is cheap. Design is the hardest part of development. -- Thadeus On Sat, Mar 5, 2011 at 2:52 PM, Vidul Petrov vidul.r...@gmail.com wrote: I agree with Stefaan. However the ':' before a variable name notation looks like the Ruby symbols whose only purpose was improved performance (lightweight strings) but lead inevitably to confusion (IMHO). On Mar 4, 5:55 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: There are some new features in trunk: 1) I got tired of writing default='value',readable=False,writable=False etc. So: Field(':name') is the same as Field('name',readable=False,writable=False) Field('.name') is the same as Field('name',readable=True,writable=False) Field('name=value') is the same as Field('name',default='value') and combinations: Field(':name=value') is the same as Field('name',default='value',readable=True,writable=False) notice Field('name=') is the same as Field('name',default='') 2) db(db.table).select((db.table.field.length()+5).sum()) note operators length(), +5, sum() can be combined in more ways than before.
[web2py] explanation of corrections in version 1.93.2
File read-me 193.2 ## 1.63.1-2 - This and an error? correct 1.93.2?? - support for multiple interfaces, thanks Jonathan What is This??? - jquery 1.5.1 - simplejson 2.1.3 - customizable simplejson - leaner app.yaml - css3 buttons in welcome - What is This??? - android support (experimental) What is This??? - Field(':hidden'), Field('.readonly'), Field('name=value') What is This??? - combined expressions print db.data.body.len().sum() What is This??? - wizard can download plugins What is This??? - better json serilization (object.custom_json) - better xml serialization (object.custom_xml) - better formstyle support - better comet_messaging.py (needs more testing) What is This??? - many bug fixes -- Ovidio Marinho Falcao Neto ovidio...@gmail.com Tecnologia da Informaçao Casa Civil do Governador 83 3214 7885 - 88269088 Paraiba
[web2py] invalid request
i have to comunicate beetwen 2 files with url. for example *http://127.0.0.1/myapp/default/page * ... *http://127.0.0.1myapp/default/page?q=abcdefg* a dont have page?q=abcdefg file so web2py shows me invalid request. how can i solve this problem? i'm a litle noob in web2py and english,sry
Re: [web2py] Re: Error in templating system
On Mar 5, 2011, at 4:38 PM, Thadeus Burgess wrote: Ok, when put into this context I agree, it should be fixed. It should all behave the same. I'll create some more unit tests to expose the current behavior and then remove the special case. In the meantime, the workaround is to observe this rule: if a code block begins with '=' (not counting initial whitespace), then the entire code block should be on one line. Example: {{ =this }} {{ =but not this}} One exception: I assume (and will test) that this is OK: {{ =some long string }} ...which doesn't make sense on its own, but might with interpolation. -- Thadeus On Fri, Mar 4, 2011 at 8:22 PM, Jonathan Lundell jlund...@pobox.com wrote: s a strange set of rules, if you ask me. And confusing, as we've already seen, especially since the error message is not hel
[web2py] How to make a simple counter
Hi guys, I am pretty new to web2py and really enjoy learning this neat framework. However, I've just encountered a problem, while trying to developing a simple image gallery. I want to put a simple counter under each image, but could not figure out how to do so. Here are the relevant code db.define_table('image', Field('title','string', required=True), Field('file', 'upload', required=True), Field('category',required=True), Field('created_on', 'datetime', default=request.now), Field('created_by', db.auth_user, default=auth.user_id), Field('visits', 'integer', default=0), format='%(name)s') --C O N T R O L L E R (unsuccessful) -- def show(): image = db.image(request.args(0)) or redirect(URL('index')) db.comment.image_id.default = image.id form = crud.create(db.comment, message='your comment is posted', next=URL(args=image.id)) comments = db(db.comment.image_id==image.id).select() visits = db.image(request.args(0)).visits visits.viist(+=1) #visits = db.image(request.args(0)).update_record(visits) return dict(image=image, comments=comments, form=form, visits=visits) #---V I E W--- {{extend 'layout.html'}} h1Photo: {{=image.title}}/h1 center img width=200px src={{=URL('download', args=image.file)}} / pVisits: {{=visits}}/p /center {{if len(comments):}} h2Comments/h2br /p {{for comment in comments:}} p{{=comment.author}} Wrote: i{{=comment.body}}/i/p {{pass}}/p {{else:}} h2No comments posted yet/h2 {{pass}} h2Post a comment/h2 {{=form}} I appreciate your help.
[web2py] error when insert record in appadmin
Hi all, I have a strange behaviour in appadmin trying to insert a record. It happens with all my tables except for auth's (auth_user, auth_group, etc). This is the error message: class 'pyodbc.ProgrammingError'(('42000', [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ')'. (102) (SQLExecDirectW))) I tried to understand the ticket created and could find this at gluon\dal.py in insert at line 717: locals query : 'INSERT INTO my_table() VALUES ();' Does it means it created an empty query? I'm on win7, python 2.6, web2py 1.92.1 from sources. Thanks in advance, Joaquin.
[web2py] web2py applications and apache vhosts
Hello guys, I know that this question has been posted a couple of times in this group but it seems that there is no answer yet... I have web2py installed with apache via wsgi. Everything works fine. Instead of having multiple web2py instances, I want each domain to point to a different application inside the same web2py instance. For example domain1.com will be app1, domain2.com will be app2 etc. I know that this can be done with routes, but If someone has many applications (performance-wise) it is better to be done with apache's virtual hosts. So, can anyone please provide an example apache config script? Thank you.
[web2py] Re: Type of computed fields.
I can't reproduce this with 1.91.6 nor 1.92.1, both show r.f3 as int. On Mar 5, 4:19 am, imm ianmm...@googlemail.com wrote: Hi, I'm using Version 1.91.6 (2011-01-03 17:55:14) and I'm find this behaviour with computed fields. Is correct, is the type of a computed field always a string? Example: *Define a table with a computed field:* db.define_table('entries', Field http://127.0.0.1:8080/examples/global/vars/Field('f1', 'integer'), Field http://127.0.0.1:8080/examples/global/vars/Field('f2', 'integer'), Field http://127.0.0.1:8080/examples/global/vars/Field('f3', 'integer', compute=lambda r: r['f1'] * r['f2'])) *Insert some data:* db.entries.insert(f1=9, f2=8) *Show data and type:* for r in db(db.entries).select(): ... print r.f1, type(r.f1) ... print r.f2, type(r.f2) ... print r.f3, type(r.f3) ... 9 type 'int' 8 type 'int' 72 type 'str' Thanks - Ian
Re: [web2py] explanation of corrections in version 1.93.2
Ovidio, Para definir writable e readable fazemos o seguinte: db.define_table('tabela', Field('nome'), Field('idade')) db.tabela.nome.writable=db.tabela.nome.readable = False O Massimo falou que estava cansado de ter que escrever toda vez writable... readable Então ele criou essa estrutura: Field(':hidden'), Field('.readonly'), Field('name=value') Na tabela que defini acima, fica da seguinte forma: Field(':nome') é o mesmo que: Field('nome', writable=False, readable=False) Field('.nome') é o mesmo que: Field('nome', writable=False, readable=True) Field('nome=Bruno') é o mesmo que Field('nome', default='Bruno') Field(':nome=Bruno') é o mesmo que Field('nome', default='Bruno', writable=False) Espero que tenha ajudado em algo... # --- # Bruno Barbosa # Seja livre - Use Linux!!! # http://algoritmizando.com # http://twitter.com/bruninbsb # --- 2011/3/5 Ovidio Marinho ovidio...@gmail.com File read-me 193.2 ## 1.63.1-2 - This and an error? correct 1.93.2?? - support for multiple interfaces, thanks Jonathan What is This??? - jquery 1.5.1 - simplejson 2.1.3 - customizable simplejson - leaner app.yaml - css3 buttons in welcome - What is This??? - android support (experimental) What is This??? - Field(':hidden'), Field('.readonly'), Field('name=value') What is This??? - combined expressions print db.data.body.len().sum() What is This??? - wizard can download plugins What is This??? - better json serilization (object.custom_json) - better xml serialization (object.custom_xml) - better formstyle support - better comet_messaging.py (needs more testing) What is This??? - many bug fixes -- Ovidio Marinho Falcao Neto ovidio...@gmail.com Tecnologia da Informaçao Casa Civil do Governador 83 3214 7885 - 88269088 Paraiba
[web2py] Re: error when insert record in appadmin
Update: I've tried SQLite and it's the same problem: class 'sqlite3.OperationalError'(near ): syntax error) locals query : 'INSERT INTO my_table() VALUES ();' Any kind of help will be appreciated. Joaquin. On Sat, Mar 5, 2011 at 3:09 PM, Joaquin Orbe joaquino...@gmail.com wrote: Hi all, I have a strange behaviour in appadmin trying to insert a record. It happens with all my tables except for auth's (auth_user, auth_group, etc). This is the error message: class 'pyodbc.ProgrammingError'(('42000', [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ')'. (102) (SQLExecDirectW))) I tried to understand the ticket created and could find this at gluon\dal.py in insert at line 717: locals query : 'INSERT INTO my_table() VALUES ();' Does it means it created an empty query? I'm on win7, python 2.6, web2py 1.92.1 from sources. Thanks in advance, Joaquin.
[web2py] Re: How to make a simple counter
Wow, hard to say but you definitely have some problems. For example, the typo in visits.viist(+=1). Are you getting error messages or is it just not doing what you want? Something like this perhaps? This code only adds one line to what is shown in the Book: image.update_record(visits=image.visits + 1). One thing to do is only make one db.table call per controller. You usually only need to access the database once per table. And in this case, you only need to do an image.update_record to increment the visits. def show(): image = db.image(request.args(0)) or redirect(URL('index')) db.comment.image_id.default = image.id form = crud.create(db.comment, message='your comment is posted', next=URL(args=image.id)) comments = db(db.comment.image_id==image.id).select() image.update_record(visits=image.visits + 1) return dict(image=image, comments=comments, form=form) === show.html === ... pVisits: {{=image.visits}}/p ...
[web2py] Difference between IS_HTTP_URL and IS_URL?
Is there a substantive difference between IS_HTTP_URL and IS_URL?
Re: [web2py] Difference between IS_HTTP_URL and IS_URL?
On Mar 5, 2011, at 10:09 PM, Chris wrote: Is there a substantive difference between IS_HTTP_URL and IS_URL? IS_URL is a front end to IS_HTTP_URL or IS_GENERIC_URL, and also handles unicode input.
[web2py] Re: Vertical superfish menu doesn't work well, how about yours?
On Mar 6, 5:51 am, luismurciano luismurci...@gmail.com wrote: Hello Iceberg,I had the same issue just few hours ago, the problem is that superfish-vertical.css is applied before superfish.css when you use response.files.append() and overwrites some css styles. One solution could be editing the /view/layout.html adding the superfish-vertical.css after. In 43 line {{#-- require CSS and JS files for this page (read info in base.css) --}} {{response.files.append(URL('static','css/base.css'))}} {{response.files.append(URL('static','css/superfish.css'))}} {{response.files.append(URL('static','css/superfish- vertical.css'))}} {{response.files.append(URL('static','js/superfish.js'))}} {{#-- include web2py specific js code (jquery, calendar, form stuff) --}} Remember delete response.files.append(URL(request.application,'static','css/ superfish-vertical.css')) from your controller. Tested and works fine. Thanks, Luismurciano! You are the man! (Or woman anyway.) By the way, an alternative is using out-of-box layout.html, but change my controller into: .. return {'':DIV( LINK(_href=URL(request.application,'static','css/superfish- vertical.css'), _rel=stylesheet, _type=text/css), MENU(..), )}
[web2py] Re: Little bug in admin/.../edit.html
Hi Milan, can you please email me the patch as an attachment? On Mar 5, 9:25 am, Milan Melena milan.mel...@gmail.com wrote: Symptom: when you save controller content, then disapears list of available views in gray box. 1.1 --- a/applications/admin/views/default/edit.html Fri Mar 04 17:46:21 2011 -0600 1.2 +++ b/applications/admin/views/default/edit.html Sat Mar 05 16:09:19 2011 +0100 1.3 @@ -24,15 +24,15 @@ 1.4 h2{{=T('Editing file %s',filename)}}/h2 1.5 1.6 {{if functions:}} 1.7 -div style=text-align:left; id=exposed 1.8 - p class=formfield{{=B(T('exposes:'))}} 1.9 - {{=XML(', '.join([A(f,_href=URL(a=app,c=controller,f=f)).xml() for f in functions]))}} 1.10 + p class=formfield 1.11 +span style=text-align:left; id=exposed 1.12 + {{=B(T('exposes:'))}}{{=XML(', '.join([A(f,_href=URL(a=app,c=controller,f=f)).xml() for f in functions]))}} 1.13 +/span 1.14 {{if editviewlinks:}}br/ 1.15 {{=B(T('edit views:'))}} 1.16 {{=XML(', '.join([v.xml() for v in editviewlinks]))}} 1.17 {{pass}} 1.18 /p 1.19 -/div 1.20 {{pass}} 1.21 1.22 p class=right controls Best regards Milan Melena
[web2py] Re: Just a typo in change log.
Can you help us please? Download the README file from web2py/ and reorder the items. On Mar 5, 2:54 pm, luismurciano luismurci...@gmail.com wrote: In the change log pagehttp://www.web2py.com/examples/default/changelog the version should be 1.93.1-2 instead 1.63.1-2 i guess. btw I think the last changes should be shown first so I dont have to scrolldown all the page :P
[web2py] Re: DAL new syntax RFC
OK, I will probably take it off... do not count on this feature being backward compatible, yes I need to sleep on it some more. On Mar 5, 6:49 pm, Michele Comitini michele.comit...@gmail.com wrote: +1 2011/3/6 Thadeus Burgess thade...@thadeusb.com: Explicit is better than implicit. Typing is cheap. Design is the hardest part of development. -- Thadeus On Sat, Mar 5, 2011 at 2:52 PM, Vidul Petrov vidul.r...@gmail.com wrote: I agree with Stefaan. However the ':' before a variable name notation looks like the Ruby symbols whose only purpose was improved performance (lightweight strings) but lead inevitably to confusion (IMHO). On Mar 4, 5:55 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: There are some new features in trunk: 1) I got tired of writing default='value',readable=False,writable=False etc. So: Field(':name') is the same as Field('name',readable=False,writable=False) Field('.name') is the same as Field('name',readable=True,writable=False) Field('name=value') is the same as Field('name',default='value') and combinations: Field(':name=value') is the same as Field('name',default='value',readable=True,writable=False) notice Field('name=') is the same as Field('name',default='') 2) db(db.table).select((db.table.field.length()+5).sum()) note operators length(), +5, sum() can be combined in more ways than before.
[web2py] boolean type in MySQL: CHAR(1) vs TINYINT(1)
I'm connecting to a legacy MySQL database (migrate=False) with a lot of fields declared BOOLEAN, and noticed that attempts to modify these fields with the DAL failed. The DAL issues a query like this: UPDATE sometable SET someflag='T' WHERE ... but this gets rejected by MySQL. Reading through dal.py, I see that the boolean type maps to CHAR(1) in MySQLAdapter, and represent() converts to T and F values. However, the BOOLEAN type is a synonym for TINYINT(1) in MySQL, with values 0 or 1, according to: http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html I can trivially change this behavior in dal.py for my purposes, but it would be interested to try to incorporate this into the main web2py distribution. Unfortunately, the trivial change will break backwards compatibility for people who are already depending on the current behavior. Any thoughts on how this could be done in a backwards- compatible way, or is it too much of an edge case to worry about? Cheers, Kevin
[web2py] Version typo in latest changelog
The latest changelog entry has a small typo: the version is listed as 1.63.1-2, but I believe it should be 1.93.1-2. http://web2py.com/examples/default/changelog Hopefully this is the appropriate place to report that sort of thing. Cheers, Kevin
Re: [web2py] Translation of error_messages for IS_INT_IN_RANGE and similar classes
Ok, compatibility is a reason I understand. You are right: if I make a decision, which error message would be appropriate for each single field it works fine. If there is a lot of fields with IS_INT_IN_RANGE requirements like T('enter an integer between %(min)g and %(max)g') I will use an additional variable, e.g.: mm=T('enter an integer between %(min)g and %(max)g') db.pet.legs.requires=IS_INT_IN_RANGE(0,9,mm) 2011/3/5 Jonathan Lundell jlund...@pobox.com On Mar 5, 2011, at 4:01 AM, Martin Weissenboeck wrote: This solution is not very beautiful, because I have to repeat the string 'fill this', but it works. *It does not work for classes like IS_INT_IN_RANGE,* because there is a lot of error messages, depending on the values: if minimum is None: if maximum is None: self.error_message = error_message or 'enter an integer' else: self.maximum = int(maximum) if error_message is None: error_message = 'enter an integer less than or equal to %(max)g' self.error_message = error_message % dict(max=self.maximum-1) elif maximum is None: self.minimum = int(minimum) if error_message is None: error_message = 'enter an integer greater than or equal to %(min)g' self.error_message = error_message % dict(min=self.minimum) else: self.minimum = int(minimum) self.maximum = int(maximum) if error_message is None: error_message = 'enter an integer between %(min)g and %(max)g' self.error_message = error_message % dict(min=self.minimum, max=self.maximum-1) Using the T-operator there is no way to translate these error message for example to German. And I think it looks very unprofessional to have mixes English and German messages. 1.93 was intended as a stable release without big changes, so that it can serve as the ongoing release for legacy support of Python 2.4. We'll have general support for translation in gluon fairly soon. In the meantime, using T in the constructor for IS_INT_IN_RANGE should work just fine. Is there some specific case that isn't working for you?