|
8 | 8 | PermissionDenied, |
9 | 9 | ValidationError, |
10 | 10 | ) |
| 11 | +from django.http import JsonResponse |
11 | 12 | from django.template.response import HttpResponse |
12 | 13 |
|
13 | 14 | from adminapi.filters import BaseFilter, FilterValueError |
14 | 15 | from serveradmin.api import ApiError, AVAILABLE_API_FUNCTIONS |
15 | 16 | from serveradmin.api.decorators import api_view |
| 17 | +from serveradmin.serverdb.models import Attribute |
16 | 18 | from serveradmin.serverdb.query_committer import commit_query |
17 | 19 | from serveradmin.serverdb.query_executer import execute_query |
18 | 20 | from serveradmin.serverdb.query_materializer import ( |
@@ -66,6 +68,48 @@ def dataset_query(request, app, data): |
66 | 68 | } |
67 | 69 |
|
68 | 70 |
|
| 71 | +@api_view |
| 72 | +def dataset_attributes(request, app, data): |
| 73 | + """Return all available attributes |
| 74 | +
|
| 75 | + This includes the special attributes (e.g. hostname, servertype) that |
| 76 | + are not stored in the attribute table but are queryable like any other |
| 77 | + attribute. |
| 78 | + """ |
| 79 | + attributes = list(Attribute.objects.all()) |
| 80 | + attributes.extend(Attribute.specials.values()) |
| 81 | + |
| 82 | + result = [] |
| 83 | + for attribute in attributes: |
| 84 | + result.append({ |
| 85 | + 'attribute_id': attribute.attribute_id, |
| 86 | + 'type': attribute.type, |
| 87 | + 'multi': attribute.multi, |
| 88 | + 'hovertext': attribute.hovertext, |
| 89 | + 'group': attribute.group, |
| 90 | + 'help_link': attribute.help_link, |
| 91 | + 'inet_address_family': attribute.inet_address_family, |
| 92 | + 'readonly': attribute.readonly, |
| 93 | + 'clone': attribute.clone, |
| 94 | + 'history': attribute.history, |
| 95 | + 'regexp': attribute.regexp, |
| 96 | + 'reversed_attribute': attribute.reversed_attribute_id, |
| 97 | + # Special attributes are not saved to the database, so accessing |
| 98 | + # their many-to-many target_servertype is not possible. |
| 99 | + 'target_servertypes': ( |
| 100 | + [] if attribute.special else |
| 101 | + list(attribute.target_servertype.values_list( |
| 102 | + 'servertype_id', flat=True |
| 103 | + )) |
| 104 | + ), |
| 105 | + }) |
| 106 | + |
| 107 | + return { |
| 108 | + 'status': 'success', |
| 109 | + 'result': result, |
| 110 | + } |
| 111 | + |
| 112 | + |
69 | 113 | @api_view |
70 | 114 | def dataset_new_object(request, app, data): |
71 | 115 | try: |
|
0 commit comments