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

dcrowdy at svn.annodex.net dcrowdy at svn.annodex.net
Wed Sep 12 18:18:45 PDT 2007


Author: dcrowdy
Date: 2007-09-12 18:18:45 -0700 (Wed, 12 Sep 2007)
New Revision: 3239

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/searchresults.mak
   arkaiv/trunk/data/templates/autohandler.py
   arkaiv/trunk/data/templates/autohandler.pyc
Log:
Re-implementation of searching facility again to separate model from view.


Modified: arkaiv/trunk/arkaiv/controllers/page.py
===================================================================
--- arkaiv/trunk/arkaiv/controllers/page.py	2007-09-12 23:38:26 UTC (rev 3238)
+++ arkaiv/trunk/arkaiv/controllers/page.py	2007-09-13 01:18:45 UTC (rev 3239)
@@ -512,49 +512,22 @@
  
         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)
-        c.items = []
-        for id in resultsdict['items']:
-           c.items.append(model.getitemforid(id))
-        
-        # for the metas, we need to find its item
-        # meta info is returned as result['meta'] and
-        # result['item'] - and there'll be a list of these
-        c.metas = []
-        for metaid in resultsdict['metas']:
-            result={}
-            result['meta'] = model.getheadmeta(metaid)
-            result['item'] = model.getitemforheadmeta(metaid)
-            c.metas.append(result)
-#            print result
-#        print resultsdict['metas']
-#        print c.metas
+        # actually we can only search for a single search term at the moment
+        c.clips = model.searchforclips(searchterms)
+        c.items = model.searchforitems(searchterms)
+        c.metas = model.searchformetas(searchterms)
+        #print c.clips
 
-        c.clips = []
-        for clipid in resultsdict['clips']:
-            result={}
-            result['clip'] = model.getclip(clipid) 
-            result['item'] = model.getitemforclip(clipid) 
-            c.clips.append(result)
-
-        # we want to be able to add found items to a playlist
         c.playlists=model.getplaylists()
         c.playlistinfo = ""
         for playlist in c.playlists:
             c.playlistinfo = c.playlistinfo + "<option>" + playlist['name'] + "</option>"
-            
-
+ 
         return render('/searchresults.mak')
 
+
     def editheadmetaname(self):
         text = request.params['myparam']
         id = request.params['id']

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 23:38:26 UTC (rev 3238)
+++ arkaiv/trunk/arkaiv/model/__init__.py	2007-09-13 01:18:45 UTC (rev 3239)
@@ -12,6 +12,7 @@
 
 from pylons import config
 from sqlalchemy import Column, MetaData, Table, ForeignKey, types
+from sqlalchemy.sql import and_, or_, not_
 from sqlalchemy.orm import mapper, relation
 from sqlalchemy.orm import scoped_session, sessionmaker
 #from sacontext import PylonsSAContext
@@ -761,50 +762,7 @@
     Session.commit()
     return
 
-def search(searchterms):
-    # 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 + "%"
-    # look for item names:
-    item_q = Session.query(Item)
-    items = item_q.select(items_table.c.name.like(searchstring))
-    itemnames = []
-    for item in items:
-        itemnames.append(item.ixi)
-
-    # look for meta names:
-    meta_q = Session.query(Meta)
-    metas = meta_q.select(metas_table.c.name.like(searchstring))
-    metanames = []
-    for meta in metas:
-        metanames.append(meta.ixm)
-
-    metas = meta_q.select(metas_table.c.content.like(searchstring))
-    # keep appending to the metanames list
-    for meta in metas:
-        metanames.append(meta.ixm)
-
-    # And search clips now:
-    clip_q = Session.query(Clip)
-    clips = clip_q.select(clips_table.c.desc.like(searchstring))
-    clipnames = []
-    for clip in clips:
-        clipnames.append(clip.ixc)
-
-    resultsdict['items'] = itemnames
-    resultsdict['metas'] = metanames
-    resultsdict['clips'] = clipnames
-    Session.commit()
-
-    return resultsdict
-
 def deletemeta(metaid):
     meta_q = Session.query(Meta)
     m = meta_q.filter_by(ixm=metaid).first()
@@ -817,5 +775,66 @@
 def searchforclips(searchterm):
     # search for clips within the database, and return a list of dictionaries
     # with keys "clipindex", "itemindex", "itemname", "clipdesc", "clipid"
+    searchstring = "%" + searchterm + "%"
+    clip_q = Session.query(Clip)
+    c = clip_q.select(clips_table.c.desc.like(searchstring))
+    clips = []
+    ic_q = Session.query(Itemclips)
+    it_q = Session.query(Item)
+    for i in c:
+        clip = {}
+        ic = ic_q.filter_by(ixc=i.ixc).first()
+        item = it_q.filter_by(ixi=ic.ixi).first() 
+        clip['itemindex'] =  item.ixi
+        clip['itemname'] = item.name
+        clip['index'] = i.ixc
+        clip['id'] = i.id
+        clip['desc'] = i.desc
+        clips.append(clip)
+        #clipnames.append(clip.ixc)
 
-    return
+    return clips
+
+def searchforitems(searchterm):
+    searchstring = "%" + searchterm + "%"
+    item_q = Session.query(Item)
+    i = item_q.select(items_table.c.name.like(searchstring))
+    items = []
+    for n in i:
+        item = {}
+        item['index'] = n.ixi
+        item['name'] = n.name
+        item['cmmlfile'] = n.cmmlfile
+        items.append(item)
+
+    return items
+
+def searchformetas(searchterm):
+    """ searches in the meta name and content fields of the database
+
+        returns a list of dictionaries with keys:
+            index, name, content, itemindex, itemname
+    """
+    searchstring = "%" + searchterm + "%"
+    meta_q = Session.query(Meta)
+    s = or_((metas_table.c.name.like(searchstring)), (metas_table.c.content.like(searchstring)))
+    m = meta_q.select(s)
+    #m = meta_q.select((metas_table.c.name.like(searchstring))
+#    m = meta_q.select((metas_table.c.name.like(searchstring)), or_(metas_table.c.content.like(searchstring)))
+    hm_q = Session.query(Headmetas)
+    ih_q = Session.query(Itemheads)
+    i_q = Session.query(Item)
+    metas = []
+    for n in m:
+        meta = {}
+        hm = hm_q.filter_by(ixm=n.ixm).first()
+        ih = ih_q.filter_by(ixh=hm.ixh).first()
+        i = i_q.filter_by(ixi=ih.ixi).first()
+        meta['index'] = n.ixm
+        meta['name'] = n.name
+        meta['content'] = n.content
+        meta['itemindex'] = i.ixi
+        meta['itemname'] = i.name
+        metas.append(meta)
+
+    return metas

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

Modified: arkaiv/trunk/arkaiv/templates/searchresults.mak
===================================================================
--- arkaiv/trunk/arkaiv/templates/searchresults.mak	2007-09-12 23:38:26 UTC (rev 3238)
+++ arkaiv/trunk/arkaiv/templates/searchresults.mak	2007-09-13 01:18:45 UTC (rev 3239)
@@ -5,11 +5,11 @@
 <p>Items:</p>
 % for item in c.items:
 <li>
-	${item.ixi}
-	${ h.link_to(item.name, h.url(action="displayitem", edit="no", id=item.ixi))}
+	${item['index']}
+	${ h.link_to(item['name'], h.url(action="displayitem", edit="no", id=item['index']))}
 </li>
 % endfor
-<hr>
+
 <p>Meta names:</p>
 <form name='metas' action='additemstoplaylist'>
 <table>
@@ -21,12 +21,12 @@
 <%
 i = 0
 %>
-% for metaresult in c.metas:
+% for meta in c.metas:
 <tr>
-<td>${metaresult['meta'].name}</td>
-<td>${metaresult['meta'].content}</td>
-<td>${ h.link_to(metaresult['item'].name, h.url(action="displayitem", edit="no", id=metaresult['item'].ixi))}</td>
-<td><input type='checkbox' name='${i}' value='${metaresult['item'].ixi}'></td>
+<td>${meta['name']}</td>
+<td>${meta['content']}</td>
+<td>${ h.link_to(meta['itemname'], h.url(action="displayitem", edit="no", id=meta['itemindex']))}</td>
+<td><input type='checkbox' name='${i}' value='${meta['itemindex']}'></td>
 </tr>
 <%
 i = i + 1
@@ -39,6 +39,7 @@
 ${ h.hidden_field('nummetas', value=i) }
 ${ h.submit('Add') } 
 </form>
+
 <hr>
 Clips:
 <table>
@@ -51,12 +52,12 @@
 <%
 i = 0
 %>
-% for clipresult in c.clips:
+% for clip in c.clips:
 <tr>
-<td>${clipresult['clip'].id}</td>
-<td>${clipresult['clip'].desc}</td>
-<td>${ h.link_to(clipresult['item'].name, h.url(action="displayitem", edit="no", id=clipresult['item'].ixi, playclip=clipresult['clip'].id))}</td>
-<td><input type='checkbox' name='${i}' value='${clipresult['clip'].ixc}'></td>
+<td>${clip['id']}</td>
+<td>${clip['itemname']}</td>
+<td>${ h.link_to(clip['desc'], h.url(action="displayitem", edit="no", id=clip['itemindex'], playclip=clip['id']))}</td>
+<td><input type='checkbox' name='${i}' value='${clip['index']}'></td>
 </tr>
 <%
 i = i + 1

Modified: arkaiv/trunk/data/templates/autohandler.py
===================================================================
--- arkaiv/trunk/data/templates/autohandler.py	2007-09-12 23:38:26 UTC (rev 3238)
+++ arkaiv/trunk/data/templates/autohandler.py	2007-09-13 01:18:45 UTC (rev 3239)
@@ -1,7 +1,7 @@
 from mako import runtime, filters, cache
 UNDEFINED = runtime.UNDEFINED
 _magic_number = 2
-_modified_time = 1189492026.7317741
+_modified_time = 1189635019.326093
 _template_filename=u'/home/dcrowdy/src/working/trunk/arkaiv/templates/autohandler'
 _template_uri=u'/autohandler'
 _template_cache=cache.Cache(__name__, _modified_time)

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



More information about the commits mailing list