Example #1
0
def home():
    address = flask.request.args.get('address')
    nocheck = (flask.request.args.get('force') == 'true')
    if address:
        reponame = cleanname(address)
        if not models.Repo.get(name=reponame):
            try:
                if nocheck:
                    if flask.request.args.get('reponame') != address:
                        return flask.render_template(
                            'index.html', error='reponame not match')

                    desc = 'unknown desc - forceadd'
                else:
                    desc = checkrepo(reponame)
            except Exception as e:
                force_add = '''
                If you confirm this is a go main package. 
                <form class="pull-right">
                    <input type="hidden" name="address" value="{reponame}">
                    <input type="hidden" name="force" value="true">
                    <input type="text" name="reponame" placeholder="Type repo name again">
                    <button class="btn btn-warning btn-xs">force add</button>
                </form>'''.format(reponame=reponame)
                error = str(e) + ' <br>- ' + force_add
                return flask.render_template('index.html',
                                             error=flask.Markup(error))
            repo = models.Repo(name=reponame)
            repo.created = datetime.datetime.today()
            repo.description = desc
            repo.author = 'unknown .. unfinished'

            # add new job
            build = models.Build(repo=repo,
                                 tag='branch:master',
                                 status='initing')
            job = models.Job(build=build,
                             status='initing',
                             created=datetime.datetime.today())
            models.commit()
            taskqueue.que.put(job.id)

        return flask.redirect('/' + reponame, 302)

    new = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.created))[:10]
    top = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.down_count))[:10]

    #error = 'Beta version, only for test for the time now.'
    error = None
    return flask.render_template('index.html',
                                 top_repos=top,
                                 new_repos=new,
                                 error=error)
Example #2
0
def item_dump():
    items = Item.query.order_by(desc(Item.mu)).all()
    data = [['Mu', 'Sigma Squared', 'Name', 'Location', 'Description']]
    data += [[
        str(item.mu),
        str(item.sigma_sq), item.name, item.location, item.description
    ] for item in items]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')
Example #3
0
def home():
    address = flask.request.args.get('address')
    nocheck = (flask.request.args.get('force') == 'true')
    if address:
        reponame = cleanname(address)
        if not models.Repo.get(name=reponame):
            try:
                if nocheck:
                    if flask.request.args.get('reponame') != address:
                        return flask.render_template('index.html', error='reponame not match')

                    desc = 'unknown desc - forceadd'
                else:
                    desc = checkrepo(reponame)
            except Exception as e:
                force_add = '''
                If you confirm this is a go main package. 
                <form class="pull-right">
                    <input type="hidden" name="address" value="{reponame}">
                    <input type="hidden" name="force" value="true">
                    <input type="text" name="reponame" placeholder="Type repo name again">
                    <button class="btn btn-warning btn-xs">force add</button>
                </form>'''.format(reponame=reponame)
                error = str(e) + ' <br>- ' + force_add
                return flask.render_template('index.html', error=flask.Markup(error))
            repo = models.Repo(name=reponame)
            repo.created = datetime.datetime.today()
            repo.description = desc
            repo.author = 'unknown .. unfinished'

            # add new job
            build = models.Build(repo=repo, tag='branch:master', status='initing')
            job = models.Job(build=build, status='initing', created=datetime.datetime.today())
            models.commit()
            taskqueue.que.put(job.id)

        return flask.redirect('/'+reponame, 302)

    new = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.created))[:10]
    top = models.select(r for r in models.Repo).\
            order_by(models.desc(models.Repo.down_count))[:10]

    #error = 'Beta version, only for test for the time now.'
    error=None
    return flask.render_template('index.html', top_repos=top, new_repos=new, error=error)
Example #4
0
def tasklist(bid):
    build = models.Build.get(id=bid)
    repo = build.repo

    jobs = models.select(b for b in models.Job \
            if b.build == build).order_by(models.desc(models.Job.created))

    kwargs = dict(repo=repo, build=build, jobs=jobs)
    return render_template('tasklist.html', **kwargs)
Example #5
0
def tasklist(bid):
    build = models.Build.get(id=bid)
    repo = build.repo

    jobs = models.select(b for b in models.Job \
            if b.build == build).order_by(models.desc(models.Job.created))

    kwargs = dict(repo=repo, build=build, jobs=jobs)
    return render_template('tasklist.html', **kwargs)
Example #6
0
def get_none_intern_articles(start, limit):
    query = (
        get_article_ids_by(is_published=True)
        .filter("fid<>1 and date>now() and fid in (select id from feed where enabled=1)")
        .order_by(desc(Article.date))
    )
    rs = query.offset(start).limit(limit).all()
    n = query.count()
    return n, [r for r, in rs]
def recent_feed():
    feed = AtomFeed("Catalog", feed_url=request.host_url, subtitle="Recent item feed for Catalog")
    for item in session.query(Item).order_by(desc(Item.id)).limit(10).all():
        feed.add(
            item.name,
            item.description,
            content_type="html",
            owner=item.user.name,
            url=url_for("view_item", id=item.id, _external=True),
            updated=item.updated_date,
            created=item.created_date,
        )

    return feed.get_response()
Example #8
0
def admin():
    annotators = Annotator.query.all()
    items = Item.query.order_by(desc(Item.mu)).all()
    decisions = Decision.query.all()
    counts = {}
    item_counts = {}
    for d in decisions:
        a = d.annotator_id
        w = d.winner_id
        l = d.loser_id
        counts[a] = counts.get(a, 0) + 1
        item_counts[w] = item_counts.get(w, 0) + 1
        item_counts[l] = item_counts.get(l, 0) + 1
    annotators.sort(key=lambda i: -counts.get(i.id, 0))
    return render_template('admin.html',
                           annotators=annotators,
                           counts=counts,
                           item_counts=item_counts,
                           items=items,
                           votes=len(decisions))
Example #9
0
def get_comment_by_user(type, target_id, user_id, start, limit):
    '''只看楼主(其实随便哪个都可以啦)'''
    query = Comment.get_ids().filter_by(type=type, target_id=target_id, author_id=author_id).order_by(desc(Comment.id))
    rs = query.offset(start).limit(limit).all()
    n = query.count()
    return n, [r for r, in rs]
Example #10
0
def get_comment_by_type(type, target_id, start, limit):
    '''某入口下的评论'''
    query = Comment.get_ids().filter_by(type=type, target_id=target_id).order_by(desc(Comment.id))
    rs = query.offset(start).limit(limit).all()
    n = query.count()
    return n, [r for r, in rs]
def view_main():
    cats = session.query(Category).all()
    recent_items = session.query(Item).order_by(desc(Item.id)).limit(10)
    return render_template("main.html", login_session=login_session, categories=cats, recent_items=recent_items)
Example #12
0
def get_page(start, limit, fid, is_published):
    query = get_article_ids_by(fid=fid, is_published=is_published).order_by(desc(Article.date))
    rs = query.offset(start).limit(limit).all()
    n = query.count()
    return n, [r for r, in rs]
Example #13
0
def get_favorite_page(uid, start, limit):
    query = Favorite.query.filter_by(uid=uid).order_by(desc(Favorite.id))
    n = query.count()
    rs = query.offset(start).limit(limit).all()
    return n, rs