[xiph-commits] r3232 - in arkaiv/trunk/arkaiv: . config controllers
lib model templates
dcrowdy at svn.annodex.net
dcrowdy at svn.annodex.net
Mon Sep 10 23:42:59 PDT 2007
Author: dcrowdy
Date: 2007-09-10 23:42:58 -0700 (Mon, 10 Sep 2007)
New Revision: 3232
Modified:
arkaiv/trunk/arkaiv/__init__.pyc
arkaiv/trunk/arkaiv/config/__init__.pyc
arkaiv/trunk/arkaiv/config/environment.py
arkaiv/trunk/arkaiv/config/environment.pyc
arkaiv/trunk/arkaiv/config/middleware.pyc
arkaiv/trunk/arkaiv/config/routing.pyc
arkaiv/trunk/arkaiv/controllers/__init__.pyc
arkaiv/trunk/arkaiv/controllers/error.pyc
arkaiv/trunk/arkaiv/controllers/page.pyc
arkaiv/trunk/arkaiv/lib/__init__.pyc
arkaiv/trunk/arkaiv/lib/app_globals.pyc
arkaiv/trunk/arkaiv/lib/base.py
arkaiv/trunk/arkaiv/lib/base.pyc
arkaiv/trunk/arkaiv/lib/helpers.pyc
arkaiv/trunk/arkaiv/model/__init__.py
arkaiv/trunk/arkaiv/model/__init__.py.old
arkaiv/trunk/arkaiv/model/__init__.pyc
arkaiv/trunk/arkaiv/model/cmmlparser.pyc
arkaiv/trunk/arkaiv/model/oggzinfo.pyc
arkaiv/trunk/arkaiv/templates/collections.mak
arkaiv/trunk/arkaiv/templates/mainpage.mak
arkaiv/trunk/arkaiv/websetup.py
arkaiv/trunk/arkaiv/websetup.pyc
Log:
Upgraded model for sqlalchemy 0.4beta5 - the big API jump made. This has broken some things but easily fixed... famous last words.
Modified: arkaiv/trunk/arkaiv/__init__.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/config/__init__.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/config/environment.py
===================================================================
--- arkaiv/trunk/arkaiv/config/environment.py 2007-09-10 22:06:38 UTC (rev 3231)
+++ arkaiv/trunk/arkaiv/config/environment.py 2007-09-11 06:42:58 UTC (rev 3232)
@@ -1,5 +1,6 @@
"""Pylons environment configuration"""
import os
+from sqlalchemy import engine_from_config
from pylons import config
@@ -29,3 +30,5 @@
# CONFIGURATION OPTIONS HERE (note: all config options will override any
# Pylons config options)
+ config['pylons.g'].sa_engine = engine_from_config(config, 'sqlalchemy.')
+
Modified: arkaiv/trunk/arkaiv/config/environment.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/config/middleware.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/config/routing.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/controllers/__init__.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/controllers/error.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/controllers/page.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/lib/__init__.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/lib/app_globals.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/lib/base.py
===================================================================
--- arkaiv/trunk/arkaiv/lib/base.py 2007-09-10 22:06:38 UTC (rev 3231)
+++ arkaiv/trunk/arkaiv/lib/base.py 2007-09-11 06:42:58 UTC (rev 3232)
@@ -20,7 +20,10 @@
# WSGIController.__call__ dispatches to the Controller method the
# request is routed to. This routing information is available in
# environ['pylons.routes_dict']
- return WSGIController.__call__(self, environ, start_response)
+ try:
+ return WSGIController.__call__(self, environ, start_response)
+ finally:
+ model.Session.remove()
# Include the '_' function in the public names
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
Modified: arkaiv/trunk/arkaiv/lib/base.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/lib/helpers.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/model/__init__.py
===================================================================
--- arkaiv/trunk/arkaiv/model/__init__.py 2007-09-10 22:06:38 UTC (rev 3231)
+++ arkaiv/trunk/arkaiv/model/__init__.py 2007-09-11 06:42:58 UTC (rev 3232)
@@ -10,148 +10,153 @@
#
# Author: Denis Crowdy <Denis.Crowdy at mq.edu.au>
-import sqlalchemy as sqla
-from sqlalchemy.orm import mapper
-from sacontext import PylonsSAContext
+from pylons import config
+from sqlalchemy import Column, MetaData, Table, ForeignKey, types
+from sqlalchemy.orm import mapper, relation
+from sqlalchemy.orm import scoped_session, sessionmaker
+#from sacontext import PylonsSAContext
import arkaiv.lib.helpers as h
from operator import itemgetter
#from arkaiv.model.oggzinfo import OggzInfo
-sac = PylonsSAContext()
-sac.add_engine_from_config("default")
+#sac = PylonsSAContext()
+#sac.add_engine_from_config("default")
+Session = scoped_session(sessionmaker(autoflush=True, transactional=True, bind=config['pylons.g'].sa_engine))
-system_table = sqla.Table('system', sac.metadata,
- sqla.Column('db_version', sqla.Integer)
+metadata = MetaData()
+
+system_table = Table('system', metadata,
+ Column('db_version', types.Integer)
)
-collections_table = sqla.Table('collections', sac.metadata,
- sqla.Column('ixk', sqla.Integer, primary_key=True),
- sqla.Column('name', sqla.String())
+collections_table = Table('collections', metadata,
+ Column('ixk', types.Integer, primary_key=True),
+ Column('name', types.String())
)
-items_table = sqla.Table('items', sac.metadata,
- sqla.Column('ixi', sqla.Integer, primary_key=True),
- sqla.Column('name', sqla.String()),
- sqla.Column('cmmlfile', sqla.String())
+items_table = Table('items', metadata,
+ Column('ixi', types.Integer, primary_key=True),
+ Column('name', types.String()),
+ Column('cmmlfile', types.String())
)
-collection_items_table = sqla.Table('collection_items', sac.metadata,
- sqla.Column('ixci', sqla.Integer, primary_key=True),
- sqla.Column('ixk', sqla.Integer, sqla.ForeignKey('collections.ixk')),
- sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi'))
+collection_items_table = Table('collection_items', metadata,
+ Column('ixci', types.Integer, primary_key=True),
+ Column('ixk', types.Integer, ForeignKey('collections.ixk')),
+ Column('ixi', types.Integer, ForeignKey('items.ixi'))
)
-playlists_table = sqla.Table('playlists', sac.metadata,
- sqla.Column('ixp', sqla.Integer, primary_key=True),
- sqla.Column('name', sqla.String())
+playlists_table = Table('playlists', metadata,
+ Column('ixp', types.Integer, primary_key=True),
+ Column('name', types.String())
)
-playlist_items_table = sqla.Table('playlist_items', sac.metadata,
- sqla.Column('ixpi', sqla.Integer, primary_key=True),
- sqla.Column('ixp', sqla.Integer(), sqla.ForeignKey('playlists.ixp')),
- sqla.Column('ixi', sqla.Integer(), sqla.ForeignKey('items.ixi')),
- sqla.Column('ixc', sqla.Integer(), sqla.ForeignKey('clips.ixc'))
+playlist_items_table = Table('playlist_items', metadata,
+ Column('ixpi', types.Integer, primary_key=True),
+ Column('ixp', types.Integer(), ForeignKey('playlists.ixp')),
+ Column('ixi', types.Integer(), ForeignKey('items.ixi')),
+ Column('ixc', types.Integer(), ForeignKey('clips.ixc'))
)
-sources_table = sqla.Table('sources', sac.metadata,
- sqla.Column('ixs', sqla.Integer, primary_key=True),
- sqla.Column('path', sqla.String())
+sources_table = Table('sources', metadata,
+ Column('ixs', types.Integer, primary_key=True),
+ Column('path', types.String())
)
-item_sources_table = sqla.Table('item_sources', sac.metadata,
- sqla.Column('ixis', sqla.Integer, primary_key=True),
- sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi')),
- sqla.Column('ixs', sqla.Integer, sqla.ForeignKey('sources.ixs')
+item_sources_table = Table('item_sources', metadata,
+ Column('ixis', types.Integer, primary_key=True),
+ Column('ixi', types.Integer, ForeignKey('items.ixi')),
+ Column('ixs', types.Integer, ForeignKey('sources.ixs')
))
-item_clips_table = sqla.Table('item_clips', sac.metadata,
- sqla.Column('ixic', sqla.Integer, primary_key=True),
- sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi')),
- sqla.Column('ixc', sqla.Integer, sqla.ForeignKey('clips.ixc')
+item_clips_table = Table('item_clips', metadata,
+ Column('ixic', types.Integer, primary_key=True),
+ Column('ixi', types.Integer, ForeignKey('items.ixi')),
+ Column('ixc', types.Integer, ForeignKey('clips.ixc')
))
-item_heads_table = sqla.Table('item_heads', sac.metadata,
- sqla.Column('ixih', sqla.Integer, primary_key=True),
- sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi')),
- sqla.Column('ixh', sqla.Integer, sqla.ForeignKey('heads.ixh')
+item_heads_table = Table('item_heads', metadata,
+ Column('ixih', types.Integer, primary_key=True),
+ Column('ixi', types.Integer, ForeignKey('items.ixi')),
+ Column('ixh', types.Integer, ForeignKey('heads.ixh')
))
-metas_table = sqla.Table('metas', sac.metadata,
- sqla.Column('ixm', sqla.Integer, primary_key=True),
- sqla.Column('id', sqla.String()),
- sqla.Column('name', sqla.String()),
- sqla.Column('content', sqla.String()),
- sqla.Column('scheme', sqla.String())
+metas_table = Table('metas', metadata,
+ Column('ixm', types.Integer, primary_key=True),
+ Column('id', types.String()),
+ Column('name', types.String()),
+ Column('content', types.String()),
+ Column('scheme', types.String())
)
-head_metas_table = sqla.Table('head_metas', sac.metadata,
- sqla.Column('ixhm', sqla.Integer, primary_key=True),
- sqla.Column('ixh', sqla.Integer, sqla.ForeignKey('heads.ixh')),
- sqla.Column('ixm', sqla.Integer, sqla.ForeignKey('metas.ixm')
+head_metas_table = Table('head_metas', metadata,
+ Column('ixhm', types.Integer, primary_key=True),
+ Column('ixh', types.Integer, ForeignKey('heads.ixh')),
+ Column('ixm', types.Integer, ForeignKey('metas.ixm')
))
-clip_metas_table = sqla.Table('clip_metas', sac.metadata,
- sqla.Column('ixcm', sqla.Integer, primary_key=True),
- sqla.Column('ixc', sqla.Integer, sqla.ForeignKey('clips.ixc')),
- sqla.Column('ixm', sqla.Integer, sqla.ForeignKey('metas.ixm')
+clip_metas_table = Table('clip_metas', metadata,
+ Column('ixcm', types.Integer, primary_key=True),
+ Column('ixc', types.Integer, ForeignKey('clips.ixc')),
+ Column('ixm', types.Integer, ForeignKey('metas.ixm')
))
-heads_table = sqla.Table('heads', sac.metadata,
- sqla.Column('ixh', sqla.Integer, primary_key=True),
- sqla.Column('id', sqla.String()),
- sqla.Column('title', sqla.String())
+heads_table = Table('heads', metadata,
+ Column('ixh', types.Integer, primary_key=True),
+ Column('id', types.String()),
+ Column('title', types.String())
)
-clips_table = sqla.Table('clips', sac.metadata,
- sqla.Column('ixc', sqla.Integer, primary_key=True ),
- sqla.Column('start_time', sqla.Float ),
- sqla.Column('end_time', sqla.Float ),
- sqla.Column('id', sqla.String()),
- sqla.Column('a_href', sqla.String()),
- sqla.Column('a_text', sqla.String()),
- sqla.Column('img_src', sqla.String()),
- sqla.Column('desc', sqla.String()),
+clips_table = Table('clips', metadata,
+ Column('ixc', types.Integer, primary_key=True ),
+ Column('start_time', types.Float ),
+ Column('end_time', types.Float ),
+ Column('id', types.String()),
+ Column('a_href', types.String()),
+ Column('a_text', types.String()),
+ Column('img_src', types.String()),
+ Column('desc', types.String()),
)
-rename_table = sqla.Table('rename', sac.metadata,
- sqla.Column('ixr', sqla.Integer, primary_key=True),
- sqla.Column('oldname', sqla.String()),
- sqla.Column('newname', sqla.String())
+rename_table = Table('rename', metadata,
+ Column('ixr', types.Integer, primary_key=True),
+ Column('oldname', types.String()),
+ Column('newname', types.String())
)
-channels_table = sqla.Table('channels', sac.metadata,
- sqla.Column('ixch', sqla.Integer, primary_key=True ),
- sqla.Column('title', sqla.String()),
- sqla.Column('link', sqla.String()),
- sqla.Column('description', sqla.String()),
- sqla.Column('language', sqla.String()),
- sqla.Column('copyright', sqla.String()),
- sqla.Column('managingEditor', sqla.String()),
- sqla.Column('webMaster', sqla.String()),
- sqla.Column('image_path', sqla.String())
+channels_table = Table('channels', metadata,
+ Column('ixch', types.Integer, primary_key=True ),
+ Column('title', types.String()),
+ Column('link', types.String()),
+ Column('description', types.String()),
+ Column('language', types.String()),
+ Column('copyright', types.String()),
+ Column('managingEditor', types.String()),
+ Column('webMaster', types.String()),
+ Column('image_path', types.String())
)
-stories_table = sqla.Table('stories', sac.metadata,
- sqla.Column('ixst', sqla.Integer, primary_key=True ),
- sqla.Column('id', sqla.String()),
- sqla.Column('title', sqla.String()),
- sqla.Column('pubdate', sqla.String()),
- sqla.Column('link', sqla.String()),
- sqla.Column('description', sqla.String()),
- sqla.Column('author', sqla.String()),
- sqla.Column('category', sqla.String())
+stories_table = Table('stories', metadata,
+ Column('ixst', types.Integer, primary_key=True ),
+ Column('id', types.String()),
+ Column('title', types.String()),
+ Column('pubdate', types.String()),
+ Column('link', types.String()),
+ Column('description', types.String()),
+ Column('author', types.String()),
+ Column('category', types.String())
)
-source_info_table = sqla.Table('source_info', sac.metadata,
- sqla.Column('ixs', sqla.Integer, primary_key=True ),
- sqla.Column('duration', sqla.String()),
- sqla.Column('bitrate', sqla.String()),
- sqla.Column('resolution', sqla.String()),
- sqla.Column('framerate', sqla.String()),
- sqla.Column('has_video', sqla.Integer),
- sqla.Column('has_audio', sqla.Integer),
- sqla.Column('audio', sqla.String())
+source_info_table = Table('source_info', metadata,
+ Column('ixs', types.Integer, primary_key=True ),
+ Column('duration', types.String()),
+ Column('bitrate', types.String()),
+ Column('resolution', types.String()),
+ Column('framerate', types.String()),
+ Column('has_video', types.Integer),
+ Column('has_audio', types.Integer),
+ Column('audio', types.String())
)
class System(object):
@@ -230,71 +235,73 @@
def __str__(self):
return self.name
-sqla.mapper(Collection, collections_table, extension=sac.ext)
-sqla.mapper(Collectionitems, collection_items_table, extension=sac.ext)
+mapper(Collection, collections_table)
+mapper(Collectionitems, collection_items_table)
-sqla.mapper(Item, items_table, properties = {
- 'my_collections' : sqla.relation(Collection,
- secondary = collection_items_table)},
- extension=sac.ext)
+mapper(Item, items_table, properties = {
+ 'my_collections' : relation(Collection,
+ secondary = collection_items_table)})
-sqla.mapper(Playlist, playlists_table, extension=sac.ext)
+mapper(Playlist, playlists_table)
-sqla.mapper(Playlistitems, playlist_items_table, extension=sac.ext)
+mapper(Playlistitems, playlist_items_table)
-#sqla.mapper(Collection, collections_table, extension=sac.ext)
+#mapper(Collection, collections_table)
-sqla.mapper(Source, sources_table, properties = {
- 'my_items' : sqla.relation(Item, secondary = item_sources_table)
- },
- extension=sac.ext)
-sqla.mapper(Sourceinfo, source_info_table, extension=sac.ext)
-sqla.mapper(Itemsources, item_sources_table, extension=sac.ext)
-sqla.mapper(Head, heads_table, properties = {
- 'my_items' : sqla.relation(Item, secondary = item_heads_table)
- },
- extension=sac.ext)
-sqla.mapper(Itemheads, item_heads_table, extension=sac.ext)
-sqla.mapper(Meta, metas_table, properties = {
- 'my_heads' : sqla.relation(Head, secondary = head_metas_table)
- },
- extension=sac.ext)
-sqla.mapper(Headmetas, head_metas_table, extension=sac.ext)
-sqla.mapper(Clip, clips_table, properties = {
- 'my_items' : sqla.relation(Item, secondary = item_clips_table)
- },
- extension=sac.ext)
-sqla.mapper(Itemclips, item_clips_table, extension=sac.ext)
+mapper(Source, sources_table, properties = {
+ 'my_items' : relation(Item, secondary = item_sources_table)
+ })
+mapper(Sourceinfo, source_info_table)
+mapper(Itemsources, item_sources_table)
+mapper(Head, heads_table, properties = {
+ 'my_items' : relation(Item, secondary = item_heads_table)
+ })
+mapper(Itemheads, item_heads_table)
+mapper(Meta, metas_table, properties = {
+ 'my_heads' : relation(Head, secondary = head_metas_table)
+ })
+mapper(Headmetas, head_metas_table)
+mapper(Clip, clips_table, properties = {
+ 'my_items' : relation(Item, secondary = item_clips_table)
+ })
+
+mapper(Itemclips, item_clips_table)
+
def getallitems():
- item = items_table
- i = item.select().execute().fetchall()
+# item = items_table
+ item_q = Session.query(Item)
+ i = item_q.all()
+# i = item.select().execute().fetchall()
return i
def addnewcollection(name):
newcollection = Collection()
newcollection.name = name
- sac.session.flush()
+ Session.save(newcollection)
+ Session.commit()
return
def getcollections():
- coll = collections_table
- c = coll.select().execute().fetchall()
+# coll = collections_table
+# c = coll.select().execute().fetchall()
+ coll_q = Session.query(Collection)
+ c = coll_q.all()
return c
def getitemsincollection(id):
- coll_items_q = sac.query(Collectionitems)
+ coll_items_q = Session.query(Collectionitems)
# get a list of ids
cilist = coll_items_q.filter_by(ixk=id)
itemlist = []
for ci in cilist:
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=ci.ixi)
itemlist.append(i)
- sac.session.flush()
+ Session.commit()
return itemlist
def getplaylists():
@@ -311,15 +318,15 @@
"""
newplaylist = Playlist()
newplaylist.name = name
- sac.session.flush()
+ Session.commit()
return
def addcliptoplaylist(list, clipid):
# get the id for the list
- p_q = sac.query(Playlist)
+ p_q = Session.query(Playlist)
p = p_q.get_by(name=list)
# get the item id:
- ic_q = sac.query(Itemclips)
+ ic_q = Session.query(Itemclips)
ic = ic_q.get_by(ixc=clipid)
# add an entry to playlist_items
pi = Playlistitems()
@@ -327,25 +334,25 @@
pi.ixi = ic.ixi
pi.ixp = p.ixp
- sac.session.flush()
+ Session.commit()
return
def additemtoplaylist(list, itemid):
- p_q = sac.query(Playlist)
+ p_q = Session.query(Playlist)
p = p_q.get_by(name=list)
pi = Playlistitems()
#pi.ixc = clipid
pi.ixi = itemid
pi.ixp = p.ixp
- sac.session.flush()
+ Session.commit()
return
def getclipsfromplaylist(listid):
- pi_q = sac.query(Playlistitems)
+ pi_q = Session.query(Playlistitems)
pi = pi_q.filter_by(ixp=listid)
- c_q = sac.query(Clip)
+ c_q = Session.query(Clip)
cliplist = []
for item in pi:
c = c_q.get_by(ixc=item.ixc)
@@ -357,9 +364,9 @@
""" This gets items in the playlist that have no clip info
"""
- pi_q = sac.query(Playlistitems)
+ pi_q = Session.query(Playlistitems)
pi = pi_q.filter_by(ixp=listid)
- i_q = sac.query(Item)
+ i_q = Session.query(Item)
itemlist = []
for item in pi:
#print item.ixc
@@ -373,16 +380,16 @@
""" deletes a playlist and items in the playlist_items table
given the playlist name
"""
- p_q = sac.query(Playlist)
+ p_q = Session.query(Playlist)
p = p_q.get_by(name=listname)
# then get all items in the playlist_items table
- pi_q = sac.query(Playlistitems)
+ pi_q = Session.query(Playlistitems)
pi = pi_q.filter_by(ixp=p.ixp)
for item in pi:
- sac.session.delete(item)
+ Session.delete(item)
- sac.session.delete(p)
- sac.session.flush()
+ Session.delete(p)
+ Session.commit()
def addsource(itemname, source, cmmlfile):
new_item = Item()
@@ -392,16 +399,19 @@
new_source.path = source
new_source.my_items.append(new_item)
- sac.session.flush()
+ Session.save(new_item)
+ Session.save(new_source)
+ Session.commit()
return new_item.ixi
def additemtocollection(itemid, collection):
new_coll_item = Collectionitems()
- coll_q = sac.query(Collection)
+ coll_q = Session.query(Collection)
c = coll_q.get_by(name=collection)
new_coll_item.ixk = c.ixk
new_coll_item.ixi = itemid
- sac.session.flush()
+ Session.save(new_coll_item)
+ Session.commit()
return
def edititemname(itemid, text):
@@ -409,49 +419,49 @@
"""
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=itemid)
i.name = text
- sac.session.flush()
+ Session.commit()
return
def getitemname(id):
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=id)
name = i.name
return name
def getitemforid(id):
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=id)
return i
def getitemforclip(clipid):
- ic_q = sac.query(Itemclips)
+ ic_q = Session.query(Itemclips)
ic = ic_q.get_by(ixc=clipid)
- i_q = sac.query(Item)
+ i_q = Session.query(Item)
i = i_q.get_by(ixi=ic.ixi)
return i
def getclip(clipid):
- c_q = sac.query(Clip)
+ c_q = Session.query(Clip)
c = c_q.get_by(ixc=clipid)
return c
def getheadmeta(id):
- meta_q = sac.query(Meta)
+ meta_q = Session.query(Meta)
m = meta_q.get_by(ixm=id)
print m.ixm
return m
def getitemforheadmeta(metaid):
#first get the head
- hm_q = sac.query(Headmetas)
+ hm_q = Session.query(Headmetas)
h = hm_q.get_by(ixm=metaid)
- ih_q = sac.query(Itemheads)
+ ih_q = Session.query(Itemheads)
ih = ih_q.get_by(ixh=h.ixh)
- i_q = sac.query(Item)
+ i_q = Session.query(Item)
i = i_q.get_by(ixi=ih.ixi)
print "i is: "
print i
@@ -460,14 +470,14 @@
def getitemcmmlfile(id):
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=id)
cmmlfile = i.cmmlfile
return cmmlfile
def getsourcesforitem(id):
# get the results from item_sources for given item id
- item_sources_q = sac.query(Itemsources)
+ item_sources_q = Session.query(Itemsources)
s = item_sources_q.get_by(ixi=id)
sid = s.ixs
return sid
@@ -477,37 +487,37 @@
Returns the source path
"""
- source_q = sac.query(Source)
+ source_q = Session.query(Source)
s = source_q.get_by(ixs=id)
path = s.path
return path
def addhead(info):
# get the item this refers to:
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=info['itemid'])
new_head = Head()
new_head.id = info['id']
new_head.title = info['title']
new_head.my_items.append(i)
- sac.session.flush()
+ Session.commit()
return new_head.ixh
def edithead(info):
- head_q = sac.query(Head)
- itemhead_q = sac.query(Itemheads)
+ head_q = Session.query(Head)
+ itemhead_q = Session.query(Itemheads)
ih = itemhead_q.get_by(ixi=info['itemid'])
h = head_q.get_by(ixh=ih.ixh)
h.id = info['id']
h.title = info['title']
- sac.session.flush()
+ Session.commit()
return
def getclipinfoforitem(id):
- item_clip_q = sac.query(Itemclips)
+ item_clip_q = Session.query(Itemclips)
iclist = item_clip_q.filter_by(ixi=id).all()
cliplist = []
- clip_q = sac.query(Clip)
+ clip_q = Session.query(Clip)
# FIXME - why not just return a list of the objects? Why the dictionary
# step? Madness.
@@ -527,13 +537,13 @@
cliplist.append(clipinfo)
# great way to sort a list of dictionaries:
sortedcliplist = sorted(cliplist, key=itemgetter('start_time'))
- sac.session.flush()
+ Session.commit()
return sortedcliplist
def getheadinfoforitem(id):
headdict = {}
- head_q = sac.query(Head)
- itemhead_q = sac.query(Itemheads)
+ head_q = Session.query(Head)
+ itemhead_q = Session.query(Itemheads)
ih = itemhead_q.get_by(ixi=id)
h = head_q.get_by(ixh=ih.ixh)
headdict['ixh'] = h.ixh
@@ -542,16 +552,16 @@
return headdict
def getmetasforhead(headid):
- head_meta_q = sac.query(Headmetas)
+ head_meta_q = Session.query(Headmetas)
hmlist = head_meta_q.filter_by(ixh=headid).all()
metalist = []
- meta_q = sac.query(Meta)
+ meta_q = Session.query(Meta)
for hm in hmlist:
metainfo = {}
m = meta_q.get_by(ixm=hm.ixm)
metalist.append(m)
- sac.session.flush()
+ Session.commit()
return metalist
def getmetainfoforhead(id):
@@ -560,10 +570,10 @@
# displayitem FIXME
# now return a list of metas with that id in head_metas table
- head_meta_q = sac.query(Headmetas)
+ head_meta_q = Session.query(Headmetas)
hmlist = head_meta_q.filter_by(ixh=id).all()
metalist = []
- meta_q = sac.query(Meta)
+ meta_q = Session.query(Meta)
for hm in hmlist:
# get individual meta info
metainfo = {}
@@ -575,7 +585,7 @@
metainfo['scheme'] = m.scheme
metalist.append(metainfo)
- sac.session.flush()
+ Session.commit()
return metalist
def addmeta(info):
@@ -583,7 +593,7 @@
returns the newly created meta item
"""
- head_q = sac.query(Head)
+ head_q = Session.query(Head)
h = head_q.get_by(ixh=info['headindex'])
new_meta = Meta()
new_meta.id = info['id']
@@ -591,7 +601,7 @@
new_meta.content = info['content']
new_meta.scheme = info['scheme']
new_meta.my_heads.append(h)
- sac.session.flush()
+ Session.commit()
return new_meta
def syncmetaid(metaid):
@@ -599,10 +609,10 @@
"""
- meta_q = sac.query(Meta)
+ meta_q = Session.query(Meta)
m = meta_q.get_by(ixm=metaid)
m.id = metaid
- sac.session.flush()
+ Session.commit()
return
def editmeta(metaid, field, text):
@@ -614,17 +624,17 @@
returns nothing yet...
"""
- meta_q = sac.query(Meta)
+ meta_q = Session.query(Meta)
m = meta_q.get_by(ixm=metaid)
if field=="name":
m.name = text
elif field=="content":
m.content = text
- sac.session.flush()
+ Session.commit()
return
def addclip(info):
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=info['itemid'])
new_clip = Clip()
new_clip.start_time = info['starttime']
@@ -638,56 +648,56 @@
new_clip.img_src = info['img_src']
new_clip.desc = info['desc']
new_clip.my_items.append(i)
- sac.session.flush()
+ Session.commit()
return
def deleteclip(id):
- clip_q = sac.query(Clip)
+ clip_q = Session.query(Clip)
c = clip_q.get_by(ixc=id)
- sac.session.delete(c)
- sac.session.flush()
+ Session.delete(c)
+ Session.commit()
return
def deleteitem(id):
- item_q = sac.query(Item)
+ item_q = Session.query(Item)
i = item_q.get_by(ixi=id)
- sac.session.delete(i)
+ Session.delete(i)
# remove head info
- ih_q = sac.query(Itemheads)
+ ih_q = Session.query(Itemheads)
ih = ih_q.get_by(ixi=id)
# remove meta tags from this head
- hm_q = sac.query(Headmetas)
+ hm_q = Session.query(Headmetas)
hm = hm_q.filter_by(ixh=ih.ixh)
- m_q = sac.query(Meta)
+ m_q = Session.query(Meta)
for headmeta in hm:
m = m_q.get_by(ixm=headmeta.ixm)
-# sac.session.delete(headmeta)
- sac.session.delete(m)
+# Session.delete(headmeta)
+ Session.delete(m)
# Remove all clips
- ic_q = sac.query(Itemclips)
- c_q = sac.query(Clip)
+ ic_q = Session.query(Itemclips)
+ c_q = Session.query(Clip)
ic = ic_q.filter_by(ixi=id)
for itemclip in ic:
c = c_q.get_by(ixc=itemclip.ixc)
- sac.session.delete(c)
+ Session.delete(c)
# remove the head entry
- h_q = sac.query(Head)
+ h_q = Session.query(Head)
h = h_q.get_by(ixh=ih.ixh)
- sac.session.delete(h)
+ Session.delete(h)
# remove the source information as well
- is_q = sac.query(Itemsources)
+ is_q = Session.query(Itemsources)
i_s = is_q.get_by(ixi=id)
- s_q = sac.query(Source)
+ s_q = Session.query(Source)
s = s_q.get_by(ixs=i_s.ixs)
- #sac.session.delete(i_s)
- sac.session.delete(s)
+ #Session.delete(i_s)
+ Session.delete(s)
- sac.session.flush()
+ Session.commit()
return
def search(searchterms):
@@ -698,14 +708,14 @@
resultsdict={}
searchstring = "%" + searchterms + "%"
# look for item names:
- item_q = sac.query(Item)
+ 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 = sac.query(Meta)
+ meta_q = Session.query(Meta)
metas = meta_q.select(metas_table.c.name.like(searchstring))
metanames = []
for meta in metas:
@@ -717,7 +727,7 @@
metanames.append(meta.ixm)
# And search clips now:
- clip_q = sac.query(Clip)
+ clip_q = Session.query(Clip)
clips = clip_q.select(clips_table.c.desc.like(searchstring))
clipnames = []
for clip in clips:
@@ -726,14 +736,14 @@
resultsdict['items'] = itemnames
resultsdict['metas'] = metanames
resultsdict['clips'] = clipnames
- sac.session.flush()
+ Session.commit()
return resultsdict
def deletemeta(metaid):
- meta_q = sac.query(Meta)
+ meta_q = Session.query(Meta)
m = meta_q.get_by(ixm=metaid)
- sac.session.delete(m)
- sac.session.flush()
+ Session.delete(m)
+ Session.commit()
return
Modified: arkaiv/trunk/arkaiv/model/__init__.py.old
===================================================================
--- arkaiv/trunk/arkaiv/model/__init__.py.old 2007-09-10 22:06:38 UTC (rev 3231)
+++ arkaiv/trunk/arkaiv/model/__init__.py.old 2007-09-11 06:42:58 UTC (rev 3232)
@@ -0,0 +1,739 @@
+# Copyright (C) 2007 Denis Crowdy, Macquarie University, Australia
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For exact contribution history, see the revision
+# history and logs.
+#
+# Author: Denis Crowdy <Denis.Crowdy at mq.edu.au>
+
+import sqlalchemy as sqla
+from sqlalchemy.orm import mapper
+from sacontext import PylonsSAContext
+import arkaiv.lib.helpers as h
+from operator import itemgetter
+#from arkaiv.model.oggzinfo import OggzInfo
+
+sac = PylonsSAContext()
+sac.add_engine_from_config("default")
+
+system_table = sqla.Table('system', sac.metadata,
+ sqla.Column('db_version', sqla.Integer)
+)
+
+collections_table = sqla.Table('collections', sac.metadata,
+ sqla.Column('ixk', sqla.Integer, primary_key=True),
+ sqla.Column('name', sqla.String())
+)
+
+items_table = sqla.Table('items', sac.metadata,
+ sqla.Column('ixi', sqla.Integer, primary_key=True),
+ sqla.Column('name', sqla.String()),
+ sqla.Column('cmmlfile', sqla.String())
+)
+
+collection_items_table = sqla.Table('collection_items', sac.metadata,
+ sqla.Column('ixci', sqla.Integer, primary_key=True),
+ sqla.Column('ixk', sqla.Integer, sqla.ForeignKey('collections.ixk')),
+ sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi'))
+)
+
+playlists_table = sqla.Table('playlists', sac.metadata,
+ sqla.Column('ixp', sqla.Integer, primary_key=True),
+ sqla.Column('name', sqla.String())
+)
+
+playlist_items_table = sqla.Table('playlist_items', sac.metadata,
+ sqla.Column('ixpi', sqla.Integer, primary_key=True),
+ sqla.Column('ixp', sqla.Integer(), sqla.ForeignKey('playlists.ixp')),
+ sqla.Column('ixi', sqla.Integer(), sqla.ForeignKey('items.ixi')),
+ sqla.Column('ixc', sqla.Integer(), sqla.ForeignKey('clips.ixc'))
+)
+
+
+sources_table = sqla.Table('sources', sac.metadata,
+ sqla.Column('ixs', sqla.Integer, primary_key=True),
+ sqla.Column('path', sqla.String())
+)
+
+item_sources_table = sqla.Table('item_sources', sac.metadata,
+ sqla.Column('ixis', sqla.Integer, primary_key=True),
+ sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi')),
+ sqla.Column('ixs', sqla.Integer, sqla.ForeignKey('sources.ixs')
+))
+
+item_clips_table = sqla.Table('item_clips', sac.metadata,
+ sqla.Column('ixic', sqla.Integer, primary_key=True),
+ sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi')),
+ sqla.Column('ixc', sqla.Integer, sqla.ForeignKey('clips.ixc')
+))
+
+item_heads_table = sqla.Table('item_heads', sac.metadata,
+ sqla.Column('ixih', sqla.Integer, primary_key=True),
+ sqla.Column('ixi', sqla.Integer, sqla.ForeignKey('items.ixi')),
+ sqla.Column('ixh', sqla.Integer, sqla.ForeignKey('heads.ixh')
+))
+
+metas_table = sqla.Table('metas', sac.metadata,
+ sqla.Column('ixm', sqla.Integer, primary_key=True),
+ sqla.Column('id', sqla.String()),
+ sqla.Column('name', sqla.String()),
+ sqla.Column('content', sqla.String()),
+ sqla.Column('scheme', sqla.String())
+)
+
+head_metas_table = sqla.Table('head_metas', sac.metadata,
+ sqla.Column('ixhm', sqla.Integer, primary_key=True),
+ sqla.Column('ixh', sqla.Integer, sqla.ForeignKey('heads.ixh')),
+ sqla.Column('ixm', sqla.Integer, sqla.ForeignKey('metas.ixm')
+))
+
+clip_metas_table = sqla.Table('clip_metas', sac.metadata,
+ sqla.Column('ixcm', sqla.Integer, primary_key=True),
+ sqla.Column('ixc', sqla.Integer, sqla.ForeignKey('clips.ixc')),
+ sqla.Column('ixm', sqla.Integer, sqla.ForeignKey('metas.ixm')
+))
+
+heads_table = sqla.Table('heads', sac.metadata,
+ sqla.Column('ixh', sqla.Integer, primary_key=True),
+ sqla.Column('id', sqla.String()),
+ sqla.Column('title', sqla.String())
+)
+
+clips_table = sqla.Table('clips', sac.metadata,
+ sqla.Column('ixc', sqla.Integer, primary_key=True ),
+ sqla.Column('start_time', sqla.Float ),
+ sqla.Column('end_time', sqla.Float ),
+ sqla.Column('id', sqla.String()),
+ sqla.Column('a_href', sqla.String()),
+ sqla.Column('a_text', sqla.String()),
+ sqla.Column('img_src', sqla.String()),
+ sqla.Column('desc', sqla.String()),
+)
+
+rename_table = sqla.Table('rename', sac.metadata,
+ sqla.Column('ixr', sqla.Integer, primary_key=True),
+ sqla.Column('oldname', sqla.String()),
+ sqla.Column('newname', sqla.String())
+)
+
+channels_table = sqla.Table('channels', sac.metadata,
+ sqla.Column('ixch', sqla.Integer, primary_key=True ),
+ sqla.Column('title', sqla.String()),
+ sqla.Column('link', sqla.String()),
+ sqla.Column('description', sqla.String()),
+ sqla.Column('language', sqla.String()),
+ sqla.Column('copyright', sqla.String()),
+ sqla.Column('managingEditor', sqla.String()),
+ sqla.Column('webMaster', sqla.String()),
+ sqla.Column('image_path', sqla.String())
+)
+
+stories_table = sqla.Table('stories', sac.metadata,
+ sqla.Column('ixst', sqla.Integer, primary_key=True ),
+ sqla.Column('id', sqla.String()),
+ sqla.Column('title', sqla.String()),
+ sqla.Column('pubdate', sqla.String()),
+ sqla.Column('link', sqla.String()),
+ sqla.Column('description', sqla.String()),
+ sqla.Column('author', sqla.String()),
+ sqla.Column('category', sqla.String())
+)
+
+source_info_table = sqla.Table('source_info', sac.metadata,
+ sqla.Column('ixs', sqla.Integer, primary_key=True ),
+ sqla.Column('duration', sqla.String()),
+ sqla.Column('bitrate', sqla.String()),
+ sqla.Column('resolution', sqla.String()),
+ sqla.Column('framerate', sqla.String()),
+ sqla.Column('has_video', sqla.Integer),
+ sqla.Column('has_audio', sqla.Integer),
+ sqla.Column('audio', sqla.String())
+)
+
+class System(object):
+ def __str__(self):
+ return self.name
+
+class Collection(object):
+ def __str__(self):
+ return self.name
+
+class Item(object):
+ def __str__(self):
+ return self.name
+
+class Collectionitems(object):
+ def __str__(self):
+ return self.name
+
+class Playlist(object):
+ def __str__(self):
+ return self.name
+
+class Playlistitems(object):
+ def __str__(self):
+ return self.name
+
+class Source(object):
+ def __str__(self):
+ return self.name
+
+class Itemsources(object):
+ def __str__(self):
+ return self.name
+
+class Itemclips(object):
+ def __str__(self):
+ return self.name
+
+class Itemheads(object):
+ def __str__(self):
+ return self.name
+
+class Meta(object):
+ def __str__(self):
+ return self.name
+
+class Headmetas(object):
+ def __str__(self):
+ return self.name
+
+class Clipmetas(object):
+ def __str__(self):
+ return self.name
+
+class Head(object):
+ def __str__(self):
+ return self.name
+
+class Clip(object):
+ def __str__(self):
+ return self.name
+
+class Rename(object):
+ def __str__(self):
+ return self.name
+
+class Channel(object):
+ def __str__(self):
+ return self.name
+
+class Story(object):
+ def __str__(self):
+ return self.name
+
+class Sourceinfo(object):
+ def __str__(self):
+ return self.name
+
+sqla.mapper(Collection, collections_table, extension=sac.ext)
+sqla.mapper(Collectionitems, collection_items_table, extension=sac.ext)
+
+sqla.mapper(Item, items_table, properties = {
+ 'my_collections' : sqla.relation(Collection,
+ secondary = collection_items_table)},
+ extension=sac.ext)
+
+
+sqla.mapper(Playlist, playlists_table, extension=sac.ext)
+
+sqla.mapper(Playlistitems, playlist_items_table, extension=sac.ext)
+
+#sqla.mapper(Collection, collections_table, extension=sac.ext)
+
+sqla.mapper(Source, sources_table, properties = {
+ 'my_items' : sqla.relation(Item, secondary = item_sources_table)
+ },
+ extension=sac.ext)
+sqla.mapper(Sourceinfo, source_info_table, extension=sac.ext)
+sqla.mapper(Itemsources, item_sources_table, extension=sac.ext)
+sqla.mapper(Head, heads_table, properties = {
+ 'my_items' : sqla.relation(Item, secondary = item_heads_table)
+ },
+ extension=sac.ext)
+sqla.mapper(Itemheads, item_heads_table, extension=sac.ext)
+sqla.mapper(Meta, metas_table, properties = {
+ 'my_heads' : sqla.relation(Head, secondary = head_metas_table)
+ },
+ extension=sac.ext)
+sqla.mapper(Headmetas, head_metas_table, extension=sac.ext)
+sqla.mapper(Clip, clips_table, properties = {
+ 'my_items' : sqla.relation(Item, secondary = item_clips_table)
+ },
+ extension=sac.ext)
+sqla.mapper(Itemclips, item_clips_table, extension=sac.ext)
+
+
+def getallitems():
+ item = items_table
+ i = item.select().execute().fetchall()
+ return i
+
+def addnewcollection(name):
+ newcollection = Collection()
+ newcollection.name = name
+ sac.session.flush()
+ return
+
+def getcollections():
+ coll = collections_table
+ c = coll.select().execute().fetchall()
+ return c
+
+def getitemsincollection(id):
+ coll_items_q = sac.query(Collectionitems)
+ # get a list of ids
+ cilist = coll_items_q.filter_by(ixk=id)
+ itemlist = []
+ for ci in cilist:
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=ci.ixi)
+ itemlist.append(i)
+
+ sac.session.flush()
+ return itemlist
+
+def getplaylists():
+ """ Return a list of all current playlists
+
+ """
+ play = playlists_table
+ p = play.select().execute().fetchall()
+ return p
+
+def addnewplaylist(name):
+ """ Add a new named playlist to the database
+
+ """
+ newplaylist = Playlist()
+ newplaylist.name = name
+ sac.session.flush()
+ return
+
+def addcliptoplaylist(list, clipid):
+ # get the id for the list
+ p_q = sac.query(Playlist)
+ p = p_q.get_by(name=list)
+ # get the item id:
+ ic_q = sac.query(Itemclips)
+ ic = ic_q.get_by(ixc=clipid)
+ # add an entry to playlist_items
+ pi = Playlistitems()
+ pi.ixc = clipid
+ pi.ixi = ic.ixi
+ pi.ixp = p.ixp
+
+ sac.session.flush()
+ return
+
+def additemtoplaylist(list, itemid):
+ p_q = sac.query(Playlist)
+ p = p_q.get_by(name=list)
+ pi = Playlistitems()
+ #pi.ixc = clipid
+ pi.ixi = itemid
+ pi.ixp = p.ixp
+
+ sac.session.flush()
+ return
+
+
+def getclipsfromplaylist(listid):
+ pi_q = sac.query(Playlistitems)
+ pi = pi_q.filter_by(ixp=listid)
+ c_q = sac.query(Clip)
+ cliplist = []
+ for item in pi:
+ c = c_q.get_by(ixc=item.ixc)
+ cliplist.append(c)
+
+ return cliplist
+
+def getitemsfromplaylist(listid):
+ """ This gets items in the playlist that have no clip info
+
+ """
+ pi_q = sac.query(Playlistitems)
+ pi = pi_q.filter_by(ixp=listid)
+ i_q = sac.query(Item)
+ itemlist = []
+ for item in pi:
+ #print item.ixc
+ if (not item.ixc):
+ i = i_q.get_by(ixi=item.ixi)
+ itemlist.append(i)
+
+ return itemlist
+
+def deleteplaylist(listname):
+ """ deletes a playlist and items in the playlist_items table
+ given the playlist name
+ """
+ p_q = sac.query(Playlist)
+ p = p_q.get_by(name=listname)
+ # then get all items in the playlist_items table
+ pi_q = sac.query(Playlistitems)
+ pi = pi_q.filter_by(ixp=p.ixp)
+ for item in pi:
+ sac.session.delete(item)
+
+ sac.session.delete(p)
+ sac.session.flush()
+
+def addsource(itemname, source, cmmlfile):
+ new_item = Item()
+ new_source = Source()
+ new_item.name = itemname
+ new_item.cmmlfile = cmmlfile
+ new_source.path = source
+ new_source.my_items.append(new_item)
+
+ sac.session.flush()
+ return new_item.ixi
+
+def additemtocollection(itemid, collection):
+ new_coll_item = Collectionitems()
+ coll_q = sac.query(Collection)
+ c = coll_q.get_by(name=collection)
+ new_coll_item.ixk = c.ixk
+ new_coll_item.ixi = itemid
+ sac.session.flush()
+ return
+
+def edititemname(itemid, text):
+ """ Edits the name of an item
+
+
+ """
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=itemid)
+ i.name = text
+ sac.session.flush()
+
+ return
+
+def getitemname(id):
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=id)
+ name = i.name
+ return name
+
+def getitemforid(id):
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=id)
+ return i
+
+def getitemforclip(clipid):
+ ic_q = sac.query(Itemclips)
+ ic = ic_q.get_by(ixc=clipid)
+ i_q = sac.query(Item)
+ i = i_q.get_by(ixi=ic.ixi)
+ return i
+
+def getclip(clipid):
+ c_q = sac.query(Clip)
+ c = c_q.get_by(ixc=clipid)
+ return c
+
+def getheadmeta(id):
+ meta_q = sac.query(Meta)
+ m = meta_q.get_by(ixm=id)
+ print m.ixm
+ return m
+
+def getitemforheadmeta(metaid):
+ #first get the head
+ hm_q = sac.query(Headmetas)
+ h = hm_q.get_by(ixm=metaid)
+ ih_q = sac.query(Itemheads)
+ ih = ih_q.get_by(ixh=h.ixh)
+ i_q = sac.query(Item)
+ i = i_q.get_by(ixi=ih.ixi)
+ print "i is: "
+ print i
+ print "i.ixi is" + str(i.ixi)
+ return i
+
+
+def getitemcmmlfile(id):
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=id)
+ cmmlfile = i.cmmlfile
+ return cmmlfile
+
+def getsourcesforitem(id):
+ # get the results from item_sources for given item id
+ item_sources_q = sac.query(Itemsources)
+ s = item_sources_q.get_by(ixi=id)
+ sid = s.ixs
+ return sid
+
+def getsourcepath(id):
+ """ get the source path given a sourceid
+
+ Returns the source path
+ """
+ source_q = sac.query(Source)
+ s = source_q.get_by(ixs=id)
+ path = s.path
+ return path
+
+def addhead(info):
+ # get the item this refers to:
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=info['itemid'])
+ new_head = Head()
+ new_head.id = info['id']
+ new_head.title = info['title']
+ new_head.my_items.append(i)
+ sac.session.flush()
+ return new_head.ixh
+
+def edithead(info):
+ head_q = sac.query(Head)
+ itemhead_q = sac.query(Itemheads)
+ ih = itemhead_q.get_by(ixi=info['itemid'])
+ h = head_q.get_by(ixh=ih.ixh)
+ h.id = info['id']
+ h.title = info['title']
+ sac.session.flush()
+ return
+
+def getclipinfoforitem(id):
+ item_clip_q = sac.query(Itemclips)
+ iclist = item_clip_q.filter_by(ixi=id).all()
+ cliplist = []
+ clip_q = sac.query(Clip)
+
+ # FIXME - why not just return a list of the objects? Why the dictionary
+ # step? Madness.
+
+ for ic in iclist:
+ # get individual meta info
+ clipinfo = {}
+ c = clip_q.get_by(ixc=ic.ixc)
+ clipinfo['ixc'] = c.ixc
+ clipinfo['start_time'] = c.start_time
+ clipinfo['end_time'] = c.end_time
+ clipinfo['id'] = c.id
+ clipinfo['a_href'] = c.a_href
+ clipinfo['a_text'] = c.a_text
+ clipinfo['img_src'] = c.img_src
+ clipinfo['desc'] = c.desc
+ cliplist.append(clipinfo)
+ # great way to sort a list of dictionaries:
+ sortedcliplist = sorted(cliplist, key=itemgetter('start_time'))
+ sac.session.flush()
+ return sortedcliplist
+
+def getheadinfoforitem(id):
+ headdict = {}
+ head_q = sac.query(Head)
+ itemhead_q = sac.query(Itemheads)
+ ih = itemhead_q.get_by(ixi=id)
+ h = head_q.get_by(ixh=ih.ixh)
+ headdict['ixh'] = h.ixh
+ headdict['id'] = h.id
+ headdict['title'] = h.title
+ return headdict
+
+def getmetasforhead(headid):
+ head_meta_q = sac.query(Headmetas)
+ hmlist = head_meta_q.filter_by(ixh=headid).all()
+ metalist = []
+ meta_q = sac.query(Meta)
+ for hm in hmlist:
+ metainfo = {}
+ m = meta_q.get_by(ixm=hm.ixm)
+ metalist.append(m)
+
+ sac.session.flush()
+ return metalist
+
+def getmetainfoforhead(id):
+
+# 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
+ head_meta_q = sac.query(Headmetas)
+ hmlist = head_meta_q.filter_by(ixh=id).all()
+ metalist = []
+ meta_q = sac.query(Meta)
+ for hm in hmlist:
+ # get individual meta info
+ metainfo = {}
+ m = meta_q.get_by(ixm=hm.ixm)
+ metainfo['ixm'] = m.ixm
+ metainfo['id'] = m.id
+ metainfo['name'] = m.name
+ metainfo['content'] = m.content
+ metainfo['scheme'] = m.scheme
+ metalist.append(metainfo)
+
+ sac.session.flush()
+ return metalist
+
+def addmeta(info):
+ """ Given a dictionary of meta info, adds a meta item to database
+
+ returns the newly created meta item
+ """
+ head_q = sac.query(Head)
+ h = head_q.get_by(ixh=info['headindex'])
+ new_meta = Meta()
+ new_meta.id = info['id']
+ new_meta.name = info['name']
+ new_meta.content = info['content']
+ new_meta.scheme = info['scheme']
+ new_meta.my_heads.append(h)
+ sac.session.flush()
+ return new_meta
+
+def syncmetaid(metaid):
+ """ Given the meta primary key, it sets id to the same value
+
+ """
+
+ meta_q = sac.query(Meta)
+ m = meta_q.get_by(ixm=metaid)
+ m.id = metaid
+ sac.session.flush()
+ return
+
+def editmeta(metaid, field, text):
+ """ Edits a meta tag in the database
+
+ metaid
+ field - the field (or database column) to change
+ text - the text that replaces the existing entry
+
+ returns nothing yet...
+ """
+ meta_q = sac.query(Meta)
+ m = meta_q.get_by(ixm=metaid)
+ if field=="name":
+ m.name = text
+ elif field=="content":
+ m.content = text
+ sac.session.flush()
+ return
+
+def addclip(info):
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=info['itemid'])
+ new_clip = Clip()
+ new_clip.start_time = info['starttime']
+ try:
+ new_clip.end_time = info['endtime']
+ except:
+ pass
+ new_clip.id = info['id']
+ new_clip.a_href = info['a_href']
+ new_clip.a_text = info['a_text']
+ new_clip.img_src = info['img_src']
+ new_clip.desc = info['desc']
+ new_clip.my_items.append(i)
+ sac.session.flush()
+ return
+
+def deleteclip(id):
+ clip_q = sac.query(Clip)
+ c = clip_q.get_by(ixc=id)
+ sac.session.delete(c)
+ sac.session.flush()
+ return
+
+def deleteitem(id):
+ item_q = sac.query(Item)
+ i = item_q.get_by(ixi=id)
+ sac.session.delete(i)
+
+ # remove head info
+ ih_q = sac.query(Itemheads)
+ ih = ih_q.get_by(ixi=id)
+
+ # remove meta tags from this head
+ hm_q = sac.query(Headmetas)
+ hm = hm_q.filter_by(ixh=ih.ixh)
+ m_q = sac.query(Meta)
+ for headmeta in hm:
+ m = m_q.get_by(ixm=headmeta.ixm)
+# sac.session.delete(headmeta)
+ sac.session.delete(m)
+
+ # Remove all clips
+ ic_q = sac.query(Itemclips)
+ c_q = sac.query(Clip)
+ ic = ic_q.filter_by(ixi=id)
+ for itemclip in ic:
+ c = c_q.get_by(ixc=itemclip.ixc)
+ sac.session.delete(c)
+
+ # remove the head entry
+ h_q = sac.query(Head)
+ h = h_q.get_by(ixh=ih.ixh)
+ sac.session.delete(h)
+
+ # remove the source information as well
+ is_q = sac.query(Itemsources)
+ i_s = is_q.get_by(ixi=id)
+ s_q = sac.query(Source)
+ s = s_q.get_by(ixs=i_s.ixs)
+ #sac.session.delete(i_s)
+ sac.session.delete(s)
+
+ sac.session.flush()
+ 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
+
+ resultsdict={}
+ searchstring = "%" + searchterms + "%"
+ # look for item names:
+ item_q = sac.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 = sac.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 = sac.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
+ sac.session.flush()
+
+ return resultsdict
+
+def deletemeta(metaid):
+ meta_q = sac.query(Meta)
+ m = meta_q.get_by(ixm=metaid)
+ sac.session.delete(m)
+ sac.session.flush()
+ return
+
Modified: arkaiv/trunk/arkaiv/model/__init__.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/model/cmmlparser.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/model/oggzinfo.pyc
===================================================================
(Binary files differ)
Modified: arkaiv/trunk/arkaiv/templates/collections.mak
===================================================================
--- arkaiv/trunk/arkaiv/templates/collections.mak 2007-09-10 22:06:38 UTC (rev 3231)
+++ arkaiv/trunk/arkaiv/templates/collections.mak 2007-09-11 06:42:58 UTC (rev 3232)
@@ -5,8 +5,8 @@
% for coll in c.collections:
<li>
- ${coll[0]}
- ${ h.link_to(coll[1], h.url(action="displaycollection", edit="no", id=coll[0], name=coll[1])) }
+ ${coll.ixk}
+ ${ h.link_to(coll.name, h.url(action="displaycollection", edit="no", id=coll.ixk, name=coll.name)) }
</li>
% endfor
Modified: arkaiv/trunk/arkaiv/templates/mainpage.mak
===================================================================
--- arkaiv/trunk/arkaiv/templates/mainpage.mak 2007-09-10 22:06:38 UTC (rev 3231)
+++ arkaiv/trunk/arkaiv/templates/mainpage.mak 2007-09-11 06:42:58 UTC (rev 3232)
@@ -6,7 +6,7 @@
% for item in c.items:
<li>
<!--${item.ixi}-->
- ${ h.link_to(item.name, h.url(action="displayitem", edit="no", id=item[0])) }
+ ${ h.link_to(item.name, h.url(action="displayitem", edit="no", id=item.ixi)) }
</li>
% endfor
Modified: arkaiv/trunk/arkaiv/websetup.py
===================================================================
--- arkaiv/trunk/arkaiv/websetup.py 2007-09-10 22:06:38 UTC (rev 3231)
+++ arkaiv/trunk/arkaiv/websetup.py 2007-09-11 06:42:58 UTC (rev 3232)
@@ -9,7 +9,7 @@
conf = appconfig('config:' + filename)
load_environment(conf.global_conf, conf.local_conf)
- from arkaiv.lib.base import model
+ from arkaiv import model
print "Creating tables"
- model.sac.metadata.create_all()
+ model.metadata.create_all(bind=config['pylons.g'].sa_engine)
print "Successfully setup"
Modified: arkaiv/trunk/arkaiv/websetup.pyc
===================================================================
(Binary files differ)
More information about the commits
mailing list