[web2py] Escaping placeholders for db.executesql in MySQL.
Here's an example of a problem that I have with a MySQL database and escaping of executesql placeholders. I am using web2py 1.99.7 on Ubuntu with Python2.5 testDAL works, but testDB throws this error: (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1\\'')' at line 1") Is there some additional escaping that I need to do for testDB ? Thanks, Chris Guest SQL: CREATE TABLE `test1` ( `ID` int(11) NOT NULL auto_increment, `Text` varchar(5000) default NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB; model: db.define_table( 'test1', Field('Text', 'string'), ) controller: textStr = '1' def testDB(): reprTextStr = repr(textStr) test1 = db.executesql("insert into test1 (t1) VALUES (%s)", placeholders =(reprTextStr,)) return dict(success=1) def testDAL(): reprTextStr = repr(textStr) test1 = db.test1.insert(Text=reprTextStr) test1_id = db._adapter.lastrowid('test1') return dict(test1_id=test1_id) SELECT * FROM test1 -> ; ++--+ | ID | Text | ++--+ | 2 | '1' | | 3 | '1' | | 4 | '1' | ++--+ --
[web2py] Re: Escaping placeholders for db.executesql in MySQL.
I opened the ticket as you suggested and you've confirmed that in executesql the values in the placeholders argument are passed directly to the driver without escaping. I've tried doing the same call with the MSSQL adaptor using the pyodbc driver. db.executesql("insert into test1 (t1) VALUES (?)", placeholders =("'1'",)) This time the values are escaped and all is well. So I am still unclear if this is a web2py bug in the implementation of executesql or a difference in how the underlying drivers perform. I also note that there was a change in drivers from MySQLdb to pymysql in web2py 1.90 . I will also try this testDB method with 1.89.1 . In the short term, as I want to use executesql with both MSSQL and MySQL I will probably write a wrapper function like this: def executesql(db, query, placeholders=None, as_dict=False): if db._name=='mssql': query = query.replace('%s', '?') elif db._name=='mysql': if placeholders is not None: placeholders = mysql_escape(placeholders) return db.executesql(query, placeholders, as_dict) Is there a single mysql_escape function that I should be using from the pymysql driver or should I be writing my own? On Wednesday, October 10, 2012 1:31:59 PM UTC+11, Massimo Di Pierro wrote: > > Please open a ticket about this. I can fix it later tonight or tomorrow. > > --
[web2py] Re: Escaping placeholders for db.executesql in MySQL.
Thanks Massimo. That worked for me. --
[web2py] Passing pyodbc timeout argument for a specific request.
I'm using SQL Server with pyodbc on Linux. ( Web2py 1.99.7 ) I have been trying to force a database timeout in certain methods in my controller. I added the following conditional to models/db.py db_connection_string='mssql://dbuser:pwd@dbserver/DB?DRIVER=FreeTDS' if request.function == 'test_wait': db = DAL(db_connection_string, migrate=migrate, driver_args=dict(timeout=3)) else: db = DAL(db_connection_string, migrate=migrate, pool_size=100) and this method to my controller: def test_wait(): db.executesql("WAITFOR DELAY '00:00:30'") return 'OK' I had presumed that the timeout argument would be passed to pyodbc.connect and I get a timeout error raised. Instead I am seeing 'OK' returned. Is there a better way to enforce a query timeout? Chris Guest --
[web2py] Logging SQL statements.
Currently, my sql.log contains the DAL generated SQL statements that were used to generated the database schema. Is there a way to log all SQL statements that DAL generates? I am getting a SQL error after I customised my Auth tables for a legacy database, and I'd like to see exactly what SQL is being generated. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Logging SQL statements.
Thanks, that worked. I made this change to gluons/tools.py until I captured the error. def insert(self, **fields): query = self._insert(**fields) self._db['_lastsql'] = query * logging.error('insert:\n%s'%query) ... On Apr 1, 12:55 pm, mdipierro wrote: > The last sql statement is in db._lastsql so you can do a try catch and > print (or log) the value of that variable on error. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Using primarykey on the auth tables.
I have a client requirement for tables in my database to be prefixed with 'tbl_' and to have an ID field caled recid. For legacy purposes, auth_user is implemented as a VIEW on an existing table. For this reason, my use of the Auth module is becoming quite customised. I had presumed that including the following arguments in the table definition would map the table's ID to the correct field. Field('recid','id') primarykey=['recid'] However, I am getting this error: Traceback (most recent call last): File "gluon/restricted.py", line 173, in restricted exec ccode in environment File "/var/www/web2py/web2py.1.76.5/applications/MyApp/models/ db.py", line 104, in migrate=False) File "gluon/sql.py", line 1263, in define_table **dict(primarykey=args['primarykey'])) File "gluon/sql.py", line 2105, in __init__ field.requires = sqlhtml_validators(field) File "gluon/sql.py", line 465, in sqlhtml_validators requires = validators.IS_IN_DB(field._db,referenced.id, File "gluon/sql.py", line 1573, in __getattr__ return dict.__getitem__(self,key) KeyError: 'id' Here is an example of the customisation that I have made in db/ models.py : # tbl_auth_user auth.settings.table_user_name = 'view_auth_user' passfield = auth.settings.password_field table = db.define_table( auth.settings.table_user_name, Field('recid','id'), Field('first_name', length=50, default='', label=auth.messages.label_first_name), Field('last_name', length=50, default='', label=auth.messages.label_last_name), Field('long_name', length=50, default='', label='Long Name'), Field('email', length=512, default='', label=auth.messages.label_email), Field('username', length=15, default='', unique=True), Field(passfield, 'password', length=512, readable=False, label=auth.messages.label_password), Field('registration_key', length=512, writable=False, readable=False, default='', label=auth.messages.label_registration_key), primarykey=['recid'], migrate=False, format='%(first_name)s %(last_name)s (%(id)s)' ) table.first_name.requires = \ IS_NOT_EMPTY(error_message=auth.messages.is_empty) table.last_name.requires = \ IS_NOT_EMPTY(error_message=auth.messages.is_empty) #table[passfield].requires = [CRYPT(key=auth.settings.hmac_key)] table.email.requires = \ [IS_EMAIL(error_message=auth.messages.invalid_email), IS_NOT_IN_DB(db, '%s.email' % auth.settings.table_user_name)] table.username.requires = IS_NOT_IN_DB(db, table.username) table.registration_key.default = '' auth.settings.table_user = db[auth.settings.table_user_name] view_auth_user has the following fields: RECID FIRST_NAME LAST_NAME LONG_NAME PASSWORD2 USERNAME EMAIL REGISTRATION_KEY The traceback falls over on line 104 of modesl/db.py which is the end of db.define_table call below: # auth_membership auth.settings.table_membership_name = 'tbl_auth_membership' table = db.define_table( auth.settings.table_membership_name, Field('recid','id'), Field('user_id', auth.settings.table_user, label=auth.messages.label_user_id), Field('group_id', auth.settings.table_group, label=auth.messages.label_group_id), primarykey=['recid'], migrate=False) table.user_id.requires = IS_IN_DB(db, '%s.recid' % auth.settings.table_user_name, '%(first_name)s %(last_name)s (%(recid)s)') table.group_id.requires = IS_IN_DB(db, '%s.recid' % auth.settings.table_group_name, '%(role)s (%(recid)s)') auth.settings.table_membership = db[auth.settings.table_membership_name] Regards, Chris Guest -- To unsubscribe, reply using "remove me" as the subject.
[web2py] Re: Using primarykey on the auth tables.
Denes, I also went down this path and this is what I got. When the Auth class references self.user.id it appears to be expecting that the user table will have a field called 'id'. From glancing at the code it appears that self.user.id is expected to be a key in a Storage , so in effect the name of the id field is hard coded. Traceback (most recent call last): File "gluon/restricted.py", line 173, in restricted exec ccode in environment File "/var/www/web2py/web2py.1.76.5/applications/MyApp/controllers/ default.py", line 434, in File "gluon/globals.py", line 96, in self._caller = lambda f: f() File "/var/www/web2py/web2py.1.76.5/applications/MyApp/controllers/ default.py", line 81, in user return dict(form=auth()) File "gluon/tools.py", line 723, in __call__ return self.login() File "gluon/tools.py", line 1130, in login self.log_event(log % self.user) KeyError: 'id' Below is a patch for gluons/tools.py, that uses auth.settings.id_field to determine the id field. It fixes the errors that I was having, but I haven't tested it extensively and I'm not sure if I'm missing something obvious in my configuration that would remove the need for this change. Chris Guest 580a581 > self.settings.id_field = 'id' 955a957,959 > if self.settings.id_field!='id': > user.id = user[self.settings.id_field] > 1108a1113,1114 > if self.settings.id_field!='id': > user.id = user[self.settings.id_field] 1263a1270,1271 > if self.settings.id_field!='id': > user.id = user[self.settings.id_field] -- To unsubscribe, reply using "remove me" as the subject.
[web2py] MySQL insert on table with_alias causing error
I am running web2py.2.0.9 and I get an error on doing INSERTS with MySQL if I define a table with an Alias. Apparently the DAL will attempt to do this SQL: INSERT INTO tbl_favourite_header AS favourite_header(CreationDate,Description,ChangeDate,MemberID) VALUES ('2013-03-01 12:12:10', 'my favourite', '2013-03-01 12:12:10', 3) My table definition looks like this: db.define_table( 'tbl_favourite_header', Field('Description', 'string'), Field('CreationDate', 'datetime'), Field('ChangeDate', 'datetime'), Field('MemberID', 'integer'), Field('GroupID', 'integer'), ).with_alias('favourite_header') I get this execption when I try to do an insert. Traceback (most recent call last): File "/var/www/web2py/web2py.2.0.9/gluon/restricted.py", line 209, in restricted exec ccode in environment File "/var/www/web2py/web2py.2.0.9/applications/abc/controllers/favourites.py", line 176, in File "/var/www/web2py/web2py.2.0.9/gluon/globals.py", line 186, in self._caller = lambda f: f() File "/var/www/web2py/web2py.2.0.9/applications/abc/controllers/favourites.py", line 80, in create MemberID=session.member.rid File "/var/www/web2py/web2py.2.0.9/gluon/dal.py", line 7798, in insert ret = self._db._adapter.insert(self,self._listify(fields)) File "/var/www/web2py/web2py.2.0.9/gluon/dal.py", line 1142, in insert raise e ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS favourite_header(CreationDate,Description,ChangeDate,MemberID) VALUES ('2013-' at line 1") I have encountered this error before in previous version of web2py and generally patched it by doing something like this: diff gluon/dal.00.py gluon/dal.py 1133c1133,1134 < return 'INSERT INTO %s(%s) VALUES (%s);' % (table, keys, values) --- > tableName = ('%s' % table).split(' ')[0] > return 'INSERT INTO %s(%s) VALUES (%s);' % (tableName, keys, values) I appreciate that this is a fairly naive approach as it assumes that the table name will never have a space in it. I wonder if someone could come up with a more robust fix to this problem. Chris -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Web2py won't connect to MSSQL
I recently had a similar problem where I could import pyodbc at the python shell, but I was getting a DLL error when I tried to import pyodbc under mod_wsgi. I suggest that you put "import pyodbc" inside your wsgihandler.py (or at the top of db.py) and see what errors are being produced. I had recently had this problem and resolved it by following the steps described here: http://code.google.com/p/pyodbc/issues/detail?id=214 Chris Guest
[web2py] Mixing Internationalisation and Business Idiom
I have a conceptual issue about how I design some aspects of an application. I need to make my app customisable with respect to business idiom and in the longer term, I would like my app to embrace internationalisation. I'm curious to know if anyone has ever tackled the issue of business idiom in a systematic way like internationalisation. AN example would be if I deploy my app at three different multinational companies. CompanyA likes to call their stores "Stores". CompanyB likes to call their stores "Sites". CompanyC likes to call their stores "Shops". I'd ideally like to do something like have an en-gb.py , en-us.py and then also have a 2ndary set of idiomatic translations such as en- companya.py en-companyb.py and en-companyc.py . Of course this isn't standard practice and I would have to write my own custom version of T . I'm curious to find out what solutions other developers may have had for this kind of problem.
[web2py] Change in Row structure for queries on tables with_alias.
I've just deployed 1.98.2 and noticed that some of the with_alias behaviour has changed. With 1.89.1, if I defined my tables like this: db.define_table( 'tbl_site', Field('Code', 'integer'), Field('Name', 'string'), Field('Active', 'integer') ).with_alias('site') db.define_table( 'tbl_site_description', Field('SiteCode', 'integer'), Field('Description', 'string'), Field('ImageLarge', 'string'), Field('ImageSmall', 'string'), Field('LongName', 'string') ).with_alias('site_description') and ran this query: siteResults = db(db.site.Active==1).select(db.site.ALL, db.site_description.Description, left=db.site_description.on(db.site.Code==db.site_description.SiteCode)) I would get a row structure that looked like this: at 0xbd9c610c>, 'SiteCode': 55101L, 'delete_record': at 0xbd9c6144>, 'Active': 1, 'Name': 'Home'}>, 'tbl_site_description': }> Now I get this row structure. at 0x7fa453cad8c0>, 'SiteCode': 55101L 'delete_record': at 0x7fa453cad938>, 'Active': 1, 'Name': 'Home'}>, 'site_description': }> The simplest workaround for me is to define a helper function like this: def _getRowAttr(row, attr, attrAlias): return attr in row and row[attr] or row[attrAlias] and call _getRowAttr(row, 'site', 'tbl_site') when I need to make my code compatible with an older version. This doesn't bother me too much, but I'm wondering if this behaviour was intentional or an artefact of a new feature. Is it likely to stay this way?
[web2py] DAL connection to SQL Server 2005 hanging with Linux
I have setup web2py version 1.98.2 on Ubuntu Lucid Lynx. My dal is connecting to SQL Server 2005 using a connection string like this. db_connection_string = r'mssql://dbuser:pword92.168.1.1/mydb? DRIVER=FreeTDS' After my application has been running for some hours or days, there seems to some kind of deadlock occurring upon connection to the dal: db = DAL(config.db_connection_string, migrate=False) Once this happens in one request it happens in all requests and all non-static web2py requests time out. I am not seeing any errors in the logs, apart from being told it has timed out: [info] [client 192.168.1.231] Request header read timeout There are at present 33 open connections to the SQL Server db (including 4 from web2py). From my understanding the maximum number of connections is 32767. So I'm curious if anyone else has seen this kind of behaviour or if there are any suggestions as to how this may be debugged.
[web2py] Using SQLCustomType to implement bigint in MySQL
I am trying to define a custom type on a MySQL db and I get the error below. My motivation is to store data in Bigint rather than Integer. bigint = SQLCustomType( type = 'integer', native = 'bigint', ) db.define_table('s1', Field('target_id', bigint) ) db.s1.insert(target_id=55142201924) I presume that I don't need to specify an encoder or a decoder. The table creation is fine, but subsequent insert statements fail. Once the tables are created, I can replace bigint with 'integer' and everything works smoothly. But I'm wondering if I am missing something crucial in my db.py . Traceback (most recent call last): File "/home/www-data/web2py.1.99.2/gluon/restricted.py", line 194, in restricted exec ccode in environment File "/home/www-data/web2py.1.99.2/applications/groupiedev/models/ db.py", line 84, in db.s1.insert(target_id=55142201924) File "/home/www-data/web2py.1.99.2/gluon/dal.py", line 4976, in insert return self._db._adapter.insert(self,self._listify(fields)) File "/home/www-data/web2py.1.99.2/gluon/dal.py", line 880, in insert query = self._insert(table,fields) File "/home/www-data/web2py.1.99.2/gluon/dal.py", line 876, in _insert values = ','.join(self.expand(v,f.type) for f,v in fields) TypeError: sequence item 0: expected string, int found
[web2py] Re: From html view to pdf.
Annet, When I explored this a few years ago, I ended up going with an XML solution called RML (report markup language). This was developed by the makers of reportlab, but there are also free implemntations of RML available (such as the z3c implementation.) Once I had installed rml2pdf developed XML templates, I used a pdf view like this in order to render my RML to pdf. RML is very well documented, and I think you will find examples that are very similar to your requirements. Chris {{ import gluon.contenttype import StringIO import z3c.rml.rml2pdf as rml2pdf resp = StringIO.StringIO() rml = response.render('%s/%s.xml' % (request.controller,request.function)) filename = '%s.pdf'%request.function resp = rml2pdf.parseString(rml, filename=filename) #creates the pdf response.headers['Content-Type'] = gluon.contenttype.contenttype('.pdf') response.headers['Content-disposition'] = "attachment; filename= \"%s\"" % filename response.write(resp.read(), escape=False) }}
[web2py] New Application Wizard - Layout Themes and Plugins
I have noticed that the "New Application Wizard" ( /admin/wizard/step1 ) does not contain any Layout Themes or Plugins. See attachment. According to this post ( https://groups.google.com/d/msg/web2py/frUArP3gp6w/PCx2Z-3gxIkJ ) from 2011, these selections are populated by these AJAX calls: http://www.web2py.com/plugins/default/plugins.json http://www.web2py.com/plugins/default/plugins.json I have listed the results that I am getting below and I have also attached a screen shot of what the page looks like. I am just trying to determine if this is a broken feature in the Wizard or if I have something odd with my local setup. (I have setup web2py on my local linux VM at a site that uses lots of firewalls and proxies to get between me and the internet.) Are others seeing the same behaviour that I am getting? Is this Wizard still the preferred way of deploying a new site? I am using Version 2.9.12-stable+timestamp.2015.01.17.06.11.03 Thanks, Chris -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] web2py spreadsheet.py - does it use cache.ram correctly?
I am taking a look at the spreadsheet controller in /examples/spreadsheet in web2py Version 2.9.12 (on CentOS 6.6) . The callback function is throwing this error. Traceback (most recent call last): File "/var/www/web2py/gluon/restricted.py", line 224, in restricted exec ccode in environment File "/var/www/web2py/applications/examples/controllers/spreadsheet.py", line 12, in File "/var/www/web2py/gluon/globals.py", line 393, in self._caller = lambda f: f() File "/var/www/web2py/applications/examples/controllers/spreadsheet.py", line 4, in callback return cache.ram('sheet1', lambda: None, None).process(request) AttributeError: 'NoneType' object has no attribute 'process' I can't see other examples of code that call a ram.cache().process() method. Is this code using some defunct functionality? I can see a lot of uses for this spreadsheet module and would be very happy to assist with getting it working out of the box. Does anyone have a working example that they can point me to? Chris -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: web2py spreadsheet.py - does it use cache.ram correctly?
>From what I can see, the call in the index function works fine, but the problem is in all calls to the callback. Would it work better with a session data instead of cache.ram? On Monday, February 16, 2015 at 4:24:51 PM UTC+11, Massimo Di Pierro wrote: > > I was wrong in saying I was wrong. The example in spreadsheet.py says: > > def callback(): > > return cache.ram('sheet1', lambda: None, > None).process(request) > > > def index(): > > # standard spreadsheet method > > sheet = cache.ram('sheet1', > > lambda: Sheet(10, 10, URL(r=request, f='callback')), 0) > > so the index() function stores a Sheet object in the cache.ram, the > callback function retrieves it and calls a method of that object. Notice > there is a problem. This only works when you have a single process sharing > cache.ram. > > On Sunday, 15 February 2015 21:08:11 UTC-6, Massimo Di Pierro wrote: >> >> That line is clearly wrong! >> >> On Sunday, 15 February 2015 19:06:31 UTC-6, chris_g wrote: >>> >>> >>> I am taking a look at the spreadsheet controller in >>> /examples/spreadsheet in web2py Version 2.9.12 (on CentOS 6.6) . >>> >>> The callback function is throwing this error. >>> >>> >>> Traceback (most recent call last): >>> File "/var/www/web2py/gluon/restricted.py", line 224, in restricted >>> exec ccode in environment >>> File >>> "/var/www/web2py/applications/examples/controllers/spreadsheet.py", line >>> 12, in >>> File "/var/www/web2py/gluon/globals.py", line 393, in >>> self._caller = lambda f: f() >>> File >>> "/var/www/web2py/applications/examples/controllers/spreadsheet.py", line 4, >>> in callback >>> return cache.ram('sheet1', lambda: None, None).process(request) >>> AttributeError: 'NoneType' object has no attribute 'process' >>> >>> >>> I can't see other examples of code that call a ram.cache().process() >>> method. Is this code using some defunct functionality? >>> >>> I can see a lot of uses for this spreadsheet module and would be very >>> happy to assist with getting it working out of the box. >>> >>> Does anyone have a working example that they can point me to? >>> >>> Chris >>> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Using SQLFORM.grid to create a parent-child form
I have two tables with a 1-to-many relationship that I would like to represent in a parent-child form. SQLFORM.grid plays quite nicely with the children data, but what I'd like to do is include a row at the top of the form that includes parent data. This is really only a need to add some editable and non-editable options at the top of the field. Is this possible? Could someone show me a simple example of how it can be done? Chris Guest -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Customisable error messages for a form determined by device type.
I am happily using the web2py FORM and custom validator's for form validation using JSON messaging. The problem I have is a customer wants verbose messages for webpages, but succinct messages for everything else. For eg, On the webpage "You must enter an email address", "A password is required", " is an invalid post code" while on an iPhone app or Mobile Webpage, "email required", "password required", "invalid postcode". Device type is easy enough to determine by data from request.user_agent(), so that isn't a big issue. I'm just curious to see how others approach this kind of situation. Obviously, I'd like to keep my registration method and FORM object function common so I don't have to maintain the same code in multiple places. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Use IS_MATCH for optional form entry
How do I use IS_MATCH for field validation if the field only contains data? This works for me: IS_MATCH('^\d{10}', extract=True, error_message='Telephone number should have 10 digits.') so long as a 10 digit number is required. But what if I a want to make it acceptable to enter a 10 digit number or leave the field blank? Is there a way to make the IS_MATCH validator checked only if a non-empty string has been passed to the FORM for that field? Apologies if this is a very obvious question - but I've tried several approaches and haven't come up with a satisfactory solution. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Use IS_MATCH for optional form entry
Thank you Johann, that worked for me. On Monday, April 7, 2014 4:52:34 PM UTC+10, Johann Spies wrote: > > On 7 April 2014 08:21, chris_g > wrote: > > >> How do I use IS_MATCH for field validation if the field only contains >> data? >> >> This works for me: >> IS_MATCH('^\d{10}', extract=True, error_message='Telephone number should >> have 10 digits.') >> >> so long as a 10 digit number is required. >> >> But what if I a want to make it acceptable to enter a 10 digit number or >> leave the field blank? >> >> Is there a way to make the IS_MATCH validator checked only if a non-empty >> string has been passed to the FORM for that field? >> > > What about IS_EMPTY_OR(IS_MATCH('^\d{10}', extract=True, > error_message='Telephone number should have 10 digits.')) ? > > Regards > Johann > -- > Because experiencing your loyal love is better than life itself, > my lips will praise you. (Psalm 63:3) > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py:/] Re: Other new DAL features in trunk
This is marvellous news. I read the manual last night and realised that the field ID restriction was the only thing stopping me deploying web2py in conjunction with a major legacy app that I am using. Thanks Michael for getting this feature happening. Can I confirm one thing, with a table like this: create table store ( ID int, StoreID int, Name varchar(60) ) where I want to use StoreID as the 'id' field, but there happens to be an existing field called 'ID'. I have this situation because due to some historical replication issues. Chris Guest --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~--~~~~--~~--~--~---
[web2py] xhtml2pdf / pisa in a web2py view
Has anyone had any luck running Pisa in a web2py view? I've only had success with using it at the command line: pisa example.html --> pisa.pdf I've tried putting the following in a view, but I am getting an empty string returned. {{ import logging import os import StringIO import xhtml2pdf.pisa as pisa filename = '%s/%s.html' % (request.controller,request.function) if os.path.exists(os.path.join(request.folder,'views',filename)): html=response.render(filename) else: html=BODY(BEAUTIFY(response._vars)).xml() pass result = StringIO.StringIO() pdf = pisa.CreatePDF(html, result) =result.read() }} --
[web2py] Re: xhtml2pdf / pisa in a web2py view
I believe I need to use a file reference to the html like this: pdf = pisa.CreatePDF( StringIO.StringIO(html) , result) But I am still getting an empty string. --
[web2py] Re: xhtml2pdf / pisa in a web2py view
Thanks Paolo. The code in that plugin was helpful (although I ended up with different formatting of my PDF using appreport) than I do with the standalone product. Anyway, putting this in my controller worked for me. (There was a bug in my original code - using the read method of StringIO instead of getvalue .) def report_pisa(): results = dict(success=1) if request.extension=="pdf": import xhtml2pdf.pisa as pisa import StringIO html = response.render('report/report_pisa.html', results) doc = StringIO.StringIO() pdf = pisa.CreatePDF(html, dest = doc) return doc.getvalue() return results On Sunday, November 11, 2012 8:53:21 PM UTC+11, Paolo Caruccio wrote: > > did you try appreport (a web2py plugin) > https://github.com/lucasdavila/web2py-appreport ? > > > Il giorno domenica 11 novembre 2012 06:39:21 UTC+1, chris_g ha scritto: >> >> >> Has anyone had any luck running Pisa in a web2py view? >> I've only had success with using it at the command line: >> pisa example.html >> --> pisa.pdf >> >> I've tried putting the following in a view, but I am getting an empty >> string returned. >> >> {{ >> import logging >> import os >> import StringIO >> import xhtml2pdf.pisa as pisa >> filename = '%s/%s.html' % (request.controller,request.function) >> if os.path.exists(os.path.join(request.folder,'views',filename)): >>html=response.render(filename) >> else: >>html=BODY(BEAUTIFY(response._vars)).xml() >> pass >> result = StringIO.StringIO() >> pdf = pisa.CreatePDF(html, result) >> =result.read() >> }} >> >> >> >> --
[web2py] Integrating iPhone device tokens into web2py auth
I'm looking into supporting Apple push notifications in an iPhone app that connects to a web2py server. In order to know which devices to push details to, web2py's auth module would presumably need to maintain "Device Tokens". I'm curious if anyone has implemented a solution that takes care of this. I'd like to see how it was integrated with web2py's auth. Thanks, Chris -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: Integrating iPhone device tokens into web2py auth
Thanks for all the interesting responses. Here is Apple's description of the Push notificaiton process: http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html There appears to be a similar framework for Android: http://developer.android.com/google/gcm/index.html To clarify, this process uses a "Device Token" which is generated per app/iPhone . The UDID is not shared with the notification provider (ie the web2py app). This process is not designed as an alternative to authentication. I am looking at OAuth in addition to Push notifications. Push notifications It is merely to notify the user of status changes with the application. Fortunately my potential requirement will only involve authenticated users receiving notifications. I would be guessing that the Device token would be attached to the session data and/or to the auth_event table. Presumably, users can be simultaneously logged in on iOS and Android devices and would expect to receive the correct notifications for their respective devices. At this point I have done very little research into this, but I wanted to start discussing these schemes with other developers who are encounter similar needs. -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.