def WagtailPageType( model: kocherga.wagtail.models.KochergaPage, db_fields: List[str], related_fields: Dict[str, Union[Tuple[str, g.ObjectType], g.ObjectType]] = {}, extra_fields={}, ): def extend_extra(inner_extra): return {**basic_fields(), **inner_extra} def build_extra(): if isinstance(extra_fields, FunctionType): return extend_extra(extra_fields()) else: return extend_extra(extra_fields) # TODO - because DjangoObjectType orders db_fields before extra_fields, field order for WagtailPage types is # awkward. result = django_utils.DjangoObjectType( model.graphql_type, model, db_fields=db_fields, related_fields=related_fields, extra_fields=build_extra, ) result.interfaces = [types.WagtailPage] return result
from kocherga.auth.schema import types as auth_types from kocherga.graphql import django_utils, g from .. import models Comment = django_utils.DjangoObjectType( 'Comment', model=models.Comment, db_fields=['id', 'created', 'text'], extra_fields={ 'author': g.NN(auth_types.AuthUser), }, ) Commentable = g.InterfaceType( 'Commentable', fields={ 'comments_count': g.NN(g.Int), 'comments': g.NNList(Comment), }, )
from kocherga.wagtail import graphql_utils as wagtail_utils from ... import models TildaPage = django_utils.DjangoObjectType( 'TildaPage', models.TildaPage, db_fields=[ 'id', 'page_id', 'path', 'body', 'title', 'description', 'show_header_and_footer', ], extra_fields=lambda: g.fields( { 'og_image': wagtail_utils.image_rendition_field( models.TildaPage, 'og_image' ), 'assets': g.Field(g.NNList(TildaAsset), resolve=resolve_assets), 'css': g.Field(g.NNList(TildaAsset), resolve=resolve_css), 'js': g.Field(g.NNList(TildaAsset), resolve=resolve_js), 'imported_dt': imported_dt().as_field(), }, ), ) class imported_dt(helpers.BaseField): def resolve(self, obj, info):
from kocherga.graphql import g, helpers, django_utils from kocherga.auth.schema.types import AuthUser from ... import models CashierPayment = django_utils.DjangoObjectType( 'CashierPayment', model=models.Payment, db_fields=['id', 'amount', 'created_dt', 'redeem_dt', 'comment'], method_fields=['is_redeemed'], extra_fields={'whom': g.NN(AuthUser)}, ) CashierPaymentConnection = helpers.ConnectionType(CashierPayment)
from kocherga.graphql import django_utils from ... import models RatioTrainer = django_utils.DjangoObjectType( 'RatioTrainer', models.Trainer, db_fields=['id', 'short_name', 'long_name']) RatioActivity = django_utils.DjangoObjectType( 'RatioActivity', model=models.Activity, db_fields=['id', 'time', 'activity_type', 'name', 'location'], extra_fields={'trainer': RatioTrainer}, ) RatioTrainingDay = django_utils.DjangoObjectType( 'RatioTrainingDay', model=models.TrainingDay, db_fields=['id', 'date'], related_fields={'activities': ('schedule', RatioActivity)}, )
import datetime from kocherga.graphql import django_utils, g, helpers from kocherga.kkm.kkmserver import ( SignMethodCalculation, sign_method_calculation_descriptions, ) from .. import models OfdFiscalDrive = django_utils.DjangoObjectType( 'OfdFiscalDrive', model=models.OfdFiscalDrive, db_fields=[ 'id', 'fiscal_drive_number', ], ) OfdDocument = django_utils.DjangoObjectType( 'OfdDocument', model=models.OfdDocument, db_fields=[ 'id', 'document_id', 'cash', 'electronic', 'check_type', ], extra_fields={ 'created':
from kocherga.graphql import g, django_utils from ... import models EventsGoogleEvent = django_utils.DjangoObjectType( 'EventsGoogleEvent', model=models.GoogleEvent, db_fields=['google_id', 'html_link'], extra_fields={ 'id': g.Field(g.NN(g.ID), resolve=lambda obj, info: obj.google_id) }, # avoid leaking integer ids to public )
from typing import Optional from kocherga.graphql import django_utils from .. import models from kocherga.graphql.permissions import user_perm ZoomMeeting = django_utils.DjangoObjectType( 'ZoomMeeting', model=models.Meeting, db_fields=['id', 'zoom_id', 'join_url'], related_fields=lambda: {'instances': ZoomMeetingInstance}, extra_fields={'participants_count': Optional[int]}, ) ZoomMeetingInstance = django_utils.DjangoObjectType( 'ZoomMeetingInstance', model=models.MeetingInstance, db_fields=['id', 'zoom_uuid', 'start_time', 'end_time'], extra_fields=lambda: { 'participants': django_utils.related_field( models.MeetingInstance, 'participants', item_type=ZoomParticipant, permissions=[user_perm('zoom.view_participants')], ), }, ) ZoomParticipant = django_utils.DjangoObjectType( 'ZoomParticipant',
from kocherga.comments.schema.utils import build_commentable_fields from kocherga.events.schema import types as event_types from kocherga.graphql import django_utils, g, helpers from .. import models, permissions CommunityLeadStatus = g.EnumType('CommunityLeadStatus', models.Lead.Status) CommunityLead = django_utils.DjangoObjectType( 'CommunityLead', model=models.Lead, db_fields=['id', 'name', 'description', 'created', 'updated'], related_fields=lambda: { 'events': event_types.Event, 'initiatives': CommunityInitiative, }, extra_fields={ 'created_by': auth_types.AuthUser, 'curated_by': auth_types.AuthUser, 'status': g.NN(CommunityLeadStatus), **build_commentable_fields(permissions=[permissions.manage_crm]), }, interfaces=[comment_types.Commentable], ) CommunityLeadConnection = helpers.ConnectionType(CommunityLead) # -------------------- CommunityInitiativeStatus = g.EnumType('CommunityInitiativeStatus', models.Initiative.Status)
from kocherga.graphql import g, django_utils, helpers from kocherga.staff.schema import types as staff_types from ... import models ZadarmaCall = django_utils.DjangoObjectType( 'ZadarmaCall', model=models.Call, db_fields=[ 'call_id', 'ts', 'call_type', 'disposition', 'clid', 'destination', 'sip', 'is_recorded', 'watchman', ], extra_fields=lambda: { 'record': record_field(), 'id': g.Field(g.NN(g.ID), resolve=lambda obj, info: obj.call_id), }, ) def record_field(): def resolve(obj, info): return obj.record.url if obj.record else None
from kocherga.graphql import django_utils from kocherga.wagtail import graphql_utils as wagtail_utils from .. import models def TelegramChat_extra_fields(): from kocherga.projects.schema.types import ProjectPage return { 'photo': wagtail_utils.image_rendition_field(models.Chat, 'photo'), 'project': ProjectPage, 'link': str, } TelegramChat = django_utils.DjangoObjectType( 'TelegramChat', model=models.Chat, db_fields=['id', 'username', 'title', 'force_public', 'delisted'], extra_fields=TelegramChat_extra_fields, )
from kocherga.graphql import g, django_utils from kocherga.staff.schema import types as staff_types from .. import models WatchmenGrade = django_utils.DjangoObjectType( 'WatchmenGrade', model=models.Grade, db_fields=['id', 'code', 'multiplier']) WatchmenShift = django_utils.DjangoObjectType( 'WatchmenShift', model=models.Shift, db_fields=['date', 'shift', 'is_night'], extra_fields=lambda: { 'id': g.Field(g.NN(g.ID), resolve=lambda obj, info: f"{obj.date}:{obj.shift}"), 'watchman': WatchmenWatchman, }, ) WatchmenWatchman = django_utils.DjangoObjectType( 'WatchmenWatchman', model=models.Watchman, db_fields=['id', 'priority'], extra_fields=lambda: { 'member': g.NN(staff_types.StaffMember), 'grade': WatchmenGrade, }, )
from kocherga.graphql import django_utils from ... import models EventsGoogleCalendar = django_utils.DjangoObjectType( 'EventsGoogleCalendar', model=models.GoogleCalendar, db_fields=['id'], extra_fields={'url': str}, )
args = helpers.connection_args() result = g.NN(RatioPromocodeConnection) RatioTraining = django_utils.DjangoObjectType( 'RatioTraining', model=models.Training, db_fields=[ 'id', 'name', 'slug', 'training_type', 'date', 'telegram_link', 'salaries_paid', 'discount_by_email', 'discount_percent_by_email', 'promocode_email', 'new_ticket_email', 'notion_created_email', ], related_fields=related_fields, method_fields=['tickets_count', 'total_income'], extra_fields={ **fields.as_dict(), }, ) RatioTrainingConnection = helpers.ConnectionType(RatioTraining)
('WagtailRootPagePermission' if obj.page.is_root() else 'WagtailSpecificPagePermission'), ) # AuthGroup is very private so we don't need additional checks here permissions = [] def resolve(self, group, info): return group.page_permissions.all() result = g.NNList(WagtailPagePermission) AuthGroup = django_utils.DjangoObjectType( 'AuthGroup', model=auth_models.Group, db_fields=[ 'id', 'name', ], related_fields={ 'permissions': AuthPermission, }, extra_fields={ 'users': g.Field(g.NNList(AuthUser), resolve=lambda obj, info: obj.user_set.all()), **c.as_dict(), }, )