diff --git a/tailbone/api/__init__.py b/tailbone/api/__init__.py index 27206f70..787165fe 100644 --- a/tailbone/api/__init__.py +++ b/tailbone/api/__init__.py @@ -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') diff --git a/tailbone/api/common.py b/tailbone/api/common.py index d72f6be6..dd74fe6f 100644 --- a/tailbone/api/common.py +++ b/tailbone/api/common.py @@ -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')