Example #1
0
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,
    }
Example #2
0
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):
        return obj.imported_dt

    permissions = [permissions.staffonly]
Example #3
0
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,
        ),
    })
Example #4
0
    'RatioTestimonialProduct',
    model=models.TestimonialProduct,
    db_fields=[
        'id',
        'title',
        'color',
        'link',
    ],
)

RatioTestimonial = DjangoObjectType(
    'RatioTestimonial',
    model=models.Testimonial,
    db_fields=[
        'id',
        'author_name',
        'author_description',
    ],
    extra_fields={
        'author_image':
        wagtail_utils.image_rendition_field(models.Testimonial,
                                            'author_image'),
        'text':
        wagtail_utils.richtext_field(models.Testimonial, 'text'),
        'product':
        RatioTestimonialProduct,
    },
)

RatioTestimonialConnection = helpers.ConnectionType(RatioTestimonial)
Example #5
0
                '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(),
        'instances':
        instances_field(),
        'vk_group':
        vk_group_field(),
        'timepad_category':
        timepad_category_field(),
    }),
)


def suggested_dates_field():
    def resolve(obj, info, limit, until_ts=None, from_date=None, to_date=None):
        from_date_parsed = None
Example #6
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 = []
Example #7
0
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(
Example #8
0
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,
        ),
    },
)


class ProjectIndexPage_projects(helpers.BaseField):
    def resolve(self, _, info, is_active=None):
        qs = models.ProjectPage.objects.all().live()
Example #9
0
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',
    {**django_utils.model_fields(models.FbAnnouncement, ['link', 'group'])},
)

EventsAnnouncements = g.ObjectType(
    'EventsAnnouncements',
    g.fields({
        'timepad': g.NN(EventsAnnouncementTimepad),
        'vk': g.NN(EventsAnnouncementVk),
        'fb': g.NN(EventsAnnouncementFb),
    }),