From 002e384004744d986976fb8475946e89e2d3824d Mon Sep 17 00:00:00 2001 From: erlehmann Date: Sat, 13 Dec 2008 11:58:11 +0000 Subject: [PATCH] new database format, rudimentary search function git-svn-id: http://yolanda.mister-muffin.de/svn@414 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/yolanda/controllers/account.py | 10 +++++++--- trunk/yolanda/controllers/search.py | 11 ++++++++--- trunk/yolanda/controllers/upload.py | 22 ++++++++++++---------- trunk/yolanda/model/entities.py | 24 +++++++++++++++++++----- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/trunk/yolanda/controllers/account.py b/trunk/yolanda/controllers/account.py index 3d4108f..05dff90 100644 --- a/trunk/yolanda/controllers/account.py +++ b/trunk/yolanda/controllers/account.py @@ -7,6 +7,10 @@ log = logging.getLogger(__name__) class AccountController(BaseController): def index(self): + c.message = { + 'type': 'warning', + 'text': 'Your username will be saved indefinitely.' + } return render('/xhtml/account.mako') def __before__(self): @@ -17,16 +21,16 @@ class AccountController(BaseController): #FIXME: do not operate in stateless mode - replace store with local # openid store (app global) to make login faster with less overhead self.consumer = Consumer(self.openid_session, None) - openid = request.params.get('username', None) + openid = request.params.get('openid_identifier', None) try: authrequest = self.consumer.begin(openid) except DiscoveryFailure, e: # invalid openid c.message = { 'type': 'error', - 'text': 'You were not logged on due to entering an invalid OpenID.' + 'text': 'You were not logged on due to the given OpenID being invalid.' } - return render('/xhtml/index.mako') + return render('/xhtml/account.mako') redirecturl = authrequest.redirectURL( h.url_for('',qualified=True), diff --git a/trunk/yolanda/controllers/search.py b/trunk/yolanda/controllers/search.py index 53c6619..8b3430c 100644 --- a/trunk/yolanda/controllers/search.py +++ b/trunk/yolanda/controllers/search.py @@ -27,13 +27,18 @@ class SearchController(BaseController): c.query = request.params['query'] - raw_results = model.Video.query.filter_by(dc_title=c.query).all() + # extremely simple search + raw_results = [] + raw_results.extend(model.Video.query.filter_by(dc_title=c.query).all()) + raw_results.extend(model.Video.query.filter(model.Video.dc_creator.has(name=c.query)).all()) + raw_results.extend(model.Video.query.filter(model.Video.dc_contributor.any(name=c.query)).all()) if not raw_results: c.message = { - 'type': 'warning' + 'type': 'warning', + 'text': 'No results for query "%s".' % c.query } - c.message['text']='No results for query "%s".' % c.query +# c.message['text']='No results for query "%s".' % c.query return render('/xhtml/results.mako') c.results = [] diff --git a/trunk/yolanda/controllers/upload.py b/trunk/yolanda/controllers/upload.py index aa0096a..1aa833d 100644 --- a/trunk/yolanda/controllers/upload.py +++ b/trunk/yolanda/controllers/upload.py @@ -58,17 +58,18 @@ class UploadController(BaseController): # TODO: set up safeguards against omitted / wrong data # set up database entry + video = model.Video( # Dublin Core terms - dc_title = request.params['title'], - dc_creator = request.params['creator'], - dc_subject = request.params['subject'], + dc_title = request.params['dc_title'], + dc_subject = [model.DC_Subject(name=subject.lstrip()) for subject in request.params['dc_subject'].split(',')], + dc_creator = model.DC_Creator(name = request.params['dc_creator']), - dc_abstract = request.params['abstract'], + dc_abstract = request.params['dc_abstract'], # TODO: enable several contributors - dc_contributor = '', + dc_contributor = [model.DC_Contributor(name=contributor.lstrip()) for contributor in request.params['dc_contributor'].split(',')], # TODO: insert real data dc_created = datetime(9999,9,9).strftime("%Y-%m-%d %H:%M:%S"), @@ -82,23 +83,24 @@ class UploadController(BaseController): dc_identifier = '', dc_source = '', - dc_language = request.params['language'], + dc_language = request.params['dc_language'], # TODO: insert videolength dc_extent = timedelta(0), - dc_spatial = request.params['spatial'], + dc_spatial = request.params['dc_spatial'], dc_temporal = datetime(9999,9,9).strftime("%Y-%m-%d %H:%M:%S"), dc_rightsHolder = '', # Creative Commons properties - cc_commercial = (request.params['commercial'] == 'commercial'), - cc_sharealike = (request.params['modification'] == 'sharealike'), - cc_derivatives = (request.params['modification'] != 'noderivatives'), + cc_commercial = (request.params['commercial'] == 'cc_commercial'), + cc_sharealike = (request.params['modification'] == 'cc_sharealike'), + cc_derivatives = (request.params['modification'] != 'cc_noderivatives'), sha256=sha256 ) + model.session.commit() # copy file to temporary destination diff --git a/trunk/yolanda/model/entities.py b/trunk/yolanda/model/entities.py index 2a21ed8..93714ab 100644 --- a/trunk/yolanda/model/entities.py +++ b/trunk/yolanda/model/entities.py @@ -3,16 +3,14 @@ from elixir import * class Video(Entity): using_options(tablename='videos') - # Important: Keep this in sync with upload.py ! - # Dublin Core terms dc_title = Field(Unicode(255)) - dc_creator = Field(Unicode(255)) - dc_subject = Field(UnicodeText) + dc_creator = ManyToOne('DC_Creator') + dc_subject = ManyToMany('DC_Subject') dc_abstract = Field(UnicodeText) - dc_contributor = Field(Unicode(255)) + dc_contributor = ManyToMany('DC_Contributor') dc_created = Field(DateTime) dc_valid = Field(DateTime) @@ -41,3 +39,19 @@ class Video(Entity): # everything else sha256 = Field(String(64)) + +# Dublin Core terms + +class DC_Creator(Entity): + name = Field(Unicode(255)) + videos = OneToMany('Video') + +class DC_Subject(Entity): + name = Field(Unicode(32)) + videos = ManyToMany('Video') + +class DC_Contributor(Entity): + name = Field(Unicode(255)) + videos = ManyToMany('Video') + +