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 rattail.db.auth import authenticate_user, set_user_password, cache_permissions
|
||||||
|
|
||||||
|
from cornice import Service
|
||||||
|
|
||||||
from tailbone.api import APIView, api
|
from tailbone.api import APIView, api
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.auth import login_user, logout_user
|
from tailbone.auth import login_user, logout_user
|
||||||
|
@ -172,28 +174,34 @@ class AuthenticationView(APIView):
|
||||||
def _auth_defaults(cls, config):
|
def _auth_defaults(cls, config):
|
||||||
|
|
||||||
# session
|
# session
|
||||||
config.add_route('api.session', '/session', request_method='GET')
|
check_session = Service(name='check_session', path='/session')
|
||||||
config.add_view(cls, attr='check_session', route_name='api.session', renderer='json')
|
check_session.add_view('GET', 'check_session', klass=cls)
|
||||||
|
config.add_cornice_service(check_session)
|
||||||
|
|
||||||
# login
|
# login
|
||||||
config.add_route('api.login', '/login', request_method=('OPTIONS', 'POST'))
|
login = Service(name='login', path='/login')
|
||||||
config.add_view(cls, attr='login', route_name='api.login', renderer='json')
|
login.add_view('POST', 'login', klass=cls)
|
||||||
|
config.add_cornice_service(login)
|
||||||
|
|
||||||
# logout
|
# logout
|
||||||
config.add_route('api.logout', '/logout', request_method=('OPTIONS', 'POST'))
|
logout = Service(name='logout', path='/logout')
|
||||||
config.add_view(cls, attr='logout', route_name='api.logout', renderer='json')
|
logout.add_view('POST', 'logout', klass=cls)
|
||||||
|
config.add_cornice_service(logout)
|
||||||
|
|
||||||
# become root
|
# become root
|
||||||
config.add_route('api.become_root', '/become-root', request_method=('OPTIONS', 'POST'))
|
become_root = Service(name='become_root', path='/become-root')
|
||||||
config.add_view(cls, attr='become_root', route_name='api.become_root', renderer='json')
|
become_root.add_view('POST', 'become_root', klass=cls)
|
||||||
|
config.add_cornice_service(become_root)
|
||||||
|
|
||||||
# stop root
|
# stop root
|
||||||
config.add_route('api.stop_root', '/stop-root', request_method=('OPTIONS', 'POST'))
|
stop_root = Service(name='stop_root', path='/stop-root')
|
||||||
config.add_view(cls, attr='stop_root', route_name='api.stop_root', renderer='json')
|
stop_root.add_view('POST', 'stop_root', klass=cls)
|
||||||
|
config.add_cornice_service(stop_root)
|
||||||
|
|
||||||
# change password
|
# change password
|
||||||
config.add_route('api.change_password', '/change-password', request_method=('OPTIONS', 'POST'))
|
change_password = Service(name='change_password', path='/change-password')
|
||||||
config.add_view(cls, attr='change_password', route_name='api.change_password', renderer='json')
|
change_password.add_view('POST', 'change_password', klass=cls)
|
||||||
|
config.add_cornice_service(change_password)
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2019 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -31,6 +31,8 @@ from rattail.db import model
|
||||||
from rattail.mail import send_email
|
from rattail.mail import send_email
|
||||||
from rattail.util import OrderedDict
|
from rattail.util import OrderedDict
|
||||||
|
|
||||||
|
from cornice import Service
|
||||||
|
|
||||||
import tailbone
|
import tailbone
|
||||||
from tailbone import forms
|
from tailbone import forms
|
||||||
from tailbone.forms.common import Feedback
|
from tailbone.forms.common import Feedback
|
||||||
|
@ -111,12 +113,14 @@ class CommonView(APIView):
|
||||||
def defaults(cls, config):
|
def defaults(cls, config):
|
||||||
|
|
||||||
# about
|
# about
|
||||||
config.add_route('api.about', '/about', request_method='GET')
|
about = Service(name='about', path='/about')
|
||||||
config.add_view(cls, attr='about', route_name='api.about', renderer='json')
|
about.add_view('GET', 'about', klass=cls)
|
||||||
|
config.add_cornice_service(about)
|
||||||
|
|
||||||
# feedback
|
# feedback
|
||||||
config.add_route('api.feedback', '/feedback', request_method=('OPTIONS', 'POST'))
|
feedback = Service(name='feedback', path='/feedback')
|
||||||
config.add_view(cls, attr='feedback', route_name='api.feedback', renderer='json')
|
feedback.add_view('POST', 'feedback', klass=cls)
|
||||||
|
config.add_cornice_service(feedback)
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
|
|
Loading…
Reference in a new issue