예제 #1
0
def index():
    page = get_page()

    pagination = Bookmark.objects(is_private=False).order_by('-updated_at').paginate(page, per_page=20)

    return render_template('bookmarks/index.html',
                           pagination=pagination)
예제 #2
0
def view(username):
    page = get_page()
    user = User.objects.get_or_404(username=username)

    pastes = user.pastes.order_by('-updated_at')
    if not (current_user.is_authenticated and current_user.user == user):
        pastes = pastes(is_private=False)

    pagination = pastes.paginate(page, per_page=20)

    pastes = Paste.objects(user=user)
    syntax = {}
    for paste in pastes:
        for code in paste.codes:
            if code.syntax.name not in syntax:
                syntax[code.syntax.name] = 1
            else:
                syntax[code.syntax.name] += 1

    if len(syntax.keys()) > 3:
        most_syntax = [get_most_syntax(syntax) for i in range(3)]
    else:
        most_syntax = [Syntax.objects(name=key).first() for key in syntax]

    return render_template('users/user.html',
                           user=user,
                           pagination=pagination,
                           most_syntax=most_syntax,
                           tags=Tag.objects().order_by('-popularity')[:10])
예제 #3
0
def my_list():
    page = get_page()

    pagination = Bookmark.objects(user=current_user.user).order_by('-updated_at').paginate(page, per_page=20)

    return render_template('bookmarks/index.html',
                           pagination=pagination)
예제 #4
0
def index():
    page = get_page()
    pagination = Paste.objects(is_private=False).order_by('-updated_at').paginate(page=page, per_page=20)

    return render_template('index.html',
                           pagination=pagination,
                           tags=Tag.objects().order_by('-popularity')[:10])
예제 #5
0
def index():
    page = get_page()

    pagination = Bookmark.objects(is_private=False).order_by('-updated_at').paginate(page, per_page=20)

    return render_template('bookmarks/index.html',
                           pagination=pagination)
예제 #6
0
def index():
    page = get_page()
    pagination = Paste.objects(is_private=False).order_by('-updated_at').paginate(page=page, per_page=20)

    return render_template('index.html',
                           pagination=pagination,
                           tags=Tag.objects().order_by('-popularity')[:10])
예제 #7
0
def my_bookmark():
    page = get_page()

    pagination = Bookmark.objects(user=current_user.user).order_by('-updated_at').paginate(page, per_page=20)

    return render_template('bookmarks/index.html',
                           pagination=pagination)
예제 #8
0
def search_paste():
    page = get_page()
    q = request.args['q']
    keyword, pagination = get_pastes_from_search(q, p=page)
    return render_template('search.html',
                           query_string=q,
                           keyword=keyword,
                           pagination=pagination)
예제 #9
0
def index():
    page = get_page()
    pastes = Paste.objects(is_private=False).order_by('-updated_at')
    pastes, summary = paginate(pastes, page)

    return {'pastes': pastes,
            'page_summary': summary,
            'tags': Tag.objects().order_by('-popularity')[:10]}
예제 #10
0
def tag(tag_name):
    tag = Tag.objects.get_or_404(name=tag_name)
    page = get_page()

    pastes = tag.pastes(is_private=False).order_by('-updated_at')
    pastes, summary = paginate(pastes, page)

    return {'tag': tag, 'pastes': pastes, 'page_summary': summary}
예제 #11
0
def search_paste():
    page = get_page()
    q = request.args['q']
    keyword, pagination = get_pastes_from_search(q, p=page)
    return render_template('search.html',
                           query_string=q,
                           keyword=keyword,
                           pagination=pagination)
예제 #12
0
def messages():
    page = get_page()
    pagination = Message.objects(user=current_user.user).order_by('-created_at').paginate(page, per_page=20)
    for item in pagination.items:
        item.is_read = True
        item.save()
    return render_template('users/messages.html',
                           pagination=pagination)
예제 #13
0
def view(tag_name):
    tag = Tag.objects.get_or_404(key=tag_name)
    page = get_page()

    pastes = tag.pastes(is_private=False).order_by('-updated_at')
    pagination = pastes.paginate(page, per_page=20)

    return render_template('tags/view.html', tag=tag, pagination=pagination)
예제 #14
0
def view_followers(username):
    page = get_page()
    user = User.objects.get_or_404(username=username)

    pagination = User.objects(followings=user).paginate(page, per_page=20)

    return render_template('users/followers.html',
                           user=user,
                           pagination=pagination)
예제 #15
0
def messages():
    page = get_page()
    pagination = Message.objects(
        user=current_user.user).order_by('-created_at').paginate(page,
                                                                 per_page=20)
    for item in pagination.items:
        item.is_read = True
        item.save()
    return render_template('users/messages.html', pagination=pagination)
예제 #16
0
def view_bookmarks(username):
    page = get_page()

    user = User.objects(username=username).get_or_404()

    pagination = Bookmark.objects(user=user).order_by('-updated_at').paginate(page, per_page=20)

    return render_template('bookmarks/index.html',
                           pagination=pagination)
예제 #17
0
def view_bookmarks(username):
    page = get_page()

    user = User.objects(username=username).get_or_404()

    pagination = Bookmark.objects(user=user).order_by('-updated_at').paginate(
        page, per_page=20)

    return render_template('bookmarks/index.html', pagination=pagination)
예제 #18
0
def tag(tag_name):
    tag = Tag.objects.get_or_404(name=tag_name)
    page = get_page()

    pastes = tag.pastes(is_private=False).order_by('-updated_at')
    pastes, summary = paginate(pastes, page)

    return {'tag': tag,
            'pastes': pastes,
            'page_summary': summary}
예제 #19
0
def index():
    page = get_page()
    pastes = Paste.objects(is_private=False).order_by('-updated_at')
    pastes, summary = paginate(pastes, page)

    return {
        'pastes': pastes,
        'page_summary': summary,
        'tags': Tag.objects().order_by('-popularity')[:10]
    }
예제 #20
0
def view_likes(username):
    user = User.objects.get_or_404(username=username)

    page = get_page()
    likes = Paste.objects(id__in=[str(i.id) for i in user.likes]).order_by('-updated_at')
    pagination = likes.paginate(page, per_page=20)

    return render_template('users/likes.html',
                           user=user,
                           pagination=pagination)
예제 #21
0
def view(tag_name):
    tag = Tag.objects.get_or_404(key=tag_name)
    page = get_page()

    pastes = tag.pastes(is_private=False).order_by('-updated_at')
    pagination = pastes.paginate(page, per_page=20)

    return render_template('tags/view.html',
                           tag=tag,
                           pagination=pagination)
예제 #22
0
def likes_get(username):
    user = get_user(username)

    page = get_page()
    likes = user.likes.order_by('-updated_at')
    likes, summary = paginate(likes, page)

    return {'user': user,
            'likes': likes,
            'page_summary': summary,
            'tags': Tag.objects().order_by('-popularity')[:10]}
예제 #23
0
def likes_get(username):
    user = get_user(username)

    page = get_page()
    likes = user.likes.order_by('-updated_at')
    likes, summary = paginate(likes, page)

    return {
        'user': user,
        'likes': likes,
        'page_summary': summary,
        'tags': Tag.objects().order_by('-popularity')[:10]
    }
예제 #24
0
def view_user(username):
    page = get_page()
    user = User.objects.get_or_404(username=username)

    pastes = user.pastes.order_by('-updated_at')
    if not (current_user.is_authenticated and current_user.user == user):
        pastes = pastes(is_private=False)

    pagination = pastes.paginate(page, per_page=20)

    return render_template('users/user.html',
                           user=user,
                           pagination=pagination,
                           tags=Tag.objects().order_by('-popularity')[:10])
예제 #25
0
def user_index(username):
    page = get_page()
    user = get_user(username)

    pastes = user.pastes.order_by('-updated_at')
    if not (request.user and request.user == user):
        pastes = pastes(is_private=False)

    pastes, summary = paginate(pastes, page)

    return {'user': user,
            'pastes': pastes,
            'page_summary': summary,
            'tags': Tag.objects().order_by('-popularity')[:10]}
예제 #26
0
def view(tag_name):
    tag = Tag.objects.get_or_404(key=tag_name)
    page = get_page()

    if request.args.get('filter', None) == 'mine' and current_user.is_authenticated:
        pastes = tag.pastes(user=current_user.user).order_by('-updated_at')
    else:
        pastes = tag.pastes(is_private=False).order_by('-updated_at')
    pagination = pastes.paginate(page, per_page=20)

    return render_template('tags/view.html',
                           tag=tag,
                           hot_pastes=Paste.objects(is_private=False).order_by('-views')[:10],
                           pagination=pagination)
예제 #27
0
def user_index(username):
    page = get_page()
    user = get_user(username)

    pastes = user.pastes.order_by('-updated_at')
    if not (request.user and request.user == user):
        pastes = pastes(is_private=False)

    pastes, summary = paginate(pastes, page)

    return {
        'user': user,
        'pastes': pastes,
        'page_summary': summary,
        'tags': Tag.objects().order_by('-popularity')[:10]
    }
예제 #28
0
def view(tag_name):
    criteria = {}
    tag = Tag.objects.get_or_404(key=tag_name)
    if request.args.get('filter', None) != 'mine' or not current_user.is_authenticated:
        criteria['is_private'] = False
    syntax = Syntax.objects(key=tag_name).first()
    if syntax:
        criteria['codes__syntax'] = syntax
    else:
        criteria['tags'] = tag
    pastes = Paste.objects(**criteria).order_by('-updated_at')
    page = get_page()

    pagination = pastes.paginate(page, per_page=20)

    return render_template('tags/view.html',
                           tag=tag,
                           hot_pastes=Paste.objects(is_private=False).order_by('-views')[:10],
                           pagination=pagination)
예제 #29
0
def index():
    page = get_page()
    pagination = Paste.objects(is_private=False).order_by('-updated_at').paginate(page=page, per_page=20)

    print datetime.today()

    return render_template('index.html',
                           pagination=pagination,
                           hot_pastes=Paste.objects(is_private=False).order_by('-views')[:10],
                           pastes_count=Paste.objects().count(),
                           comments_count=Comment.objects().count(),
                           users_count=User.objects().count(),
                           syntax_count=Syntax.objects().count(),
                           bookmarks_count=Bookmark.objects().count(),
                           users_increased=User.objects(created_at__gt=date.today()).count(),
                           pastes_increased=Paste.objects(created_at__gt=date.today()).count(),
                           comments_increased=Comment.objects(created_at__gt=date.today()).count(),
                           bookmarks_increased=Bookmark.objects(created_at__gt=date.today()).count(),
                           tags=Tag.objects().order_by('-popularity')[:10])
예제 #30
0
def view(tag_name):
    criteria = {}
    tag = Tag.objects.get_or_404(key=tag_name)
    if request.args.get('filter',
                        None) != 'mine' or not current_user.is_authenticated:
        criteria['is_private'] = False
    syntax = Syntax.objects(key=tag_name).first()
    if syntax:
        criteria['codes__syntax'] = syntax
    else:
        criteria['tags'] = tag
    pastes = Paste.objects(**criteria).order_by('-updated_at')
    page = get_page()

    pagination = pastes.paginate(page, per_page=20)

    return render_template(
        'tags/view.html',
        tag=tag,
        hot_pastes=Paste.objects(is_private=False).order_by('-views')[:10],
        pagination=pagination)
예제 #31
0
def index():
    page = get_page()
    pagination = Paste.objects(
        is_private=False).order_by('-updated_at').paginate(page=page,
                                                           per_page=20)

    print datetime.today()

    return render_template(
        'index.html',
        pagination=pagination,
        hot_pastes=Paste.objects(is_private=False).order_by('-views')[:10],
        pastes_count=Paste.objects().count(),
        comments_count=Comment.objects().count(),
        users_count=User.objects().count(),
        syntax_count=Syntax.objects().count(),
        bookmarks_count=Bookmark.objects().count(),
        users_increased=User.objects(created_at__gt=date.today()).count(),
        pastes_increased=Paste.objects(created_at__gt=date.today()).count(),
        comments_increased=Comment.objects(
            created_at__gt=date.today()).count(),
        bookmarks_increased=Bookmark.objects(
            created_at__gt=date.today()).count(),
        tags=Tag.objects().order_by('-popularity')[:10])
예제 #32
0
def messages():
    page = get_page()
    pagination = Message.objects(user=current_user.user).order_by('-created_at').paginate(page, per_page=20)
    return render_template('users/messages.html',
                           pagination=pagination)
예제 #33
0
 def comments(self):
     page = get_page()
     return Comment.objects(paste=self).order_by('-created_at').paginate(
         page=page, per_page=20)
예제 #34
0
def messages():
    page = get_page()
    pagination = Message.objects(
        user=current_user.user).order_by('-created_at').paginate(page,
                                                                 per_page=20)
    return render_template('users/messages.html', pagination=pagination)
예제 #35
0
 def comments(self):
     page = get_page()
     return Comment.objects(paste=self).order_by('-created_at').paginate(page=page, per_page=20)