Use dropdowns (with textbox option for new tags) for tag manipulation.
authorW. Trevor King <wking@drexel.edu>
Wed, 21 Jul 2010 18:58:51 +0000 (14:58 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 21 Jul 2010 18:58:51 +0000 (14:58 -0400)
cookbook/server.py
cookbook/template/recipe.html

index d60641448f45458aa2236c8a431994892dc093d8..94f70f6c10c1456f6127a3fa76352130d2e3c26b 100644 (file)
@@ -103,6 +103,14 @@ class Server (object):
 
     def _clean_tag(self, tag):
         """Sanitize tag."""
+        if not isinstance(tag, types.StringType):
+            if len(tag) == 2 and '' in tag:
+                # User used either dropdown or textbox
+                tag.remove('')
+                tag = tag[0]
+            else:
+                # User used both dropdown and textbox
+                return None
         m = self.tag_regexp.match(tag)
         if m != None:
             return m.group()
index b335014c490928b6e75dc920b41a392436f432e7..5864d23a649564592eed3c649264ed0e4a21cf55 100644 (file)
        </span><br />
     {% endif %}
     </p>
-    <form action="add_tag" method="post">
+    <form action="add_tag" method="get">
       <input type="hidden" name="name" value="{{ recipe.name }}"/>
+      <select name="tag">
+       <option value="">textbox</option>
+       {% for tag in cookbook.tags() %}
+       <option value="{{ tag }}">{{ tag }}</option>
+       {% endfor %}
+      </select>
       <input type="text" name="tag" value=""/>
       <input type="submit" value="Add tag" />
     </form>
-    <form action="remove_tag" method="post">
+    {% if recipe.tags %}
+    <form action="remove_tag" method="get">
       <input type="hidden" name="name" value="{{ recipe.name }}"/>
-      <input type="text" name="tag" value=""/>
+      <select name="tag">
+       {% for tag in recipe.tags %}
+       <option value="{{ tag }}">{{ tag }}</option>
+       {% endfor %}
+      </select>
       <input type="submit" value="Remove tag" />
     </form>
+    {% endif %}
 
     <div id="recipe-ingredient-blocks">
     {% for ingredient_block in recipe.ingredient_blocks %}