Add basic API view for "about" page

i.e. this returns app version and some package versions
This commit is contained in:
Lance Edgar 2019-08-29 19:06:51 -05:00
parent 19c734683b
commit 47efc88228
2 changed files with 39 additions and 1 deletions

View file

@ -31,6 +31,7 @@ from .master import APIMasterView, SortColumn
def includeme(config):
config.include('tailbone.api.common')
config.include('tailbone.api.auth')
config.include('tailbone.api.customers')
config.include('tailbone.api.upgrades')

View file

@ -26,9 +26,12 @@ Tailbone Web API - "Common" Views
from __future__ import unicode_literals, absolute_import
import rattail
from rattail.db import model
from rattail.mail import send_email
from rattail.util import OrderedDict
import tailbone
from tailbone import forms
from tailbone.forms.common import Feedback
from tailbone.api import APIView, api
@ -36,6 +39,37 @@ from tailbone.db import Session
class CommonView(APIView):
"""
Misc. "common" views for the API.
"""
@api
def about(self):
"""
Generic view to show "about project" info page.
"""
return {
'project_title': self.get_project_title(),
'project_version': self.get_project_version(),
'packages': self.get_packages(),
}
def get_project_title(self):
return self.rattail_config.app_title(default="Tailbone")
def get_project_version(self):
import tailbone
return tailbone.__version__
def get_packages(self):
"""
Should return the full set of packages which should be displayed on the
'about' page.
"""
return OrderedDict([
('rattail', rattail.__version__),
('Tailbone', tailbone.__version__),
])
@api
def feedback(self):
@ -65,10 +99,13 @@ class CommonView(APIView):
return {'error': "Form did not validate!"}
@classmethod
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')
# feedback
config.add_route('api.feedback', '/feedback', request_method=('OPTIONS', 'POST'))
config.add_view(cls, attr='feedback', route_name='api.feedback', renderer='json')