From 05bdaab9f071ea5918b37427861cf4149f44e622 Mon Sep 17 00:00:00 2001 From: erlehmann Date: Sat, 20 Dec 2008 10:04:58 +0000 Subject: [PATCH] adding tagcloud everywhere, patching the database into an unusable mess git-svn-id: http://yolanda.mister-muffin.de/svn@419 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/yolanda/controllers/index.py | 8 +------- trunk/yolanda/controllers/upload.py | 21 ++++++++++++++++++--- trunk/yolanda/lib/base.py | 12 ++++++++++++ trunk/yolanda/model/entities.py | 16 ++++++++++++---- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/trunk/yolanda/controllers/index.py b/trunk/yolanda/controllers/index.py index 7c7b216..37832bf 100644 --- a/trunk/yolanda/controllers/index.py +++ b/trunk/yolanda/controllers/index.py @@ -8,13 +8,7 @@ class IndexController(BaseController): def index(self): - tags = {} - for tag in model.DC_Subject.query.all(): - if tag.name in tags.keys(): - tags[tag.name]+=1 - else: - tags[tag.name] = 1 - c.tagcloud = tags + # TODO: write elixir devs a mail to see how this works un-hackish return render('/xhtml/index.mako') diff --git a/trunk/yolanda/controllers/upload.py b/trunk/yolanda/controllers/upload.py index fbba055..49d106b 100644 --- a/trunk/yolanda/controllers/upload.py +++ b/trunk/yolanda/controllers/upload.py @@ -59,18 +59,23 @@ class UploadController(BaseController): # set up database entry + raise RuntimeError + video = model.Video( # Dublin Core terms dc_title = request.params['dc_title'], dc_alternative = 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_subject = [model.DC_Subject(name=u'lol'), model.DC_Subject(name=u'wut')], +# dc_subject = self.getsubjects(), +# dc_creator = model.DC_Creator(name = request.params['dc_creator']), dc_abstract = request.params['dc_abstract'], # TODO: enable several contributors - dc_contributor = [model.DC_Contributor(name=contributor.lstrip()) for contributor in request.params['dc_contributor'].split(',')], +# dc_contributor = [model.DC_Contributor(name=contributor.lstrip()) for contributor in request.params['dc_contributor'].split(',')], +# dc_contributor = [model.DC_Contributor(name=u'lol'), model.DC_Contributor(name=u'wut')], # TODO: insert real data dc_created = datetime(9999,9,9).strftime("%Y-%m-%d %H:%M:%S"), @@ -136,3 +141,13 @@ class UploadController(BaseController): videoencode = encode.Encode(source,destination) videoencode.run() os.unlink(source) + + def getsubjects(self): + dc_subject = [] + for subject in request.params['dc_subject'].split(','): + s = model.DC_Subject.get_by(name=subject.lstrip()) + if s: + dc_subject.append(s) + else: + dc_subject.append(model.DC_Subject(name=subject.lstrip())) + return dc_subject diff --git a/trunk/yolanda/lib/base.py b/trunk/yolanda/lib/base.py index cfb9821..7d74236 100644 --- a/trunk/yolanda/lib/base.py +++ b/trunk/yolanda/lib/base.py @@ -23,6 +23,18 @@ class BaseController(WSGIController): # available in environ['pylons.routes_dict'] return WSGIController.__call__(self, environ, start_response) + def __before__(self): + + tags = {} + for tag in model.DC_Subject.query.all(): + if tag.name in tags.keys(): + tags[tag.name]+=1 + else: + tags[tag.name] = 1 + c.tagcloud = tags + + print "__before__ %s" % tags + # Include the '_' function in the public names __all__ = [__name for __name in locals().keys() if not __name.startswith('_') \ or __name == '_'] diff --git a/trunk/yolanda/model/entities.py b/trunk/yolanda/model/entities.py index 5dd7a6c..dbdae61 100644 --- a/trunk/yolanda/model/entities.py +++ b/trunk/yolanda/model/entities.py @@ -2,7 +2,7 @@ from elixir import * from sqlalchemy import UniqueConstraint class Video(Entity): - using_options(tablename='videos') +# using_options(tablename='videos') # Dublin Core terms dc_title = Field(Unicode(255)) @@ -45,15 +45,23 @@ class Video(Entity): # Dublin Core terms class DC_Creator(Entity): - name = Field(Unicode(255), unique = True) + name = Field(Unicode(255), primary_key = True) videos = OneToMany('Video') + def __repr__(self): + return '' % self.name + class DC_Subject(Entity): - name = Field(Unicode(32), unique = True) + name = Field(Unicode(32), primary_key = True) videos = ManyToMany('Video') + def __repr__(self): + return '' % self.name + class DC_Contributor(Entity): - name = Field(Unicode(255), unique = True) + name = Field(Unicode(255), primary_key = True) videos = ManyToMany('Video') + def __repr__(self): + return '' % self.name