How to use the rdmo.options.models.Option function in rdmo

To help you get started, we’ve selected a few rdmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rdmorganiser / rdmo / rdmo / projects / models.py View on Github external
default=0,
        verbose_name=_('Set index'),
        help_text=_('The position of this value in an entity collection (i.e. in the question set)')
    )
    collection_index = models.IntegerField(
        default=0,
        verbose_name=_('Collection index'),
        help_text=_('The position of this value in an attribute collection.')
    )
    text = models.TextField(
        blank=True,
        verbose_name=_('Text'),
        help_text=_('The string stored for this value.')
    )
    option = models.ForeignKey(
        Option, blank=True, null=True, on_delete=models.SET_NULL, related_name='+',
        verbose_name=_('Option'),
        help_text=_('The option stored for this value.')
    )
    value_type = models.CharField(
        max_length=8, choices=VALUE_TYPE_CHOICES,
        verbose_name=_('Value type'),
        help_text=_('Type of this value.')
    )
    unit = models.CharField(
        max_length=64, blank=True,
        verbose_name=_('Unit'),
        help_text=_('Unit for this value.')
    )

    class Meta:
        ordering = ('attribute', 'set_index', 'collection_index' )
github rdmorganiser / rdmo / rdmo / projects / imports.py View on Github external
attribute_uri = get_uri(value_node.find('attribute'), ns_map)
    if attribute_uri is not None:
        try:
            value.attribute = Attribute.objects.get(uri=attribute_uri)
        except Attribute.DoesNotExist:
            log.info('Attribute %s not in db. Skipping.', attribute_uri)
            return

    value.set_index = value_node.find('set_index').text
    value.collection_index = value_node.find('collection_index').text
    value.text = value_node.find('text').text or ''

    option_uri = get_uri(value_node.find('option'), ns_map)
    if option_uri is not None:
        try:
            value.option = Option.objects.get(uri=option_uri)
        except Option.DoesNotExist:
            log.info('Option %s not in db. Skipping.', option_uri)
            return

    value_type_node = value_node.find('value_type')
    if value_type_node is not None:
        value.value_type = value_type_node.text or ''

    unit_node = value_node.find('unit')
    if unit_node is not None:
        value.unit = unit_node.text or ''

    value.created = value_node.find('created').text
    value.updated = value_node.find('updated').text

    value.save()
github rdmorganiser / rdmo / rdmo / options / models.py View on Github external
def save(self, *args, **kwargs):
        self.path = Option.build_path(self.key, self.optionset)
        self.uri = get_uri_prefix(self) + '/options/' + self.path

        super(Option, self).save(*args, **kwargs)
github rdmorganiser / rdmo / rdmo / conditions / imports.py View on Github external
condition.source = None
    if element['source']:
        try:
            condition.source = Attribute.objects.get(uri=element['source'])
        except Attribute.DoesNotExist:
            pass

    condition.relation = element['relation']
    condition.target_text = element['target_text'] or ''

    condition.target_option = None
    if element['target_option']:
        try:
            condition.target_option = Option.objects.get(uri=element['target_option'])
        except Option.DoesNotExist:
            pass

    try:
        ConditionUniqueKeyValidator(condition).validate()
    except ValidationError as e:
        log.info('Condition not saving "%s" due to validation error (%s).', element['uri'], e)
        pass
    else:
        log.info('Condition saving to "%s".', element['uri'])
        condition.save()
github rdmorganiser / rdmo / rdmo / options / imports.py View on Github external
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']
github rdmorganiser / rdmo / rdmo / options / imports.py View on Github external
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']
github rdmorganiser / rdmo / rdmo / options / viewsets.py View on Github external
)

    @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)
        return Response(serializer.data)


class OptionViewSet(ModelViewSet):
    permission_classes = (HasModelPermission, )
    queryset = Option.objects.order_by('optionset__order', 'order')
    serializer_class = OptionSerializer

    filter_backends = (DjangoFilterBackend,)
    filter_fields = (
        'uri',
        'key',
        'optionset'
    )

    @action(detail=False)
    def index(self, request):
        serializer = OptionIndexSerializer(self.get_queryset(), many=True)
        return Response(serializer.data)
github rdmorganiser / rdmo / rdmo / projects / imports.py View on Github external
if attribute_uri is not None:
        try:
            value.attribute = Attribute.objects.get(uri=attribute_uri)
        except Attribute.DoesNotExist:
            log.info('Attribute %s not in db. Skipping.', attribute_uri)
            return

    value.set_index = value_node.find('set_index').text
    value.collection_index = value_node.find('collection_index').text
    value.text = value_node.find('text').text or ''

    option_uri = get_uri(value_node.find('option'), ns_map)
    if option_uri is not None:
        try:
            value.option = Option.objects.get(uri=option_uri)
        except Option.DoesNotExist:
            log.info('Option %s not in db. Skipping.', option_uri)
            return

    value_type_node = value_node.find('value_type')
    if value_type_node is not None:
        value.value_type = value_type_node.text or ''

    unit_node = value_node.find('unit')
    if unit_node is not None:
        value.unit = unit_node.text or ''

    value.created = value_node.find('created').text
    value.updated = value_node.find('updated').text

    value.save()
github rdmorganiser / rdmo / rdmo / options / admin.py View on Github external
class OptionSetAdmin(admin.ModelAdmin):
    search_fields = ('uri', )
    readonly_fields = ('uri', )


class OptionAdmin(admin.ModelAdmin):
    search_fields = ['uri'] + get_language_fields('text')
    list_display = ('uri', 'text', 'additional_input')
    readonly_fields = ('uri', 'path')
    list_filter = ('optionset', 'additional_input')


admin.site.register(OptionSet, OptionSetAdmin)
admin.site.register(Option, OptionAdmin)