Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class ValueTypeTests(TestListViewsetMixin, DomainTestCase):
url_names = {
'viewset': 'internal-domain:valuestype'
}
status_map = {
'list_viewset': {
'editor': 200, 'reviewer': 200, 'reviewer': 200, 'api': 200, 'user': 200, 'anonymous': 403
}
}
class OptionSetTests(TestListViewsetMixin, TestRetrieveViewsetMixin, DomainTestCase):
instances = OptionSet.objects.all()
url_names = {
'viewset': 'internal-domain:optionset'
}
class ConditionTests(TestListViewsetMixin, TestRetrieveViewsetMixin, DomainTestCase):
instances = Condition.objects.all()
url_names = {
'viewset': 'internal-domain:condition'
}
class DomainExportTests(TestExportViewMixin, DomainTestCase):
url_names = {
def save(self, *args, **kwargs):
self.uri = get_uri_prefix(self) + '/options/' + self.label
super(OptionSet, self).save(*args, **kwargs)
for option in self.options.all():
option.save()
from rdmo.core.permissions import HasModelPermission
from .models import OptionSet, Option
from .serializers.v1 import (
OptionSetSerializer,
OptionSerializer,
OptionSetIndexSerializer,
OptionIndexSerializer,
OptionSetNestedSerializer
)
class OptionSetViewSet(ModelViewSet):
permission_classes = (HasModelPermission, )
queryset = OptionSet.objects.order_by('order')
serializer_class = OptionSetSerializer
filter_backends = (DjangoFilterBackend,)
filter_fields = (
'uri',
'key'
)
@action(detail=False)
def nested(self, request):
serializer = OptionSetNestedSerializer(self.get_queryset(), many=True)
return Response(serializer.data)
@action(detail=False)
def index(self, request):
serializer = OptionSetIndexSerializer(self.get_queryset(), many=True)
attribute.unit = attribute_node['unit']
attribute.save()
if hasattr(attribute_node, 'range'):
import_verbose_name(attribute_node.range, attribute)
if hasattr(attribute_node, 'verbosename'):
import_verbose_name(attribute_node.verbosename, attribute)
if hasattr(attribute_node, 'optionsets'):
for optionset_node in attribute_node.optionsets.iterchildren():
try:
optionset_uri = optionset_node.get(get_ns_tag('dc:uri', nsmap))
optionset = OptionSet.objects.get(uri=optionset_uri)
attribute.optionsets.add(optionset)
except OptionSet.DoesNotExist:
pass
if hasattr(attribute_node, 'conditions'):
for condition_node in attribute_node.conditions.iterchildren():
try:
condition_uri = condition_node.get(get_ns_tag('dc:uri', nsmap))
condition = Condition.objects.get(uri=condition_uri)
attribute.conditions.add(condition)
except Condition.DoesNotExist:
pass
def import_option(element):
try:
option = Option.objects.get(uri=element['uri'])
except Option.DoesNotExist:
log.info('Option not in db. Created with uri %s.', element['uri'])
option = Option()
try:
option.optionset = OptionSet.objects.get(uri=element['optionset'])
except OptionSet.DoesNotExist:
log.info('OptionSet not in db. Skipping.')
return
option.uri_prefix = element['uri_prefix']
option.key = element['key']
option.comment = element['comment']
option.order = element['order']
option.text_en = element['text_en']
option.text_de = element['text_de']
option.additional_input = element['additional_input']
try:
OptionUniquePathValidator(option).validate()
def import_optionset(element):
try:
optionset = OptionSet.objects.get(uri=element['uri'])
except OptionSet.DoesNotExist:
log.info('OptionSet not in db. Created with uri %s.', element['uri'])
optionset = OptionSet()
optionset.uri_prefix = element['uri_prefix']
optionset.key = element['key']
optionset.comment = element['comment']
optionset.order = element['order']
try:
OptionSetUniqueKeyValidator(optionset).validate()
except ValidationError as e:
log.info('OptionSet not saving "%s" due to validation error (%s).', element['uri'], e)
return
else:
question.save()
question.conditions.clear()
if element['conditions'] is not None:
for condition in element['conditions']:
try:
question.conditions.add(Condition.objects.get(uri=condition))
except Condition.DoesNotExist:
pass
question.optionsets.clear()
if element['optionsets'] is not None:
for condition in element['optionsets']:
try:
question.optionsets.add(OptionSet.objects.get(uri=condition))
except OptionSet.DoesNotExist:
pass
def handle(self, *args, **options):
for obj in Condition.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in OptionSet.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in Option.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in AttributeEntity.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in Catalog.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in Section.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in Subsection.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
def import_optionset(element):
try:
optionset = OptionSet.objects.get(uri=element['uri'])
except OptionSet.DoesNotExist:
log.info('OptionSet not in db. Created with uri %s.', element['uri'])
optionset = OptionSet()
optionset.uri_prefix = element['uri_prefix']
optionset.key = element['key']
optionset.comment = element['comment']
optionset.order = element['order']
try:
OptionSetUniqueKeyValidator(optionset).validate()
except ValidationError as e:
log.info('OptionSet not saving "%s" due to validation error (%s).', element['uri'], e)
return
else:
log.info('OptionSet saving to "%s".', element['uri'])
optionset.save()
model = OptionSet
fields = (
'id',
'uri_prefix',
'key',
'comment',
'order',
'conditions'
)
validators = (OptionSetUniqueKeyValidator(),)
class OptionSerializer(serializers.ModelSerializer):
key = serializers.CharField(required=True)
optionset = serializers.PrimaryKeyRelatedField(queryset=OptionSet.objects.all(), required=True)
class Meta:
model = Option
fields = (
'id',
'optionset',
'uri_prefix',
'key',
'comment',
'order',
'text_en',
'text_de',
'additional_input'
)
validators = (OptionUniquePathValidator(),)