On Mon, Jul 20, 2009 at 9:33 AM, Jonathan Lundell <[email protected]>wrote:
> > On Jul 20, 2009, at 7:22 AM, mdipierro wrote: > > > > > The error is here: > > > > IS_NOT_IN_DB(db,db.strona) > > > > the second argument has to be a field, not a table. > > Would it be an overcomplication to sprinkle a few asserts throughout > web2py to help out with this kind of thing? I can imagine it'd speed > development, without having an impact on production performance. > Asserts are useful documentation as well. ... there might be a better way; first - this _should_ be development time; even a DEBUGLEVEL check in the code would be messy.... A static web2py specific set of tests (is this one of the reasons others don't like doctests as compared to nose or pyunit?) to check these ... a web2py-lint sort of thing might be useful... (I haven't looked at this, just thinking out loud...) - Yarko > > > > > > On Jul 20, 8:10 am, Karol Grębski <[email protected]> wrote: > >> I'm not sure if I'm doing something wrong, or if it's a bug in > >> web2py, > >> but I get an interesting ticket when I try tu submit a new news into > >> my database. Any sudgestions? > >> > >> *** > >> > >> Traceback (most recent call last): > >> File "/home/mlody/Desktop/cherry/web2py/gluon/restricted.py", line > >> 107, in restricted > >> exec ccode in environment > >> File "/home/mlody/Desktop/cherry/web2py/applications/komi/ > >> controllers/default.py", line 106, in <module> > >> File "/home/mlody/Desktop/cherry/web2py/gluon/globals.py", line > >> 100, > >> in <lambda> > >> self._caller = lambda f: f() > >> File "/home/mlody/Desktop/cherry/web2py/gluon/tools.py", line 1256, > >> in f > >> return action(*a, **b) > >> File "/home/mlody/Desktop/cherry/web2py/applications/komi/ > >> controllers/default.py", line 65, in nowa_wiesc > >> if form.accepts(request.vars, session): > >> File "/home/mlody/Desktop/cherry/web2py/gluon/sqlhtml.py", line > >> 709, > >> in accepts > >> onvalidation, > >> File "/home/mlody/Desktop/cherry/web2py/gluon/html.py", line 1122, > >> in accepts > >> status = self._traverse(status) > >> File "/home/mlody/Desktop/cherry/web2py/gluon/html.py", line 439, > >> in > >> _traverse > >> newstatus = c._traverse(status) and newstatus > >> File "/home/mlody/Desktop/cherry/web2py/gluon/html.py", line 439, > >> in > >> _traverse > >> newstatus = c._traverse(status) and newstatus > >> File "/home/mlody/Desktop/cherry/web2py/gluon/html.py", line 439, > >> in > >> _traverse > >> newstatus = c._traverse(status) and newstatus > >> File "/home/mlody/Desktop/cherry/web2py/gluon/html.py", line 439, > >> in > >> _traverse > >> newstatus = c._traverse(status) and newstatus > >> File "/home/mlody/Desktop/cherry/web2py/gluon/html.py", line 446, > >> in > >> _traverse > >> newstatus = self._validate() > >> File "/home/mlody/Desktop/cherry/web2py/gluon/html.py", line 935, > >> in > >> _validate > >> (value, errors) = validator(value) > >> File "/home/mlody/Desktop/cherry/web2py/gluon/validators.py", line > >> 303, in __call__ > >> (tablename, fieldname) = str(self.field).split('.') > >> ValueError: need more than 1 value to unpack > >> > >> *** > >> > >> The controller function is: > >> > >> *** > >> > >> @auth.requires_login() > >> def nowa_wiesc(): > >> form = SQLFORM.factory( > >> SQLField('tytul', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db, > >> db.strona)]), > >> SQLField('tresc', 'text', requires=IS_NOT_EMPTY()), > >> SQLField('zrodlo', length=2000, requires=IS_NULL_OR(IS_URL > >> ())), > >> labels={'tytul':'Tytuł', 'tresc':'Treść wieści', > >> 'zrodlo':'Link do źródła'}) > >> > >> if form.accepts(request.vars, session): > >> strona_id = db.strona.insert( > >> tytul=form.vars.tytul, > >> adres=CLEANUP(form.vars.tytul), > >> tresc=form.vars.tresc, > >> statyczna=False > >> status=2) > >> > >> wiesc_id = db.wiesc.insert( > >> strona=strona_id, > >> zrodlo=form.vars.zrodlo) > >> > >> db.wiesc_glos.insert(wiesc=wiesc_id) > >> > >> redirect(URL(r=request, f='wiesc', args=CLEANUP > >> (form.vars.tytul))) > >> > >> return dict(formularz=form) > >> > >> *** > >> > >> And my model is: > >> > >> *** > >> > >> db.define_table('strona', > >> SQLField('tytul'), > >> SQLField('adres'), > >> SQLField('statyczna', 'boolean'), > >> SQLField('tresc', 'text'), > >> SQLField('kto', db.auth_user), > >> SQLField('kiedy', 'datetime'), > >> SQLField('status', 'integer')) > >> > >> db.strona.tytul.length = 120 > >> db.strona.tytul.requires = IS_NOT_EMPTY() > >> db.strona.adres.requires = IS_NOT_EMPTY() > >> db.strona.kto.default = auth.user.id if auth.user else 0 > >> db.strona.kto.writable = False > >> db.strona.kiedy.default = request.now > >> db.strona.kiedy.writable = False > >> > >> db.define_table('wiesc', > >> SQLField('strona', db.strona), > >> SQLField('zrodlo')) > >> > >> db.wiesc.zrodlo.length = 2000 > >> > >> db.define_table('wiesc_glos', > >> SQLField('kto', db.auth_user), > >> SQLField('kiedy', 'datetime'), > >> SQLField('wiesc', db.wiesc)) > >> > >> db.wiesc_glos.kto.default = auth.user.id if auth.user else 0 > >> db.wiesc_glos.kto.writable = False > >> db.wiesc_glos.kiedy.default = request.now > >> db.wiesc_glos.kiedy.writable = False > >> > >> *** > >> > >> I also think I should explain some conventions: > >> - the table 'strona' conatins generally all type of pages content > >> (articles, news etc), > >> - 'tytul' means 'title', > >> - 'tresc' means 'content', > >> - 'adres' means 'adres' ;) (I use that for a cleaned version of the > >> title which I use in URLs), > >> - 'statyczna' means 'static' (true if it's not any 'special' page > >> type like an article, a news etc), > >> - 'kto' means 'who', > >> - 'kiedy' means 'when', > >> - 'status' can have 3 values: 0 means that the page is a draft, 1 > >> that it is private, 2 that it is public, > >> - the table 'wiesc' contains news (the shared functionality of > >> different page types is put into 'pages' - that's somewhat similiar > >> to > >> the 'nodes' idea in Drupal, if you're familiar with it), > >> - 'strona' is of course a refference to a page, > >> - 'zrodlo' contains a URL which is the source of the news, > >> - the users can vote on news - it should work somewhat similiar to > >> digg - that's what the 'wiesc_glos' table is for, > >> - 'kto' means 'who' (the user who voted), > >> - 'kiedy' means 'when' (when the vote was made, I'm not really sure > >> if I need this one...), > >> - 'wiesc' is (as you can see) a relation with a news (the news that > >> the user votes for). > >> > >> (Jeez, I have to switch to english names, or it'll be a pain in the > >> ass to ask for help here more frequently. ^^) > >> > >> What I'm trying to do in the controller is to create a new news > >> (which > >> needs a page). I also assume that the news author would vote on the > >> news, so I do that automatically. The problem seems to be with the > >> 'form.accepts' call. Am I doing something wrong with it? > >> > >> Cheers! > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

