Add simple graphql types for CourseSessionAttendanceCourse
This commit is contained in:
parent
7e8773cd17
commit
a75bb14e4c
|
|
@ -127,6 +127,15 @@ export type CoursePageInterface = {
|
||||||
translation_key?: Maybe<Scalars['String']['output']>;
|
translation_key?: Maybe<Scalars['String']['output']>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CourseSessionAttendanceCourseType = {
|
||||||
|
__typename?: 'CourseSessionAttendanceCourseType';
|
||||||
|
end?: Maybe<Scalars['DateTime']>;
|
||||||
|
id: Scalars['ID'];
|
||||||
|
location: Scalars['String'];
|
||||||
|
start?: Maybe<Scalars['DateTime']>;
|
||||||
|
trainer: Scalars['String'];
|
||||||
|
};
|
||||||
|
|
||||||
export type CourseType = {
|
export type CourseType = {
|
||||||
__typename?: 'CourseType';
|
__typename?: 'CourseType';
|
||||||
category_name: Scalars['String']['output'];
|
category_name: Scalars['String']['output'];
|
||||||
|
|
@ -216,6 +225,7 @@ export type Query = {
|
||||||
assignment?: Maybe<AssignmentObjectType>;
|
assignment?: Maybe<AssignmentObjectType>;
|
||||||
assignment_completion?: Maybe<AssignmentCompletionObjectType>;
|
assignment_completion?: Maybe<AssignmentCompletionObjectType>;
|
||||||
course?: Maybe<CourseType>;
|
course?: Maybe<CourseType>;
|
||||||
|
course_session_attendance_course?: Maybe<CourseSessionAttendanceCourseType>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -236,6 +246,12 @@ export type QueryCourseArgs = {
|
||||||
id?: InputMaybe<Scalars['Int']['input']>;
|
id?: InputMaybe<Scalars['Int']['input']>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export type QueryCourse_Session_Attendance_CourseArgs = {
|
||||||
|
assignment_user_id?: InputMaybe<Scalars['ID']>;
|
||||||
|
id: Scalars['ID'];
|
||||||
|
};
|
||||||
|
|
||||||
export type SendFeedbackInput = {
|
export type SendFeedbackInput = {
|
||||||
clientMutationId?: InputMaybe<Scalars['String']['input']>;
|
clientMutationId?: InputMaybe<Scalars['String']['input']>;
|
||||||
course_session: Scalars['Int']['input'];
|
course_session: Scalars['Int']['input'];
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,25 @@
|
||||||
type Query {
|
type Query {
|
||||||
|
course_session_attendance_course(id: ID!, assignment_user_id: ID): CourseSessionAttendanceCourseType
|
||||||
course(id: Int): CourseType
|
course(id: Int): CourseType
|
||||||
assignment(id: ID, slug: String): AssignmentObjectType
|
assignment(id: ID, slug: String): AssignmentObjectType
|
||||||
assignment_completion(assignment_id: ID!, course_session_id: ID!, assignment_user_id: ID): AssignmentCompletionObjectType
|
assignment_completion(assignment_id: ID!, course_session_id: ID!, assignment_user_id: ID): AssignmentCompletionObjectType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CourseSessionAttendanceCourseType {
|
||||||
|
id: ID!
|
||||||
|
location: String!
|
||||||
|
trainer: String!
|
||||||
|
end: DateTime
|
||||||
|
start: DateTime
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
The `DateTime` scalar type represents a DateTime
|
||||||
|
value as specified by
|
||||||
|
[iso8601](https://en.wikipedia.org/wiki/ISO_8601).
|
||||||
|
"""
|
||||||
|
scalar DateTime
|
||||||
|
|
||||||
type CourseType {
|
type CourseType {
|
||||||
id: ID!
|
id: ID!
|
||||||
title: String!
|
title: String!
|
||||||
|
|
@ -63,13 +79,6 @@ interface CoursePageInterface {
|
||||||
frontend_url: String
|
frontend_url: String
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
|
||||||
The `DateTime` scalar type represents a DateTime
|
|
||||||
value as specified by
|
|
||||||
[iso8601](https://en.wikipedia.org/wiki/ISO_8601).
|
|
||||||
"""
|
|
||||||
scalar DateTime
|
|
||||||
|
|
||||||
type UserType {
|
type UserType {
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@ import graphene
|
||||||
from vbv_lernwelt.assignment.graphql.mutations import AssignmentMutation
|
from vbv_lernwelt.assignment.graphql.mutations import AssignmentMutation
|
||||||
from vbv_lernwelt.assignment.graphql.queries import AssignmentQuery
|
from vbv_lernwelt.assignment.graphql.queries import AssignmentQuery
|
||||||
from vbv_lernwelt.course.schema import CourseQuery
|
from vbv_lernwelt.course.schema import CourseQuery
|
||||||
|
from vbv_lernwelt.course_session.graphql.queries import CourseSessionQuery
|
||||||
from vbv_lernwelt.feedback.graphql.mutations import FeedbackMutation
|
from vbv_lernwelt.feedback.graphql.mutations import FeedbackMutation
|
||||||
|
|
||||||
|
|
||||||
class Query(AssignmentQuery, CourseQuery, graphene.ObjectType):
|
class Query(AssignmentQuery, CourseQuery, CourseSessionQuery, graphene.ObjectType):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
import structlog
|
||||||
|
|
||||||
|
logger = structlog.get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CourseSessionMutation:
|
||||||
|
pass
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
import graphene
|
||||||
|
from rest_framework.exceptions import PermissionDenied
|
||||||
|
|
||||||
|
from vbv_lernwelt.course.models import CourseSession
|
||||||
|
from vbv_lernwelt.course.permissions import has_course_access, is_course_session_expert
|
||||||
|
from vbv_lernwelt.course_session.graphql.types import CourseSessionAttendanceCourseType
|
||||||
|
from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse
|
||||||
|
|
||||||
|
|
||||||
|
class CourseSessionQuery(object):
|
||||||
|
course_session_attendance_course = graphene.Field(
|
||||||
|
CourseSessionAttendanceCourseType,
|
||||||
|
id=graphene.ID(required=True),
|
||||||
|
assignment_user_id=graphene.ID(required=False),
|
||||||
|
)
|
||||||
|
|
||||||
|
def resolve_course_session_attendance_course(
|
||||||
|
root,
|
||||||
|
info,
|
||||||
|
id=None,
|
||||||
|
user_id=graphene.ID(required=False),
|
||||||
|
):
|
||||||
|
if user_id is None:
|
||||||
|
user_id = info.context.user.id
|
||||||
|
|
||||||
|
attendance_course = CourseSessionAttendanceCourse.objects.filter(
|
||||||
|
id=id,
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if attendance_course is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if str(user_id) == str(info.context.user.id) or is_course_session_expert(
|
||||||
|
info.context.user, attendance_course.course_session_id
|
||||||
|
):
|
||||||
|
course_id = CourseSession.objects.get(
|
||||||
|
id=attendance_course.course_session_id
|
||||||
|
).course_id
|
||||||
|
if has_course_access(info.context.user, course_id):
|
||||||
|
return attendance_course
|
||||||
|
raise PermissionDenied()
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
import graphene
|
||||||
|
from graphene_django import DjangoObjectType
|
||||||
|
|
||||||
|
from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse
|
||||||
|
|
||||||
|
|
||||||
|
class CourseSessionAttendanceCourseType(DjangoObjectType):
|
||||||
|
course_session_id = graphene.ID(source="course_session_id")
|
||||||
|
learning_content_id = graphene.ID(source="learning_content_id")
|
||||||
|
due_date_id = graphene.ID(source="due_date_id")
|
||||||
|
end = graphene.DateTime()
|
||||||
|
start = graphene.DateTime()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CourseSessionAttendanceCourse
|
||||||
|
fields = (
|
||||||
|
"id",
|
||||||
|
"course_session_id",
|
||||||
|
"learning_content_id",
|
||||||
|
"due_date_id",
|
||||||
|
"location",
|
||||||
|
"trainer",
|
||||||
|
"start",
|
||||||
|
"end",
|
||||||
|
# "attendance_user_list",
|
||||||
|
)
|
||||||
|
|
||||||
|
def resolve_start(self, info):
|
||||||
|
if self.due_date is None:
|
||||||
|
return None
|
||||||
|
return self.due_date.start
|
||||||
|
|
||||||
|
def resolve_end(self, info):
|
||||||
|
if self.due_date is None:
|
||||||
|
return None
|
||||||
|
return self.due_date.end
|
||||||
|
|
@ -14,7 +14,7 @@ class CourseSessionAttendanceCourseSerializer(serializers.ModelSerializer):
|
||||||
model = CourseSessionAttendanceCourse
|
model = CourseSessionAttendanceCourse
|
||||||
fields = [
|
fields = [
|
||||||
"id",
|
"id",
|
||||||
"course_session_id",
|
"course_session",
|
||||||
"learning_content_id",
|
"learning_content_id",
|
||||||
"due_date_id",
|
"due_date_id",
|
||||||
"location",
|
"location",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from graphene_django.utils.testing import GraphQLTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class MyFancyTestCase(GraphQLTestCase):
|
||||||
|
def test_some_query(self):
|
||||||
|
response = self.query(
|
||||||
|
"""
|
||||||
|
query {
|
||||||
|
myModel {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
op_name="myModel",
|
||||||
|
)
|
||||||
|
|
||||||
|
content = json.loads(response.content)
|
||||||
|
|
||||||
|
# This validates the status code and if you get errors
|
||||||
|
self.assertResponseNoErrors(response)
|
||||||
|
|
||||||
|
# Add some more asserts if you like
|
||||||
|
...
|
||||||
Loading…
Reference in New Issue