From 73b73c2591e1772ab746fc0413f9bdf8a4852921 Mon Sep 17 00:00:00 2001 From: James Southern Date: Tue, 7 Aug 2018 18:27:49 +0100 Subject: [PATCH] Prepend REST verbs to all view methods Example: `def vote_comment` becomes `def put_vote_comment` --- tildes/pylama.ini | 5 +++++ tildes/tildes/views/api/web/comment.py | 8 ++++---- tildes/tildes/views/api/web/group.py | 4 ++-- tildes/tildes/views/api/web/topic.py | 14 +++++++------- tildes/tildes/views/api/web/user.py | 10 +++++----- tildes/tildes/views/group.py | 2 +- tildes/tildes/views/metrics.py | 2 +- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tildes/pylama.ini b/tildes/pylama.ini index 6ffcd2b..9eab6c4 100644 --- a/tildes/pylama.ini +++ b/tildes/pylama.ini @@ -40,6 +40,11 @@ ignored-classes = APIv0, venusian.AttachInfo # - R0201 - method could be a function (for @pre_load-type methods) ignore = R0201 +[pylama:tildes/views/api/web/*] +# ignored checks for web API specifically: +# - C0103 - invalid function names (endpoints can have very long ones) +ignore = C0103 + [pylama:tests/*] # ignored checks for tests specifically: # - D100 - missing module-level docstrings diff --git a/tildes/tildes/views/api/web/comment.py b/tildes/tildes/views/api/web/comment.py index b7d6b54..d0758b6 100644 --- a/tildes/tildes/views/api/web/comment.py +++ b/tildes/tildes/views/api/web/comment.py @@ -196,7 +196,7 @@ def delete_comment(request: Request) -> dict: permission='vote', renderer='comment_contents.jinja2', ) -def vote_comment(request: Request) -> dict: +def put_vote_comment(request: Request) -> dict: """Vote on a comment with Intercooler.""" comment = request.context @@ -231,7 +231,7 @@ def vote_comment(request: Request) -> dict: permission='vote', renderer='comment_contents.jinja2', ) -def unvote_comment(request: Request) -> dict: +def delete_vote_comment(request: Request) -> dict: """Remove the user's vote from a comment with Intercooler.""" comment = request.context @@ -261,7 +261,7 @@ def unvote_comment(request: Request) -> dict: renderer='comment_contents.jinja2', ) @use_kwargs(CommentTagSchema(only=('name',)), locations=('matchdict',)) -def tag_comment(request: Request, name: CommentTagOption) -> Response: +def put_tag_comment(request: Request, name: CommentTagOption) -> Response: """Add a tag to a comment.""" comment = request.context @@ -296,7 +296,7 @@ def tag_comment(request: Request, name: CommentTagOption) -> Response: renderer='comment_contents.jinja2', ) @use_kwargs(CommentTagSchema(only=('name',)), locations=('matchdict',)) -def untag_comment(request: Request, name: CommentTagOption) -> Response: +def delete_tag_comment(request: Request, name: CommentTagOption) -> Response: """Remove a tag (that the user previously added) from a comment.""" comment = request.context diff --git a/tildes/tildes/views/api/web/group.py b/tildes/tildes/views/api/web/group.py index ab53c75..8526cbe 100644 --- a/tildes/tildes/views/api/web/group.py +++ b/tildes/tildes/views/api/web/group.py @@ -22,7 +22,7 @@ from tildes.views.decorators import ic_view_config permission='subscribe', renderer='group_subscription_box.jinja2', ) -def subscribe_group(request: Request) -> dict: +def put_subscribe_group(request: Request) -> dict: """Subscribe to a group with Intercooler.""" group = request.context @@ -57,7 +57,7 @@ def subscribe_group(request: Request) -> dict: permission='subscribe', renderer='group_subscription_box.jinja2', ) -def unsubscribe_group(request: Request) -> dict: +def delete_subscribe_group(request: Request) -> dict: """Remove the user's subscription from a group with Intercooler.""" group = request.context diff --git a/tildes/tildes/views/api/web/topic.py b/tildes/tildes/views/api/web/topic.py index 6e33b66..1fc0435 100644 --- a/tildes/tildes/views/api/web/topic.py +++ b/tildes/tildes/views/api/web/topic.py @@ -80,7 +80,7 @@ def delete_topic(request: Request) -> Response: renderer='topic_voting.jinja2', permission='vote', ) -def vote_topic(request: Request) -> Response: +def put_topic_vote(request: Request) -> Response: """Vote on a topic with Intercooler.""" topic = request.context @@ -115,7 +115,7 @@ def vote_topic(request: Request) -> Response: renderer='topic_voting.jinja2', permission='vote', ) -def unvote_topic(request: Request) -> Response: +def delete_topic_vote(request: Request) -> Response: """Remove the user's vote from a topic with Intercooler.""" topic = request.context @@ -156,7 +156,7 @@ def get_topic_tags(request: Request) -> dict: permission='tag', ) @use_kwargs({'tags': String()}) -def tag_topic(request: Request, tags: str) -> dict: +def put_tag_topic(request: Request, tags: str) -> dict: """Apply tags to a topic with Intercooler.""" topic = request.context @@ -207,7 +207,7 @@ def get_topic_group(request: Request) -> dict: permission='move', ) @use_kwargs(GroupSchema(only=('path',))) -def move_topic(request: Request, path: str) -> dict: +def patch_move_topic(request: Request, path: str) -> dict: """Move a topic to a different group with Intercooler.""" topic = request.context @@ -243,7 +243,7 @@ def move_topic(request: Request, path: str) -> dict: request_method='PUT', permission='lock', ) -def lock_topic(request: Request) -> Response: +def put_topic_lock(request: Request) -> Response: """Lock a topic with Intercooler.""" topic = request.context @@ -258,7 +258,7 @@ def lock_topic(request: Request) -> Response: request_method='DELETE', permission='lock', ) -def unlock_topic(request: Request) -> Response: +def delete_topic_lock(request: Request) -> Response: """Unlock a topic with Intercooler.""" topic = request.context @@ -286,7 +286,7 @@ def get_topic_title(request: Request) -> dict: permission='edit_title', ) @use_kwargs(TopicSchema(only=('title',))) -def edit_topic_title(request: Request, title: str) -> dict: +def patch_topic_title(request: Request, title: str) -> dict: """Edit a topic's title with Intercooler.""" topic = request.context diff --git a/tildes/tildes/views/api/web/user.py b/tildes/tildes/views/api/web/user.py index 30c2326..faf986e 100644 --- a/tildes/tildes/views/api/web/user.py +++ b/tildes/tildes/views/api/web/user.py @@ -34,7 +34,7 @@ PASSWORD_FIELD = UserSchema(only=('password',)).fields['password'] 'new_password': PASSWORD_FIELD, 'new_password_confirm': PASSWORD_FIELD, }) -def change_password( +def patch_change_password( request: Request, old_password: str, new_password: str, @@ -62,7 +62,7 @@ def change_password( permission='change_email_address', ) @use_kwargs(UserSchema(only=('email_address', 'email_address_note'))) -def change_email_address( +def patch_change_email_address( request: Request, email_address: str, email_address_note: str @@ -94,7 +94,7 @@ def change_email_address( request_param='ic-trigger-name=auto-mark-notifications-read', permission='change_auto_mark_notifications_read_setting', ) -def change_auto_mark_notifications(request: Request) -> Response: +def patch_change_auto_mark_notifications(request: Request) -> Response: """Change the user's "automatically mark notifications read" setting.""" user = request.context @@ -110,7 +110,7 @@ def change_auto_mark_notifications(request: Request) -> Response: request_param='ic-trigger-name=open-links-new-tab', permission='change_open_links_new_tab_setting', ) -def change_open_links_new_tab(request: Request) -> Response: +def patch_change_open_links_new_tab(request: Request) -> Response: """Change the user's "open links in new tabs" setting.""" user = request.context @@ -130,7 +130,7 @@ def change_open_links_new_tab(request: Request) -> Response: request_param='ic-trigger-name=comment-visits', permission='change_comment_visits_setting', ) -def change_track_comment_visits(request: Request) -> Response: +def patch_change_track_comment_visits(request: Request) -> Response: """Change the user's "track comment visits" setting.""" user = request.context diff --git a/tildes/tildes/views/group.py b/tildes/tildes/views/group.py index a0ff40a..f4951b9 100644 --- a/tildes/tildes/views/group.py +++ b/tildes/tildes/views/group.py @@ -7,7 +7,7 @@ from tildes.models.group import Group @view_config(route_name='groups', renderer='groups.jinja2') -def list_groups(request: Request) -> dict: +def get_list_groups(request: Request) -> dict: """Show a list of all groups.""" groups = request.query(Group).order_by(Group.path).all() diff --git a/tildes/tildes/views/metrics.py b/tildes/tildes/views/metrics.py index 3d20d1c..bb99253 100644 --- a/tildes/tildes/views/metrics.py +++ b/tildes/tildes/views/metrics.py @@ -11,7 +11,7 @@ from pyramid.view import view_config renderer='string', permission=NO_PERMISSION_REQUIRED, ) -def metrics(request: Request) -> str: +def get_metrics(request: Request) -> str: """Merge together the metrics from all workers and output them.""" registry = CollectorRegistry() multiprocess.MultiProcessCollector(registry)