[web2py] admin password in web2py docker not correct
Hi, Hope to save someone with the same problem some time: i encountered a problem running web2py in a docker; the admin password as set from the start command was not recognised when trying to log into the admin interface. Wrong dockerfile snippet: EXPOSE 8000 CMD ["/usr/bin/python", "/home/web2py/web2py.py", "-i 0.0.0.0", "-p 8000", "-a admin"] web2py thinks (sees) the admin password being ' admin' (space in front of the password). What *does* work: EXPOSE 8000 CMD ["/usr/bin/python", "/home/web2py/web2py.py", "-i 0.0.0.0", "-p 8000", "-a","admin"] If acceptable, this problem could also be solved by changing save_password in gluon/main.py: else: # use provided password cpassword = CRYPT()(password.strip(' '))[0] Best regards, Jaap -- 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: max value in linked tables
Thanks a lot, i learned something new today :) Obvious solution, once you think of it, and much quicker than building loops. Best regards, Jaap On Monday, December 29, 2014 10:51:01 AM UTC+1, Massimo Di Pierro wrote: db.employee_contract.contract_id == db.contract.id) (db.employee_contract.employee_id == db.employee.id I think you should do it: contracts = ((db.employee_contract.contract_id == db.contract.id) (db.employee_contract.employee_id == db.employee.id)) rows = db(contracts).select(db.employee.ALL, db.contract.ALL, orderby= db.employee.id|~db.contract.start_date, distinct=db.employee.id) On Sunday, 28 December 2014 15:57:10 UTC-6, JaapP wrote: Hi, Any hints about how to tackle the following problem greatly appreciated: given three tables: *employee*: id name ... *contract*: id start_date fte100 ... *employee_contract:* id employee_id contract_id An employee can have one or more contracs; they are linked through the employee_contract table. I would like to find a query that returns the contract details for the latest contract for an employee; i've solved a little step of my puzzle and can retrieve the latest contract by doing something like this: employee_id = 10 contr = db( (db.employee.id == employee_id) (db.employee_contract.contract_id == db.contract.id) (db.employee_contract.employee_id == db.employee.id) ).select(db.employee.ALL, db.contract.start_date.max()) latest_start_date = contr.contract.start_date.max() but i need also the corresponding contract.fte100 field. Can this be done by using the DAL, or should i construct a loop to find the answer? Best regards, Jaap -- 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] max value in linked tables
Hi, Any hints about how to tackle the following problem greatly appreciated: given three tables: *employee*: id name ... *contract*: id start_date fte100 ... *employee_contract:* id employee_id contract_id An employee can have one or more contracs; they are linked through the employee_contract table. I would like to find a query that returns the contract details for the latest contract for an employee; i've solved a little step of my puzzle and can retrieve the latest contract by doing something like this: employee_id = 10 contr = db( (db.employee.id == employee_id) (db.employee_contract.contract_id == db.contract.id) (db.employee_contract.employee_id == db.employee.id) ).select(db.employee.ALL, db.contract.start_date.max()) latest_start_date = contr.contract.start_date.max() but i need also the corresponding contract.fte100 field. Can this be done by using the DAL, or should i construct a loop to find the answer? Best regards, Jaap -- 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: max value in linked tables
the last line in my code example should have been: latest_start_date = contr[db.contract.start_date.max()] -- 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] Calling javascript from submenu
Hello, i'm trying to call a javascript function from a submenu item and having some troubles with this. Calling javascript from a level 1 menu works just fine, like this: response.menu = [ (T('File'), False, URL(), [ (T('New'), False, URL('project', 'create'), []) ]), (A('click me',_onclick=alert('hello')),None,None) ] However, if i try moving the second menu item to a level 2 section like this: response.menu = [ (T('File'), False, URL(), [ (T('New'), False, URL('project', 'create'), []) ]), (T('View'), False, URL() , [ (A('click me',_onclick=alert('hello')),None,None) ]) ] The function does work, but after showing the alert box, the browser is redirected to http://localhost:8000/undefined My Firefox console window shows: [11:46:30.410] Empty string passed to getElementById(). @ http://localhost:8000/Isidor/static/js/jquery.js:3 [11:46:30.568] GET http://localhost:8000/undefined [HTTP/1.1 404 NOT FOUND 1ms] Any ideas at what i'm doing wrong? Jaap -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] can i build a ROWS object from scratch?
Hi All, i've been struggling and googling this problem for may hours, hope someone can give me a hint: i'm trying to create a ROWS object from data i receive from an external webservice. I do not have a corresponding table in the database, and would like to do something like this: *NOT WORKING CODE:* def rowsWithoutDB(): auth=HTTPBasicAuth('username', 'password') r = requests.get(http://myURL/projects.xml;, auth=auth) projects = BeautifulStoneSoup(r.content) rows = Rows() rows.colnames = ['controle.redmine'] for project in projects.findAll('project'): pid = str(project.contents[3].text) rows.append({'controle':{'redmine':pid}}) return dict(rows=rows) But, this does not do the trick. If i inspect a rows object generated with a db().select() i see that all records are of type ROW The above example results gives the records a dict type. I found a similar question ( https://groups.google.com/forum/#!msg/web2py/CS-beWsQ9KY/iSy8VEUhH5EJ ) but this was only partially answered. I hope somebody can help! Thanks, Jaap -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: can i build a ROWS object from scratch?
Hello Anthony, Your code is working for me! If you want to display the rows from a view with {{=rows}} i still get an error, but i use a custom table builder which takes a rows object as input, and this works just fine. In the end, my mistake was not importing a row object, only a rows object.. Thanks a lot for taking the time to answer my question! Jaap -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] record versioning and standalone DAL
Hi, i've build a (very small) standalone side project (so, running without Web2Py) that uses the Web2Py DAL, and all goes well. Now i'm trying to enable record versioning. but this seems not to be working (thread._local object has no attribute 'request') Has anybody succeeded in using record versioning in a standalone project? Any hints greatly appreciated! Jaap -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: meta generating queries
Hi Anthony, Thanks (again) for taking the time to answer my question! This gets me going again! I will post the working result here in case somebody else is trying to archieve something like this. Cheers, Jaap --
[web2py] meta generating queries
Hi All, In the past few days i have been struggling with the problem of generating a dynamic query. My goal is to create a reusable model, which gives the possibility to search all fields in a given table for the presence of a string. The result will be a list of id's with the records in which the searched string is present in any field. My problem always comes down to the simple point that, although i am able to build a query by examining the table, in the end my constructed query is a string. Whenever i try to execute i get an error, as far as i understand caused by the feeding of a string to the db(). Can anybody give me a hint in the right direction? Thanks in advance, Jaap My sample (*not working*) code: class SmartSearch(object): def __init__(self,table): _start_query = '' _fields = [] _select = '' _start_query += '(db.' + str(table) + '.id0)' _select += 'db.' + str(table) + '.id,' for item in table: _fields.append(str(item)) if type(item.requires).__name__ == 'IS_IN_DB': _start_query += '(' + 'db.' + str(item) + '==db.' + str(item .requires.ktable) + '.id' + ')' self._start_query = _start_query[:-1] self._select = _select self._fields = _fields return def search(self, search_string, search_mode='AND'): items = search_string.split() _query = '' for item in items: _sub_query = '' for field in self._fields: _sub_query += '(db.' + field + '.like(%' + item + '%))|' _sub_query = _sub_query[:-1] _sub_query = '(' + _sub_query + ')' if search_mode == 'AND': _query += _sub_query + '' else: _query += _sub_query + '|' _query = _query[:-1] totaal_query = self._start_query + '(' + _query + ')' result = db(totaal_query).select(self._select) return --
[web2py] Re: Selective removing sessions
i found the answer, thought to post in case somebody is struggling with the same problem. you can access the session.session_data with cPickle.loads(sessie.session_data)['auth']['user']['id'] --
[web2py] Selective removing sessions
Hi All, i would like to remove sessions for some selected users. I can't find a way to relate a session to a user, is there a way to do this? I already store the sessions in the database, so removing all sessions is easy: @auth.requires_membership('Administrators') def invalidate_sessions(): sessions = db(db.web2py_session_Charon.id0).select(db. web2py_session_Charon.ALL) for sessie in sessies: db(db.web2py_session_Charon.id==sessie.id).delete() ... But i cannot find how to delete only sessions which belong to a particular user. I can see that the session.data contains all sorts of fields but cannot figure out how to use this to find the corresponding user.id Does anybody have a hint in the right direction? Thanks in advance! Jaap --
[web2py] Re: How to build a modular menu
Hi Johan, following code works for me to insert some items from the db into a submenu: response.menu = [ ('Home', False, URL('default','index'), []), ] if auth.is_logged_in(): locaties = db(db.locatie.apotheek_id==auth.user.apotheek_id).select() if locaties: locaties_lijst = [] for locatie in locaties: locaties_lijst.append( (locatie.naam, False, URL(c='rapporten',f='boekingsverslag',args=locatie.id),[]) ) locaties_lijst.append( ('Compleet', False, URL(c='rapporten',f='boekingsverslag_compleet'),[]) ) response.menu += (( ('Rapporten', False, URL(),[ ('Saldo\'s', False, URL('rapporten','saldos'),[]), ('Boekingsverslag', False, URL(), locaties_lijst) ]), ('Beheer', URL(), False,[ ('geld locaties', False, URL(), [ ('overzicht', False, URL('beheer','locaties_overzicht')), ('toevoegen', False, URL('beheer','locatie_toevoegen'))]) ]) )) --
[web2py] Re: using existing DB connection inside module/class
Hi Anthony, Sorry for the delay.. The code as you show above looks indeed much the same as my code. I already discovered before that restarting Web2py server after module changes is a good idea. So this is not the solution for my problem. Your code works fine for me as well. After removing the db.commit from my own code it still works fine Probably i changed something else as well. Thanks a lot for your time and help! Jaap On Feb 25, 3:38 pm, Anthony abasta...@gmail.com wrote: Hmm, the following test code works for me without any db.commit: *In /controllers/default.py:* def index(): db.define_table('time', Field('time')) from mymodule import DbTest test = DbTest(db) return dict(results=db(db.time).select()) *In /views/default/index.html:* {{extend 'layout.html'}} {{=results}} *In /modules/mymodule.py:* from gluon import current class DbTest(object): def __init__(self, db): self._insert(db=db) def _insert(self, db): db.time.insert(time=current.request.now) That looks like the same pattern that your app is using. Is it possible you made a change to your toolbox module and didn't restart web2py or have module change tracking turned on? Have you tried removing the db.commit() and restarting web2py to see if it works without it? Maybe try my sample code above and see if that works for you. Anthony On Saturday, February 25, 2012 5:46:50 AM UTC-5, JaapP wrote: On Feb 24, 6:38 pm, Anthony abasta...@gmail.com wrote: On Friday, February 24, 2012 12:24:03 PM UTC-5, JaapP wrote: Hi Wikus, Thanks a lot! Adding a db.commit() after an insert causes the database to be updated. The db.commit() shouldn't be needed. Can you show some code? Anthony This is an extract of the code that's working now thanks to the db.commit() : Controller: from applications.Charon.modules.toolbox import * @auth.requires_login() def verbinden(): deviceservice = db.deviceservices(request.args(0)) ipaddress = deviceservice.ipaddress query = db((db.deviceservices.id == request.args(0))\ (db.deviceservices.client_id == db.clients.id)\ (db.deviceservices.servicetype_id == db.services.id) \ ).select().first() protocol = query.services.type klantnummer = query.clients.number verbinding = SmartFindConnection(klantnummer=klantnummer,db=db,deviceservice=deviceservice,request_user=auth.user_id) ... ... ... modules/toolbox.py: class SmartFindConnection(object): def __init__(self,klantnummer,db,deviceservice,request_user): self._pdcred = db( (db.deviceservices.devicename == 'KJHLKJHLH') (db.clients.name == 'IUYIUYI') ).select(db.deviceservices.ALL).first() self.request_user = request_user self.pd_user = TempUser(self._pdcred.ipaddress,self._pdcred.port,'root',self._pdcred.rootpassword) self.pd_user.useradd() # tijdelijke proxydoei gebruiker aanmaken self._log_session(db=db,deviceservice=self._pdcred) self._klant = db((db.deviceservices.client_id==db.clients.id) (db.clients.number==klantnummer) (db.services.type=='SSH') (db.deviceservices.devicename.like('%V01%')) ).select(db.deviceservices.ALL).first() ... ... ... def _log_session(self,db,deviceservice): db.sessions.insert( client_id = deviceservice.client_id, user_id = self.request_user, deviceservice_id=deviceservice.id, state='Active', username=self.pd_user.temp_username, creation_date=datetime.datetime.now() ) db.commit() ... ... ...
[web2py] Re: using existing DB connection inside module/class
On Feb 24, 6:38 pm, Anthony abasta...@gmail.com wrote: On Friday, February 24, 2012 12:24:03 PM UTC-5, JaapP wrote: Hi Wikus, Thanks a lot! Adding a db.commit() after an insert causes the database to be updated. The db.commit() shouldn't be needed. Can you show some code? Anthony This is an extract of the code that's working now thanks to the db.commit() : Controller: from applications.Charon.modules.toolbox import * @auth.requires_login() def verbinden(): deviceservice = db.deviceservices(request.args(0)) ipaddress = deviceservice.ipaddress query = db((db.deviceservices.id == request.args(0))\ (db.deviceservices.client_id == db.clients.id)\ (db.deviceservices.servicetype_id == db.services.id) \ ).select().first() protocol = query.services.type klantnummer = query.clients.number verbinding = SmartFindConnection(klantnummer=klantnummer,db=db,deviceservice=deviceservice,request_user=auth.user_id) ... ... ... modules/toolbox.py: class SmartFindConnection(object): def __init__(self,klantnummer,db,deviceservice,request_user): self._pdcred = db( (db.deviceservices.devicename == 'KJHLKJHLH') (db.clients.name == 'IUYIUYI') ).select(db.deviceservices.ALL).first() self.request_user = request_user self.pd_user = TempUser(self._pdcred.ipaddress,self._pdcred.port,'root',self._pdcred.rootpassword) self.pd_user.useradd() # tijdelijke proxydoei gebruiker aanmaken self._log_session(db=db,deviceservice=self._pdcred) self._klant = db((db.deviceservices.client_id==db.clients.id) (db.clients.number==klantnummer) (db.services.type=='SSH') (db.deviceservices.devicename.like('%V01%')) ).select(db.deviceservices.ALL).first() ... ... ... def _log_session(self,db,deviceservice): db.sessions.insert( client_id = deviceservice.client_id, user_id = self.request_user, deviceservice_id=deviceservice.id, state='Active', username=self.pd_user.temp_username, creation_date=datetime.datetime.now() ) db.commit() ... ... ...
[web2py] using existing DB connection inside module/class
Hi All, i've been struggling with the following problem for some time and hope anyone can help. When i instantiate a class in a controller (class is in separate file in Modules folder) and i want to use the database from within this instance, i have to pass the DB to the class. Inside this instance, querying the db works normal. But, when i try to insert a new record into the database the database (sqlite) is not updated. Debugging shows me that the db object inside the instance is actually updated. So my question: how should i use the web2py database connection inside a class? As far as i can understand when passing the DB to a class this creates a new DB object that is not connected to the file store.. Any help greatly appreciated! Jaap
Re: [web2py] using existing DB connection inside module/class
Hi Johann, Thanks for your quick reply! I will test the suggestions as made in the previous thread (don't know if this works: https://groups.google.com/forum/?fromgroups#!topic/web2py/0k0Fvw6fmb8 ). bye, Jaap
[web2py] Re: using existing DB connection inside module/class
Hi Wikus, Thanks a lot! Adding a db.commit() after an insert causes the database to be updated. Bye, Jaap
[web2py] Re: SQLForm.grid - How do I use it properly?
One more reason to stick to using fields could be that with fields you can specify the order in which the columns are shown, this didn't work for 'columns' On 14 nov, 18:13, Jim Steil j...@qlf.com wrote: Ok, columns are gone again... Might just be best to stick with using fields. -Jim On 11/14/2011 8:47 AM, Jim Steil wrote: I stand corrected on the 'columns' comment. Massimo added it back in this morning. -Jim On 11/14/2011 8:45 AM, Jim Steil wrote: here are a few thoughts... 1. Make sure you create this test in a new app. If you're updating or adding functionality to an already existing app, then your layout and base.css need to be updated. 2. If using jquery-ui, then you need to download jquery-ui and include it in your layout.html with a line like this: {{response.files.append(URL('static','jquery-ui/js/jquery-ui-1.8.16.custom.min.js'))}} {{response.files.append(URL('static','jquery-ui/css/sunny/jquery-ui-1.8.16.custom.css'))}} 3. Don't use the 'columns' argument. It is going away in the next release. Instead, use 'fields'. In your case, use the following: fields = [db.projects_posts.title, db.projects_posts.project_details, db.projects_posts.estimated_worth] 4. I typically do not specify the 'headers' arg. Instead, set the 'label' on your table definition. That way you only have to do it once and can use it all over. If you need to override it for a particular function, then just set the 'label' attribute in that function. 5. At this time there is no documentation available for SQLFORM.grid or SQLFORM.smartgrid. The best thing to do would be to look through this group for all the posts. Massimo is working on an updated version of that manual that he is hoping to have complete by the end of this month. That should contain information on .grid and .smartgrid. 6. If you are going to be playing around with this I would recommend that you work with the code in trunk. I don't recall what state the .grid was in when 1.99.2 was released. As for answers for your specific questions: Q: What is the exact proper method to use SQLForm.grid - I think your on the right track. Just need to clean up your css and layout.html files to get the proper formatting. Q: What all libraries do I need to include? where? If you want to use jquery-ui then you need to download it and reference it in your layout.html. Q: How to make links work the way they should ? I'd like some more information on what is going on here before giving an answer. Q: Can search be customized? How? I don't remember if the search_form is implemented in 1.99.2, but there is a search facility built in that allows the users to create a custom search. I am not a fan of it and have some other ideas how developers could be allowed to create custom search forms, but I haven't opened a ticket on it yet. Q: Is this documented in online book? - did not find much about it in version 3.2 though. Documentation will be coming with the next version of the book targeted for the end of the month. Hope this helps. -Jim On 11/14/2011 6:54 AM, Rahul wrote: Hi All, Can anyone let me know how to use SQLForm.grid properly or tell me what I am missing. I have not installed any jquery plugin for the same (assuming that it is part of 1.99.2 by default). I cannot see the complete grid, just some buttons and data as per my query below. Also the links do not function when clicked. The table does not show any backgroud color or anything. Simply it doesnt look like a jquery grid. My code is as below - My machine - Windows7 , IE9 and Firefox 7.0, Chrome. Web2py- Latest stable (1.99.1) #-Controller- (default.py)--- def index(): example action using the internationalization operator T and flash rendered by views/default/index.html or views/generic.html #Posts grid - SQLForm.grid #grid = SQLFORM.grid(db.projects_posts) query = ((db.projects_posts.post_visibility==Classified)) columns = ('projects_posts.title', 'projects_posts.project_details', 'projects_posts.estimated_worth' ) headers ={'projects_posts.title': 'Title', 'projects_posts.project_details': 'Details', 'projects_posts.estimated_worth': 'Worth'} form = SQLFORM.grid( query=query, columns=columns, headers=headers, deletable=False, editable=False, csv=False, maxtextlength=64 ) return dict(form=form) #- View --- (index.html) {{extend 'layout.html'}} {{=form}} Also, if possible please refer me to the proper documentation for SQLForm.grid. Again, if I include the parameter form = SQLForm.grid(., ui=jquery-ui) in above code, the buttons disappear and it only shows me links for 'view' etc. Q: What is
[web2py] columns option removed from sqlform.grid?
Hi , could anyone give me an hint on this one please: i've been playing with sqlform.grid and noticed that in web2py Version 1.99.3 (2011-11-11 10:27:54) dev i cannot use the columns option any more (TypeError: grid() got an unexpected keyword argument 'colums') This did work in previous version of web2py. Should i use an other option to select the columns i want to display or just revert back to older version of web2py? Thanks in advance for any help! Jaap
[web2py] Re: columns option removed from sqlform.grid?
Thanks a lot, works perfect! And now i even can set the order in which the columns are displayed; this did not work with 'columns' Bye, Jaap On 11 nov, 19:43, Jim Steil j...@qlf.com wrote: This was due to a non-backward-compatible change that Massimo implemented a day or so ago. You should be able to substitute your usage of columns with fields. However, the syntax is a bit different. Here is an example. Using columns - no longer supported columns = ['table.field1', 'table.field2'] Using fields - fields = [db.table.field1, db.table.field2] grid = SQLFORM.grid(query, fields=fields) I'm still having some issues when using fields in SQLFORM.smartgrid, but I think it should work fine in SQLFORM.grid. -Jim On 11/11/2011 12:22 PM, JaapP wrote: Hi , could anyone give me an hint on this one please: i've been playing with sqlform.grid and noticed that in web2py Version 1.99.3 (2011-11-11 10:27:54) dev i cannot use the columns option any more (TypeError: grid() got an unexpected keyword argument 'colums') This did work in previous version of web2py. Should i use an other option to select the columns i want to display or just revert back to older version of web2py? Thanks in advance for any help! Jaap
[web2py] crud.update change field value in controller
Hi, i am trying to use a crud.update function and want to change the value of a field before passing to the view. i've spent a couple of hours trying and searchin. I found this post http://permalink.gmane.org/gmane.comp.python.web2py/37314 but the suggested use of 'db.table.field.update=' doesn't change the field value as seen in the controller. Anybody an idea how this should be implemented? thanks! Jaap
[web2py] Re: crud.update change field value in controller
My code looks like this: #CONTROLLER def bevestig(): db.bestelling.bedrag.update = '10' bestelling = crud.update(db.bestelling,request.args(0),deletable=False,onaccept= muntgeld_bijboeken) return dict(bestelling=bestelling) #VIEW {{=bestelling}} The value shown by the controller for 'bedrag' is the value as stated in the DB for this record; i would expect the value to be '10' I also tried moving the update part below the crud.update line, but same result :) On Aug 28, 4:44 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: I do not understand. Can you make a concrete example? On Aug 28, 9:37 am, JaapP j...@tetra.nl wrote: Hi, i am trying to use a crud.update function and want to change the value of a field before passing to the view. i've spent a couple of hours trying and searchin. I found this posthttp://permalink.gmane.org/gmane.comp.python.web2py/37314 but the suggested use of 'db.table.field.update=' doesn't change the field value as seen in the controller. Anybody an idea how this should be implemented? thanks! Jaap
[web2py] Re: crud.update change field value in controller
Thanks a lot! So now i first do an update of the record in the db and afterwards create the crud.update form. this works perfect. But just for my curiosity; when using an 'crud.create' setting default values with 'db.table.field.default=...' works fine, as far as i understand from the post i refered to in the beginning Massimo suggests using 'db.table.field.update=...' for changing the existing value? Jaap On Aug 28, 5:16 pm, Bruno Rocha rochacbr...@gmail.com wrote: On Sun, Aug 28, 2011 at 12:06 PM, JaapP j...@tetra.nl wrote: db.bestelling.bedrag.update = '10' It is wrong. shoud be simething like: db(db.bestelling.id==request.args(0)).update(bedrag = '10') -- Bruno Rocha [ About me:http://zerp.ly/rochacbruno] [ Aprenda a programar:http://CursoDePython.com.br] [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br] [ Consultoria em desenvolvimento web:http://www.blouweb.com]
[web2py] Re: table, grid, smartgrid, getting better
Hi Massimo, i tried to play a little bit with the 'query=...' part but i can't get it working; #CONTROLLER def locaties(): locaties = SQLFORM.grid(db.locatie,query=db.locatie.mutatie_user_id==auth.user.id) return dict(locaties=locaties) Error: locaties = SQLFORM.grid(db.locatie,query=db.locatie.mutatie_user_id==auth.user.id) TypeError: grid() got multiple values for keyword argument 'query' i tried to simplify the query, put () around the query but still the same error message. Do you have any idea what i'm doing wrong? thanks for the great framework!! Jaap
[web2py] Re: table, grid, smartgrid, getting better
Thanks a lot; this works like a charm!! On Aug 21, 4:59 pm, Massimo Di Pierro massimo.dipie...@gmail.com wrote: SQLFORM.grid(db.locatie,query=db.locatie.mutatie_user_id==auth.user.id) should be SQLFORM.grid(query=db.locatie.mutatie_user_id==auth.user.id) it will figure out the table automatically On Aug 21, 7:19 am, JaapP j...@tetra.nl wrote: Hi Massimo, i tried to play a little bit with the 'query=...' part but i can't get it working; #CONTROLLER def locaties(): locaties = SQLFORM.grid(db.locatie,query=db.locatie.mutatie_user_id==auth.user.id) return dict(locaties=locaties) Error: locaties = SQLFORM.grid(db.locatie,query=db.locatie.mutatie_user_id==auth.user.id) TypeError: grid() got multiple values for keyword argument 'query' i tried to simplify the query, put () around the query but still the same error message. Do you have any idea what i'm doing wrong? thanks for the great framework!! Jaap