On Mon, Nov 08, 2010 at 07:19:51AM -0800, Yohann REBATTU wrote: > I'm running into the same issue as you. > > i'll try to be a bit more specific: > i my case, it seems the trouble lies in tag removing: > only one tag on two is actually removed each time, > > i've no problem with adding tags to page, but removing all four tags > of one page will remove the first and third tags of the page but not > the second neither the fourth.
This *sounds* like you're doing something like
for tag in page.tags:
page.tags.remove(tag)
which fails, since when the for loop moves to position #2 in the list, item
#1 has already been deleted and item #3 was shifted into position #2.
The simplest fix is
for tag in list(page.tags):
page.tags.remove(tag)
because then you're iterating over a copy of the list which doesn't
change when you remove tags.
> On Oct 8, 3:40 pm, Stratos Papadopoulos <[email protected]> wrote:
> > More specifically the code in:
> >
> > http://pylonsbook.com/en/1.1/simplesite-tutorial-part-2.html#tags-man...
> >
> > and the update_tags() action.
Here it is:
def update_tags(self, id=None):
...
for i, tag in enumerate(page.tags):
if tag.id not in self.form_result['tags']:
del page.tags[i]
...
and it's doing exactly what I thought. If you change it to
for i, tag in enumerate(list(page.tags)):
if tag.id not in self.form_result['tags']:
del page.tags[i]
it should work (disclaimer: I haven't tested the fix).
If I'm right, can you please report the error at
http://apress.com/book/errata/773? Something like
"Chapter 14, section Adding Tags To Pages, in update_tags()
the for loop should be
for i, tag in enumerate(list(page.tags)):
instead of
for i, tag in enumerate(page.tags):
otherwise when you remove tags, every second tag will
erroneously persist."
Marius Gedminas
--
Photons have energy, and trying to cram too many into too small of a space can
cause a black hole to form, which is, needless to say, not a desirable trait
for an optical computer.
-- http://scottaaronson.com/blog/?p=261#comment-13693
signature.asc
Description: Digital signature
