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()
> > ...
> > ...
> > ...

Reply via email to