Turbogearsbook - Bookmarker - example

0 views
Skip to first unread message

emzett

unread,
Dec 6, 2006, 12:18:19 AM12/6/06
to TurboGears
I have tried to follow the bookmarker example in chapter 5 of the
Turbogearsbook. But
now I get the following error message when trying to update on of the
bookmarks:

File "C:\Python24\Scripts\bookmarker\bookmarker\controllers.py", line
84, in save_bookmark
description=kwargs["description"])
File
"C:\Python24\lib\site-packages\sqlobject-0.7.1dev_r1860-py2.4.egg\sqlobject\declarative.py",
line 93, in _wrapper
return fn(self, *args, **kwargs)
File
"C:\Python24\lib\site-packages\sqlobject-0.7.1dev_r1860-py2.4.egg\sqlobject\main.py",
line 1197, in __init__
self._create(id, **kw)
File
"C:\Python24\lib\site-packages\sqlobject-0.7.1dev_r1860-py2.4.egg\sqlobject\main.py",
line 1224, in _create
self._SO_finishCreate(id)
File
"C:\Python24\lib\site-packages\sqlobject-0.7.1dev_r1860-py2.4.egg\sqlobject\main.py",
line 1248, in _SO_finishCreate
id, names, values)
File
"C:\Python24\lib\site-packages\sqlobject-0.7.1dev_r1860-py2.4.egg\sqlobject\dbconnection.py",
line 764, in queryInsertID
return self._dbConnection._queryInsertID(
File
"C:\Python24\lib\site-packages\sqlobject-0.7.1dev_r1860-py2.4.egg\sqlobject\sqlite\sqliteconnection.py",
line 167, in _queryInsertID
c.execute(q)
IntegrityError: column bookmark_name is not unique

In think the bug must be in the 'bookmark' or 'save_bookmark', which
look like:

@expose(template="bookmarker.templates.form")
def bookmark(self, *args, **kwargs):
if args and args[0] == "add":
values=""
submit_action="/save_bookmark/"

if args and args[0] == "edit":
from sqlobject import SQLObjectNotFound
try:
b= Bookmarks.get(args[1])
default_options= []
for a in b.categories:
default_options.append(a.id)

values = {"bookmarkName" : b.bookmarkName,
"link" : b.link,
"description" : b.description,
"categories" : default_options}

except SQLObjectNotFound:
values=""
flash("That's not an valid Bookmark,do you want to add
one?")
submit_action="/save_bookmark/edit/%s" % args[1]
return dict(form=bookmark_form, values=values,
action=submit_action)

@expose()
@error_handler(bookmark)
@validate(form=bookmark_form)
def save_bookmark(self, *args, **kwargs):
try:
b=Bookmarks.get(args[1])
b.bookmarkName = kwargs["bookmarkName"]
b.link =kwargs["link"]
b.description = kwargs["description"]
Bookmarks.updateCategories(b,kwargs["categories"])
except:
b=Bookmarks(bookmarkName=kwargs["bookmarkName"],

link=kwargs["link"],

description=kwargs["description"])
for item in kwargs["categories"]:
b.addCategories(Categories.get(item))
raise redirect("/index")

Does anybody have an idea what's missing ?

Besides, the form validators do not work.

Regards,

Markus

Mark Ramm

unread,
Dec 6, 2006, 5:53:30 PM12/6/06
to turbo...@googlegroups.com
I'll take a look at this tonight if I can.

--Mark Ramm


--
Mark Ramm-Christensen
email: mark at compoundthinking dot com
blog: www.compoundthinking.com/blog

Mark Ramm

unread,
Dec 6, 2006, 9:02:40 PM12/6/06
to turbo...@googlegroups.com
Just looking at the code below, do you think it's possible that you
have two bookmarks with the same name?

Could you send your model code? Perhaps the problem is there.

--Mark

On 12/6/06, emzett <m...@zmija.de> wrote:
>

> I have tried to follow the bookmarker example in chapter 5 of the
> Turbogearsbook. But
> now I get the following error message when trying to update on of the
> bookmarks:
>
> File "C:\Python24\Scripts\bookmarker\bookmarker\controllers.py", line
> 84, in save_bookmark
> description=kwargs["description"])

Snipped.

Mark Ramm

unread,
Dec 6, 2006, 9:30:50 PM12/6/06
to turbo...@googlegroups.com
You may also want to download the code from:

http://www.turbogearsbook.com/code

and see if there are any differences between the code you have and
that version.

--Mark Ramm

On 12/6/06, emzett <m...@zmija.de> wrote:
>

Jeff Hinrichs - DM&T

unread,
Dec 6, 2006, 9:46:00 PM12/6/06
to turbo...@googlegroups.com
Mark,
Any chance you are going to have a RSS feed so we can keep up to date
with the errata and additions to the site?

-Jeff


--
Jeff Hinrichs
Dundee Media & Technology, Inc
je...@dundeemt.com
402.320.0821

Mark Ramm

unread,
Dec 6, 2006, 10:22:03 PM12/6/06
to turbo...@googlegroups.com
Good idea.

I'll look into the options tomorrow. Right now the site is just
static HTML, but I think I thought I saw a TG based web watcher with
RSS feed output, so that might be an easy option.

--Mark Ramm

Reply all
Reply to author
Forward
0 new messages