Exemple #1
0
class ResourcesPage(Page, CossBaseModel):
    """Resources Page for Open Source Clubs."""
    heading_text = fields.RichTextField(verbose_name='Text', blank=True)
    heading_image = models.ForeignKey('wagtailimages.Image',
                                      null=True,
                                      blank=True,
                                      on_delete=models.SET_NULL,
                                      related_name='+',
                                      verbose_name='Image')
    mentors_description = fields.StreamField([
        (
            'info',
            InputTextContentBlock(required=True),
        ),
    ])
    resources_title = models.CharField(verbose_name='Title',
                                       blank=True,
                                       default='',
                                       max_length=50)
    resources_cta_text = models.CharField(verbose_name='CTA Text',
                                          blank=True,
                                          default='',
                                          max_length=50)
    resources_cta_link = models.URLField(verbose_name='Link',
                                         blank=True,
                                         default='')
    guides = fields.RichTextField(verbose_name='Guides', blank=True)
    bottom_content_block = fields.StreamField([
        (
            'cta',
            BottomCTAContentBlock(),
        ),
    ],
                                              null=True,
                                              blank=True)

    def get_mentors(self):
        # TODO: Add filter for mentors that belong to each club
        return ClubProfile.objects.filter(is_mentor=True)

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('heading_text'),
            FieldPanel('heading_image'),
        ],
                        heading='Heading'),
        StreamFieldPanel('mentors_description'),
        MultiFieldPanel([
            FieldPanel('resources_title'),
            FieldPanel('resources_cta_text'),
            FieldPanel('resources_cta_link'),
            FieldPanel('guides'),
        ],
                        heading='Resources'),
        StreamFieldPanel('bottom_content_block'),
    ]
Exemple #2
0
class AboutPage(models.Page):
    uuid = UUIDField(editable=False, default=uuid.uuid4)  # Hydra needs uuids

    body = fields.StreamField([
        ('banner', ImageChooserBlock()), ('heading', HeadingBlock()),
        ('paragraph', blocks.RichTextBlock()), ('video', EmbedBlock()),
        ('awards',
         blocks.ListBlock(AwardBlock(label="awards"),
                          template='about/blocks/awards_list.html'))
    ])

    def create_hydra_content(self):
        cr = CreateContentRequest(
            headline=self.title,
            body=self.body.render_as_block(),
            product_id=ALLOWED_SERVICES.usmf.value,
            url=self.url,
            publish_at=self.first_published_at,
            uuid=str(self.uuid),
            visibility=100,  # 100 is publish
            is_static=True,  # Don't include in aggregators
        )
        # Hydra requires first and last name but does its own look up and ignores these values.
        cr.set_primary_author(1589, 'Motley', 'Fool Staff')
        return cr

    content_panels = models.Page.content_panels + [
        StreamFieldPanel('body'),
        ReadOnlyPanel('uuid', heading='Page UUID'),
    ]
class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('wagtailcore', '0030_index_on_pagerevision_created_at'),
    ]

    operations = [
        migrations.CreateModel(
            name='MyTestPage',
            fields=[
                ('page_ptr',
                 models.OneToOneField(
                     auto_created=True,
                     on_delete=django.db.models.deletion.CASCADE,
                     parent_link=True,
                     primary_key=True,
                     serialize=False,
                     to='wagtailcore.Page')),
                ('body',
                 fields.StreamField(
                     (('char_array',
                       blocks.ListBlock(blocks.CharBlock())), ))),
            ],
            options={
                'abstract': False,
            },
            bases=('wagtailcore.page', ),
        ),
    ]
class Migration(migrations.Migration):

    initial = True

    dependencies = [("wagtailcore", "0030_index_on_pagerevision_created_at")]

    operations = [
        migrations.CreateModel(
            name="MyTestPage",
            fields=[
                (
                    "page_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="wagtailcore.Page",
                    ),
                ),
                (
                    "body",
                    fields.StreamField(
                        (("char_array",
                          blocks.ListBlock(blocks.CharBlock())), )),
                ),
            ],
            options={"abstract": False},
            bases=("wagtailcore.page", ),
        )
    ]
class Row(RowMixin):
    content = fields.StreamField([
        ('column', SnippetChooserBlock('grid.Column')),
    ])

    panels = RowMixin.panels + [
        StreamFieldPanel('content'),
    ]
class Column(ColumnMixin):

    content = fields.StreamField([
        ('row', SnippetChooserBlock('grid.Row')),
    ] + LIVE_CLEAN_BLOCKS + UNCHAINED_COMPONENTS_BLOCKS)

    panels = ColumnMixin.panels + [
        StreamFieldPanel('content'),
    ]
Exemple #7
0
class LinksSetting(BaseSetting):
    class Meta:
        abstract = True

    links = fields.StreamField([
        ('link', extension_blocks.LinkBlock()),
    ])

    panels = (StreamFieldPanel('links'), )
Exemple #8
0
class SocialMediaSetting(BaseSetting):
    class Meta:
        abstract = True

    profiles = fields.StreamField([
        ('profile', extension_blocks.SocialMediaProfileBlock()),
    ])

    panels = (StreamFieldPanel('profiles'), )
Exemple #9
0
class ActivitiesPage(Page, CossBaseModel):
    """Activities Page for Open Source Clubs."""
    description = fields.RichTextField(blank=True)
    activity = fields.StreamField([(
        'info',
        CardContentBlock(required=True),
    )])

    content_panels = Page.content_panels + [
        FieldPanel('description'),
        StreamFieldPanel('activity'),
    ]
Exemple #10
0
class FAQPage(Page, CossBaseModel):
    """FAQ Page for Open Source Clubs."""
    faq = fields.StreamField([
        (
            'question',
            InputTextContentBlock(required=True),
        ),
    ])

    content_panels = Page.content_panels + [
        StreamFieldPanel('faq'),
    ]
Exemple #11
0
class ContentPage(Page):
    class Meta:
        abstract = True

    featured_image = models.ForeignKey('wagtailimages.Image',
                                       models.PROTECT,
                                       null=True,
                                       blank=True,
                                       related_name='+')
    body = fields.StreamField([
        ('text', extension_blocks.TextBlock()),
        ('table', TableBlock()),
        ('images', extension_blocks.ImagesBlock()),
    ],
                              blank=True)

    content_panels = Page.content_panels + [
        ImageChooserPanel('featured_image'),
        StreamFieldPanel('body'),
    ]
Exemple #12
0
class BlogPage(models.Orderable, models.Page):

    template = 'home/blog_page.html'
    date_posted = djangomodels.DateField('Publicatie datum',
                                         default=date.today)
    author = djangomodels.CharField('Auteur', max_length=40, null=True)

    blog_content = fields.StreamField([
        ('blog_title',
         TitleBlock(
             help_text=
             'Dit is de titel van het artikel, voorzien van een afbeelding')),
        ('blogintro',
         IntroTextBlock(
             help_text='Hiermee kan je optioneel een korte inleiding voorzien')
         ),
        ('subtitle', Heading2Block()),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageWithCaptionBlock()),
        ('quote', PullQuoteBlock()),
    ],
                                      verbose_name='Blog inhoud')
Exemple #13
0
class AboutSnippet(models.Model):
    title = models.CharField(default='', max_length=50)
    header_text = fields.RichTextField(blank=True)
    body_title = models.CharField(verbose_name='Title',
                                  blank=True,
                                  default='',
                                  max_length=50)
    body_text = fields.RichTextField(verbose_name='Text', blank=True)
    body_image = models.ForeignKey('wagtailimages.Image',
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   verbose_name='Image')
    info_title = models.CharField(verbose_name='Title',
                                  blank=True,
                                  default='',
                                  max_length=50)
    info_text = fields.RichTextField(verbose_name='Text', blank=True)
    details_title = models.CharField(verbose_name='Title',
                                     blank=True,
                                     default='',
                                     max_length=50)
    details = fields.StreamField([
        (
            'section',
            InputTextContentBlock(),
        ),
    ],
                                 null=True,
                                 blank=True,
                                 verbose_name='Blocks')
    collaborators_title = models.CharField(verbose_name='Title',
                                           blank=True,
                                           default='',
                                           max_length=50)
    collaborators_text = fields.RichTextField(verbose_name='Text', blank=True)
    collaborators_cta_text = models.CharField(verbose_name='CTA Text',
                                              blank=True,
                                              default='',
                                              max_length=50)
    collaborators_cta_link = models.URLField(verbose_name='CTA Link',
                                             blank=True,
                                             default='')
    collaborators = fields.StreamField([
        (
            'info',
            CardContentBlock(),
        ),
    ],
                                       null=True,
                                       blank=True)
    bottom_content_block = fields.StreamField([
        (
            'cta',
            BottomCTAContentBlock(),
        ),
    ],
                                              null=True,
                                              blank=True)
    optional_text_block_title = models.CharField(verbose_name='Title',
                                                 blank=True,
                                                 default='',
                                                 max_length=50)
    optional_text_block = fields.StreamField([
        (
            'secondary_section',
            InputTextContentBlock(),
        ),
    ],
                                             null=True,
                                             blank=True,
                                             verbose_name='Blocks')

    panels = [
        FieldPanel('title'),
        FieldPanel('header_text'),
        MultiFieldPanel([
            FieldPanel('body_title'),
            FieldPanel('body_text'),
            ImageChooserPanel('body_image'),
        ],
                        heading='Body'),
        MultiFieldPanel([
            FieldPanel('info_title'),
            FieldPanel('info_text'),
        ],
                        heading='Info'),
        MultiFieldPanel([
            FieldPanel('details_title'),
            StreamFieldPanel('details'),
        ],
                        heading='Details'),
        MultiFieldPanel([
            FieldPanel('collaborators_title'),
            FieldPanel('collaborators_text'),
            FieldPanel('collaborators_cta_text'),
            FieldPanel('collaborators_cta_link'),
            StreamFieldPanel('collaborators'),
        ],
                        heading='Collaborators Section'),
        StreamFieldPanel('bottom_content_block'),
        MultiFieldPanel([
            FieldPanel('optional_text_block_title'),
            StreamFieldPanel('optional_text_block'),
        ],
                        heading='Secondary Input block'),
    ]

    class Meta:
        verbose_name_plural = 'About Snippets'

    def __str__(self):
        return self.title
Exemple #14
0
class HomePage(Page, CossBaseModel):
    """Landing HomePage for OpenSource clubs."""

    logo = models.ForeignKey('wagtailimages.Image',
                             null=True,
                             blank=True,
                             on_delete=models.SET_NULL,
                             related_name='+')
    heading_text = fields.RichTextField(
        verbose_name='Text',
        blank=True,
        default='',
    )
    heading_cta_text = models.CharField(verbose_name='CTA Text',
                                        blank=True,
                                        default='',
                                        max_length=50)
    heading_cta_link = models.URLField(verbose_name='CTA Link',
                                       blank=True,
                                       default='')
    heading_image = models.ForeignKey('wagtailimages.Image',
                                      null=True,
                                      blank=True,
                                      on_delete=models.SET_NULL,
                                      related_name='+')
    discourse = models.ForeignKey('discourse.DiscourseCategory',
                                  null=True,
                                  blank=True,
                                  on_delete=models.SET_NULL,
                                  related_name='+')
    testimonial = models.ForeignKey('home.Testimonial',
                                    null=True,
                                    blank=True,
                                    on_delete=models.SET_NULL,
                                    related_name='+')
    bottom_content_block = fields.StreamField([
        (
            'cta',
            BottomCTAContentBlock(),
        ),
    ],
                                              null=True,
                                              blank=True)

    opengraph_image = models.ForeignKey('wagtailimages.Image',
                                        null=True,
                                        blank=True,
                                        on_delete=models.SET_NULL,
                                        related_name='+',
                                        verbose_name='Open Graph Image')

    def get_category_landing_page(self):
        if self.get_children().type(CategoryLandingPage):
            try:
                return CategoryLandingPage.objects.get()
            except (CategoryLandingPage.DoesNotExist,
                    CategoryLandingPage.MultipleObjectsReturned):
                pass
        return CategoryLandingPage.objects.none()

    content_panels = Page.content_panels + [
        FieldPanel('logo'),
        FieldPanel('opengraph_image'),
        MultiFieldPanel([
            FieldPanel('heading_text'),
            FieldPanel('heading_cta_text'),
            FieldPanel('heading_cta_link'),
            FieldPanel('heading_image'),
        ],
                        heading='Heading'),
        SnippetChooserPanel('discourse'),
        SnippetChooserPanel('testimonial'),
        StreamFieldPanel('bottom_content_block')
    ]
Exemple #15
0
class ContactDetailsSetting(BaseSetting):

    CACHE_KEY_OPENING_TODAY = "wagtail_extensions_opening_today_{:%Y%m%d}"

    locations = fields.StreamField([
        ('location', extension_blocks.LocationBlock()),
    ])

    panels = (StreamFieldPanel('locations'), )

    class Meta:
        abstract = True

    @classmethod
    def get_opening_today_cache_key(cls, date):
        return cls.CACHE_KEY_OPENING_TODAY.format(date)

    @property
    def primary_location(self):
        return utils.true_or_nth(self.locations,
                                 lambda x: x.value.get('primary') == True)

    @property
    def primary_department(self):
        location = self.primary_location
        if location:
            departments = location.value.get('departments', [])
            return utils.true_or_nth(departments,
                                     lambda x: x.get('primary') == True)
        return None

    @property
    def primary_phone(self):
        department = self.primary_department
        if department:
            phones = self.primary_department.get('phones', [])
            return utils.nth(phones, 0)
        return None

    @property
    def primary_opening_times(self):
        location = self.primary_location
        if location:
            return location.value.get('opening_times')
        return None

    @property
    def primary_opening_today(self):
        today = date.today()
        cache_key = self.get_opening_today_cache_key(today)
        times = cache.get(cache_key)
        if times is None:
            opening_times = self.primary_opening_times
            if opening_times:
                specific_times = utils.first_true(
                    opening_times, lambda x: x.get('date') == today)
                times = specific_times or utils.first_true(
                    opening_times,
                    lambda x: x.get('weekday') == today.weekday())
                cache.set(cache_key, dict(times), 60 * 60 * 24)
        return times