コード例 #1
0
class CustomImage(AbstractImage):
    license = models.ForeignKey(
        "utils.LicenseSnippet",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )
    description = models.TextField(
        blank=True,
        max_length=165,
    )
    author = models.CharField(
        blank=True,
        max_length=165,
        null=True,
    )
    image_source_url = models.URLField(blank=True)

    admin_form_fields = Image.admin_form_fields + (
        "description",
        "author",
        "license",
        "image_source_url",
    )

    graphql_fields = [
        GraphQLSnippet("license", snippet_model="utils.Button"),
        GraphQLString("description"),
        GraphQLString("author"),
        GraphQLBoolean("image_source_url"),
    ]
コード例 #2
0
class Button(models.Model):
    button_title = models.CharField(null=True, blank=False, max_length=255)
    button_embed = models.CharField(null=True, blank=True, max_length=255)
    button_link = models.URLField(null=True, blank=True)
    button_page = models.ForeignKey(
        "wagtailcore.Page",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )

    graphql_fields = [
        GraphQLString("button_title"),
        GraphQLString("button_embed"),
        GraphQLString("button_link"),
        GraphQLPage("button_page"),
    ]

    panels = [
        FieldPanel("button_title"),
        FieldPanel("button_embed"),
        FieldPanel("button_link"),
        PageChooserPanel("button_page"),
    ]

    def __str__(self):
        return self.button_title
コード例 #3
0
ファイル: models.py プロジェクト: aichner/wagtail-template
class _S_SmallBlock(blocks.StructBlock):
    charblock = blocks.CharBlock()
    textblock = blocks.TextBlock()
    emailblock = blocks.EmailBlock()

    graphql_fields = [
        GraphQLString("charblock"),
        GraphQLString("textblock"),
        GraphQLString("emailblock"),
    ]
コード例 #4
0
ファイル: models.py プロジェクト: aichner/wagtail-template
class _S_BigBlock(blocks.StructBlock):
    integerblock = blocks.IntegerBlock()
    floatblock = blocks.FloatBlock()
    decimalblock = blocks.DecimalBlock()
    regexblock = blocks.RegexBlock(regex="")
    urlblock = blocks.URLBlock()
    booleanblock = blocks.BooleanBlock()
    dateblock = blocks.DateBlock()

    graphql_fields = [
        GraphQLInt("integerblock"),
        GraphQLFloat("floatblock"),
        GraphQLFloat("decimalblock"),
        GraphQLString("regexblock"),
        GraphQLString("urlblock"),
        GraphQLBoolean("booleanblock"),
        GraphQLString("dateblock"),
    ]
コード例 #5
0
class TagBlock(blocks.StructBlock):
    SIGNIFICANCE_CHOICES = [
        ("success", "Success"),
        ("danger", "Danger"),
        ("warning", "Warning"),
        ("info", "Info"),
        ("light", "Light"),
        ("dark", "Dark"),
    ]
    name = blocks.CharBlock(required=True, max_length=16)
    significance = blocks.ChoiceBlock(
        choices=SIGNIFICANCE_CHOICES, required=True, icon="cup"
    )

    graphql_fields = [
        GraphQLString("name"),
        GraphQLString("significance"),
    ]
コード例 #6
0
ファイル: models.py プロジェクト: snek-shipyard/ohrwurm
class ProjectAudioChannel(index.Indexed, ClusterableModel):
    title = models.CharField(null=True, blank=False, max_length=250)
    description = models.TextField(null=True, blank=True)
    channel_id = models.CharField(null=True, blank=True, max_length=250)
    avatar_image = models.ForeignKey(
        settings.WAGTAILIMAGES_IMAGE_MODEL,
        null=True,
        blank=True,
        related_name="+",
        on_delete=models.SET_NULL,
    )
    members = ParentalManyToManyField(get_user_model(),
                                      related_name="pacs",
                                      null=True,
                                      blank=True)

    search_fields = [
        index.SearchField("title"),
        index.SearchField("created_at"),
        index.SearchField("description"),
        index.FilterField("snekuser_id"),
    ]

    graphql_fields = [
        GraphQLString("title", required=True),
        GraphQLString("description"),
        GraphQLString("channel_id"),
        GraphQLImage("avatar_image"),
        GraphQLCollection(GraphQLForeignKey, "members", get_user_model()),
    ]

    def __str__(self):
        return f"{self.title}"

    @classmethod
    @login_required
    def bifrost_queryset(cls, info, **kwargs):
        return cls.objects.filter(members=info.context.user)
コード例 #7
0
ファイル: models.py プロジェクト: aichner/wagtail-template
class _S_LightBlock(blocks.StructBlock):
    documentchooserblock = docblocks.DocumentChooserBlock()
    imagechooserblock = ImageChooserBlock()
    snippetchooserblock = SnippetChooserBlock(target_model="utils.Button")
    embedblock = EmbedBlock()
    staticblock = blocks.StaticBlock()

    graphql_fields = [
        GraphQLDocument("documentchooserblock"),
        GraphQLImage("imagechooserblock"),
        GraphQLSnippet("snippetchooserblock", snippet_model="utils.Button"),
        GraphQLEmbed("embedblock"),
        GraphQLString("staticblock"),
    ]
コード例 #8
0
ファイル: models.py プロジェクト: snek-shipyard/ohrwurm
class SNEKUser(AbstractUser, ClusterableModel):
    username = models.CharField(
        "username",
        null=True,
        blank=False,
        error_messages={"unique": "A user with that username already exists."},
        help_text="Required. 36 characters or fewer. Letters, digits and @/./+/-/_ only.",
        max_length=36,
        unique=True,
        validators=[django.contrib.auth.validators.UnicodeUsernameValidator()],
    )
    password_changed = models.BooleanField(default=False)
    telegram_user_id = models.CharField(null=True, blank=True, max_length=250)

    def is_ohrwurm_supervisor(self, info, **kwargs):
        return self.groups.filter(name="ohrwurm-supervisor").exists()

    # Custom save function
    def save(self, *args, **kwargs):
        super(SNEKUser, self).save(*args, **kwargs)

    panels = [
        FieldPanel("username"),
        MultiFieldPanel(
            [
                FieldPanel("is_active"),
                FieldPanel("password_changed"),
            ],
            "Settings",
        ),
        MultiFieldPanel(
            [
                FieldPanel("telegram_user_id"),
            ],
            "Telegram",
        ),
    ]

    graphql_fields = [
        GraphQLString("username"),
        GraphQLBoolean("is_active"),
        GraphQLBoolean("is_ohrwurm_supervisor"),
        GraphQLBoolean("password_changed"),
        GraphQLCollection(GraphQLForeignKey, "pacs", "track.ProjectAudioChannel"),
    ]

    def __str__(self):
        return self.username
コード例 #9
0
ファイル: models.py プロジェクト: aichner/wagtail-template
class _S_TallBlock(blocks.StructBlock):
    timeblock = blocks.TimeBlock()
    datetimeblock = blocks.DateTimeBlock()
    richtextblock = blocks.RichTextBlock()
    rawhtmlblock = blocks.RawHTMLBlock()
    blockquoteblock = blocks.BlockQuoteBlock()
    choiceblock = blocks.ChoiceBlock(choices=[
        ("apples", "Apple"),
        ("bananas", "Bananas"),
    ])

    graphql_fields = [
        GraphQLString("timeblock"),
        GraphQLString("datetimeblock"),
        GraphQLString("richtextblock"),
        GraphQLString("rawhtmlblock"),
        GraphQLString("blockquoteblock"),
        GraphQLString("choiceblock"),
    ]
コード例 #10
0
class SNEKDocument(AbstractDocument):
    description = models.TextField(max_length=255, blank=True, null=True)
    admin_form_fields = WagtailDocument.admin_form_fields + ("description",)

    graphql_fields = (GraphQLString("description"),)
コード例 #11
0
ファイル: models.py プロジェクト: aichner/wagtail-template
class HomePage(Page):
    # Only allow creating HomePages at the root level
    parent_page_types = ["wagtailcore.Page"]

    bigintegerfield = models.BigIntegerField(blank=False, null=True)
    booleanfield = models.BooleanField(blank=False, null=True)
    charfield = models.CharField(max_length=22, blank=False, null=True)
    datefield = models.DateField(blank=False, null=True)
    datetimefield = models.DateTimeField(blank=False, null=True)
    decimalfield = models.DecimalField(decimal_places=5,
                                       max_digits=22,
                                       blank=False,
                                       null=True)
    durationfield = models.DurationField(blank=False, null=True)
    emailfield = models.EmailField(blank=False, null=True)
    floatfield = models.FloatField(blank=False, null=True)
    imagefield = models.ForeignKey(
        settings.WAGTAILIMAGES_IMAGE_MODEL,
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
    )
    integerfield = models.IntegerField(blank=False, null=True)
    genericipaddressfield = models.GenericIPAddressField(blank=False,
                                                         null=True)
    nullbooleanfield = models.NullBooleanField(blank=False, null=True)
    positiveintegerfield = models.PositiveIntegerField(blank=False, null=True)
    positivesmallintegerfield = models.SmallIntegerField(blank=False,
                                                         null=True)
    slugfield = models.SlugField(blank=False, null=True)
    smallintegerfield = models.SmallIntegerField(blank=False, null=True)
    textfield = models.TextField(blank=False, null=True)
    timefield = models.TimeField(blank=False, null=True)
    urlfield = models.URLField(blank=False, null=True)
    uuidfield = models.UUIDField(blank=False, null=True, default=uuid.uuid4)

    sections = fields.StreamField(
        [
            ("s_smallblock", _S_SmallBlock()),
            ("s_bigblock", _S_BigBlock()),
            ("s_tallblock", _S_TallBlock()),
            ("s_lightblock", _S_LightBlock()),
        ],
        null=True,
        blank=False,
    )

    graphql_fields = [
        GraphQLInt("bigintegerfield"),
        GraphQLInt("binaryfield"),
        GraphQLBoolean("booleanfield"),
        GraphQLString("charfield"),
        GraphQLString("datefield"),
        GraphQLString("datetimefield"),
        GraphQLFloat("decimalfield"),
        GraphQLString("durationfield"),
        GraphQLString("emailfield"),
        GraphQLString("filepathfield"),
        GraphQLFloat("floatfield"),
        GraphQLInt("integerfield"),
        GraphQLString("genericipaddressfield"),
        GraphQLBoolean("nullbooleanfield"),
        GraphQLInt("positiveintegerfield"),
        GraphQLString("slugfield"),
        GraphQLInt("smallintegerfield"),
        GraphQLString("textfield"),
        GraphQLString("timefield"),
        GraphQLString("urlfield"),
        GraphQLString("uuidfield"),
        GraphQLStreamfield("sections"),
        GraphQLInt("positivesmallintegerfield"),
    ]

    main_content_panels = [
        FieldPanel("bigintegerfield"),
        FieldPanel("booleanfield"),
        FieldPanel("charfield"),
        FieldPanel("datefield"),
        FieldPanel("datetimefield"),
        FieldPanel("decimalfield"),
        FieldPanel("durationfield"),
        FieldPanel("emailfield"),
        FieldPanel("floatfield"),
        ImageChooserPanel("imagefield"),
        FieldPanel("integerfield"),
        FieldPanel("genericipaddressfield"),
        FieldPanel("nullbooleanfield"),
        FieldPanel("positiveintegerfield"),
        FieldPanel("positivesmallintegerfield"),
        FieldPanel("slugfield"),
        FieldPanel("smallintegerfield"),
        FieldPanel("textfield"),
        FieldPanel("timefield"),
        FieldPanel("urlfield"),
        FieldPanel("uuidfield"),
        StreamFieldPanel("sections"),
    ]

    content_panels = Page.content_panels + main_content_panels
コード例 #12
0
ファイル: models.py プロジェクト: snek-shipyard/ohrwurm
class Track(index.Indexed, TimeStampMixin):
    title = models.CharField(null=True, blank=False, max_length=250)
    audio_file = models.FileField(upload_to="tracks/",
                                  blank=True,
                                  validators=[validate_audio_file])
    audio_channel = models.CharField(null=True, blank=True, max_length=250)
    audio_format = models.CharField(null=True, blank=True, max_length=250)
    audio_codec = models.CharField(null=True, blank=True, max_length=250)
    audio_bitrate = models.CharField(null=True, blank=True, max_length=250)
    description = models.TextField(null=True, blank=True)
    tags = StreamField([("tag", TagBlock(required=True, icon="tag"))],
                       blank=True)
    attendees = StreamField(
        [("attendee", AttendeeBlock(required=True, icon="user"))], blank=True)
    transcript = models.TextField(null=True, blank=True)
    pac = ParentalKey("ProjectAudioChannel",
                      related_name="tracks",
                      on_delete=models.CASCADE)

    graphql_fields = [
        GraphQLString("title", required=True),
        GraphqlDatetime("created_at", required=True),
        GraphQLString("audio_file_url"),
        GraphQLString("audio_channel"),
        GraphQLString("audio_format"),
        GraphQLString("audio_codec"),
        GraphQLString("audio_bitrate"),
        GraphQLString("description"),
        GraphQLStreamfield("tags"),
        GraphQLStreamfield("attendees"),
        GraphQLString("transcript"),
        GraphQLForeignKey("pac", "track.ProjectAudioChannel"),
    ]

    search_fields = [
        index.SearchField("title"),
        index.SearchField("created_at"),
        index.SearchField("description"),
        index.SearchField("tags"),
        index.SearchField("attendees"),
        index.SearchField("transcript"),
        index.FilterField("pac"),
        index.FilterField("snekuser_id"),
    ]

    panels = [
        FieldPanel("title"),
        ReadOnlyPanel("created_at"),
        FieldPanel("audio_file"),
        FieldPanel("audio_channel"),
        FieldPanel("audio_format"),
        FieldPanel("audio_codec"),
        FieldPanel("audio_bitrate"),
        FieldPanel("description"),
        StreamFieldPanel("tags"),
        StreamFieldPanel("attendees"),
        FieldPanel("transcript"),
        FieldPanel("pac"),
    ]

    def audio_file_url(self, info, **kwargs):
        return ("%s%s" % (settings.BASE_URL, self.audio_file.url)
                if self.audio_file.name else None)

    def __str__(self):
        return f"{self.title}"

    @classmethod
    @login_required
    def bifrost_queryset(cls, info, **kwargs):
        return cls.objects.filter(pac__members=info.context.user)
コード例 #13
0
class AttendeeBlock(blocks.StructBlock):
    name = blocks.CharBlock(required=True, max_length=250)

    graphql_fields = [
        GraphQLString("name"),
    ]