Browse Source

Prepend REST verbs to all view methods

Example: `def vote_comment` becomes `def put_vote_comment`
merge-requests/26/head
James Southern 6 years ago
committed by Deimos
parent
commit
73b73c2591
  1. 5
      tildes/pylama.ini
  2. 8
      tildes/tildes/views/api/web/comment.py
  3. 4
      tildes/tildes/views/api/web/group.py
  4. 14
      tildes/tildes/views/api/web/topic.py
  5. 10
      tildes/tildes/views/api/web/user.py
  6. 2
      tildes/tildes/views/group.py
  7. 2
      tildes/tildes/views/metrics.py

5
tildes/pylama.ini

@ -40,6 +40,11 @@ ignored-classes = APIv0, venusian.AttachInfo
# - R0201 - method could be a function (for @pre_load-type methods) # - R0201 - method could be a function (for @pre_load-type methods)
ignore = R0201 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/*] [pylama:tests/*]
# ignored checks for tests specifically: # ignored checks for tests specifically:
# - D100 - missing module-level docstrings # - D100 - missing module-level docstrings

8
tildes/tildes/views/api/web/comment.py

@ -196,7 +196,7 @@ def delete_comment(request: Request) -> dict:
permission='vote', permission='vote',
renderer='comment_contents.jinja2', renderer='comment_contents.jinja2',
) )
def vote_comment(request: Request) -> dict:
def put_vote_comment(request: Request) -> dict:
"""Vote on a comment with Intercooler.""" """Vote on a comment with Intercooler."""
comment = request.context comment = request.context
@ -231,7 +231,7 @@ def vote_comment(request: Request) -> dict:
permission='vote', permission='vote',
renderer='comment_contents.jinja2', 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.""" """Remove the user's vote from a comment with Intercooler."""
comment = request.context comment = request.context
@ -261,7 +261,7 @@ def unvote_comment(request: Request) -> dict:
renderer='comment_contents.jinja2', renderer='comment_contents.jinja2',
) )
@use_kwargs(CommentTagSchema(only=('name',)), locations=('matchdict',)) @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.""" """Add a tag to a comment."""
comment = request.context comment = request.context
@ -296,7 +296,7 @@ def tag_comment(request: Request, name: CommentTagOption) -> Response:
renderer='comment_contents.jinja2', renderer='comment_contents.jinja2',
) )
@use_kwargs(CommentTagSchema(only=('name',)), locations=('matchdict',)) @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.""" """Remove a tag (that the user previously added) from a comment."""
comment = request.context comment = request.context

4
tildes/tildes/views/api/web/group.py

@ -22,7 +22,7 @@ from tildes.views.decorators import ic_view_config
permission='subscribe', permission='subscribe',
renderer='group_subscription_box.jinja2', renderer='group_subscription_box.jinja2',
) )
def subscribe_group(request: Request) -> dict:
def put_subscribe_group(request: Request) -> dict:
"""Subscribe to a group with Intercooler.""" """Subscribe to a group with Intercooler."""
group = request.context group = request.context
@ -57,7 +57,7 @@ def subscribe_group(request: Request) -> dict:
permission='subscribe', permission='subscribe',
renderer='group_subscription_box.jinja2', 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.""" """Remove the user's subscription from a group with Intercooler."""
group = request.context group = request.context

14
tildes/tildes/views/api/web/topic.py

@ -80,7 +80,7 @@ def delete_topic(request: Request) -> Response:
renderer='topic_voting.jinja2', renderer='topic_voting.jinja2',
permission='vote', permission='vote',
) )
def vote_topic(request: Request) -> Response:
def put_topic_vote(request: Request) -> Response:
"""Vote on a topic with Intercooler.""" """Vote on a topic with Intercooler."""
topic = request.context topic = request.context
@ -115,7 +115,7 @@ def vote_topic(request: Request) -> Response:
renderer='topic_voting.jinja2', renderer='topic_voting.jinja2',
permission='vote', 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.""" """Remove the user's vote from a topic with Intercooler."""
topic = request.context topic = request.context
@ -156,7 +156,7 @@ def get_topic_tags(request: Request) -> dict:
permission='tag', permission='tag',
) )
@use_kwargs({'tags': String()}) @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.""" """Apply tags to a topic with Intercooler."""
topic = request.context topic = request.context
@ -207,7 +207,7 @@ def get_topic_group(request: Request) -> dict:
permission='move', permission='move',
) )
@use_kwargs(GroupSchema(only=('path',))) @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.""" """Move a topic to a different group with Intercooler."""
topic = request.context topic = request.context
@ -243,7 +243,7 @@ def move_topic(request: Request, path: str) -> dict:
request_method='PUT', request_method='PUT',
permission='lock', permission='lock',
) )
def lock_topic(request: Request) -> Response:
def put_topic_lock(request: Request) -> Response:
"""Lock a topic with Intercooler.""" """Lock a topic with Intercooler."""
topic = request.context topic = request.context
@ -258,7 +258,7 @@ def lock_topic(request: Request) -> Response:
request_method='DELETE', request_method='DELETE',
permission='lock', permission='lock',
) )
def unlock_topic(request: Request) -> Response:
def delete_topic_lock(request: Request) -> Response:
"""Unlock a topic with Intercooler.""" """Unlock a topic with Intercooler."""
topic = request.context topic = request.context
@ -286,7 +286,7 @@ def get_topic_title(request: Request) -> dict:
permission='edit_title', permission='edit_title',
) )
@use_kwargs(TopicSchema(only=('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.""" """Edit a topic's title with Intercooler."""
topic = request.context topic = request.context

10
tildes/tildes/views/api/web/user.py

@ -34,7 +34,7 @@ PASSWORD_FIELD = UserSchema(only=('password',)).fields['password']
'new_password': PASSWORD_FIELD, 'new_password': PASSWORD_FIELD,
'new_password_confirm': PASSWORD_FIELD, 'new_password_confirm': PASSWORD_FIELD,
}) })
def change_password(
def patch_change_password(
request: Request, request: Request,
old_password: str, old_password: str,
new_password: str, new_password: str,
@ -62,7 +62,7 @@ def change_password(
permission='change_email_address', permission='change_email_address',
) )
@use_kwargs(UserSchema(only=('email_address', 'email_address_note'))) @use_kwargs(UserSchema(only=('email_address', 'email_address_note')))
def change_email_address(
def patch_change_email_address(
request: Request, request: Request,
email_address: str, email_address: str,
email_address_note: str email_address_note: str
@ -94,7 +94,7 @@ def change_email_address(
request_param='ic-trigger-name=auto-mark-notifications-read', request_param='ic-trigger-name=auto-mark-notifications-read',
permission='change_auto_mark_notifications_read_setting', 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.""" """Change the user's "automatically mark notifications read" setting."""
user = request.context user = request.context
@ -110,7 +110,7 @@ def change_auto_mark_notifications(request: Request) -> Response:
request_param='ic-trigger-name=open-links-new-tab', request_param='ic-trigger-name=open-links-new-tab',
permission='change_open_links_new_tab_setting', 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.""" """Change the user's "open links in new tabs" setting."""
user = request.context user = request.context
@ -130,7 +130,7 @@ def change_open_links_new_tab(request: Request) -> Response:
request_param='ic-trigger-name=comment-visits', request_param='ic-trigger-name=comment-visits',
permission='change_comment_visits_setting', 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.""" """Change the user's "track comment visits" setting."""
user = request.context user = request.context

2
tildes/tildes/views/group.py

@ -7,7 +7,7 @@ from tildes.models.group import Group
@view_config(route_name='groups', renderer='groups.jinja2') @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.""" """Show a list of all groups."""
groups = request.query(Group).order_by(Group.path).all() groups = request.query(Group).order_by(Group.path).all()

2
tildes/tildes/views/metrics.py

@ -11,7 +11,7 @@ from pyramid.view import view_config
renderer='string', renderer='string',
permission=NO_PERMISSION_REQUIRED, 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.""" """Merge together the metrics from all workers and output them."""
registry = CollectorRegistry() registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry) multiprocess.MultiProcessCollector(registry)

Loading…
Cancel
Save