How to use the rdmo.questions.models.QuestionSet 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 / viewsets.py View on Github external
def get_queryset(self):
        return QuestionSet.objects.order_by_catalog(self.project.catalog)
github rdmorganiser / rdmo / rdmo / projects / viewsets.py View on Github external
def prev(self, request, pk=None):
        try:
            return Response({'id': QuestionSet.objects.get_prev(pk).pk})
        except QuestionSet.DoesNotExist:
            raise NotFound()
github rdmorganiser / rdmo / rdmo / questions / admin.py View on Github external
search_fields = ['uri'] + get_language_fields('title') + get_language_fields('help')
    list_display = ('uri', 'attribute', 'is_collection')
    readonly_fields = ('uri', 'path')
    list_filter = ('section__catalog', 'section', 'is_collection')


class QuestionItemAdmin(admin.ModelAdmin):
    search_fields = ['uri'] + get_language_fields('help') + get_language_fields('text')
    list_display = ('uri', 'attribute', 'text', 'is_collection')
    readonly_fields = ('uri', 'path')
    list_filter = ('questionset__section__catalog', 'questionset__section', 'is_collection', 'widget_type', 'value_type')


admin.site.register(Catalog, CatalogAdmin)
admin.site.register(Section, SectionAdmin)
admin.site.register(QuestionSet, QuestionSetAdmin)
admin.site.register(Question, QuestionItemAdmin)
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
max_length=512, blank=True, null=True,
        verbose_name=_('Path'),
        help_text=_('The path part of the URI of this question (auto-generated).')
    )
    comment = models.TextField(
        blank=True, null=True,
        verbose_name=_('Comment'),
        help_text=_('Additional internal information about this question.')
    )
    attribute = models.ForeignKey(
        Attribute, blank=True, null=True, on_delete=models.SET_NULL, related_name='+',
        verbose_name=_('Attribute'),
        help_text=_('The attribute this question belongs to.')
    )
    questionset = models.ForeignKey(
        QuestionSet, on_delete=models.CASCADE, related_name='questions',
        verbose_name=_('Questionset'),
        help_text=_('The question set this question belongs to.')
    )
    is_collection = models.BooleanField(
        default=False,
        verbose_name=_('is collection'),
        help_text=_('Designates whether this question is a collection.')
    )
    order = models.IntegerField(
        default=0,
        verbose_name=_('Order'),
        help_text=_('The position of this question in lists.')
    )
    help_lang1 = models.TextField(
        null=True, blank=True,
        verbose_name=_('Help (primary)'),
github rdmorganiser / rdmo / rdmo / questions / imports.py View on Github external
def import_questionset(element):
    try:
        questionset = QuestionSet.objects.get(uri=element['uri'])
    except QuestionSet.DoesNotExist:
        log.info('QuestionSet not in db. Created with uri %s.', element['uri'])
        questionset = QuestionSet()

    try:
        questionset.section = Section.objects.get(uri=element['section'])
    except Section.DoesNotExist:
        log.info('Section not in db. Skipping.')
        return

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

    if element['attribute']:
        try:
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
def save(self, *args, **kwargs):
        self.path = QuestionSet.build_path(self.key, self.section)
        self.uri = get_uri_prefix(self) + '/questions/' + self.path

        super(QuestionSet, self).save(*args, **kwargs)

        for question in self.questions.all():
            question.save()

        # invalidate the cache so that changes appear instantly
        caches['api'].clear()
        return self.uri
github rdmorganiser / rdmo / rdmo / projects / serializers / v1 / questionset.py View on Github external
def get_progress(self, obj):
        try:
            return QuestionSet.on_site.active(self.context['request'].user).get_progress(obj.pk)
        except QuestionSet.DoesNotExist:
            return None
github rdmorganiser / rdmo / rdmo / questions / imports.py View on Github external
def import_question(element):
    try:
        question = Question.objects.get(uri=element['uri'])
    except Question.DoesNotExist:
        log.info('QuestionSet not in db. Created with uri %s.', element['uri'])
        question = Question()

    try:
        question.questionset = QuestionSet.objects.get(uri=element['questionset'])
    except QuestionSet.DoesNotExist:
        log.info('QuestionSet not in db. Skipping.')
        return

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

    if element['attribute']:
        try:
            question.attribute = Attribute.objects.get(uri=element['attribute'])
        except Attribute.DoesNotExist:
            pass

    question.is_collection = element['is_collection']
    question.order = element['order']
github rdmorganiser / rdmo / rdmo / projects / serializers / v1 / questionset.py View on Github external
next = serializers.SerializerMethodField()
    prev = serializers.SerializerMethodField()
    progress = serializers.SerializerMethodField()

    section = serializers.SerializerMethodField()

    attribute = AttributeSerializer()

    conditions = ConditionSerializer(default=None, many=True)

    verbose_name = serializers.SerializerMethodField()
    verbose_name_plural = serializers.SerializerMethodField()

    class Meta:
        model = QuestionSet
        fields = (
            'id',
            'title',
            'help',
            'verbose_name',
            'verbose_name_plural',
            'attribute',
            'is_collection',
            'next',
            'prev',
            'progress',
            'section',
            'questions',
            'conditions'
        )
github rdmorganiser / rdmo / rdmo / projects / serializers / v1 / questionset.py View on Github external
def get_progress(self, obj):
        try:
            return QuestionSet.objects.get_progress(obj.pk)
        except QuestionSet.DoesNotExist:
            return None