|
1 |
# passerelle - uniform access to multiple data sources and services
|
|
2 |
# Copyright (C) 2019 Entr'ouvert
|
|
3 |
#
|
|
4 |
# This program is free software: you can redistribute it and/or modify it
|
|
5 |
# under the terms of the GNU Affero General Public License as published
|
|
6 |
# by the Free Software Foundation, either version 3 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU Affero General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU Affero General Public License
|
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
|
|
17 |
|
1 |
18 |
from __future__ import absolute_import
|
2 |
19 |
|
3 |
20 |
import collections
|
4 |
21 |
import re
|
5 |
22 |
|
6 |
23 |
from django import template
|
7 |
|
from django.utils.html import mark_safe, format_html, conditional_escape, escape
|
|
24 |
from django.utils.html import mark_safe, format_html
|
8 |
25 |
from django.utils.translation import ugettext as _
|
9 |
26 |
from django.contrib.contenttypes.models import ContentType
|
10 |
27 |
from django.contrib.auth import get_permission_codename
|
... | ... | |
16 |
33 |
|
17 |
34 |
register = template.Library()
|
18 |
35 |
|
|
36 |
|
19 |
37 |
@register.inclusion_tag('passerelle/includes/access-rights-table.html', takes_context=True)
|
20 |
38 |
def access_rights_table(context, resource, permission):
|
21 |
39 |
resource_type = ContentType.objects.get_for_model(resource)
|
22 |
|
rights = AccessRight.objects.filter(resource_type=resource_type,
|
23 |
|
resource_pk=resource.id, codename=permission)
|
|
40 |
rights = AccessRight.objects.filter(resource_type=resource_type, resource_pk=resource.id, codename=permission)
|
24 |
41 |
context['permission'] = permission
|
25 |
42 |
context['access_rights_list'] = rights
|
26 |
43 |
context['resource_type'] = resource_type.id
|
... | ... | |
28 |
45 |
context['trusted_services'] = get_trusted_services()
|
29 |
46 |
return context
|
30 |
47 |
|
|
48 |
|
31 |
49 |
@register.filter(name='resource_type')
|
32 |
50 |
def as_resource_type(resource):
|
33 |
51 |
return ContentType.objects.get_for_model(resource).id
|
34 |
52 |
|
|
53 |
|
35 |
54 |
@register.inclusion_tag('passerelle/includes/resource-logs-table.html', takes_context=True)
|
36 |
55 |
def resource_logs_table(context, resource):
|
37 |
56 |
request = context.get('request')
|
... | ... | |
92 |
111 |
def render_json_schema(schema):
|
93 |
112 |
if not isinstance(schema, dict):
|
94 |
113 |
if schema is True:
|
95 |
|
return mark_safe('<em>ALWAYS VALID</em>')
|
|
114 |
return mark_safe('<em>%s</em>') % _('always valid')
|
96 |
115 |
if schema is False:
|
97 |
|
return mark_safe('<em>ALWAYS INVALID</em>')
|
|
116 |
return mark_safe('<em>%s</em>') % _('always invalid')
|
98 |
117 |
return format_html('<tt>{!r}</tt>', schema)
|
99 |
118 |
|
100 |
119 |
def many_of(name, schemas):
|
... | ... | |
165 |
184 |
required_keys = schema.pop('required', [])
|
166 |
185 |
additional_properties = schema.pop('additionalProperties', True)
|
167 |
186 |
if unflatten:
|
168 |
|
s += ', <em class="unflatten">unflatten</em>'
|
|
187 |
s += format_html(', <em class="unflatten">%s</em>', _('unflatten'))
|
169 |
188 |
if merge_extra:
|
170 |
|
s += ', <em class="merge-extra">merge_extra</em>'
|
|
189 |
s += format_html(', <em class="merge-extra">%s</em>', _('merge extra'))
|
171 |
190 |
if not additional_properties:
|
172 |
|
s += ', <em class="additional-properties-false">no additional properties</em>'
|
|
191 |
s += format_html(', <em class="additional-properties-false">{}</em>', _('no additional properties'))
|
173 |
192 |
if title:
|
174 |
193 |
s += format_html(', <em class="title">{}</em>', title)
|
175 |
194 |
if schema:
|
... | ... | |
205 |
224 |
return mark_safe(s)
|
206 |
225 |
if typ == 'boolean':
|
207 |
226 |
if not schema:
|
208 |
|
return mark_safe('<b>bool</b>')
|
|
227 |
return mark_safe('<b>boolean</b>')
|
209 |
228 |
return format_html('<em>unknown {!r}</em>', original_schema)
|
210 |
229 |
|
211 |
230 |
|
212 |
|
-
|