[cvs-annodex] commit (/annodex): cmmlwiki/trunk/cmmlwiki-admin cmmlwiki/trunk/edit.cgi cmmlwiki/trunk/view.cgi

conrad nobody at lists.annodex.net
Mon Apr 11 23:36:07 EST 2005


Update of /annodex (new revision 1235)

Modified files:
   cmmlwiki/trunk/cmmlwiki-admin
   cmmlwiki/trunk/edit.cgi
   cmmlwiki/trunk/view.cgi

Log Message:
expand project/source/clip tables


Modified: cmmlwiki/trunk/cmmlwiki-admin
===================================================================
--- cmmlwiki/trunk/cmmlwiki-admin	2005-04-11 10:28:00 UTC (rev 1234)
+++ cmmlwiki/trunk/cmmlwiki-admin	2005-04-11 13:36:06 UTC (rev 1235)
@@ -40,6 +40,7 @@
     # sources
     sql = """CREATE TABLE sources (
              ixs INTEGER PRIMARY KEY,
+             ixp INTEGER,
              path VARCHAR(256)
              )"""
     cur.execute(sql)
@@ -54,6 +55,7 @@
     # heads
     sql = """CREATE TABLE heads (
              ixh INTEGER PRIMARY KEY,
+             ixp INTEGER,
              id VARCHAR(20),
              title VARCHAR(80)
              )"""
@@ -62,6 +64,7 @@
     # clips
     sql = """CREATE TABLE clips (
              ixc INTEGER PRIMARY KEY,
+             ixp INTEGER,
              start_time INTEGER,
              id VARCHAR(20),
              a_href VARCHAR(80),
@@ -124,7 +127,8 @@
     row = cur.next()
     ixp = row['ixp']
 
-    cur.execute ('INSERT INTO sources (ixs, path) VALUES (NULL, "%s")' % (path))
+    sql = 'INSERT INTO sources (ixs, ixp, path) VALUES (NULL, "%s", "%s")' % (ixp, path)
+    cur.execute (sql)
     cur.execute ('SELECT (ixs) FROM sources WHERE path="%s"' % (path))
     row = cur.next()
     ixs = row[0]

Modified: cmmlwiki/trunk/edit.cgi
===================================================================
--- cmmlwiki/trunk/edit.cgi	2005-04-11 10:28:00 UTC (rev 1234)
+++ cmmlwiki/trunk/edit.cgi	2005-04-11 13:36:06 UTC (rev 1235)
@@ -157,7 +157,15 @@
     row = cur.next()
     return row['name']
     
+def attr_str (attr, dict, key):
+    if (dict.has_key(key)):
+      return 'attr="%s"' % dict[key]
+    else:
+      return ''
 
+def key_isprintable (dict, key):
+    return (dict.has_key(key) and dict[key] != None and dict[key] != '')
+
 def toc(ixp):
     content_type ("text/html")
 
@@ -175,46 +183,80 @@
 </p>
 <p/>
 """ % (name, view_base, name)
-  
-    sql = "SELECT * FROM clips ORDER BY start_time"
+
+    #sql = 'SELECT * FROM clips'
+    sql = """SELECT * FROM clips, projects
+             WHERE clips.ixp="%s"
+             ORDER BY clips.start_time""" % (ixp)
     #sql = """SELECT * FROM clips
     #         JOIN project_clips
     #         ON clips.ixc=project_clips.ixc
-    #         ORDER BY start_time""")
-    cur.execute (sql)
+    #         ORDER BY clips.start_time"""
+    #sql = """SELECT * FROM clips,project_clips
+    #         WHERE clips.ixc=project_clips.ixc"""
+    #sql = """SELECT * FROM project_clips,clips
+    #         WHERE project_clips.ixp="%s"
+    #         AND project_clips.ixc=clips.ixc
+    #         """ % ixp
+    cur.execute(sql)
     for row in cur.fetchall():
-        print '<div id="%(id)s" class="clip">' % row
+        #print '<p>%s</p>' % row.keys()
+        #print '<p>%s</p>' % row
 
-        if (row['img_src'] == None):
+        print '<div %s class="clip">' % (attr_str(id, row, 'clips.id'))
+
+        if (key_isprintable (row, 'clips.img_src')):
+            print '<img src="%(clips.img_src)s" align="left"/>' % row
+        else:
             print '[no image]'
-        else:
-            print '<img src="%(img_src)s" align="left"/>' % row
 
-        print """
-<h3>%(start_time)s: %(id)s</h3>
-<table>
+        print '<h3>'
+        if (key_isprintable (row, 'clips.start_time')):
+            print '%s' % row['clips.start_time']
+        if (key_isprintable (row, 'clips.id')):
+            print ': %(clips.id)s' % row
+        print '</h3>'
+ 
+        print '<table>'
+
+        if (key_isprintable (row, 'clips.a_href')):
+            print """
 <tr>
   <th>Link:</th>
-  <td colspan="3"><p><a href="%(a_href)s">%(a_href)s</a></p><td>
+  <td colspan="3"><p><a href="%(clips.a_href)s">%(clips.a_href)s</a></p><td>
 </tr>
+""" % row
+
+        if (key_isprintable (row, 'clips.desc')):
+            print """
 <tr>
   <th>Desc:</th>
-  <td colspan="3"><p>%(desc)s</p></td>
+  <td colspan="3"><p>%(clips.desc)s</p></td>
 </tr>
+""" % row
+
+        print """
 </table>
 <p align="right">
-""" % row
-        print '[<a href="%s/%s?id=%s">view</a>]' % (view_base, name, row['id'])
-        print '[<a href="?action=edit&ixc=%s">edit</a>]' % (row['ixc'])
+"""
+        if (key_isprintable (row, 'clips.id')):
+            print '[<a href="%s/%s?id=%s">view</a>]' % (view_base, name, row['clips.id'])
+        elif (key_isprintable (row, 'clips.start_time')):
+            print '[<a href="%s/%s?t=%s">view</a>]' % (view_base, name, row['clips.start_time'])
+            
 
-        print """[<a href="?action=delete&ixc=%(ixc)s">delete</a>]</p>
-</div>
-""" % row
+        if (key_isprintable (row, 'clips.ixc')):
+            print '[<a href="?action=edit&ixc=%s">edit</a>]' % (row['clips.ixc'])
 
+            print '[<a href="?action=delete&ixc=%(clips.ixc)s">delete</a>]</p>'
+
+        print '</div>'
+
     html_foot()
 
 def store(ixp, form):
     values = {}
+    values['ixp'] = ixp
     values['ixc'] = form['ixc'].value
     values['start_time'] = form['start_time'].value
     values['id'] = form['id'].value
@@ -225,17 +267,22 @@
     con = sqlite.connect(db, autocommit=1)
     cur = con.cursor()
 
-    if (form['ixc'].value == -1):
-        sql = """SELECT ixc FROM
-                 INSERT INTO clips (start_time, id, img_src, a_href, desc)
-                 VALUES ("%(start_time)s","%(id)s","%(img_src)s","%(a_href)s","%(desc)s") """ % values
+    if (form['ixc'].value == "-1"):
+        sql = """INSERT INTO clips (ixp, start_time, id, img_src, a_href, desc)
+                 VALUES ("%(ixp)s","%(start_time)s","%(id)s","%(img_src)s","%(a_href)s","%(desc)s") """ % values
         cur.execute(sql)
+        sql = 'SELECT ixc FROM clips WHERE id="%s"' % values['id']
+        cur.execute(sql)
         try:
             row = cur.next()
             values['ixc'] = row['ixc']
         except StopIteration:
             error ('ixc not found')
 
+        sql = """INSERT INTO project_clips (ixp, ixc)
+                 VALUES ("%s","%s") """ % (ixp, values['ixc'])
+        cur.execute (sql)
+
     else:
         sql = """UPDATE clips
                  SET start_time="%(start_time)s",id="%(id)s",img_src="%(img_src)s",a_href="%(a_href)s",desc="%(desc)s"
@@ -246,15 +293,13 @@
     #except sqlite.DatabaseError:
     #    error ('Database not initialized')
 
-    sql = """INSERT INTO project_clips (ixp, ixc)
-             VALUES ("%s","%s") """ % (ixp, values['ixc'])
-    cur.execute (sql)
-
     try:
       store = form["store"].value
     except KeyError:
       store = "Preview TOC"
 
+    if (store == "Save"):
+      toc(ixp)
     if (store == "Preview TOC"):
       toc(ixp)
     elif (store == "Preview Video"):
@@ -299,7 +344,7 @@
     ixp = get_ixp (path_info)
 
     try:
-        action = form["action"].value
+        action = form['action'].value
     except:
         if (ixp != -1):
             action = "toc"

Modified: cmmlwiki/trunk/view.cgi
===================================================================
--- cmmlwiki/trunk/view.cgi	2005-04-11 10:28:00 UTC (rev 1234)
+++ cmmlwiki/trunk/view.cgi	2005-04-11 13:36:06 UTC (rev 1235)
@@ -38,12 +38,18 @@
 </html>
 """
 
-def anxenc(infile, id="", t=0.0):
+def anxenc(ixp, id="", t=0.0):
     content_type ("application/x-annodex")
 
     con = sqlite.connect(db)
     cur = con.cursor()
 
+    # Get the source
+    sql = 'SELECT * FROM sources WHERE ixp="%s"' % ixp
+    cur.execute(sql)
+    row = cur.next()
+    source = row['path']
+
     # Work out the named time offset
     if (id == ""):
         offset = float(t)
@@ -56,10 +62,11 @@
     # Begin the import
     annodex.init_importers("*/*")
     anx = annodex.Anx(1, "w")
-    anx.writer_import(infile, offset=offset)
+    anx.writer_import(source, offset=offset)
 
     # Insert clips
-    cur.execute("""SELECT * FROM clips ORDER BY start_time""")
+    sql = 'SELECT * FROM clips WHERE ixp="%s" ORDER BY start_time' % ixp
+    cur.execute(sql)
     for row in cur.fetchall():
         clip = annodex.Clip(anchor=annodex.Anchor(text="%(a_href)s" % row,
                                                   href="%(a_href)s" % row))
@@ -84,7 +91,7 @@
   
     con = sqlite.connect(db)
     cur = con.cursor()
-    sql = 'SELECT * FROM clips ORDER BY start_time'
+    sql = 'SELECT * FROM clips WHERE ixp="%s" ORDER BY start_time' % ixp
     cur.execute(sql)
     for row in cur.fetchall():
         print """<clip start="%(start_time)s">
@@ -135,7 +142,7 @@
     if (accept == "text/x-cmml"):
       fake_cmml(ixp)
     else:
-      anxenc ('/var/www/m.anx', id, t)
+      anxenc (ixp, id, t)
 
 # Call main function.
 main()


-- 
conrad



More information about the cvs-annodex mailing list