new database format, rudimentary search function

git-svn-id: http://yolanda.mister-muffin.de/svn@414 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
erlehmann 2008-12-13 11:58:11 +00:00
parent 1b78258dbf
commit 002e384004
4 changed files with 46 additions and 21 deletions

View file

@ -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),

View file

@ -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 = []

View file

@ -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

View file

@ -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')