How to use the rdmo.questions.models.Section 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 / questions / tests.py View on Github external
class CatalogTests(TestModelViewsetMixin, QuestionsTestCase):

    instances = Catalog.objects.all()
    url_names = {
        'viewset': 'internal-questions:catalog'
    }

    def prepare_create_instance(self, instance):
        instance.key += '_new'
        return instance


class SectionTests(TestModelViewsetMixin, QuestionsTestCase):

    instances = Section.objects.all()
    url_names = {
        'viewset': 'internal-questions:section'
    }

    def prepare_create_instance(self, instance):
        instance.key += '_new'
        return instance


class SubsectionTests(TestModelViewsetMixin, QuestionsTestCase):

    instances = Subsection.objects.all()
    url_names = {
        'viewset': 'internal-questions:subsection'
    }
github rdmorganiser / rdmo / rdmo / questions / viewsets.py View on Github external
def nested(self, request, pk):
        queryset = get_object_or_404(Section, pk=pk)
        serializer = SectionNestedSerializer(queryset)
        return Response(serializer.data)
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
def save(self, *args, **kwargs):
        self.path = Section.build_path(self.key, self.catalog)
        self.uri = get_uri_prefix(self) + '/questions/' + self.path
        super(Section, self).save(*args, **kwargs)
        for questionsets in self.questionsets.all():
            questionsets.save()
        return self.uri
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
def clean(self):
        self.path = Section.build_path(self.key, self.catalog)
        SectionUniquePathValidator(self)()
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:
            questionset.attribute = Attribute.objects.get(uri=element['attribute'])
        except Attribute.DoesNotExist:
            pass

    questionset.is_collection = element['is_collection']
    questionset.order = element['order']
github rdmorganiser / rdmo / rdmo / core / management / commands / set_uri_prefix.py View on Github external
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'])

        for obj in QuestionEntity.objects.all():
            self._set_uri_prefix(obj, options['uri_prefix'])

        for obj in Task.objects.all():
            self._set_uri_prefix(obj, options['uri_prefix'])

        for obj in View.objects.all():
            self._set_uri_prefix(obj, options['uri_prefix'])
github rdmorganiser / rdmo / rdmo / questions / views.py View on Github external
def get_context_data(self, **kwargs):
        context = super(CatalogsView, self).get_context_data(**kwargs)
        context['export_formats'] = settings.EXPORT_FORMATS
        context['meta'] = {
            'Catalog': get_model_field_meta(Catalog),
            'Section': get_model_field_meta(Section),
            'QuestionSet': get_model_field_meta(QuestionSet),
            'Question': get_model_field_meta(Question),
        }
        return context
github rdmorganiser / rdmo / rdmo / questions / imports.py View on Github external
def import_section(element):
    try:
        section = Section.objects.get(uri=element['uri'])
    except Section.DoesNotExist:
        log.info('Section not in db. Created with uri %s.', element['uri'])
        section = Section()

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

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

    section.order = element['order']
github rdmorganiser / rdmo / rdmo / questions / models.py View on Github external
verbose_name=_('Path'),
        help_text=_('The path part of the URI of this questionset (auto-generated).')
    )
    comment = models.TextField(
        blank=True,
        verbose_name=_('Comment'),
        help_text=_('Additional internal information about this questionset.')
    )
    attribute = models.ForeignKey(
        Attribute, blank=True, null=True,
        on_delete=models.SET_NULL, related_name='+',
        verbose_name=_('Attribute'),
        help_text=_('The attribute this questionset belongs to.')
    )
    section = models.ForeignKey(
        Section, on_delete=models.CASCADE, related_name='questionsets',
        verbose_name=_('Section'),
        help_text=_('The section this questionset belongs to.')
    )
    is_collection = models.BooleanField(
        default=False,
        verbose_name=_('is collection'),
        help_text=_('Designates whether this questionset is a collection.')
    )
    order = models.IntegerField(
        default=0,
        verbose_name=_('Order'),
        help_text=_('The position of this questionset in lists.')
    )
    title_lang1 = models.CharField(
        max_length=256, blank=True,
        verbose_name=_('Title (primary)'),
github rdmorganiser / rdmo / rdmo / questions / viewsets.py View on Github external
    @action(detail=True)
    def nested(self, request, pk):
        queryset = get_object_or_404(Catalog, pk=pk)
        serializer = CatalogNestedSerializer(queryset)
        return Response(serializer.data)

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


class SectionViewSet(ModelViewSet):
    permission_classes = (HasModelPermission, )
    queryset = Section.objects.all()
    serializer_class = SectionSerializer

    filter_backends = (DjangoFilterBackend,)
    filter_fields = (
        'uri',
        'path',
        'key',
        'catalog'
    )

    @action(detail=True)
    def nested(self, request, pk):
        queryset = get_object_or_404(Section, pk=pk)
        serializer = SectionNestedSerializer(queryset)
        return Response(serializer.data)