Пример #1
0
def community(community):
    community_ref = Community.get_or_none(Community.name == community)
    return object_list('community.html',
                       Proposal.from_community(community_ref).order_by(
                           Proposal.timestamp.desc()),
                       community=community_ref,
                       check_bounds=False)
Пример #2
0
def find_blog_with_tag(tag):
    python_entries = (
        Entry.select().where((Entry.published == True)
                             & (Entry.tag_name.contains('|' + tag + '|'))))
    query_tag = Entry.select(Entry.tag_name).distinct()
    tag_dict = dict()
    for e in query_tag:
        l = e.tag_name.strip('|').split('|')
        for ii in l:
            if ii in tag_dict:
                tag_dict[ii] += 1
            else:
                tag_dict[ii] = 1
    query = Entry.public().order_by(Entry.timestamp.desc())
    #display recently 5 articles
    ii = 1
    ll_article = []
    for kk in query:
        if ii <= 5:
            ll_article.append(kk.title)
        ii += 1

    return object_list('index.html',
                       python_entries,
                       t=tag_dict,
                       recent_article=ll_article,
                       paginate_by=12,
                       img=img_stream,
                       check_bounds=False)
Пример #3
0
def index():
	search_query = request.args.get('q')
	if search_query:
		query = Entry.search(search_query)
	else:
		query = Entry.public().order_by(Entry.timestamp.desc())
	return object_list('index.html', query, search=search_query)
Пример #4
0
def blog():
    search_query = request.args.get('q')
    if search_query:
        query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.timestamp.desc())
    return object_list('blog.html', query, search=search_query, title='Blog')
Пример #5
0
def index():
    users_with_images = User.select().join(
        Image, on=(User.id == Image.user_id)).distinct()
    return object_list('/users/index.html',
                       query=users_with_images,
                       context_variable='users_with_images',
                       paginate_by=5)
Пример #6
0
def recommend(tag_list, name):
    # query = Entry.public().where((Entry.tags.contains('Future')) | (Entry.tags.contains('transport')))
    query = Entry.public().where(Entry.tags.contains('highlight'))
    for tag in tag_list:
        query = query | Entry.public().where(Entry.tags.contains(tag))

    return object_list('pref_list.html', query, check_bounds=False, user=name)
Пример #7
0
def blog():
    search_query = request.args.get('q')
    category_type = None

    if search_query:
        if search_query.lower() in categories:
            search_query = search_query.capitalize()
            query = Entry.public().select(Entry).where(Entry.category == search_query)
            category_type = search_query
        else:
            query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.timestamp.desc())

    # Add tile images for listed entries.
    banner_images = {}
    for entry in query:
        try:
            banner_path = glob.glob(os.path.join(THUMBNAIL_PATH_LG, entry.banner_id))[0]
            banner_images[entry.banner_id] = banner_path.split("static")[1]
        except:
            flash("Failed to load banner image {} for {}".format(entry.banner_id,entry.title), 'danger')

    # The `object_list` helper will take a base query and then handle
    # paginating the results if there are more than 20. For more info see
    # the docs:
    # http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#object_list
    return object_list(
        'blog.html',
        query,
        search=search_query,
        category=category_type,
        banner_images=banner_images,
        check_bounds=False)
Пример #8
0
def drafts():
    """
    博文草稿页面
    需要登录认证
    """
    query = Entry.drafts().order_by(Entry.timestamp.desc())
    return object_list('index.html', query, check_bounds=False)
Пример #9
0
def user_detail(username):
    user = get_object_or_404(User.select(), (User.username == username))
    return object_list('user.html',
                       user.posts,
                       check_bounds=False,
                       context_variable='posts_list',
                       user=user)
Пример #10
0
def archive():
    query = Entry.archive().order_by(Entry.timestamp.desc())
    return object_list(
        'index.html',
        query,
        archive=archive,
        check_bounds=False)
Пример #11
0
def feed(feed):
    query = Proposal.public()

    # FIXME: better sorting

    community = None

    if feed == "popular":
        query = query.order_by(-Proposal.ranking)
        community = Community(name="popular",
                              description="The most popular posts on Pnyx.")

    elif feed == "upvote":
        query = query.order_by(-(Proposal.upvotes - Proposal.downvotes))
        community = Community(name="upvote",
                              description="The most upvoted posts on Pnyx.")

    elif feed == "new":
        query = query.order_by(Proposal.timestamp.desc())
        community = Community(
            name="new",
            description=gettext("The newest posts from all of Pnyx. Come here "
                                "to see posts rising and be a part of "
                                "the conversation."))

    else:
        query = query.order_by(-Proposal.ranking, Proposal.timestamp.desc())

    return object_list('community.html',
                       query,
                       community=community,
                       check_bounds=False)
Пример #12
0
def subscribers():
    """ Show list of subscriptions. """
    # Get user
    username = session.get("user", None)
    try:
        user = User.get(User.username == username)

    except User.DoesNotExist:
        abort(404)

    # Find followers
    subs = (
        User.select()
        .join(Subscription, on=Subscription.subscriber)
        .where(Subscription.publisher == user)
        .order_by(User.username.asc())
    )

    try:
        return object_list(
            "profile/subs.html", query=subs, context_variable="subs", paginate_by=10, user=user, title="Followers"
        )

    except NotFound:
        # Prevent 404 and show nicer message
        return render_template("profile/subs.html", user=user, title="Followers")
Пример #13
0
def index():
    search_query = request.args.get('q')
    if search_query:
        query = Post.search(search_query)
    else:
        query = Post.public().order_by(Post.timestamp.desc())
    return object_list('index.html', query, search=search_query)
Пример #14
0
def view_post(pid):
    page = request.args.get('page', 1, int)
    post = get_or_404(Post, Post.id == pid)
    form = UpdatePostForm()
    comment_form = CommentForm()
    com = Comment.get_post_comments(pid)
    if form.validate_on_submit():
        if post.user.id != current_user.id:
            return abort(403)
        Post.update(content=form.post_content.data).where(
            Post.id == post.id).execute()
        flash('Post update', 'success')
        return redirect(url_for('.view_post', pid=pid))
    if request.method == meth[1]:
        form.post_content.data = post.content
    all_comment = Comment.get_post_comments(pid)
    if all_comment:
        return object_list('home/view_post.html',
                           Comment.get_post_comments(pid),
                           context_variable='comment_list',
                           post=post,
                           form=form,
                           comment_form=comment_form,
                           paginate_by=2,
                           page=page)
    return render_template('home/view_post.html',
                           comment_form=comment_form,
                           post=post,
                           form=form,
                           comment_list=all_comment)
Пример #15
0
def index():
    categories = {}
    search_query = request.args.get('q')
    label_query = request.args.get('label')
    if search_query:
        query = Entry.search(search_query)
    elif label_query:
        query = Entry.select().where(Entry.label1 == '強化学習'
                                     or Entry.label2 == label_query
                                     or Entry.label3 == label_query)
    else:
        query = Entry.public().order_by(Entry.timestamp.desc())
        for entry in query:
            attr = entry.sport
            if attr not in categories:
                categories[attr] = Entry.select().where(Entry.sport == attr)

    # The `object_list` helper will take a base query and then handle
    # paginating the results if there are more than 20. For more info see
    # the docs:
    # http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#object_list
    return object_list('index.html',
                       query,
                       search=search_query,
                       label=label_query,
                       categories=categories,
                       check_bounds=False)
Пример #16
0
def drafts():
    query = Entry.drafts().order_by(Entry.timestamp.desc())
    tag_dict = dict()
    query_tag = Entry.select(Entry.tag_name).distinct()
    for e in query_tag:
        l = e.tag_name.strip('|').split('|')
        for ii in l:
            if ii in tag_dict:
                tag_dict[ii] += 1
            else:
                tag_dict[ii] = 1
    query_title = Entry.public().order_by(Entry.timestamp.desc())
    #display recently 5 articles
    ii = 1
    ll_article = []
    for kk in query_title:
        if ii <= 5:
            ll_article.append(kk.title)
        ii += 1

    return object_list('index.html',
                       query,
                       t=tag_dict,
                       recent_article=ll_article,
                       paginate_by=12,
                       img=img_stream,
                       check_bounds=False)
Пример #17
0
def drafts():
    query = Entry.drafts()\
        .order_by(Entry.timestamp.desc())
    return object_list("index.html",
                       query,
                       paginate_by=5,
                       check_bounds=False,
                       title="Drafts")
Пример #18
0
def frontpage():
    posts = (Proposal.all().where(Proposal.published == True).order_by(
        Proposal.timestamp.desc()).limit(20))

    return object_list('frontpage.html',
                       posts,
                       check_bounds=False,
                       paginate_by=50)
Пример #19
0
def find_blog_with_tag(tag):
    python_entries = (
        Entry.select().where((Entry.published == True)
                             & (Entry.tag_name.contains('|' + tag + '|'))))
    return object_list('index.html',
                       python_entries,
                       t=tag_dict,
                       check_bounds=False)
Пример #20
0
def followers(username):
    user = get_object_or_404(User, User.username == username)
    return object_list('follows.html',
                       user.followers(),
                       check_bounds=False,
                       context_variable='follows_list',
                       user=user,
                       endpoint='main.followers')
Пример #21
0
def index():
    search_query = request.args.get('q')
    if search_query:
        query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.timestamp.desc(
        ))  # return all published in chronological order
    return object_list('index.html', query, search=search_query)
Пример #22
0
def cards():
    search = None
    if request.method == 'POST':
        search = request.form.get('search_word')
    list_cards = get_cards_words(search)
    return object_list('vocabulary.html',
                       list_cards,
                       paginate_by=current_app.config['PER_PAGE'],
                       title='Vocabulary')
Пример #23
0
def taglist():
    count = fn.COUNT(EntryTags.id)
    tags_with_counts = (Tag
                        .select(Tag, count.alias('entry_count'))
                        .join(EntryTags)
                        .join(Entry)
                        .where(Entry.archived==False)
                        .group_by(Tag)
                        .order_by(count.desc(), Tag.tag))
    return object_list('taglist.html', tags_with_counts, check_bounds=False)
Пример #24
0
def category_edit(id):
    try:
        entry = Category.get(Category.id == id)
        flash('Please edit the category name below')
    except:
        entry = None
        flash('Error! The category name: %s is not existed' % name)

    query = Category.select()
    return object_list('category.html', query, paginate_by=app.config.get('PER_PAGE', 10), entry=entry)
Пример #25
0
def comments():
    author = request.args.get('author')
    query = Comment.select()
    if author:
        query = query.where(Comment.author == author)
    comments = query.order_by(Comment.created_at.desc())
    return object_list('blog/comments.html',
                       comments,
                       paginate_by=current_app.config['PER_PAGE'],
                       title='Comments')
Пример #26
0
def drafts():
    title = "Drafts"
    query = Article.drafts().order_by(Article.post_date.desc())

    if query.count() == 0:
        flash('There is no drafts yet, please create one')
        return redirect(url_for('create'))

    # pagination
    return object_list('lists.html', query, paginate_by=app.config.get('PER_PAGE', 10), title=title)
Пример #27
0
def index():
    search_query = request.args.get('q')
    if search_query:
        query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.timestamp.desc())
    return object_list('index.html',
                       query,
                       search=search_query,
                       check_bounds=False)
Пример #28
0
def index():
    search_query = request.args.get("q")
    if search_query:
        query = Entry.search(
            search_query
        )  # This method will use the SQLite full-text search index to query for matching entries. SQLite's full-text search supports boolean queries, quoted phrases, and more.
    else:
        query = Entry.public().order_by(
            Entry.timestamp.desc()
        )  # You may notice that we're also calling Entry.public() if no search is present. This method will return only published entries.
    return object_list("index.html", query, search=search_query)
def index():

    # return render_template('index.html',
    #                        users=User.select())
    users = User.select()

    #####Pagination#######
    return object_list('index.html',
                       users,
                       paginate_by=10,
                       context_variable='users')
Пример #30
0
def taglist():
    count = fn.COUNT(EntryTags.id)
    tags_with_counts = (
        Tag.select(Tag, count.alias("entry_count"))
        .join(EntryTags)
        .join(Entry)
        .where(Entry.archived == False)
        .group_by(Tag)
        .order_by(count.desc(), Tag.tag)
    )
    return object_list("taglist.html", tags_with_counts, check_bounds=False)
Пример #31
0
def feed():
    user = User.get_or_none(User.id == current_user.id)
    image_feed = user.image_feed
    if image_feed:
        return object_list('users/feed.html',
                           query=image_feed,
                           context_variable='feed_list',
                           paginate_by=8)
    else:
        flash(u'You have no image feed yet', 'info')
        return redirect(url_for('home'))
Пример #32
0
def private_time_line():
    user = get_current_user()
    posts = Post.select().where((Post.author << user.following())
                                | (Post.author == user))
    if not posts:
        flash('You can find some interesting posts and follow their author.')
        return public_time_line()
    return object_list('index.html',
                       posts,
                       check_bounds=False,
                       context_variable='posts_list')
Пример #33
0
def nyanters():
    """ Show a paginated list of users. """
    # All your nyas are belong to us
    users = User.select().order_by(User.username.asc())

    try:
        return object_list("board/users.html", query=users, context_variable="users", paginate_by=40)

    except NotFound:
        # Prevent 404 and show nicer message
        return render_template("board/users.html")
Пример #34
0
def nyanboard():
    """ Show a paginated list of nyas. """
    # All your nyas are belong to us
    nyas = Nya.select(Nya, User).join(User).order_by(Nya.timestamp.desc())

    try:
        return object_list("board/nyas.html", query=nyas, context_variable="nyas", paginate_by=40)

    except NotFound:
        # Prevent 404 and show nicer message
        return render_template("board/nyas.html")
Пример #35
0
def index():
    search_query = request.args.get('q')
    if search_query:
        query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.last_mod_date.desc())
    try:
        return object_list('index.html', query)
    except NotFound as exc:
        # peewee throws 404 `NotFound` Exception if no results found
        # but we would rather show page with no results
        return render_template('index.html', object_list=[])
Пример #36
0
def user_publication(user_id):
    try:
        user = User.get(user_id)
    except User.DoesNotExist:
        abort(404)
    return object_list('posts/user_publication.html',
                       user.publications,
                       context_variable='publications',
                       paginate_by=4,
                       page_var='page',
                       check_bounds=True,
                       **{'user': user})
Пример #37
0
def hello():
    mgr = Manager()
    measurement_classes = list()
    measurement_instances = list()
    tag = request.args.get('tag', None)
    cls = request.args.get('class', None)
    host = request.args.get('host', None)
    instance = request.args.get('instance', None)
    all_tags = mgr.get_all(Tag).order_by(Tag.name)
    extended_data = False
    related = dict()
    for m in mgr.get_all(MeasurementClass):
        measurement_classes.append(m.name)
    if not cls and not host and not instance and not tag:
        cls = 'interface'
    measurement_instances = mgr.get_instances_by_tags([tag], True)
    if cls:
        measurement_instances = mgr.get_instances_by_class(cls, True)
    elif host:
        measurement_instances = mgr.get_instances_by_host(host, True)
    elif instance:
        measurement_instances = mgr.get_instances("name", instance, True)
        extended_data = True
    graph_defs = get_graph_definitions(measurement_classes, extended_data)
    graph_periods = get_graph_periods(extended_data)
    clauses = filter_measurement_instance_clauses()
    measurement_instances = (measurement_instances
                             .where(reduce(operator.and_, clauses))
                             .order_by(MeasurementInstance.presentation['description']))

    # Create a list of related items.
    for i in measurement_instances:
        i_class = "class=%s" % i.measurement_class.name
        i_host = "host=%s" % i.host.name
        if i_class not in related:
            related[i_class] = i.measurement_class.description
        if i_host not in related:
            related[i_host] = i.host.name
    if measurement_instances.count() == 1:
        for i in measurement_instances:
            if i.measurement_class.name == 'cbqos':
                key = "instance=%s.interface.%s" % (i.name.split('.')[0], i.attrs['ifIndex'])
                related[key] = "Interface %s" % i.attrs['ifDescr']

    return object_list('netspryte.html',
                       measurement_instances,
                       context_variable="measurement_instances",
                       paginate_by=LIMIT,
                       graph_defs=graph_defs,
                       graph_periods=graph_periods,
                       related=collections.OrderedDict(sorted(related.items())),
                       tags=all_tags,
                       measurement_classes=measurement_classes)
Пример #38
0
def index():
    search_query = request.args.get("q")
    if search_query:
        query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.timestamp.desc())

    # The `object_list` helper will take a base query and then handle
    # paginating the results if there are more than 20. For more info see
    # the docs:
    # http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#object_list
    return object_list("index.html", query, search=search_query, check_bounds=False)
Пример #39
0
def index():
    search_query = request.args.get('q')
    if search_query:
        query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.last_mod_date.desc())
    try:
        return object_list('index.html', query)
    except NotFound as exc:
        # peewee throws 404 `NotFound` Exception if no results found
        # but we would rather show page with no results
        return render_template('index.html', object_list=[])
Пример #40
0
def index():
    search_query = request.args.get('q')
    if search_query:
        query = Entry.search(search_query)
    else:
        query = Entry.public().order_by(Entry.timestamp.desc())

    # The `object_list` helper will take a base query and then handle
    # paginating the results if there are more than 20. For more info see
    # the docs:
    # http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#object_list
    return object_list('index.html', query, search=search_query, check_bounds=False)
Пример #41
0
def index():
    search_query = request.args.get('q')
    if search_query:
        query = Post.search(search_query)
    else:
        query = Post.public().order_by(Post.timestamp.desc())

    return object_list(
        'pc/index.html',
        query,
        site_name=site_name,
        search=search_query,
        check_bounds=False)
Пример #42
0
def show(username):
    """ Show a profile. """
    if not username:
        username = session.get("user", None)

    # Get user
    try:
        user = User.get(User.username == username)
        myself = User.get(User.username == session.get("user", None))

    except User.DoesNotExist:
        abort(404)

    # Check if following
    try:
        sub = Subscription.get(Subscription.subscriber == myself, Subscription.publisher == user)

        # Exists
        is_following = True

    except Subscription.DoesNotExist:
        is_following = False

    # Get nyas
    if myself.username == username:
        # My account, show own and subscriptions
        nyas = (
            Nya.select(Nya, User)
            .join(User)
            .where((Nya.author == user) | (Nya.author << user.subscriptions))
            .order_by(Nya.timestamp.desc())
        )

    else:
        # Another user's account
        nyas = Nya.select(Nya, User).join(User).where(Nya.author == user).order_by(Nya.timestamp.desc())

    try:
        return object_list(
            "profile/show.html",
            query=nyas,
            context_variable="nyas",
            paginate_by=10,
            user=user,
            is_following=is_following,
        )

    except NotFound:
        # Prevent 404 and show nicer message
        return render_template("profile/show.html", user=user)
Пример #43
0
def index():
    if app.config.get('INSTALL', False):
        return redirect(url_for('install'))

    if current_user.is_authenticated:
        query = Article.select().order_by(Article.post_date.desc())
    else:
        query = Article.public().order_by(Article.post_date.desc())

    if query.count() == 0:
        flash('There is no any article at all, create one please')
        return redirect(url_for('create'))

    # pagination
    return object_list('index.html', query, paginate_by=app.config.get('PER_PAGE'))
Пример #44
0
def lists():
    tag = request.args.get('tag')
    cat = request.args.get('cat')

    if cat and not current_user.is_authenticated:
        return redirect(url_for('index'))

    # currently not support tag & cat together, maybe support later
    if tag:
        title = "By tag: %s" % tag
        query = Tag.get(Tag.name == tag).articles
    elif cat:
        title = "By category: %s" % cat
        query = Category.get(Category.name == cat).articles

    return object_list('lists.html', query, paginate_by=app.config.get('PER_PAGE', 10), title=title)
Пример #45
0
def superform():
    if request.method == 'POST':
        name = request.form['name']

        User.create(name=name)

    # Fetch all users
    users = User.select()

    try:
        return object_list('superform.html',
                query=users,
                context_variable='users')

    except NotFound:
        # Prevent 404 and show nicer message
        return render_template('superform.html')
Пример #46
0
def archive():
    query = Entry.archive().order_by(Entry.timestamp.desc())
    return object_list("index.html", query, archive=archive, check_bounds=False)
Пример #47
0
def drafts():
    query = Entry.select().where(Entry.published == False).order_by(Entry.timestamp.desc())

    return object_list('todo.html', query, check_bounds=False)
Пример #48
0
def drafts():
    query = Entry.drafts().order_by(Entry.timestamp.desc())
    return object_list('index.jinja2', query, check_bounds=False)
Пример #49
0
def index():
    posts = (Post.select())
    return object_list('posts.html', query=posts,
                        context_variable='post_list',
                        paginate_by=2)
Пример #50
0
def drafts():
    """Display unpublished Draft Entries"""
    query = Entry.drafts().order_by(Entry.last_mod_date.desc())
    return object_list('index.html', query)
Пример #51
0
def admin():
    qurey = Article.select()
    if qurey.count() == 0:
        flash('There is no any article at all, create one please')
        return redirect(url_for('create'))
    return object_list('admin.html', qurey, paginate_by=10)
Пример #52
0
def drafts():
    query = Post.drafts().order_by(Post.timestamp.desc())
    return object_list('pc/index.html', query, check_bounds=False)
Пример #53
0
def history_list():
    return object_list('history_list.html',
                       query=current_user.history,
                       context_variable='object_list',
                       check_bounds=False,
                       paginate_by=10)
Пример #54
0
def thistag(tag):
    search_query = request.args.get("q")
    query = Entry.public().select().join(EntryTags).join(Tag).where((Tag.tag == tag)).order_by(Entry.timestamp.desc())
    return object_list("index.html", query, tag=tag, search=search_query, check_bounds=False)
Пример #55
0
def drafts():
	query = Entry.drafts().order_by(Entry.timestamp.desc())
	return object_list('index.html', query)
Пример #56
0
def category():
    query = Category.select()
    return object_list('category.html', query, paginate_by=app.config.get('PER_PAGE', 10), entry=None)