django-orchestra-test/orchestra/contrib/webapps/api.py

51 lines
1.7 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from rest_framework import viewsets
2015-04-05 18:02:36 +00:00
from orchestra.api import router, LogApiMixin
2015-04-05 10:46:24 +00:00
from orchestra.contrib.accounts.api import AccountApiMixin
2014-05-08 16:59:35 +00:00
from . import settings
from .models import WebApp
2015-04-23 19:46:23 +00:00
from .options import AppOption
2014-05-08 16:59:35 +00:00
from .serializers import WebAppSerializer
2015-04-23 19:46:23 +00:00
from .types import AppType
2014-05-08 16:59:35 +00:00
2015-04-05 18:02:36 +00:00
class WebAppViewSet(LogApiMixin, AccountApiMixin, viewsets.ModelViewSet):
2015-04-23 19:46:23 +00:00
queryset = WebApp.objects.prefetch_related('options').all()
2014-05-08 16:59:35 +00:00
serializer_class = WebAppSerializer
filter_fields = ('name',)
2015-04-23 14:34:04 +00:00
def options(self, request):
metadata = super(WebAppViewSet, self).options(request)
2014-05-08 16:59:35 +00:00
names = [
2015-04-16 13:15:21 +00:00
'WEBAPPS_BASE_DIR', 'WEBAPPS_TYPES', 'WEBAPPS_WEBAPP_OPTIONS',
2014-05-08 16:59:35 +00:00
'WEBAPPS_PHP_DISABLED_FUNCTIONS', 'WEBAPPS_DEFAULT_TYPE'
]
2015-04-23 14:34:04 +00:00
metadata.data['settings'] = {
2014-05-13 13:46:40 +00:00
name.lower(): getattr(settings, name, None) for name in names
}
2015-04-23 19:46:23 +00:00
# AppTypes
meta = self.metadata_class()
app_types = {}
for app_type in AppType.get_plugins():
if app_type.serializer:
data = meta.get_serializer_info(app_type.serializer())
else:
data = {}
2015-04-24 14:03:42 +00:00
data['option_groups'] = app_type.option_groups
app_types[app_type.get_name()] = data
2015-04-23 19:46:23 +00:00
metadata.data['actions']['types'] = app_types
# Options
options = {}
for option in AppOption.get_plugins():
options[option.get_name()] = {
'verbose_name': option.get_verbose_name(),
'help_text': option.help_text,
'group': option.group,
}
metadata.data['actions']['options'] = options
2015-04-23 14:34:04 +00:00
return metadata
2014-05-08 16:59:35 +00:00
router.register(r'webapps', WebAppViewSet)