de-cgi-bin/taggr2.py
changeset 24 001f52cd057e
parent 23 10841abbc01f
child 25 4b3cf12848c2
--- a/de-cgi-bin/taggr2.py	Thu Jan 17 01:56:04 2008 +0000
+++ b/de-cgi-bin/taggr2.py	Sun Jan 20 01:07:02 2008 +0000
@@ -26,7 +26,6 @@
 from lib import db, shorturl, settings, utils, template, req
 
 
-
 tpl = template.Template("taggr")
 
 act = req.get_str("act", None)
@@ -55,9 +54,11 @@
             dirs.append((fname, fpath))
 
         elif utils.isImage(fname) :
-            key = shorturl.int2key(db.select("""SELECT id FROM images WHERE dirpath=? AND filename=?""", path, fname).fetchone()[0])
+            id = db.select("""SELECT id FROM images WHERE dirpath=? AND filename=?""", path, fname).fetchone()[0]
 
-            imgs.append((key, os.path.join(path, settings.THUMB_DIR, fname)))
+            tags = [tag for type, tag in db.select("""SELECT type, tag FROM tags WHERE image=?""", id)]
+
+            imgs.append((id, os.path.join(path, settings.THUMB_DIR, fname), tags))
 
     dirs.sort()
     imgs.sort()
@@ -72,6 +73,22 @@
         images                  = imgs,
     )
 
+elif act == "tag" :
+    img_list = req.get_int_list("img")
+    tag = req.get_str("tag")
+
+    db.insert_many("""INSERT INTO tags (image, tag) VALUES (?, ?)""", ((img, tag) for img in img_list))
+
+    print "OK"
+
+elif act == "untag" :
+    img = req.get_int("img")
+    tag = req.get_str("tag")
+
+    db.delete("""DELETE FROM tags WHERE image=? AND tag=?""", img, tag)
+
+    print "OK"
+
 elif act == None :
     dirs, imgs = dirlist(".")
 
@@ -80,7 +97,7 @@
         open_dir_contents = dirlist(path)
     else :
         open_dir = open_dir_contents = None
-
+    
     print template.Template("taggr").render(
         stylesheet_url          = utils.url("style.css", up=1),
         title                   = "Taggr",