From 4d414773b1f0106e2d8c1cbe2bb0fed28a4d02de Mon Sep 17 00:00:00 2001 From: Nick Retallack Date: Sun, 4 Oct 2009 13:20:32 -0700 Subject: [PATCH] delete tags by clicking the x, or typing in -tagtext --- floof/controllers/tag.py | 20 ++++++++++++++++++++ floof/model/art.py | 28 ++++++++++++++++++++-------- floof/templates/art/show.mako | 3 ++- floof/tests/functional/test_tag.py | 7 +++++++ 4 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 floof/controllers/tag.py create mode 100644 floof/tests/functional/test_tag.py diff --git a/floof/controllers/tag.py b/floof/controllers/tag.py new file mode 100644 index 0000000..3b69ed6 --- /dev/null +++ b/floof/controllers/tag.py @@ -0,0 +1,20 @@ +import logging + +from pylons import request, response, session, tmpl_context as c +from pylons.controllers.util import abort, redirect_to + +from floof.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +import elixir +from floof.model.art import Tag + +class TagController(BaseController): + + def delete(self, id): + tag = Tag.get(id) + if tag: + elixir.session.delete(tag) + elixir.session.commit() + redirect_to(request.referrer) \ No newline at end of file diff --git a/floof/model/art.py b/floof/model/art.py index 66cbe0b..e462d0b 100644 --- a/floof/model/art.py +++ b/floof/model/art.py @@ -6,6 +6,7 @@ # from elixir import Entity, Field, Integer, Unicode from elixir import * +import elixir from pylons import config @@ -44,14 +45,25 @@ class Art(Entity): def add_tags(self, tags, user): - for tag in tags.split(): - if len(tag) > 50: - raise "Long Tag!" # can we handle this more gracefully? - # sqlite seems happy to store strings much longer than the supplied limit... - - # elixir should really have its own find_or_create. - tagtext = find_or_create(TagText, text=tag) - tag = find_or_create(Tag, art=self, tagger=user, tagtext=tagtext) + for text in tags.split(): + if text[0] == '-': + # Nega-tags + tagtext = TagText.get_by(text=text[1:]) + if tagtext: + tag = Tag.get_by(art=self, tagger=user, tagtext=tagtext) + if tag: + elixir.session.delete(tag) + + else: + if len(text) > 50: + raise "Long Tag!" # can we handle this more gracefully? + # sqlite seems happy to store strings much longer than the supplied limit... + + + + # elixir should really have its own find_or_create. + tagtext = find_or_create(TagText, text=text) + tag = find_or_create(Tag, art=self, tagger=user, tagtext=tagtext) def __unicode__(self): diff --git a/floof/templates/art/show.mako b/floof/templates/art/show.mako index 88e3ec9..d77f364 100644 --- a/floof/templates/art/show.mako +++ b/floof/templates/art/show.mako @@ -8,7 +8,8 @@ ${h.submit('submit', 'Tag!')} ${h.end_form()} % for tag in c.art.tags: -${tag} +x +${tag} % endfor diff --git a/floof/tests/functional/test_tag.py b/floof/tests/functional/test_tag.py new file mode 100644 index 0000000..8424b43 --- /dev/null +++ b/floof/tests/functional/test_tag.py @@ -0,0 +1,7 @@ +from floof.tests import * + +class TestTagController(TestController): + + def test_index(self): + response = self.app.get(url(controller='tag', action='index')) + # Test response... -- 2.7.4