예제 #1
0
파일: types.py 프로젝트: KochergaClub/core
from kocherga.graphql import g, django_utils
from kocherga.wagtail import graphql_utils as wagtail_utils

from kocherga.wagtail.schema.types import WagtailPage

from .. import models

FaqEntry = g.ObjectType(
    'FaqEntry',
    g.fields({
        **django_utils.model_fields(models.Entry, ['id', 'question']),
        'answer':
        wagtail_utils.richtext_field(models.Entry, 'answer'),
    }),
)

FaqPage = g.ObjectType(
    'FaqPage',
    interfaces=[WagtailPage],
    fields=lambda: g.fields({
        **wagtail_utils.basic_fields(),
        **django_utils.model_fields(models.FAQPage, ['title', 'summary']),
        'prev_page':
        FaqPage,
        'next_page':
        FaqPage,
        'entries':
        django_utils.related_field(
            models.FAQPage, 'entries', item_type=FaqEntry),
        'subpages':
        g.NNList(FaqPage),
예제 #2
0
파일: event.py 프로젝트: KochergaClub/core
def build_event_fields():
    def description_field():
        def resolve(obj, info, format=None):
            # PLAIN is default for now, for backward-compatibility
            if format == 'PLAIN' or format is None:
                return markup.Markup(obj.description).as_plain()
            elif format == 'SOURCE' or format is None:
                return obj.description
            else:
                raise Exception(f"Unknown markup format {format}")

        args = g.arguments({'format': EventsMarkupFormat})
        return g.Field(g.NN(g.String), args=args, resolve=resolve)

    def resolve_public_tags(obj, info):
        return obj.public_tag_names()

    def tags_field():
        @check_permissions([permissions.manage_events])
        def resolve(obj, info):
            return obj.tag_names()

        return g.Field(g.NNList(g.String), resolve=resolve)

    def room_field():
        @check_permissions([permissions.manage_events])
        def resolve(obj, info):
            return obj.get_room()

        return g.Field(g.NN(g.String), resolve=resolve)

    def my_ticket_field():
        # note that there's no @auth decorator - we don't want any errors if user is not authenticated
        def resolve(obj, info):
            if not info.context.user.is_authenticated:
                return None  # not authorized, no ticket, but that's ok

            ticket = obj.tickets.filter(user=info.context.user).first()
            return ticket

        # lazy import - avoiding circular dependency
        from .my_ticket import MyEventsTicket

        return g.Field(MyEventsTicket, resolve=resolve)

    def announcements_field():
        from .announcements import EventsAnnouncements

        def resolve(obj, info):
            return {
                'timepad': getattr(obj, 'timepad_announcement', None),
                'vk': getattr(obj, 'vk_announcement', None),
                'fb': getattr(obj, 'fb_announcement', None),
            }

        return g.Field(g.NN(EventsAnnouncements), resolve=resolve)

    from .google_event import EventsGoogleEvent

    class public_google_event_field(helpers.BaseField):
        def resolve(self, obj, info):
            return obj.public_google_event()

        permissions = []
        result = EventsGoogleEvent

    from .feedback import EventsFeedback
    from .prototype import EventsPrototype
    from .ticket import EventsTicket
    from .youtube_video import EventsYoutubeVideo

    return g.fields({
        **django_utils.model_fields(
            models.Event,
            [
                'start',
                'end',
                'title',
                'summary',
                'registration_type',
                'pricing_type',
                'realm',
                'published',
                'event_type',
            ],
        ),
        'id':
        g.Field(g.NN(g.ID), resolve=lambda obj, info: obj.uuid),
        'event_id':
        g.Field(g.NN(g.ID), resolve=lambda obj, info: obj.uuid
                ),  # deprecated, use `id` instead
        'description':
        description_field(),
        'stream_body':
        g.NNList(WagtailBlock),
        'image':
        wagtail_utils.image_rendition_field(models.Event, 'image'),
        'project':
        ProjectPage,
        'public_tags':
        g.Field(g.NNList(g.String), resolve=resolve_public_tags),
        'announcements':
        announcements_field(),
        # signed-in fields
        'my_ticket':
        my_ticket_field(),
        # private fields
        'tags':
        tags_field(),
        'public_google_event':
        public_google_event_field().as_field(),
        'zoom_meeting':
        helpers.field_with_permissions(zoom_types.ZoomMeeting,
                                       [permissions.manage_events]),
        'prototype':
        helpers.field_with_permissions(EventsPrototype,
                                       [permissions.manage_events]),
        'visitors':
        helpers.field_with_permissions(g.String, [permissions.manage_events]),
        'creator':
        helpers.field_with_permissions(g.String, [permissions.manage_events]),
        'created':
        helpers.field_with_permissions(g.NN(g.String),
                                       [permissions.manage_events]),
        'updated':
        helpers.field_with_permissions(g.NN(g.String),
                                       [permissions.manage_events]),
        'location':
        helpers.field_with_permissions(g.NN(g.String),
                                       [permissions.manage_events]),
        'room':
        room_field(),
        'zoom_link':
        helpers.field_with_permissions(g.NN(g.String),
                                       [permissions.manage_events]),
        'timing_description_override':
        helpers.field_with_permissions(g.NN(g.String),
                                       [permissions.manage_events]),
        'tickets':
        django_utils.related_field(
            models.Event,
            'tickets',
            item_type=EventsTicket,
            permissions=[permissions.manage_events],
        ),
        'feedbacks':
        django_utils.related_field(
            models.Event,
            'feedbacks',
            item_type=EventsFeedback,
            permissions=[permissions.manage_events],
        ),
        'youtube_videos':
        django_utils.related_field(
            models.Event,
            'youtube_videos',
            item_type=EventsYoutubeVideo,
        ),
    })
예제 #3
0
from typing import Optional

from kocherga.graphql import django_utils, g, helpers
from kocherga.wagtail import graphql_utils as wagtail_utils

from ... import models

EventsWeeklyDigest = g.ObjectType(
    'EventsWeeklyDigest',
    lambda: g.fields({
        **django_utils.model_fields(models.WeeklyDigest, ['id', 'start']),
        'image':
        wagtail_utils.image_rendition_field(models.WeeklyDigest, 'image'),
        'mailchimp':
        mailchimp_field().as_field(),
        'telegram':
        telegram_field().as_field(),
        'vk':
        vk_field().as_field(),
    }),
)


class mailchimp_field(helpers.BaseField):
    def resolve(self, obj, info):
        return {
            'link': obj.mailchimp_campaign_link(),
            'is_sent': obj.mailchimp_sent,
        }

    permissions = []
예제 #4
0
from .announcements import TimepadCategory, VkGroup
from .event import Event

EventsPrototype = g.ObjectType(
    'EventsPrototype',
    lambda: g.fields({
        'id':
        g.Field(g.NN(g.ID), resolve=lambda obj, info: obj.prototype_id),
        **django_utils.model_fields(
            models.EventPrototype,
            [
                'title',
                'summary',
                'description',
                'location',
                'timing_description_override',
                'active',
                'weekday',
                'hour',
                'minute',
                'length',
            ],
        ),
        'project':
        g.Field(ProjectPage),
        'tags':
        tags_field(),
        'image':
        wagtail_utils.image_rendition_field(models.EventPrototype, 'image'),
        'suggested_dates':
        suggested_dates_field(),
예제 #5
0
파일: types.py 프로젝트: KochergaClub/core
from kocherga.graphql import g
from kocherga.graphql import django_utils
from kocherga.wagtail import graphql_utils as wagtail_utils
from kocherga.wagtail.schema.types import WagtailPage

from .. import models

BlogPostAuthor = g.ObjectType(
    'BlogPostAuthor',
    {
        **django_utils.model_fields(models.BlogPostAuthor, ['name', 'description']),
        'image': wagtail_utils.image_rendition_field(models.BlogPostAuthor, 'image'),
    },
)


BlogPostPage = g.ObjectType(
    'BlogPostPage',
    interfaces=[WagtailPage],
    fields={
        **wagtail_utils.basic_fields(),
        **django_utils.model_fields(models.BlogPostPage, ['title', 'date', 'summary']),
        'body': wagtail_utils.richtext_field(models.BlogPostPage, 'body'),
        'authors': django_utils.related_field(
            models.BlogPostPage, 'authors', item_type=BlogPostAuthor
        ),
    },
)


BlogIndexPage = g.ObjectType(
예제 #6
0
from kocherga.wagtail.schema.types import WagtailPage

from .. import models

from kocherga.wagtail.utils import filter_queryset_by_page_permissions
from kocherga.events.schema import types as event_types
from kocherga.telegram.schema import types as telegram_types

ProjectPage = g.ObjectType(
    'ProjectPage',
    interfaces=[WagtailPage],
    fields=lambda: {
        **wagtail_utils.basic_fields(),
        **django_utils.model_fields(
            models.ProjectPage,
            ['title', 'summary', 'activity_summary', 'is_active'],
        ),
        'body':
        wagtail_utils.richtext_field(models.ProjectPage, 'body'),
        'image':
        wagtail_utils.image_rendition_field(models.ProjectPage, 'image'),
        'upcoming_events':
        g.Field(g.NNList(event_types.Event)),
        'telegram_chats':
        django_utils.related_field(
            models.ProjectPage,
            field_name='telegram_chats',
            item_type=telegram_types.TelegramChat,
        ),
    },
)
예제 #7
0
# might be moved to kocherga.vk some day
VkGroup = g.ObjectType('VkGroup', g.fields({'name': str}))

# might be moved to kocherga.timepad some day
TimepadCategory = g.ObjectType(
    'TimepadCategory', g.fields({
        'id': 'ID!',
        'code': str,
        'name': str
    }))

EventsAnnouncementTimepad = g.ObjectType(
    'EventsAnnouncementTimepad',
    {
        **django_utils.model_fields(models.TimepadAnnouncement, [
            'link', 'category_code', 'prepaid_tickets'
        ])
    },
)

EventsAnnouncementVk = g.ObjectType(
    'EventsAnnouncementVk',
    {
        **django_utils.model_fields(models.VkAnnouncement, ['link', 'group']),
        'image':
        wagtail_utils.image_rendition_field(models.VkAnnouncement, 'image'),
    },
)

EventsAnnouncementFb = g.ObjectType(
    'EventsAnnouncementFb',
예제 #8
0
from kocherga.graphql import g, django_utils
import kocherga.auth.schema.types as auth_types

from ... import models

from kocherga.events.schema import types as event_types


# type MastermindDatingCohort


MastermindDatingCohort = g.ObjectType(
    'MastermindDatingCohort',
    fields=lambda: {
        **django_utils.model_fields(models.Cohort, ['id', 'leader_telegram_uid']),
        'event': g.Field(event_types.Event),
        'participants': django_utils.related_field(
            models.Cohort, 'participants', item_type=MastermindDatingParticipant
        ),
        'groups': django_utils.related_field(
            models.Cohort, 'groups', item_type=MastermindDatingGroup,
        ),
    },
)


# type MastermindDatingParticipant


def resolve_MastermindDatingParticipant_photo(obj, info):
    return obj.photo.url if obj.photo else None
예제 #9
0
    return obj.orders().count()


# TODO - pager
def resolve_MyCmCustomer_orders(obj, info):
    return obj.orders().order_by('-order_id')[:10]


MyCmCustomer = g.ObjectType(
    'MyCmCustomer',
    g.fields({
        **django_utils.model_fields(
            models.Customer,
            [
                'card_id',
                'subscription_until',
                'last_visit',
                'total_spent',
                'privacy_mode',
            ],
        ),
        'orders_count':
        g.Field(g.NN(g.Int), resolve=lambda obj, info: obj.orders().count()),
        'orders':
        g.Field(g.NNList(MyCmOrder), resolve=resolve_MyCmCustomer_orders),
    }),
)


@c.field
def membership(helper):
    @permissions.check_permissions([permissions.authenticated])