How to use the rdmo.conditions.models.Condition 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 / conditions / views.py View on Github external
def get_context_data(self, **kwargs):
        context = super(ConditionsView, self).get_context_data(**kwargs)
        context['export_formats'] = settings.EXPORT_FORMATS
        context['meta'] = {
            'Condition': get_model_field_meta(Condition)
        }
        return context
github rdmorganiser / rdmo / rdmo / conditions / viewsets.py View on Github external
'source',
        'relation',
        'target_text',
        'target_option'
    )

    @action(detail=False)
    def index(self, request):
        queryset = self.get_queryset()
        serializer = ConditionIndexSerializer(queryset, many=True)
        return Response(serializer.data)


class RelationViewSet(ChoicesViewSet):
    permission_classes = (IsAuthenticated, )
    queryset = Condition.RELATION_CHOICES
github rdmorganiser / rdmo / rdmo / conditions / models.py View on Github external
def save(self, *args, **kwargs):
        self.uri = self.build_uri()
        super(Condition, self).save(*args, **kwargs)
github rdmorganiser / rdmo / rdmo / projects / viewsets.py View on Github external
def resolve(self, request, pk=None):
        try:
            condition = Condition.objects.get(pk=request.GET.get('condition'))
            return Response({'result': condition.resolve(self.get_object(), None)})
        except Condition.DoesNotExist:
            return Response({'result': False})
github rdmorganiser / rdmo / rdmo / options / models.py View on Github external
max_length=128, blank=True,
        verbose_name=_('Key'),
        help_text=_('The internal identifier of this option set.')
    )
    comment = models.TextField(
        blank=True,
        verbose_name=_('Comment'),
        help_text=_('Additional internal information about this option set.')
    )
    order = models.IntegerField(
        default=0,
        verbose_name=_('Order'),
        help_text=_('The position of this option set in lists.')
    )
    conditions = models.ManyToManyField(
        Condition, blank=True,
        verbose_name=_('Conditions'),
        help_text=_('The list of conditions evaluated for this option set.')
    )

    class Meta:
        ordering = ('uri', )
        verbose_name = _('Option set')
        verbose_name_plural = _('Option sets')

    def __str__(self):
        return self.uri or self.key

    def save(self, *args, **kwargs):
        self.uri = get_uri_prefix(self) + '/options/' + self.label
        super(OptionSet, self).save(*args, **kwargs)
github rdmorganiser / rdmo / rdmo / conditions / imports.py View on Github external
def import_condition(element):
    try:
        condition = Condition.objects.get(uri=element['uri'])
    except Condition.DoesNotExist:
        log.info('Condition not in db. Created with uri %s.', element['uri'])
        condition = Condition()

    condition.uri_prefix = element['uri_prefix'] or ''
    condition.key = element['key'] or ''
    condition.comment = element['comment'] or ''

    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 ''
github rdmorganiser / rdmo / rdmo / conditions / imports.py View on Github external
def import_condition(element):
    try:
        condition = Condition.objects.get(uri=element['uri'])
    except Condition.DoesNotExist:
        log.info('Condition not in db. Created with uri %s.', element['uri'])
        condition = Condition()

    condition.uri_prefix = element['uri_prefix'] or ''
    condition.key = element['key'] or ''
    condition.comment = element['comment'] or ''

    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
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
max_length=256, blank=True,
        verbose_name=_('Plural name (tertiary)'),
        help_text=_('The plural name displayed for this question in the tertiary language.')
    )
    verbose_name_plural_lang4 = models.CharField(
        max_length=256, blank=True,
        verbose_name=_('Plural name (quaternary)'),
        help_text=_('The plural name displayed for this question in the quaternary language.')
    )
    verbose_name_plural_lang5 = models.CharField(
        max_length=256, blank=True,
        verbose_name=_('Plural name (quinary)'),
        help_text=_('The plural name displayed for this question in the quinary language.')
    )
    conditions = models.ManyToManyField(
        Condition, blank=True,
        verbose_name=_('Conditions'),
        help_text=_('List of conditions evaluated for this questionset.')
    )

    class Meta:
        ordering = ('section', 'order')
        verbose_name = _('Question set')
        verbose_name_plural = _('Question set')

    def __str__(self):
        return self.uri or self.key

    def save(self, *args, **kwargs):
        self.path = QuestionSet.build_path(self.key, self.section)
        self.uri = get_uri_prefix(self) + '/questions/' + self.path