コード例 #1
0
ファイル: routes.py プロジェクト: c3d2/pentamedia-portal
def datenspuren(web, errors=[]):
    try: # FIXME wrap db queries into one
        episodes = Episode.find().filter(Episode.category.startswith("ds")).\
                order_by(Episode.date).all()
        episodes.reverse()
        comments_count, ratings = [], []
        for episode in episodes:
            ids = list(map(lambda e:e.id, Episode.find(Episode.id).\
                filter_by(category = "file/{0}/{1}".\
                format(episode.category, episode.link)).all()))
            f_rts = Rating.find().filter(Rating.episode.in_(ids)).all()
            e_rts = Rating.find().filter_by(episode = episode.id).all()
            ratings += [ do_the_ratings(web, "", e_rts + f_rts)['rating'] ]
            comments_count += [
                Comment.find().filter(Comment.episode.in_(ids)).count() +
                Comment.find().filter_by( episode = episode.id).count() ]
            count = File.find().filter_by(episode = episode.id).count()
            episode.filescount = "// {0} File{1}".format(count,
                count != 1 and "s" or "")
    except Exception as e: return notfound(str(e))
    return template("episodes.tpl",
                    errors      = errors,
                    css         = "episode",
                    episodepage = zip(episodes, comments_count, ratings),
                    site        = "datenspuren"
                   )
コード例 #2
0
ファイル: cwebfetcher.py プロジェクト: c3d2/pentamedia-portal
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()
コード例 #3
0
ファイル: routes.py プロジェクト: c3d2/pentamedia-portal
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
                   )
コード例 #4
0
ファイル: cwebfetcher.py プロジェクト: c3d2/pentamedia-portal
def save_recording_in_database(filename, data, tracker, debug=False):
    # datastructure:
    # xml-file as Episode (category='ds*') with files from resource-tags
    # files from resource-tags as Episodes (category='file/ds*/:link')
    #    with self and alternatives as files
    dsfiles = deepcopy(data['files'])
    for f in data['files']:
        f.pop('alternatives')
    try:
        olds = Episode.find().filter_by(filename = filename).all()
        old_files = list(map(lambda f: f.link,
            sum(map(lambda o: File.find().\
            filter_by(episode = o.id).all(), olds), [])))
    except Exception as e: print(style.red+"errör 0:"+style.default,e)
    save_in_database(filename, data, tracker)
    for dsfile in dsfiles:
        dsdata = deepcopy(data)
        alternatives = dsfile.pop('alternatives')
        dsdata['files'] = [dsfile] + alternatives
        dsepisode = dsdata['episode']
        dsepisode['name'] = dsfile['name']
        dsepisode['long'] = dsfile['info']
        dsepisode['link'] = ospath.basename(dsfile['link']).\
            replace(" ", "_").replace("%20", "_")
        dsepisode['short'] = dsfile['type']
        dsepisode['category'] = "file/{0}/{1}".\
            format(data['episode']['category'], data['episode']['link'])
        save_in_database(filename + dsfile['link'], dsdata, tracker)
        if dsfile['link'] in old_files:
            old_files.remove(dsfile['link'])
        for alternative in alternatives:
            if alternative['link'] in old_files:
                old_files.remove(alternative['link'])
    if old_files:
        episode = Episode.find().filter_by(filename = filename).one()
    for old_file in old_files:
        print(style.red + style.bold +
            "* found dangling file (link: {0})".\
            format(old_file), "move comments and rating to",
            "[id:{0}, link:{1}, name:{2}]".\
            format(episode.id,episode.link,episode.name), style.default)
        try:
            olds = Episode.find().filter_by(filename = filename + old_file).\
                filter(Episode.category.startswith("file/")).all()
            if debug: print("* found",len(olds),"episodes to delete")
            for old in olds:
                Comment.find().filter_by(episode=old.id).update({'episode':episode.id})
                Rating.find().filter_by(episode=old.id).update({'episode':episode.id})
            print("* deleted {0} episodes".format(
                Episode.find().filter_by(filename = filename + old_file).delete()))
        except Exception as e: print(style.red+"errör 3:"+style.default,e)
        session().commit()
コード例 #5
0
ファイル: feeds.py プロジェクト: c3d2/pentamedia-portal
def feed_all_comments_counts(web):
    episodes = Episode.find().all()
    comments = {}
    for episode in episodes:
        label = episode.filename.split("/").pop()
        comments[label] = Comment.find().filter_by(episode = episode.id).count()
    return template_json(web, comments)
コード例 #6
0
ファイル: feeds.py プロジェクト: c3d2/pentamedia-portal
def feed_comments_by_slug(web, site, id, mode):
    try: # FIXME wrap db queries into one
        episode  = Episode.find().filter_by(link = id).one()
        comments = Comment.find().filter_by(episode = episode.id).\
                    order_by(Comment.date).all()
    except: return notfound("Episode not found.")
    return comments_per_episode(web, episode, comments, site, mode)
コード例 #7
0
ファイル: routes.py プロジェクト: c3d2/pentamedia-portal
def episode(web, site, id, mode, errors=[]):
    try: # FIXME wrap db queries into one
        episode  = Episode.find().filter_by(link = id).one()
        files    = File.find().filter_by(episode = episode.id).all()
        links    = Link.find().filter_by(episode = episode.id).all()
        comments = Comment.find().filter_by(episode = episode.id).\
                   order_by(Comment.date).all()
        ratings  = Rating.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))
    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))
    return template("episode.tpl",
                    errors     = errors,
                    css        = "episode",
                    episode    = episode,
                    episodes   = {episode.id: episode},
                    site       = site,
                    trackbacks = trackbacks,
                    files      = files,
                    links      = links,
                    csss       = [ "../lib/audio-js/audio-js",
                                   "../lib/audio-js/skins/vim",
                                   "vim"],
                    **opts
                   )
コード例 #8
0
ファイル: routes.py プロジェクト: c3d2/pentamedia-portal
def comments(web, site, id, mode, errors=[]):
    try: # FIXME wrap db queries into one
        episode  = Episode.find().filter_by(link = id).one()
        comments = Comment.find().filter_by(episode = episode.id).\
                   order_by(Comment.date).all()
    except: return notfound("Episode not found.")
    return template_mode(web, site, episode, mode,
                         errors   = errors,
                         comments = comments
                        )
コード例 #9
0
ファイル: feeds.py プロジェクト: c3d2/pentamedia-portal
def feed_comments_by_filename(web, filename, mode):
    filename = "content/news/{0}.xml".format(filename)
    try: # FIXME wrap db queries into one
        episode  = Episode.find().filter_by(filename = filename).one()
        comments = Comment.find().filter_by(episode = episode.id).\
                    order_by(Comment.date).all()
        if   "radio" in filename: site = "pentaradio"
        elif "cast"  in filename: site = "pentacast"
        elif "music" in filename: site = "pentamusic"
        else: site = 42 / 0
    except: return notfound("Episode not found.")
    return comments_per_episode(web, episode, comments, site, mode)
コード例 #10
0
ファイル: routes.py プロジェクト: c3d2/pentamedia-portal
def comments_by_filename(web, filename, mode, errors=[]):
    filename = "content/news/{0}.xml".format(filename)
    try: # FIXME wrap db queries into one
        episode  = Episode.find().filter_by(filename = filename).one()
        comments = Comment.find().filter_by(episode = episode.id).\
                   order_by(Comment.date).all()
        if   "radio" in filename: site = "pentaradio"
        elif "cast"  in filename: site = "pentacast"
        elif "music" in filename: site = "pentamusic"
        else: site = 42 / 0
    except Exception as e: return notfound(str(e))
    return template_mode(web, site, episode, mode,
                         errors   = errors,
                         comments = comments
                        )
コード例 #11
0
ファイル: routes.py プロジェクト: c3d2/pentamedia-portal
def main(web, site, errors=[]):
    try: # FIXME wrap db queries into one
        episodes = Episode.find().filter_by(category=site).\
                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 ]
    except Exception as e: return notfound(str(e))
    return template("episodes.tpl",
                    errors      = errors,
                    css         = "episode",
                    episodepage = zip(episodes, comments_count, ratings),
                    site        = site
                   )
コード例 #12
0
ファイル: feeds.py プロジェクト: c3d2/pentamedia-portal
def feed_comments_by_category(web, site, mode):
    # FIXME wrap db queries into one
    episodes = Episode.find().filter_by(category = site).\
               order_by(Episode.date).all()
    episodes.reverse()
    comments, id_episodes = [], {}
    for episode in episodes:
        comments.extend(Comment.find().filter_by(episode = episode.id).all())
        id_episodes[episode.id] = episode
    comments.sort(key=lambda cmnt: cmnt.date)
    comments.reverse()
    if mode == "atom":
        return template_atom(
            title    = "Pentamedia-Portal // P{0} // Comments".format(site[1:]),
            episodes = id_episodes,
            comments = comments
                       )
    elif mode == "json":
        return template_json(web, {
            "comments": list(map(comment_to_json,comments)),
            "new_link": "/{0}/{1}/comment#new".format(episode.category,episode.link)
                                  })
    else: return  notfound("Type not supported.")
コード例 #13
0
ファイル: feeds.py プロジェクト: c3d2/pentamedia-portal
def feed_all_comments(web, mode):
    # FIXME wrap db queries into one
    episodes = Episode.find().all()
    comments = Comment.find().all()
    trackbacks = Trackback.find().all()
    if mode == "atom":
        entries = comments + trackbacks
        entries.sort(key=lambda e: e.date)
        entries.reverse()
        id_episodes = {}
        for episode in episodes:
            id_episodes[episode.id] = episode
        return template_atom(
                        title    = "Pentamedia-Portal // Comments",
                        episodes = id_episodes,
                        comments = entries
                       )
    elif mode == "json":
        return template_json(web, {
            "comments":   list(map(comment_to_json, comments)),
            "trackbacks": list(map(trackback_to_json, trackbacks))
                           })
    else:  return notfound("Type not supported.")
コード例 #14
0
ファイル: routes.py プロジェクト: c3d2/pentamedia-portal
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
                   )