Use Cornice when registering all "service" API views
pretty sure we'll get *something* for "free" if we do it their way
This commit is contained in:
parent
c55830e533
commit
0e46b25f6e
|
@ -28,6 +28,8 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
from rattail.db.auth import authenticate_user, set_user_password, cache_permissions
|
||||
|
||||
from cornice import Service
|
||||
|
||||
from tailbone.api import APIView, api
|
||||
from tailbone.db import Session
|
||||
from tailbone.auth import login_user, logout_user
|
||||
|
@ -172,28 +174,34 @@ class AuthenticationView(APIView):
|
|||
def _auth_defaults(cls, config):
|
||||
|
||||
# session
|
||||
config.add_route('api.session', '/session', request_method='GET')
|
||||
config.add_view(cls, attr='check_session', route_name='api.session', renderer='json')
|
||||
check_session = Service(name='check_session', path='/session')
|
||||
check_session.add_view('GET', 'check_session', klass=cls)
|
||||
config.add_cornice_service(check_session)
|
||||
|
||||
# login
|
||||
config.add_route('api.login', '/login', request_method=('OPTIONS', 'POST'))
|
||||
config.add_view(cls, attr='login', route_name='api.login', renderer='json')
|
||||
login = Service(name='login', path='/login')
|
||||
login.add_view('POST', 'login', klass=cls)
|
||||
config.add_cornice_service(login)
|
||||
|
||||
# logout
|
||||
config.add_route('api.logout', '/logout', request_method=('OPTIONS', 'POST'))
|
||||
config.add_view(cls, attr='logout', route_name='api.logout', renderer='json')
|
||||
logout = Service(name='logout', path='/logout')
|
||||
logout.add_view('POST', 'logout', klass=cls)
|
||||
config.add_cornice_service(logout)
|
||||
|
||||
# become root
|
||||
config.add_route('api.become_root', '/become-root', request_method=('OPTIONS', 'POST'))
|
||||
config.add_view(cls, attr='become_root', route_name='api.become_root', renderer='json')
|
||||
become_root = Service(name='become_root', path='/become-root')
|
||||
become_root.add_view('POST', 'become_root', klass=cls)
|
||||
config.add_cornice_service(become_root)
|
||||
|
||||
# stop root
|
||||
config.add_route('api.stop_root', '/stop-root', request_method=('OPTIONS', 'POST'))
|
||||
config.add_view(cls, attr='stop_root', route_name='api.stop_root', renderer='json')
|
||||
stop_root = Service(name='stop_root', path='/stop-root')
|
||||
stop_root.add_view('POST', 'stop_root', klass=cls)
|
||||
config.add_cornice_service(stop_root)
|
||||
|
||||
# change password
|
||||
config.add_route('api.change_password', '/change-password', request_method=('OPTIONS', 'POST'))
|
||||
config.add_view(cls, attr='change_password', route_name='api.change_password', renderer='json')
|
||||
change_password = Service(name='change_password', path='/change-password')
|
||||
change_password.add_view('POST', 'change_password', klass=cls)
|
||||
config.add_cornice_service(change_password)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -31,6 +31,8 @@ from rattail.db import model
|
|||
from rattail.mail import send_email
|
||||
from rattail.util import OrderedDict
|
||||
|
||||
from cornice import Service
|
||||
|
||||
import tailbone
|
||||
from tailbone import forms
|
||||
from tailbone.forms.common import Feedback
|
||||
|
@ -111,12 +113,14 @@ class CommonView(APIView):
|
|||
def defaults(cls, config):
|
||||
|
||||
# about
|
||||
config.add_route('api.about', '/about', request_method='GET')
|
||||
config.add_view(cls, attr='about', route_name='api.about', renderer='json')
|
||||
about = Service(name='about', path='/about')
|
||||
about.add_view('GET', 'about', klass=cls)
|
||||
config.add_cornice_service(about)
|
||||
|
||||
# feedback
|
||||
config.add_route('api.feedback', '/feedback', request_method=('OPTIONS', 'POST'))
|
||||
config.add_view(cls, attr='feedback', route_name='api.feedback', renderer='json')
|
||||
feedback = Service(name='feedback', path='/feedback')
|
||||
feedback.add_view('POST', 'feedback', klass=cls)
|
||||
config.add_cornice_service(feedback)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
|
|
Loading…
Reference in a new issue