Repository: rdmorganiser/rdmo
Issue: Project created with API has no views

### Description / Beschreibung

When a new project is created with the RDMO API, no view is assigned to it. Views assigned to the used question catalog in the project should show up. When a project is created in the RDMO web interface, the views are displayed.

### Expected behaviour / Erwartetes Verhalten

The views should be assigned to the project based on the question catalog or can be assigned to the project via API.

### Steps to reproduce / Schritte zum Reproduzieren
 In  the RDMO API
POST /api/v1/projects/projects/

{
  "title": "Projekt XY",
  "description": "nur mal so",
  "catalog": 1
}


* 


Changed files:
rdmo/projects/serializers/v1/__init__.py, rdmo/projects/views/project_create.py, rdmo/projects/viewsets.py

diff --git a/rdmo/projects/serializers/v1/__init__.py b/rdmo/projects/serializers/v1/__init__.py
index 66dd279b..01445a61 100644
--- a/rdmo/projects/serializers/v1/__init__.py
+++ b/rdmo/projects/serializers/v1/__init__.py
@@ -55,7 +55,8 @@ class ProjectSerializer(serializers.ModelSerializer):
             'guests',
             'created',
             'updated',
-            'site'
+            'site',
+            'views'
         )
         read_only_fields = (
             'snapshots',
diff --git a/rdmo/projects/views/project_create.py b/rdmo/projects/views/project_create.py
index 511bbd49..aadc44cd 100644
--- a/rdmo/projects/views/project_create.py
+++ b/rdmo/projects/views/project_create.py
@@ -2,11 +2,9 @@ import logging
 
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.contrib.sites.shortcuts import get_current_site
-from django.http import HttpResponseRedirect
-from django.shortcuts import render
 from django.urls import reverse_lazy
-from django.utils.translation import gettext_lazy as _
 from django.views.generic import CreateView, TemplateView
+
 from rdmo.core.views import RedirectViewMixin
 from rdmo.questions.models import Catalog
 from rdmo.tasks.models import Task
@@ -45,6 +43,7 @@ class ProjectCreateView(LoginRequiredMixin, RedirectViewMixin, CreateView):
 
         # add all tasks to project
         tasks = Task.objects.filter_current_site() \\
+                            .filter_catalog(self.object.catalog) \\
                             .filter_group(self.request.user) \\
                             .filter_availability(self.request.user)
         for task in tasks:
diff --git a/rdmo/projects/viewsets.py b/rdmo/projects/viewsets.py
index fb9cd3b2..f0b3abc8 100644
--- a/rdmo/projects/viewsets.py
+++ b/rdmo/projects/viewsets.py
@@ -22,6 +22,8 @@ from rdmo.core.permissions import HasModelPermission, HasObjectPermission
 from rdmo.core.utils import human2bytes, return_file_response
 from rdmo.options.models import OptionSet
 from rdmo.questions.models import Catalog, Question, QuestionSet
+from rdmo.tasks.models import Task
+from rdmo.views.models import View
 
 from .filters import SnapshotFilterBackend, ValueFilterBackend
 from .models import (Continuation, Integration, Issue, Membership, Project,
@@ -150,6 +152,23 @@ class ProjectViewSet(ModelViewSet):
     def perform_create(self, serializer):
         project = serializer.save(site=get_current_site(self.request))
 
+        # add all tasks to project
+        tasks = Task.objects.filter_current_site() \\
+                            .filter_catalog(project.catalog) \\
+                            .filter_group(self.request.user) \\
+                            .filter_availability(self.request.user)
+        for task in tasks:
+            project.tasks.add(task)
+
+        if self.request.data.get('views') is None:
+            # add all views to project
+            views = View.objects.filter_current_site() \\
+                                .filter_catalog(project.catalog) \\
+                                .filter_group(self.request.user) \\
+                                .filter_availability(self.request.user)
+            for view in views:
+                project.views.add(view)
+
         # add current user as owner
         membership = Membership(project=project, user=self.request.user, role='owner')
         membership.save()