Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions serveradmin/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
dataset_query,
dataset_commit,
dataset_new_object,
dataset_attributes,
api_call,
)

Expand All @@ -18,5 +19,6 @@
path('dataset/query', dataset_query),
path('dataset/commit', dataset_commit),
path('dataset/new_object', dataset_new_object),
path('dataset/attributes', dataset_attributes),
path('call', api_call),
]
44 changes: 44 additions & 0 deletions serveradmin/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
PermissionDenied,
ValidationError,
)
from django.http import JsonResponse
from django.template.response import HttpResponse

from adminapi.filters import BaseFilter, FilterValueError
from serveradmin.api import ApiError, AVAILABLE_API_FUNCTIONS
from serveradmin.api.decorators import api_view
from serveradmin.serverdb.models import Attribute
from serveradmin.serverdb.query_committer import commit_query
from serveradmin.serverdb.query_executer import execute_query
from serveradmin.serverdb.query_materializer import (
Expand Down Expand Up @@ -66,6 +68,48 @@ def dataset_query(request, app, data):
}


@api_view
def dataset_attributes(request, app, data):
"""Return all available attributes

This includes the special attributes (e.g. hostname, servertype) that
are not stored in the attribute table but are queryable like any other
attribute.
"""
attributes = list(Attribute.objects.all())
attributes.extend(Attribute.specials.values())

result = []
for attribute in attributes:
result.append({
'attribute_id': attribute.attribute_id,
'type': attribute.type,
'multi': attribute.multi,
'hovertext': attribute.hovertext,
'group': attribute.group,
'help_link': attribute.help_link,
'inet_address_family': attribute.inet_address_family,
'readonly': attribute.readonly,
'clone': attribute.clone,
'history': attribute.history,
'regexp': attribute.regexp,
'reversed_attribute': attribute.reversed_attribute_id,
# Special attributes are not saved to the database, so accessing
# their many-to-many target_servertype is not possible.
'target_servertypes': (
[] if attribute.special else
list(attribute.target_servertype.values_list(
'servertype_id', flat=True
))
),
})

return {
'status': 'success',
'result': result,
}


@api_view
def dataset_new_object(request, app, data):
try:
Expand Down
Loading