mirror of https://gitlab.com/tildes/tildes.git
ajbt200128
5 years ago
committed by
Deimos
8 changed files with 103 additions and 4 deletions
-
18tildes/tildes/models/comment/comment_query.py
-
18tildes/tildes/models/topic/topic_query.py
-
1tildes/tildes/request_methods.py
-
1tildes/tildes/routes.py
-
2tildes/tildes/templates/bookmarks.jinja2
-
5tildes/tildes/templates/macros/user_menu.jinja2
-
13tildes/tildes/templates/votes.jinja2
-
49tildes/tildes/views/votes.py
@ -0,0 +1,13 @@ |
|||||
|
{% extends 'bookmarks.jinja2' %} |
||||
|
|
||||
|
{% block title %}Votes{% endblock %} |
||||
|
|
||||
|
{% block main_heading %}Votes{% endblock %} |
||||
|
|
||||
|
{% block empty_message %} |
||||
|
{% if post_type == 'topic' %} |
||||
|
You haven't voted on any topics |
||||
|
{% elif post_type == 'comment' %} |
||||
|
You haven't voted on any comments |
||||
|
{% endif %} |
||||
|
{% endblock %} |
@ -0,0 +1,49 @@ |
|||||
|
"""Views relating to voted posts.""" |
||||
|
|
||||
|
from typing import Type, Union |
||||
|
|
||||
|
from pyramid.request import Request |
||||
|
from pyramid.view import view_config |
||||
|
from sqlalchemy.sql import desc |
||||
|
from webargs.pyramidparser import use_kwargs |
||||
|
|
||||
|
from tildes.models.comment import Comment, CommentVote |
||||
|
from tildes.models.topic import Topic, TopicVote |
||||
|
from tildes.schemas.fields import PostType |
||||
|
from tildes.schemas.listing import PaginatedListingSchema |
||||
|
|
||||
|
|
||||
|
@view_config(route_name="votes", renderer="votes.jinja2") |
||||
|
@use_kwargs(PaginatedListingSchema) |
||||
|
@use_kwargs({"post_type": PostType(load_from="type", missing="topic")}) |
||||
|
def get_voted_posts( |
||||
|
request: Request, after: str, before: str, per_page: int, post_type: str |
||||
|
) -> dict: |
||||
|
"""Generate the voted posts page.""" |
||||
|
# pylint: disable=unused-argument |
||||
|
user = request.user |
||||
|
|
||||
|
vote_cls: Union[Type[CommentVote], Type[TopicVote]] |
||||
|
|
||||
|
if post_type == "comment": |
||||
|
post_cls = Comment |
||||
|
vote_cls = CommentVote |
||||
|
elif post_type == "topic": |
||||
|
post_cls = Topic |
||||
|
vote_cls = TopicVote |
||||
|
|
||||
|
query = ( |
||||
|
request.query(post_cls).only_user_voted().order_by(desc(vote_cls.created_time)) |
||||
|
) |
||||
|
|
||||
|
if before: |
||||
|
query = query.before_id36(before) |
||||
|
|
||||
|
if after: |
||||
|
query = query.after_id36(after) |
||||
|
|
||||
|
query = query.join_all_relationships() |
||||
|
|
||||
|
posts = query.all() |
||||
|
|
||||
|
return {"user": user, "posts": posts, "post_type": post_type} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue