chore: format
This commit is contained in:
parent
d4cb978de3
commit
75351b9986
|
|
@ -10,9 +10,6 @@ from django.views import defaults as default_views
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django_ratelimit.exceptions import Ratelimited
|
from django_ratelimit.exceptions import Ratelimited
|
||||||
from graphene_django.views import GraphQLView
|
from graphene_django.views import GraphQLView
|
||||||
from wagtail import urls as wagtail_urls
|
|
||||||
from wagtail.admin import urls as wagtailadmin_urls
|
|
||||||
from wagtail.documents import urls as wagtaildocs_urls
|
|
||||||
|
|
||||||
from vbv_lernwelt.assignment.views import request_assignment_completion_status
|
from vbv_lernwelt.assignment.views import request_assignment_completion_status
|
||||||
from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt
|
from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt
|
||||||
|
|
@ -57,6 +54,9 @@ from vbv_lernwelt.importer.views import (
|
||||||
t2l_sync,
|
t2l_sync,
|
||||||
)
|
)
|
||||||
from vbv_lernwelt.notify.views import email_notification_settings
|
from vbv_lernwelt.notify.views import email_notification_settings
|
||||||
|
from wagtail import urls as wagtail_urls
|
||||||
|
from wagtail.admin import urls as wagtailadmin_urls
|
||||||
|
from wagtail.documents import urls as wagtaildocs_urls
|
||||||
|
|
||||||
|
|
||||||
class SignedIntConverter(IntConverter):
|
class SignedIntConverter(IntConverter):
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,11 @@ class AssignmentObjectType(DjangoObjectType):
|
||||||
return self.find_attached_learning_content()
|
return self.find_attached_learning_content()
|
||||||
|
|
||||||
def resolve_completion(
|
def resolve_completion(
|
||||||
self,
|
self,
|
||||||
info,
|
info,
|
||||||
course_session_id,
|
course_session_id,
|
||||||
learning_content_page_id=None,
|
learning_content_page_id=None,
|
||||||
assignment_user_id=None,
|
assignment_user_id=None,
|
||||||
):
|
):
|
||||||
if learning_content_page_id is None:
|
if learning_content_page_id is None:
|
||||||
lp = self.find_attached_learning_content()
|
lp = self.find_attached_learning_content()
|
||||||
|
|
@ -94,17 +94,17 @@ class AssignmentObjectType(DjangoObjectType):
|
||||||
|
|
||||||
|
|
||||||
def resolve_assignment_completion(
|
def resolve_assignment_completion(
|
||||||
info,
|
info,
|
||||||
assignment_id,
|
assignment_id,
|
||||||
course_session_id,
|
course_session_id,
|
||||||
learning_content_page_id=None,
|
learning_content_page_id=None,
|
||||||
assignment_user_id=None,
|
assignment_user_id=None,
|
||||||
):
|
):
|
||||||
if assignment_user_id is None:
|
if assignment_user_id is None:
|
||||||
assignment_user_id = info.context.user.id
|
assignment_user_id = info.context.user.id
|
||||||
|
|
||||||
if str(assignment_user_id) == str(info.context.user.id) or is_course_session_expert(
|
if str(assignment_user_id) == str(info.context.user.id) or is_course_session_expert(
|
||||||
info.context.user, course_session_id
|
info.context.user, course_session_id
|
||||||
):
|
):
|
||||||
course_id = CourseSession.objects.get(id=course_session_id).course_id
|
course_id = CourseSession.objects.get(id=course_session_id).course_id
|
||||||
if has_course_access(info.context.user, course_id):
|
if has_course_access(info.context.user, course_id):
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,7 @@ class AssignmentCompletionStatus(Enum):
|
||||||
|
|
||||||
|
|
||||||
def is_valid_assignment_completion_status(
|
def is_valid_assignment_completion_status(
|
||||||
completion_status: AssignmentCompletionStatus,
|
completion_status: AssignmentCompletionStatus,
|
||||||
):
|
):
|
||||||
return completion_status.value in AssignmentCompletionStatus.__members__
|
return completion_status.value in AssignmentCompletionStatus.__members__
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,8 +108,8 @@ def update_assignment_completion(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
completion_status == AssignmentCompletionStatus.IN_PROGRESS
|
completion_status == AssignmentCompletionStatus.IN_PROGRESS
|
||||||
and ac.completion_status != "IN_PROGRESS"
|
and ac.completion_status != "IN_PROGRESS"
|
||||||
):
|
):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ class AttendanceCourseUserMutationTestCase(GraphQLTestCase):
|
||||||
data["completion_data"],
|
data["completion_data"],
|
||||||
{
|
{
|
||||||
user_text_input["id"]: {"user_data": {"text": "Hallo via API"}},
|
user_text_input["id"]: {"user_data": {"text": "Hallo via API"}},
|
||||||
task_id: {"user_data": {"fileId": file_id}}
|
task_id: {"user_data": {"fileId": file_id}},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -109,15 +109,11 @@ class AttendanceCourseUserMutationTestCase(GraphQLTestCase):
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
task_data,
|
task_data,
|
||||||
{
|
{
|
||||||
"user_data":
|
"user_data": {
|
||||||
{
|
"fileId": file_id,
|
||||||
"fileId": file_id,
|
"fileInfo": {"id": file_id, "name": "file.txt", "url": file_url},
|
||||||
"fileInfo": {
|
}
|
||||||
"id": file_id,
|
},
|
||||||
"name": 'file.txt',
|
|
||||||
"url": file_url}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# check DB data
|
# check DB data
|
||||||
|
|
@ -131,7 +127,7 @@ class AttendanceCourseUserMutationTestCase(GraphQLTestCase):
|
||||||
db_entry.completion_data,
|
db_entry.completion_data,
|
||||||
{
|
{
|
||||||
user_text_input["id"]: {"user_data": {"text": "Hallo via API"}},
|
user_text_input["id"]: {"user_data": {"text": "Hallo via API"}},
|
||||||
task_id: {"user_data": {"fileId": file_id}}
|
task_id: {"user_data": {"fileId": file_id}},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -175,7 +171,7 @@ class AttendanceCourseUserMutationTestCase(GraphQLTestCase):
|
||||||
data["completion_data"],
|
data["completion_data"],
|
||||||
{
|
{
|
||||||
user_text_input["id"]: {"user_data": {"text": "Hallo via API 2"}},
|
user_text_input["id"]: {"user_data": {"text": "Hallo via API 2"}},
|
||||||
task_id: {"user_data": {"fileId": file_id}}
|
task_id: {"user_data": {"fileId": file_id}},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -191,7 +187,7 @@ class AttendanceCourseUserMutationTestCase(GraphQLTestCase):
|
||||||
db_entry.completion_data,
|
db_entry.completion_data,
|
||||||
{
|
{
|
||||||
user_text_input["id"]: {"user_data": {"text": "Hallo via API 2"}},
|
user_text_input["id"]: {"user_data": {"text": "Hallo via API 2"}},
|
||||||
task_id: {"user_data": {"fileId": file_id}}
|
task_id: {"user_data": {"fileId": file_id}},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -268,7 +264,7 @@ class AttendanceCourseUserMutationTestCase(GraphQLTestCase):
|
||||||
user_text_input = find_first(
|
user_text_input = find_first(
|
||||||
subtasks,
|
subtasks,
|
||||||
pred=lambda x: (value := x.get("value"))
|
pred=lambda x: (value := x.get("value"))
|
||||||
and value.get("text", "").startswith(
|
and value.get("text", "").startswith(
|
||||||
"Gibt es zusätzliche Deckungen, die du der Person empfehlen würdest?"
|
"Gibt es zusätzliche Deckungen, die du der Person empfehlen würdest?"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,8 @@ class CourseSessionAssignment(models.Model):
|
||||||
url_expert = f"/course/{self.course_session.course.slug}/cockpit/assignment/{self.learning_content_id}?courseSessionId={self.course_session.id}"
|
url_expert = f"/course/{self.course_session.course.slug}/cockpit/assignment/{self.learning_content_id}?courseSessionId={self.course_session.id}"
|
||||||
|
|
||||||
if assignment_type in (
|
if assignment_type in (
|
||||||
AssignmentType.CASEWORK.value,
|
AssignmentType.CASEWORK.value,
|
||||||
AssignmentType.PREP_ASSIGNMENT.value,
|
AssignmentType.PREP_ASSIGNMENT.value,
|
||||||
):
|
):
|
||||||
if not self.submission_deadline_id:
|
if not self.submission_deadline_id:
|
||||||
self.submission_deadline = DueDate.objects.create(
|
self.submission_deadline = DueDate.objects.create(
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ def s3_get_client():
|
||||||
credentials = s3_get_credentials()
|
credentials = s3_get_credentials()
|
||||||
|
|
||||||
# This is needed until https://github.com/boto/boto3/issues/3015 is fixed
|
# This is needed until https://github.com/boto/boto3/issues/3015 is fixed
|
||||||
s3 = boto3.client('s3', region_name=credentials.region_name)
|
s3 = boto3.client("s3", region_name=credentials.region_name)
|
||||||
endpoint_url = s3.meta.endpoint_url
|
endpoint_url = s3.meta.endpoint_url
|
||||||
|
|
||||||
return boto3.client(
|
return boto3.client(
|
||||||
|
|
@ -56,12 +56,12 @@ def s3_get_client():
|
||||||
aws_access_key_id=credentials.access_key_id,
|
aws_access_key_id=credentials.access_key_id,
|
||||||
aws_secret_access_key=credentials.secret_access_key,
|
aws_secret_access_key=credentials.secret_access_key,
|
||||||
region_name=credentials.region_name,
|
region_name=credentials.region_name,
|
||||||
endpoint_url=endpoint_url
|
endpoint_url=endpoint_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def s3_generate_presigned_post(
|
def s3_generate_presigned_post(
|
||||||
*, file_path: str, file_type: str, file_name: str
|
*, file_path: str, file_type: str, file_name: str
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
credentials = s3_get_credentials()
|
credentials = s3_get_credentials()
|
||||||
s3_client = s3_get_client()
|
s3_client = s3_get_client()
|
||||||
|
|
@ -104,7 +104,6 @@ def s3_generate_presigned_post(
|
||||||
["starts-with", "$Content-Disposition", ""],
|
["starts-with", "$Content-Disposition", ""],
|
||||||
],
|
],
|
||||||
ExpiresIn=expires_in,
|
ExpiresIn=expires_in,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return presigned_data
|
return presigned_data
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class FileStandardUploadService:
|
||||||
self.file_obj = file_obj
|
self.file_obj = file_obj
|
||||||
|
|
||||||
def _infer_file_name_and_type(
|
def _infer_file_name_and_type(
|
||||||
self, file_name: str = "", file_type: str = ""
|
self, file_name: str = "", file_type: str = ""
|
||||||
) -> Tuple[str, str]:
|
) -> Tuple[str, str]:
|
||||||
if not file_name:
|
if not file_name:
|
||||||
file_name = self.file_obj.name
|
file_name = self.file_obj.name
|
||||||
|
|
@ -80,7 +80,7 @@ class FileStandardUploadService:
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def update(
|
def update(
|
||||||
self, file: UploadFile, file_name: str = "", file_type: str = ""
|
self, file: UploadFile, file_name: str = "", file_type: str = ""
|
||||||
) -> UploadFile:
|
) -> UploadFile:
|
||||||
_validate_file_size(self.file_obj)
|
_validate_file_size(self.file_obj)
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ class FileDirectUploadService:
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def start(
|
def start(
|
||||||
self, file_name: str, file_type: str
|
self, file_name: str, file_type: str
|
||||||
) -> Tuple[UploadFile, Dict[str, Any]]:
|
) -> Tuple[UploadFile, Dict[str, Any]]:
|
||||||
file = UploadFile(
|
file = UploadFile(
|
||||||
original_file_name=file_name,
|
original_file_name=file_name,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ def presign(request):
|
||||||
service = FileDirectUploadService(request.user)
|
service = FileDirectUploadService(request.user)
|
||||||
|
|
||||||
upload_file, pre_signed_data = service.start(
|
upload_file, pre_signed_data = service.start(
|
||||||
file_name=serializer.validated_data["file_name"], file_type=serializer.validated_data["file_type"]
|
file_name=serializer.validated_data["file_name"],
|
||||||
|
file_type=serializer.validated_data["file_type"],
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
|
|
@ -28,6 +29,6 @@ def presign(request):
|
||||||
"id": upload_file.id,
|
"id": upload_file.id,
|
||||||
"name": upload_file.original_file_name,
|
"name": upload_file.original_file_name,
|
||||||
"url": upload_file.url,
|
"url": upload_file.url,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue