Beispiel #1
0
class AgendaItemBlock(blocks.StructBlock):
    start_time = blocks.TimeBlock(label="Start", required=False)
    end_time = blocks.TimeBlock(label="End", required=False)
    description = blocks.CharBlock(max_length=100, required=False)
    location = blocks.CharBlock(max_length=100, required=False)
    speakers = blocks.ListBlock(blocks.StructBlock([
        ('name', blocks.CharBlock(required=False)),
        ('url', blocks.URLBlock(required=False)),
    ], icon='user', required=False))

    objects = PageManager()

    class Meta:
        icon = 'date'
Beispiel #2
0
class SongStreamBlock(blocks.StreamBlock):
    # Title name. Time.
    SongBlock = blocks.StructBlock([
        ('album_song',
         blocks.CharBlock(
             blank=True, required=False, label='e.g. Waiting Room')),
        ('album_song_length', blocks.TimeBlock(blank=True, required=False)),
    ],
                                   title="Song",
                                   icon="fa-music",
                                   template="blocks/songstreamblock.html")
Beispiel #3
0
class BlogPage(Page):
	author = models.CharField(max_length = 250)
	date = models.DateField('Post date')
	intro = models.CharField(max_length = 250)
	tags = ClusterTaggableManager(through = BlogPageTag, blank = True)
	body = StreamField([
		('heading', blocks.CharBlock(classname = 'full title')),
		('paragraph', blocks.RichTextBlock()),
		('url', blocks.URLBlock()),
		('date', blocks.DateBlock()),
		('time', blocks.TimeBlock()),
		('page', blocks.PageChooserBlock()),
		('image', ImageChooserBlock()),
		('doc', DocumentChooserBlock()),
		('embed', EmbedBlock()),
	])

	def main_image(self):
		gallery_item = self.gallery_images.first()

		if gallery_item:
		    return gallery_item.image
		else:
		    return None

	search_fields = Page.search_fields + [
		index.SearchField('intro'),
		index.SearchField('body'),
		index.SearchField('author'),
	]

	content_panels = Page.content_panels + [
		MultiFieldPanel([
			FieldPanel('date'),
			FieldPanel('tags'),
			], heading = 'Blog information'),
		FieldPanel('author'),
		FieldPanel('intro'),
		StreamFieldPanel('body'),
		InlinePanel('gallery_images', label = 'Gallery images')
	]
Beispiel #4
0
class SectionPage(CommentedPageMixin, TranslatablePageMixin, Page):
    description = models.TextField(null=True, blank=True)
    uuid = models.CharField(max_length=32, blank=True, null=True)
    image = models.ForeignKey('wagtailimages.Image',
                              null=True,
                              blank=True,
                              on_delete=models.SET_NULL,
                              related_name='+')

    subpage_types = ['core.ArticlePage', 'core.SectionPage']
    search_fields = Page.search_fields + (index.SearchField('description'), )
    extra_style_hints = models.TextField(
        default='',
        null=True,
        blank=True,
        help_text=_("Styling options that can be applied to this section "
                    "and all its descendants"))

    commenting_state = models.CharField(
        max_length=1,
        choices=constants.COMMENTING_STATE_CHOICES,
        blank=True,
        null=True)
    commenting_open_time = models.DateTimeField(null=True, blank=True)
    commenting_close_time = models.DateTimeField(null=True, blank=True)

    time = StreamField([
        ('time', blocks.TimeBlock(required=False)),
    ],
                       null=True,
                       blank=True,
                       help_text='The time/s content will be rotated')

    monday_rotation = models.BooleanField(default=False, verbose_name='Monday')
    tuesday_rotation = models.BooleanField(default=False,
                                           verbose_name='Tuesday')
    wednesday_rotation = models.BooleanField(default=False,
                                             verbose_name='Wednesday')
    thursday_rotation = models.BooleanField(default=False,
                                            verbose_name='Thursday')
    friday_rotation = models.BooleanField(default=False, verbose_name='Friday')
    saturday_rotation = models.BooleanField(default=False,
                                            verbose_name='Saturday')
    sunday_rotation = models.BooleanField(default=False, verbose_name='Sunday')

    content_rotation_start_date = models.DateTimeField(
        null=True, blank=True, help_text='The date rotation will begin')
    content_rotation_end_date = models.DateTimeField(
        null=True, blank=True, help_text='The date rotation will end')

    def articles(self):
        main_language_page = self.get_main_language_page()
        return list(
            chain(
                ArticlePage.objects.child_of(main_language_page).filter(
                    languages__language__is_main_language=True),
                ArticlePage.objects.filter(
                    related_sections__section__slug=self.slug)))

    def sections(self):
        main_language_page = self.get_main_language_page()
        return SectionPage.objects.child_of(main_language_page).filter(
            languages__language__is_main_language=True)

    def get_effective_extra_style_hints(self):
        if self.extra_style_hints:
            return self.extra_style_hints

        # The extra css is inherited from the parent SectionPage.
        # This will either return the current value or a value
        # from its parents.
        main_lang = SiteLanguage.objects.filter(is_main_language=True).first()
        language_rel = self.languages.all().first()
        if language_rel and main_lang == language_rel.language:
            parent_section = SectionPage.objects.all().ancestor_of(self).last()
            if parent_section:
                return parent_section.get_effective_extra_style_hints()
            return ''
        else:
            page = self.get_main_language_page()
            return page.specific.get_effective_extra_style_hints()

    def get_effective_image(self):
        if self.image:
            return self.image

        main_lang = SiteLanguage.objects.filter(is_main_language=True).first()
        language_rel = self.languages.all().first()
        if language_rel and main_lang == language_rel.language:
            parent_section = SectionPage.objects.all().ancestor_of(self).last()
            if parent_section:
                return parent_section.get_effective_image()
            return ''
        else:
            page = self.get_main_language_page()
            return page.specific.get_effective_image()

    def get_parent_section(self):
        return SectionPage.objects.all().ancestor_of(self).last()

    def featured_in_homepage_articles(self):
        main_language_page = self.get_main_language_page()
        return ArticlePage.objects.child_of(main_language_page).filter(
            languages__language__is_main_language=True,
            featured_in_homepage=True).order_by(
                '-latest_revision_created_at').specific()

    def get_context(self, request):
        context = super(SectionPage, self).get_context(request)

        try:
            p = int(request.GET.get('p', 1))
        except ValueError:
            p = 1

        context['p'] = p
        return context

    class Meta:
        verbose_name = _('Section')
Beispiel #5
0
class SiteSettings(BaseSetting):
    logo = models.ForeignKey('wagtailimages.Image',
                             null=True,
                             blank=True,
                             on_delete=models.SET_NULL,
                             related_name='+')

    ga_tag_manager = models.CharField(
        verbose_name=_('Local GA Tag Manager'),
        max_length=255,
        null=True,
        blank=True,
        help_text=_(
            "Local GA Tag Manager tracking code (e.g GTM-XXX) to be used to "
            "view analytics on this site only"))
    global_ga_tag_manager = models.CharField(
        verbose_name=_('Global GA Tag Manager'),
        max_length=255,
        null=True,
        blank=True,
        help_text=_(
            "Global GA Tag Manager tracking code (e.g GTM-XXX) to be used"
            " to view analytics on more than one site globally"))

    local_ga_tracking_code = models.CharField(
        verbose_name=_('Local GA Tracking Code'),
        max_length=255,
        null=True,
        blank=True,
        help_text=_("Local GA tracking code to be used to "
                    "view analytics on this site only"))
    global_ga_tracking_code = models.CharField(
        verbose_name=_('Global GA Tracking Code'),
        max_length=255,
        null=True,
        blank=True,
        help_text=_("Global GA tracking code to be used"
                    " to view analytics on more than one site globally"))
    show_only_translated_pages = models.BooleanField(
        default=False,
        help_text='When selecting this option, untranslated pages'
        ' will not be visible to the front end user'
        ' when they viewing a child language of the site')

    time = StreamField([
        ('time', blocks.TimeBlock(required=False)),
    ],
                       null=True,
                       blank=True,
                       help_text='The time/s content will be rotated')

    monday_rotation = models.BooleanField(default=False, verbose_name='Monday')
    tuesday_rotation = models.BooleanField(default=False,
                                           verbose_name='Tuesday')
    wednesday_rotation = models.BooleanField(default=False,
                                             verbose_name='Wednesday')
    thursday_rotation = models.BooleanField(default=False,
                                            verbose_name='Thursday')
    friday_rotation = models.BooleanField(default=False, verbose_name='Friday')
    saturday_rotation = models.BooleanField(default=False,
                                            verbose_name='Saturday')
    sunday_rotation = models.BooleanField(default=False, verbose_name='Sunday')

    content_rotation_start_date = models.DateTimeField(
        null=True, blank=True, help_text='The date rotation will begin')
    content_rotation_end_date = models.DateTimeField(
        null=True, blank=True, help_text='The date rotation will end')

    panels = [
        ImageChooserPanel('logo'),
        MultiFieldPanel(
            [
                FieldPanel('show_only_translated_pages'),
            ],
            heading="Multi Language",
        ),
        MultiFieldPanel(
            [
                FieldPanel('ga_tag_manager'),
                FieldPanel('global_ga_tag_manager'),
            ],
            heading="GA Tag Manager Settings",
        ),
        MultiFieldPanel(
            [
                FieldPanel('local_ga_tracking_code'),
                FieldPanel('global_ga_tracking_code'),
            ],
            heading="GA Tracking Code Settings",
        ),
        MultiFieldPanel(
            [
                FieldPanel('content_rotation_start_date'),
                FieldPanel('content_rotation_end_date'),
                FieldRowPanel([
                    FieldPanel('monday_rotation', classname='col6'),
                    FieldPanel('tuesday_rotation', classname='col6'),
                    FieldPanel('wednesday_rotation', classname='col6'),
                    FieldPanel('thursday_rotation', classname='col6'),
                    FieldPanel('friday_rotation', classname='col6'),
                    FieldPanel('saturday_rotation', classname='col6'),
                    FieldPanel('sunday_rotation', classname='col6'),
                ]),
                StreamFieldPanel('time'),
            ],
            heading="Content Rotation Settings",
        )
    ]
Beispiel #6
0
class OpeningTimeBlock(blocks.StructBlock):
    """
    A semi-structured opening times block.

    Period is left as a free text input to allow for
    """
    PUBLIC = 7
    PUBLIC_LABEL = 'Public holiday'
    WEEKDAYS = tuple(enumerate(calendar.day_name)) + ((PUBLIC, PUBLIC_LABEL),)

    weekday = blocks.ChoiceBlock(choices=WEEKDAYS, required=False)
    label = blocks.CharBlock(help_text='Optionally override default weekday label', required=False)
    date = blocks.DateBlock(help_text='Optionally specify a day these times are for', required=False)
    start = blocks.TimeBlock(required=False)
    end = blocks.TimeBlock(required=False)
    closed = blocks.BooleanBlock(default=False, required=False)

    class Meta:
        template = 'wagtail_extensions/blocks/openingtime.html'

    def clean(self, value):
        cleaned = super().clean(value)
        start, end, weekday, date = map(cleaned.get, ['start', 'end', 'weekday', 'date'])
        errors = defaultdict(ErrorList)

        if date and date < datetime.date.today():
            err = ValidationError('Dates need to be in the future')
            errors['date'].append(err)

        if (start or end) and not (weekday or date):
            err = ValidationError('Specifying a weekday or date is required')
            errors['weekday'].append(err)

        if start and end and end <= start:
            err = ValidationError('End must be after start')
            errors['end'].append(err)

        if errors:
            raise ValidationError("There is a problem with this opening time", params=errors)

        return cleaned

    def get_context(self, value, parent_context=None):
        ctx = super().get_context(value, parent_context=parent_context)
        weekday = ctx['value'].get('weekday')
        if weekday is not None:
            if weekday == self.PUBLIC:
                ctx['is_public'] = True
            else:
                # Next date with this weekday
                today = datetime.date.today()
                ctx['next_date'] = today + relativedelta(weekday=weekday)
        return ctx

    def to_python(self, value):
        weekday = value.get('weekday')
        if weekday:
            weekday_int = int(weekday)
            value['weekday'] = weekday_int

            label = value.get('label')
            if weekday_int == self.PUBLIC and not label:
                value['label'] = self.PUBLIC_LABEL
        return super().to_python(value)