Merge branch 'tags' into search
authorNick Retallack <nickretallack@gmil.com>
Sun, 4 Oct 2009 20:20:41 +0000 (13:20 -0700)
committerNick Retallack <nickretallack@gmil.com>
Sun, 4 Oct 2009 20:20:41 +0000 (13:20 -0700)
floof/controllers/tag.py [new file with mode: 0644]
floof/model/art.py
floof/templates/art/show.mako
floof/tests/functional/test_tag.py [new file with mode: 0644]

diff --git a/floof/controllers/tag.py b/floof/controllers/tag.py
new file mode 100644 (file)
index 0000000..3b69ed6
--- /dev/null
@@ -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
index ef50dcd..2c631f7 100644 (file)
@@ -6,6 +6,7 @@
 
 # from elixir import Entity, Field, Integer, Unicode
 from elixir import *
+import elixir
 
 from pylons import config
 
@@ -42,14 +43,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):
index 88e3ec9..d77f364 100644 (file)
@@ -8,7 +8,8 @@ ${h.submit('submit', 'Tag!')}
 ${h.end_form()}
 
 % for tag in c.art.tags:
-${tag}
+<a href="${h.url_for (controller='tag', action='delete', id=tag.id)}">x</a> 
+<a href="${h.url_for (controller='search', action='results')}?query=${tag}">${tag}</a>
 % endfor
 
 
diff --git a/floof/tests/functional/test_tag.py b/floof/tests/functional/test_tag.py
new file mode 100644 (file)
index 0000000..8424b43
--- /dev/null
@@ -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...