Ejemplo n.º 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)
Ejemplo n.º 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])
Ejemplo n.º 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)
Ejemplo n.º 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])
Ejemplo n.º 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)
Ejemplo n.º 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])
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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]}
Ejemplo n.º 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}
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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}
Ejemplo n.º 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]
    }
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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]}
Ejemplo n.º 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]
    }
Ejemplo n.º 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])
Ejemplo n.º 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]}
Ejemplo n.º 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)
Ejemplo n.º 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]
    }
Ejemplo n.º 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)
Ejemplo n.º 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])
Ejemplo n.º 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)
Ejemplo n.º 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])
Ejemplo n.º 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)
Ejemplo n.º 33
0
 def comments(self):
     page = get_page()
     return Comment.objects(paste=self).order_by('-created_at').paginate(
         page=page, per_page=20)
Ejemplo n.º 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)
Ejemplo n.º 35
0
 def comments(self):
     page = get_page()
     return Comment.objects(paste=self).order_by('-created_at').paginate(page=page, per_page=20)