How to use the rdmo.tasks.models.Task 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 / tasks / imports.py View on Github external
def import_tasks(tasks_node):
    log.info('Importing conditions')
    nsmap = get_ns_map(tasks_node.getroot())

    for task_node in tasks_node.findall('task'):
        task_uri = get_uri(task_node, nsmap)

        try:
            task = Task.objects.get(uri=task_uri)
        except Task.DoesNotExist:
            task = Task()
            log.info('Task not in db. Created with uri ' + task_uri)
        else:
            log.info('Task does exist. Loaded from uri ' + task_uri)

        task.uri_prefix = task_uri.split('/tasks/')[0]
        task.key = task_uri.split('/')[-1]

        try:
            attribute_uri = get_uri(task_node, nsmap, 'attrib')
            task.attribute = Attribute.objects.get(uri=attribute_uri)
        except (AttributeError, Attribute.DoesNotExist, KeyError):
            task.attribute = None

        for element in task_node.findall('title'):
            setattr(task, 'title_' + element.attrib['lang'], element.text)
github rdmorganiser / rdmo / rdmo / core / management / commands / set_uri_prefix.py View on Github external
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 / tasks / viewsets.py View on Github external
from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import action
from rest_framework.response import Response

from django_filters.rest_framework import DjangoFilterBackend

from rdmo.core.permissions import HasModelPermission

from .models import Task
from .serializers.v1 import TaskSerializer, TaskIndexSerializer


class TaskViewSet(ModelViewSet):
    permission_classes = (HasModelPermission, )
    queryset = Task.objects.all()
    serializer_class = TaskSerializer

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

    @action(detail=False)
    def index(self, request):
        serializer = TaskIndexSerializer(self.get_queryset(), many=True)
        return Response(serializer.data)
github rdmorganiser / rdmo / rdmo / tasks / imports.py View on Github external
def import_task(element):
    try:
        task = Task.objects.get(uri=element['uri'])
    except Task.DoesNotExist:
        log.info('Task not in db. Created with uri %s.', element['uri'])
        task = Task()

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

    for lang_code, lang_string, lang_field in get_languages():
        set_lang_field(task, 'title', element, lang_code, lang_field)
        set_lang_field(task, 'text', element, lang_code, lang_field)

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

    if element['end_attribute']:
github rdmorganiser / rdmo / rdmo / projects / imports.py View on Github external
except Catalog.DoesNotExist:
        log.info('Catalog not in db. Created with uri %s', catalog)
        project.catalog = Catalog.objects.all().first()

    project.save()

    # add user to project
    membership = Membership(project=project, user=user, role='owner')
    membership.save()

    tasks_node = root.find('tasks')
    if tasks_node is not None:
        for task_node in tasks_node.findall('task'):
            try:
                task_uri = get_uri(task_node, ns_map)
                project.tasks.add(Task.objects.get(uri=task_uri))
            except Task.DoesNotExist:
                pass

    views_node = root.find('views')
    if views_node is not None:
        for view_node in views_node.findall('view'):
            try:
                view_uri = get_uri(view_node, ns_map)
                project.views.add(View.objects.get(uri=view_uri))
            except View.DoesNotExist:
                pass

    snapshots_node = root.find('snapshots')
    if snapshots_node is not None:
        for snapshot_node in snapshots_node.findall('snapshot'):
            if snapshot_node is not None:
github rdmorganiser / rdmo / rdmo / tasks / views.py View on Github external
def get_context_data(self, **kwargs):
        context = super(TasksView, self).get_context_data(**kwargs)
        context['export_formats'] = settings.EXPORT_FORMATS
        context['meta'] = {
            'Task': get_model_field_meta(Task)
        }
        return context
github rdmorganiser / rdmo / rdmo / projects / views.py View on Github external
def form_valid(self, form):
        # add current site
        form.instance.site = get_current_site(self.request)

        # save the project
        response = super(ProjectCreateView, self).form_valid(form)

        # add all tasks to project
        tasks = Task.objects.filter_current_site().filter_group(self.request.user)
        for task in tasks:
            form.instance.tasks.add(task)

        # add all views to project
        views = View.objects.filter_current_site().filter_catalog(self.object.catalog).filter_group(self.request.user)
        for view in views:
            form.instance.views.add(view)

        # add current user as owner
        membership = Membership(project=form.instance, user=self.request.user, role='owner')
        membership.save()

        return response
github rdmorganiser / rdmo / rdmo / tasks / imports.py View on Github external
def import_task(element):
    try:
        task = Task.objects.get(uri=element['uri'])
    except Task.DoesNotExist:
        log.info('Task not in db. Created with uri %s.', element['uri'])
        task = Task()

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

    for lang_code, lang_string, lang_field in get_languages():
        set_lang_field(task, 'title', element, lang_code, lang_field)
        set_lang_field(task, 'text', element, lang_code, lang_field)

    if element['start_attribute']:
        try:
            task.start_attribute = Attribute.objects.get(uri=element['start_attribute'])
        except Attribute.DoesNotExist:
github rdmorganiser / rdmo / rdmo / projects / models.py View on Github external
max_length=256,
        verbose_name=_('Title'),
        help_text=_('The title for this project.')
    )
    description = models.TextField(
        blank=True,
        verbose_name=_('Description'),
        help_text=_('A description for this project (optional).')
    )
    catalog = models.ForeignKey(
        Catalog, related_name='+', on_delete=models.SET_NULL, null=True,
        verbose_name=_('Catalog'),
        help_text=_('The catalog which will be used for this project.')
    )
    tasks = models.ManyToManyField(
        Task, blank=True,
        verbose_name=_('Tasks'),
        help_text=_('The tasks that will be used for this project.')
    )
    views = models.ManyToManyField(
        View, blank=True,
        verbose_name=_('Views'),
        help_text=_('The views that will be used for this project.')
    )

    class Meta:
        ordering = ('title', )
        verbose_name = _('Project')
        verbose_name_plural = _('Projects')

    def __str__(self):
        return self.title