예제 #1
0
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
예제 #2
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"),
    ]
예제 #3
0
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"),
    ]
예제 #4
0
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