Beispiel #1
0
def save_in_database(filename, data, tracker):
    olds = Episode.find().filter_by(filename = filename).all()
    for key in ['files', 'links', 'previews']:
        if key not in data:
            data[key] = []
    for old in olds:
        try:
            Link.find().filter_by(episode = old.id).delete()
            File.find().filter_by(episode = old.id).delete()
            Preview.find().filter_by(episode = old.id).delete()
        except Exception as e: print(style.red+"errör 1:"+style.default,e)
    updated = len(olds)
    if olds:
        episode = Episode.find().filter_by(id = olds.pop(0).id)
        episode.update(data['episode'])
        episode = episode.one()
    else:
        episode = Episode(filename=filename, **data['episode'])
        episode.save()
    for old in olds:
        try:
            Comment.find().filter_by(episode=old.id).update({'episode':episode.id})
            Rating.find().filter_by(episode=old.id).update({'episode':episode.id})
            Episode.find().filter_by(id = old.id).delete()
        except Exception as e: print(style.red+"errör 2:"+style.default,e)
    if updated: print(style.green+"* update db: ",filename,style.default)
    else: print(style.green+"* add to db: ",filename,style.default)
    list(map(lambda kwargs: File(episode=episode.id, **kwargs).add(), data['files']))
    list(map(lambda kwargs: Preview(episode=episode.id, **kwargs).add(), data['previews']))
    list(map(lambda kwargs: Link(episode=episode.id, **kwargs).add(), data['links']))
    tracker.check_all(filename, episode, data['links'])
    session().commit()
Beispiel #2
0
def datenspur(web, id, mode, errors=[]):
    try: # FIXME wrap db queries into one
        episodes = Episode.find().filter(Episode.category.endswith(id)).\
                order_by(Episode.date).all()
        episodes.reverse()
        comments_count = [ Comment.find().filter_by(episode = e.id).count()
                        for e in episodes ]
        ratings = [ do_the_ratings(web, "", Rating.find().\
                    filter_by(episode = e.id).all())['rating']
                    for e in episodes ]
        episode = Episode.find().filter_by(link = id).one()
        for ep in episodes:
            ep.has_screen = True
            ep.files = File.find().filter_by(episode = ep.id).all()
            ep.preview = get_preview(Preview.find().\
                filter_by(episode = episode.id).all(), ep.files)
        comments = Comment.find().filter_by(episode = episode.id).all()
        rating = Rating.find().filter_by(episode = episode.id).all()
    except Exception as e: return notfound(str(e))
    if mode is None: mode = ""
    if len(mode): mode = mode[1:]
    opts = {}
    opts.update(create_session(web, mode))
    opts.update(do_the_comments(web, mode, comments))
    opts.update(do_the_ratings(web, mode, rating))
    return template("datenspuren.tpl",
                    errors      = errors,
                    css         = "episode",
                    episodepage = zip(episodes, comments_count, ratings),
                    site        = "datenspuren",
                    full_site   = "datenspuren/" + id,
                    episode     = episode,
                    **opts
                   )
Beispiel #3
0
def datenspur_file(web, id, filename, mode, errors=[]):
    try: # FIXME wrap db queries into one
        episode = Episode.find().filter_by(link = filename).\
                filter(Episode.category.endswith(id)).\
                order_by(Episode.date).one()
        comments = Comment.find().filter_by(episode = episode.id).all()
        files    = File.find().filter_by(episode = episode.id).all()
        ratings  = Rating.find().filter_by(episode = episode.id).all()
        previews = Preview.find().filter_by(episode = episode.id).all()
        trackbacks = Trackback.find().filter_by(episode = episode.id).\
                    order_by(Trackback.date).all()
    except Exception as e: return notfound(str(e))
    episode.files = files
    if mode is None: mode = ""
    if len(mode): mode = mode[1:]
    opts = {}
    opts.update(create_session(web, mode))
    opts.update(do_the_comments(web, mode, comments))
    opts.update(do_the_ratings(web, mode, ratings))
    preview = get_preview(previews, files)
    csss = [ "../lib/video-js/video-js", "../lib/video-js/skins/vim", "vim"]
    if episode.isaudio():
        csss = list(map(lambda s:s.replace("video", "audio"), csss))
    return template("datenspur.tpl",
                    errors     = errors,
                    css        = "episode",
                    episode    = episode,
                    episodes   = {episode.id: episode},
                    site       = "datenspuren",
                    full_site  = "datenspuren/" + id,
                    trackbacks = trackbacks,
                    files      = files,
                    preview    = preview,
                    csss       = csss,
                    **opts
                   )