Thanks for your time guy's. I will heed your advice regarding code. cnhrism
On Apr 14, 5:20 pm, Yarko Tymciurak <yark...@gmail.com> wrote: > On Tue, Apr 14, 2009 at 8:32 AM, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > this line > > > discuss=db(db.discuss.id==prodj.id).select(orderby=~db.discuss.score) > > > should be > > > discuss=db(db.discuss.id==prodj).select(orderby=~db.discuss.score) > > You use prodj 3 ways, so this is really hard to read. > > prodj: the local variable which holds the requested wiki; > prodj- the field, which contains a reference to the prodj.id field > prodj - the table name; > > Massimo shows you the syntax error, but I'm not sure that is what you > intended. > > Language (not programming language) is our primary way of communicating, so > I get very picky about being able to read code (my own included). > > This is a good reason to use the naming convention (and even your mistake > shows how good an idea this is ;-)): > > - when naming a reference to another table, make it clear that you are > pointing to an ID field in the other table: I suggest allways add "_id" to > the end of references; it will remind you what you are looking at in your > code, that is change db.discuss.prodj to db.discuss.prodj_id > > - avoid using the same name to represent multiple things in the same > context; for your local variable, I would make it clear / readable - maybe > name it requested_prodj, or this_prodj, or my_prodj.... you get the > idea... > > If you do this, you now have: > > requested_prodj: the local variable which holds the requested wiki; > prodj_id- the field, which contains a reference to the prodj.id field > prodj - the table name; > > You now have the following logic problem to solve: your controller reads: > > .... > requested_prodj=int(request.args[0]) # the requested project (id?) > .... > item=db(db.prodj.id==request.args[0]).select()[0] # the requested > project record > discuss=db(db.discuss.id==prodj.id).select(orderby=~db.discuss.score) # > argh! this is probably wrong > > so I suggest maybe you mean this: > > # you have given a readable name to request.args[0] showing intent - use > it! > item=db(db.prodj.id==requested_prodj).select()[0] # the requested > project record > discuss=db(db.discuss.prodj_id > <http://db.discuss.id>==item.id<http://prodj.id> > ).select(orderby=~db.discuss.score) # this is probably what you meant... > > As I read this, I would change the names some more to show what the intent > is more clearly, since "item" is really the requested prodj - Say what you > mean, and your debugging will shift from a mystery, to a check to see if you > are doing the right things :-) > > Hope this helps. > > Regards, > Yarko > > > > > On Apr 14, 4:52 am, murray3 <ch...@murraypost.net> wrote: > > > Thanks Julio, > > > I changed some things around but still have not got it working. Here > > > is my code: > > > now I have a problem with "id" > > > > model: > > > > db.define_table("prodj", > > > SQLField("timestamp",'datetime',default=now), > > > SQLField("uuid",length=128,writable=False,default=str(uuid.uuid4 > > > ())), > > > SQLField("active",'boolean',default=True), > > > SQLField("name")) > > > > db.define_table('discuss', > > > SQLField('uuid',length=128,writable=False,default=str > > > (uuid.uuid4())), > > > SQLField('score','integer',default=1), > > > SQLField('timestamp','datetime',default=now), > > > SQLField('author_name',db.auth_user), > > > SQLField('author_alias'), > > > SQLField('author_email'), > > > SQLField('parente','integer',default=0), > > > SQLField('prodj',db.prodj), > > > SQLField('body','text'), > > > SQLField('flagged','boolean',default=False)) > > > > controller: > > > > @auth.requires_login() > > > def show(): > > > "shows a wiki prodj" > > > #try: > > > prodj=int(request.args[0]) > > > #prodj=db(db.prodj.id==request.args[0]).select()[0] > > > #except: redirect(URL(r=request,f='index')) > > > if session.authorized: > > > form=SQLFORM(db.discuss,fields=['body'],labels={'body':''}) > > > form.vars.author=session.authorized > > > form.vars.author_alias=session.alias > > > form.vars.prodj=prodj > > > if form.accepts(request.vars,formname='0'): > > > response.flash='discuss posted' > > > else: form=None > > > #try: > > > #item=db(db.prodj.id==prodj).select()[0] > > > item=db(db.prodj.id==request.args[0]).select()[0] > > > discuss=db(db.discuss.id==prodj.id).select > > > (orderby=~db.discuss.score) > > > #except: redirect(URL(r=request,f='index')) > > > items=[] > > > tree={} > > > forms={} > > > for c in discuss: > > > if not tree.has_key(c.parente): tree[c.parente]=[c] > > > else: tree[c.parente].append(c) > > > if session.authorized: > > > f=SQLFORM(db.discuss,fields=['body'],labels={'body':''}) > > > f.vars.author=session.authorized > > > f.vars.author_alias=session.alias > > > f.vars.prodj=prodj > > > f.vars.parente=c.id > > > if f.accepts(request.vars,formname=str(c.id)): > > > session.flash='discuss posted' > > > redirect(URL(r=request,args=request.args)) > > > forms[c.id]=f > > > return dict > > > (prodj=prodj,item=item,form=form,tree=tree,forms=forms,parent=0) > > > > traceback: > > > > WARNING 2009-04-14 09:41:43,703 cache.py] no cache.disk > > > ERROR 2009-04-14 09:41:43,983 main.py] Traceback (most recent call > > > last): > > > File "c:\apps\web2py\gluon\restricted.py", line 98, in restricted > > > exec ccode in environment > > > File "c:\apps\web2py\applications\fabmonger/controllers/default.py", > > > line 246, in <module> > > > File "c:\apps\web2py\gluon\globals.py", line 75, in <lambda> > > > self._caller = lambda f: f() > > > File "c:\apps\web2py\gluon\tools.py", line 989, in f > > > return action(*a, **b) > > > File "c:\apps\web2py\applications\fabmonger/controllers/default.py", > > > line 94, in show > > > discuss=db(db.discuss.id==prodj.id).select > > > (orderby=~db.discuss.score) > > > AttributeError: 'int' object has no attribute 'id' > > > > INFO 2009-04-14 09:41:44,046 dev_appserver.py] "GET /fabmonger/ > > > default/show/2 HTTP/1.1" 200 - > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" 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 -~----------~----~----~----~------~----~------~--~---