[xiph-commits] r3237 - in arkaiv/trunk: arkaiv/controllers arkaiv/model arkaiv/templates data/templates

dcrowdy at svn.annodex.net dcrowdy at svn.annodex.net
Wed Sep 12 03:33:08 PDT 2007


Author: dcrowdy
Date: 2007-09-12 03:33:07 -0700 (Wed, 12 Sep 2007)
New Revision: 3237

Modified:
   arkaiv/trunk/arkaiv/controllers/page.py
   arkaiv/trunk/arkaiv/controllers/page.pyc
   arkaiv/trunk/arkaiv/model/__init__.py
   arkaiv/trunk/arkaiv/model/__init__.pyc
   arkaiv/trunk/arkaiv/templates/displayitem.mak
   arkaiv/trunk/arkaiv/templates/playlistview.mak
   arkaiv/trunk/data/templates/displayitem.mak.py
   arkaiv/trunk/data/templates/displayitem.mak.pyc
Log:
Further separation of model from view following some poor late night wine and caffeine fuelled decisions presenting database objects in the template.  Only the search implementation to go.


Modified: arkaiv/trunk/arkaiv/controllers/page.py
===================================================================
--- arkaiv/trunk/arkaiv/controllers/page.py	2007-09-12 01:00:42 UTC (rev 3236)
+++ arkaiv/trunk/arkaiv/controllers/page.py	2007-09-12 10:33:07 UTC (rev 3237)
@@ -135,15 +135,17 @@
     def displayplaylist(self):
         # Need to extract appropriate info for the playlist selected
         playlistid = int(request.params['id'])
+        print "playlist id is \n\n"
+        print playlistid
         c.name = request.params['name']        
         clips = model.getclipsfromplaylist(playlistid)
         items = model.getitemsfromplaylist(playlistid)
         # send a list of dictionaries to the template
-        c.cliplist = []
+#        c.cliplist = []
         for clip in clips:
             if (clip != None):
-                clipdict = {}
-                item = model.getitemforclip(clip.ixc)
+           #     clipdict = {}
+                item = model.getitemforclip(clip['index'])
                 sourceid = model.getsourcesforitem(item.ixi)
                 oggsource = model.getsourcepath(sourceid)
                 #print oggsource
@@ -152,29 +154,33 @@
                 urlpath = split(cmmlfile, path_base)
                 # Now split off the extension
                 urlpath = os.path.splitext(urlpath[1])[0]
-                #clipimageurl = media_url_base + os.path.dirname(urlpath) + "/"
+                #clipimageurl = media_url_base + os.dirname(urlpath) + "/"
                 #print clipimageurl
-                clipdict['id'] = clip.ixc
-                clipdict['url'] = media_url_base + urlpath + ".anx" + "?id=" + clip.id
-                c.cliplist.append(clipdict)
+           #     clipdict['id'] = clip.ixc
+                clip['url'] = media_url_base + urlpath + ".anx" + "?id=" + clip['id']
+                #c.cliplist.append(clipdict)
         
         for item in items:
-            itemdict = {}
-            sourceid = model.getsourcesforitem(item.ixi)
+#            itemdict = {}
+            sourceid = model.getsourcesforitem(item['index'])
             oggsource = model.getsourcepath(sourceid)
             #print oggsource
-            cmmlfile = model.getitemcmmlfile(item.ixi)
+#            cmmlfile = model.getitemcmmlfile(item.ixi)
             #print cmmlfile
-            urlpath = split(cmmlfile, path_base)
+            urlpath = split(item['cmmlfile'], path_base)
             # Now split off the extension
             urlpath = os.path.splitext(urlpath[1])[0]
             #clipimageurl = media_url_base + os.path.dirname(urlpath) + "/"
             #print clipimageurl
-            itemdict['id'] = ""
-            itemdict['url'] = media_url_base + urlpath + ".anx" + "?id=0"
-            c.cliplist.append(itemdict)
+            item['id'] = ""    # a dummy to match clip info
+            #itemdict['url'] = media_url_base + urlpath + ".anx" + "?id=0"
+            item['url'] = media_url_base + urlpath + ".anx" + "?id=0"
+#            c.cliplist.append(itemdict)
+            clips.append(item)
 
-        if (not c.cliplist):
+        c.clips = clips 
+        print c.clips
+        if (not c.clips):
             print "Nothing in clips"
             return render ('/emptyplaylistmessage.mak')
         else:
@@ -220,7 +226,7 @@
         # FIXME - this should be just a list of the meta objects - why return a
         # dict?
 
-        c.metalist = model.getmetainfoforhead(c.headdict['ixh'])
+        c.metalist = model.getmetainfoforhead(c.headdict['index'])
         c.source = model.getsourcesforitem(itemid)
         sourcedict = {}
         oggsource = model.getsourcepath(c.source)
@@ -229,18 +235,13 @@
         urlpath = split(cmmlfile, path_base)
         # Now split off the extension
         urlpath = os.path.splitext(urlpath[1])[0]
-#        clipimagepath = urlpath + "_clipimages"
         clipimageurl = media_url_base + os.path.dirname(urlpath) + "/"
-#        print clipimageurl
-#        print "urlpath: " + urlpath
         url = media_url_base + urlpath + ".anx"
         if c.playclip=="":
-#            sourcedict['urlpath'] = url 
             sourcedict['clipdetail'] = ""
         else:
             sourcedict['clipdetail'] = "?id=" + c.playclip
 
-#        sourcedict['urlpath'] = url['base'] +    # + "?id=" + c.playclip
         sourcedict['urlpath'] = url   # + "?id=" + c.playclip
         sourcedict['clipimageurl'] = clipimageurl
         # now get some source info:
@@ -276,10 +277,6 @@
 
         #  Item title is not in the cmml file - although I guess it could be
         #  linked?  On import, the item title is the same as the head title
-
-       # parser = anxParser()
-       # cmmlfilename = model.getitemcmmlfile(itemid)
-       # parser.setcmmlfilename(cmmlfilename)
         
         return text
 
@@ -306,9 +303,9 @@
         metadict['content'] = request.params['metacontent']
         metadict['scheme'] = request.params['metascheme']
         # pass a dict in to the model
-        meta = model.addmeta(metadict)
+        metaid = model.addmeta(metadict)
 
-        model.syncmetaid(meta.ixm)
+        model.syncmetaid(metaid)
         cmmlfile = model.getitemcmmlfile(metadict['itemid'])
         parser = cmmlParser()
         parser.setcmmlfilename(cmmlfile)
@@ -515,6 +512,13 @@
  
         return
 
+    def newsearch(self):
+        searchterms = request.params['searchterms']
+        clips = model.searchforclips(searchterms)
+
+        return
+
+# the old search function - to be replaced eventually by the above
     def search(self):
         searchterms = request.params['searchterms']
         resultsdict = model.search(searchterms)

Modified: arkaiv/trunk/arkaiv/controllers/page.pyc
===================================================================
(Binary files differ)

Modified: arkaiv/trunk/arkaiv/model/__init__.py
===================================================================
--- arkaiv/trunk/arkaiv/model/__init__.py	2007-09-12 01:00:42 UTC (rev 3236)
+++ arkaiv/trunk/arkaiv/model/__init__.py	2007-09-12 10:33:07 UTC (rev 3237)
@@ -285,6 +285,9 @@
     return items
 
 def addnewcollection(name):
+    """ Adds a new collection to the database given a name
+
+    """
     newcollection = Collection()
     newcollection.name = name
     Session.save(newcollection)
@@ -308,6 +311,10 @@
     return collections
 
 def getitemsincollection(id):
+    """ Gets all items from a collection given a collection index value
+
+        returns a list of dictionaries with keys "index" and "name"
+    """
     coll_items_q = Session.query(Collectionitems)
     # get a list of ids 
     cilist = coll_items_q.filter_by(ixk=id)
@@ -351,6 +358,9 @@
     return
 
 def addcliptoplaylist(list, clipid):
+    """ Adds a clip to a playlist
+
+    """
     # get the id for the list
     p_q = Session.query(Playlist)
     p = p_q.filter_by(name=list).first()
@@ -367,6 +377,9 @@
     return
 
 def additemtoplaylist(list, itemid):
+    """ Adds and item to a playlist
+
+    """
     p_q = Session.query(Playlist)
     p = p_q.filter_by(name=list).first()
     pi = Playlistitems()
@@ -382,15 +395,25 @@
 def getclipsfromplaylist(listid):
     pi_q = Session.query(Playlistitems)
     pi = pi_q.filter_by(ixp=listid).all()
+    print pi
     c_q = Session.query(Clip)
-    cliplist = []
+    clips = []
     for item in pi:
-        c = c_q.filter_by(ixc=item.ixc).first()
-#        c = c_q.filter_by(ixc=item.ixc).one()     #FIXME this doesn't work so still using the deprecated filter_by above - not sure what the problem is here
-
-        cliplist.append(c)
+        if item.ixc:
+            print item.ixc
+            clip = {}
+            c = c_q.filter_by(ixc=item.ixc).first()
+            clip['index'] = c.ixc
+            clip['start'] = c.start_time
+            clip['end'] = c.end_time
+            clip['id'] = c.id
+            clip['a_href'] = c.a_href
+            clip['a_text'] = c.a_text
+            clip['img_src'] = c.img_src
+            clip['desc'] = c.desc
+            clips.append(clip)
         
-    return cliplist
+    return clips
 
 def getitemsfromplaylist(listid):
     """ This gets items in the playlist that have no clip info
@@ -399,15 +422,18 @@
     pi_q = Session.query(Playlistitems)
     pi = pi_q.filter_by(ixp=listid).all()
     i_q = Session.query(Item)
-    itemlist = []
-    for item in pi:
+    items = []
+    for n in pi:
         #print item.ixc
-        if (not item.ixc):
-            #i = i_q.filter_by(ixi=item.ixi)
-            i = i_q.filter_by(ixi=item.ixi).first()
-            itemlist.append(i)
+        if (not n.ixc):
+            item = {}
+            i = i_q.filter_by(ixi=n.ixi).first()
+            item['index'] = i.ixi
+            item['name'] = i.name
+            item['cmmlfile'] = i.cmmlfile
+            items.append(item)
 
-    return itemlist
+    return items
 
 def deleteplaylist(listname):
     """ deletes a playlist and items in the playlist_items table
@@ -579,7 +605,7 @@
     itemhead_q = Session.query(Itemheads)
     ih = itemhead_q.filter_by(ixi=id).first()
     h = head_q.filter_by(ixh=ih.ixh).first()
-    headdict['ixh'] = h.ixh
+    headdict['index'] = h.ixh
     headdict['id'] = h.id
     headdict['title'] = h.title
     return headdict
@@ -598,28 +624,28 @@
     return metalist
 
 def getmetainfoforhead(id):
+    """ Get meta info for an item's head
 
-# This returns a dictionary - deprecated by getmetasforhead, but used in
-# displayitem  FIXME
-
-    # now return a list of metas with that id in head_metas table
+        Returns a list of dicts with keys:
+            index, id, name, content, scheme
+    """
     head_meta_q = Session.query(Headmetas)
     hmlist = head_meta_q.filter_by(ixh=id).all()
-    metalist = []
+    metas = []
     meta_q = Session.query(Meta)
     for hm in hmlist:
         # get individual meta info
-        metainfo = {}
+        meta= {}
         m = meta_q.filter_by(ixm=hm.ixm).first()
-        metainfo['ixm'] = m.ixm
-        metainfo['id'] = m.id
-        metainfo['name'] = m.name
-        metainfo['content'] = m.content
-        metainfo['scheme'] = m.scheme
-        metalist.append(metainfo)
+        meta['index'] = m.ixm
+        meta['id'] = m.id
+        meta['name'] = m.name
+        meta['content'] = m.content
+        meta['scheme'] = m.scheme
+        metas.append(meta)
 
     Session.commit()
-    return metalist
+    return metas
 
 def addmeta(info):
     """ Given a dictionary of meta info, adds a meta item to database
@@ -636,7 +662,7 @@
     new_meta.my_heads.append(h)
     Session.save(new_meta)
     Session.commit()
-    return new_meta
+    return new_meta.ixm
 
 def syncmetaid(metaid):
     """ Given the meta primary key, it sets id to the same value
@@ -739,6 +765,10 @@
     # All very rough - done in a hurry; lots of code that can be combined in a
     # single function here; need to be able to cope with multiple search words
     # too
+    
+    # Should modify this to simply send back a list of dicts with relevant keys
+    # - item.ixi, item.name, clip.ixc, clip.desc, meta.ixm, meta info and then
+    # just work on that list in the controller
 
     resultsdict={}
     searchstring = "%" + searchterms + "%"
@@ -782,3 +812,10 @@
     Session.commit()
     return
 
+# testing new search functions
+
+def searchforclips(searchterm):
+    # search for clips within the database, and return a list of dictionaries
+    # with keys "clipindex", "itemindex", "itemname", "clipdesc", "clipid"
+
+    return

Modified: arkaiv/trunk/arkaiv/model/__init__.pyc
===================================================================
(Binary files differ)

Modified: arkaiv/trunk/arkaiv/templates/displayitem.mak
===================================================================
--- arkaiv/trunk/arkaiv/templates/displayitem.mak	2007-09-12 01:00:42 UTC (rev 3236)
+++ arkaiv/trunk/arkaiv/templates/displayitem.mak	2007-09-12 10:33:07 UTC (rev 3237)
@@ -80,9 +80,9 @@
 <td>
 ${ h.form(h.url(action='deletemeta'), multipart=True) }
 ${ h.submit('Delete') }
-${ h.hidden_field('metaid', value=metainfo['ixm']) }
+${ h.hidden_field('metaid', value=metainfo['index']) }
 ${ h.hidden_field('itemid', value=c.itemid) }
-${ h.hidden_field('headid', value=c.headdict['ixh']) }
+${ h.hidden_field('headid', value=c.headdict['index']) }
 ${ h.end_form() } 
 
 </td>
@@ -106,7 +106,7 @@
 </tr>
 </table>
 ${ h.hidden_field('metascheme') }
-${ h.hidden_field('headindex', value = c.headdict['ixh']) }
+${ h.hidden_field('headindex', value = c.headdict['index']) }
 ${ h.hidden_field('itemid', value=c.itemid) }
 
 ${ h.submit('Add') } 
@@ -204,7 +204,7 @@
   <td>${ h.text_field('a_href') }</td>
 </tr>
 </table>
-${ h.hidden_field('headindex', value = c.headdict['ixh']) }
+${ h.hidden_field('headindex', value = c.headdict['index']) }
 ${ h.hidden_field('itemid', value=c.itemid) }
 ${ h.hidden_field('hasvideo', value=c.sourcedict['has_video']) }
 ${ h.submit('Add') } 

Modified: arkaiv/trunk/arkaiv/templates/playlistview.mak
===================================================================
--- arkaiv/trunk/arkaiv/templates/playlistview.mak	2007-09-12 01:00:42 UTC (rev 3236)
+++ arkaiv/trunk/arkaiv/templates/playlistview.mak	2007-09-12 10:33:07 UTC (rev 3237)
@@ -8,7 +8,7 @@
 ${ h.end_form() } 
 
 <form name="clips">
-% for clip in c.cliplist:
+% for clip in c.clips:
 <label for="${clip['id']}">
 <input id="${clip['id']}" type="checkbox" name="list" value="${clip['url']}" checked/>
 ${clip['url']}
@@ -16,7 +16,7 @@
 <br>
 % endfor
 </form>
-<embed type="application/liboggplay" src="${c.cliplist[0]['url']}" width=320 height=240/>
+<embed type="application/liboggplay" src="${c.clips[0]['url']}" width=320 height=240/>
 
 <form name="api">
 <input type="button" value="Play" onclick='Play()'/>

Modified: arkaiv/trunk/data/templates/displayitem.mak.py
===================================================================
--- arkaiv/trunk/data/templates/displayitem.mak.py	2007-09-12 01:00:42 UTC (rev 3236)
+++ arkaiv/trunk/data/templates/displayitem.mak.py	2007-09-12 10:33:07 UTC (rev 3237)
@@ -1,7 +1,7 @@
 from mako import runtime, filters, cache
 UNDEFINED = runtime.UNDEFINED
 _magic_number = 2
-_modified_time = 1189493212.3808031
+_modified_time = 1189582730.0332439
 _template_filename='/home/dcrowdy/src/working/trunk/arkaiv/templates/displayitem.mak'
 _template_uri='/displayitem.mak'
 _template_cache=cache.Cache(__name__, _modified_time)
@@ -95,13 +95,13 @@
             context.write(unicode( h.submit('Delete') ))
             context.write(u'\n')
             # SOURCE LINE 83
-            context.write(unicode( h.hidden_field('metaid', value=metainfo['ixm']) ))
+            context.write(unicode( h.hidden_field('metaid', value=metainfo['index']) ))
             context.write(u'\n')
             # SOURCE LINE 84
             context.write(unicode( h.hidden_field('itemid', value=c.itemid) ))
             context.write(u'\n')
             # SOURCE LINE 85
-            context.write(unicode( h.hidden_field('headid', value=c.headdict['ixh']) ))
+            context.write(unicode( h.hidden_field('headid', value=c.headdict['index']) ))
             context.write(u'\n')
             # SOURCE LINE 86
             context.write(unicode( h.end_form() ))
@@ -124,7 +124,7 @@
         context.write(unicode( h.hidden_field('metascheme') ))
         context.write(u'\n')
         # SOURCE LINE 109
-        context.write(unicode( h.hidden_field('headindex', value = c.headdict['ixh']) ))
+        context.write(unicode( h.hidden_field('headindex', value = c.headdict['index']) ))
         context.write(u'\n')
         # SOURCE LINE 110
         context.write(unicode( h.hidden_field('itemid', value=c.itemid) ))
@@ -225,7 +225,7 @@
         context.write(unicode( h.text_field('a_href') ))
         context.write(u'</td>\n</tr>\n</table>\n')
         # SOURCE LINE 207
-        context.write(unicode( h.hidden_field('headindex', value = c.headdict['ixh']) ))
+        context.write(unicode( h.hidden_field('headindex', value = c.headdict['index']) ))
         context.write(u'\n')
         # SOURCE LINE 208
         context.write(unicode( h.hidden_field('itemid', value=c.itemid) ))

Modified: arkaiv/trunk/data/templates/displayitem.mak.pyc
===================================================================
(Binary files differ)



More information about the commits mailing list