def put_filtered_topic_tags(request: Request, tags: str) -> dict: """Update a user's filtered topic tags list.""" if not tags: request.user.filtered_topic_tags = [] return IC_NOOP split_tags = tags.split(',') try: schema = TopicSchema(only=('tags',)) result = schema.load({'tags': split_tags}) except ValidationError: raise ValidationError({'tags': ['Invalid tags']}) request.user.filtered_topic_tags = result.data['tags'] return IC_NOOP
def put_filtered_topic_tags(request: Request, tags: str) -> dict: """Update a user's filtered topic tags list.""" if not tags or tags.isspace(): request.user.filtered_topic_tags = [] return IC_NOOP split_tags = tags.replace("\r", "").split("\n") try: schema = TopicSchema(only=("tags",)) result = schema.load({"tags": split_tags}) except ValidationError: raise ValidationError({"tags": ["Invalid tags"]}) request.user.filtered_topic_tags = result.data["tags"] return IC_NOOP
from tildes.models.topic import Topic, TopicSchedule, TopicVisit from tildes.models.user import UserGroupSettings from tildes.schemas.comment import CommentSchema from tildes.schemas.fields import ShortTimePeriod from tildes.schemas.listing import TopicListingSchema from tildes.schemas.topic import TopicSchema from tildes.views.decorators import rate_limit_view from tildes.views.financials import get_financial_data DefaultSettings = namedtuple("DefaultSettings", ["order", "period"]) @view_config(route_name="group_topics", request_method="POST", permission="post_topic") @use_kwargs(TopicSchema(only=("title", "markdown", "link"))) @use_kwargs( { "tags": String(missing=""), "confirm_repost": Boolean(missing=False) }, locations=( "form", ), # will crash due to trying to find JSON data without this ) def post_group_topics( request: Request, title: str, markdown: str, link: str, tags: str, confirm_repost: bool,
request_method='GET', renderer='topic_contents.jinja2', permission='view', ) def get_topic_contents(request: Request) -> dict: """Get a topic's body with Intercooler.""" return {'topic': request.context} @ic_view_config( route_name='topic', request_method='PATCH', renderer='topic_contents.jinja2', permission='edit', ) @use_kwargs(TopicSchema(only=('markdown', ))) def patch_topic(request: Request, markdown: str) -> dict: """Update a topic with Intercooler.""" topic = request.context topic.markdown = markdown return {'topic': topic} @ic_view_config( route_name='topic', request_method='DELETE', permission='delete', ) def delete_topic(request: Request) -> Response:
"""Root factories for topics.""" from pyramid.httpexceptions import HTTPFound from pyramid.request import Request from webargs.pyramidparser import use_kwargs from tildes.lib.id import id36_to_id from tildes.models.topic import Topic from tildes.resources import get_resource from tildes.schemas.topic import TopicSchema @use_kwargs( TopicSchema(only=('topic_id36',)), locations=('matchdict',), ) def topic_by_id36(request: Request, topic_id36: str) -> Topic: """Get a topic specified by {topic_id36} in the route (or 404).""" query = ( request.query(Topic) .include_deleted() .include_removed() .filter_by(topic_id=id36_to_id(topic_id36)) ) topic = get_resource(request, query) # if there's also a group specified in the route, check that it's the same # group as the topic was posted in, otherwise redirect to correct group if 'group_path' in request.matchdict: path_from_route = request.matchdict['group_path'].lower()
def title_schema(): """Fixture for generating a title-only TopicSchema.""" return TopicSchema(only=("title", ))
request_method="GET", renderer="topic_contents.jinja2", permission="view", ) def get_topic_contents(request: Request) -> dict: """Get a topic's body with Intercooler.""" return {"topic": request.context} @ic_view_config( route_name="topic", request_method="PATCH", renderer="topic_contents.jinja2", permission="edit", ) @use_kwargs(TopicSchema(only=("markdown", )), location="form") def patch_topic(request: Request, markdown: str) -> dict: """Update a topic with Intercooler.""" topic = request.context topic.markdown = markdown return {"topic": topic} @ic_view_config(route_name="topic", request_method="DELETE", permission="delete") def delete_topic(request: Request) -> Response: """Delete a topic with Intercooler and redirect to its group.""" topic = request.context
# Copyright (c) 2018 Tildes contributors <*****@*****.**> # SPDX-License-Identifier: AGPL-3.0-or-later """Root factories for topics.""" from pyramid.httpexceptions import HTTPFound, HTTPNotFound from pyramid.request import Request from webargs.pyramidparser import use_kwargs from tildes.lib.id import id36_to_id from tildes.models.topic import Topic from tildes.resources import get_resource from tildes.schemas.topic import TopicSchema @use_kwargs(TopicSchema(only=("topic_id36",)), locations=("matchdict",)) def topic_by_id36(request: Request, topic_id36: str) -> Topic: """Get a topic specified by {topic_id36} in the route (or 404).""" try: topic_id = id36_to_id(topic_id36) except ValueError: raise HTTPNotFound query = ( request.query(Topic) .include_deleted() .include_removed() .filter_by(topic_id=topic_id) ) try:
from tildes.models.topic import Topic, TopicVisit from tildes.models.user import UserGroupSettings from tildes.schemas.comment import CommentSchema from tildes.schemas.fields import Enum, ShortTimePeriod from tildes.schemas.topic import TopicSchema from tildes.schemas.topic_listing import TopicListingSchema DefaultSettings = namedtuple('DefaultSettings', ['order', 'period']) @view_config( route_name='group_topics', request_method='POST', permission='post_topic', ) @use_kwargs(TopicSchema(only=('title', 'markdown', 'link'))) @use_kwargs({'tags': String()}) def post_group_topics( request: Request, title: str, markdown: str, link: str, tags: str, ) -> HTTPFound: """Post a new topic to a group.""" if link: new_topic = Topic.create_link_topic( group=request.context, author=request.user, title=title, link=link,