Exemple #1
0
class EventPage(AbstractContentPage):
    """A model for event single pages."""

    parent_page_types = ['events.EventIndexPage']
    subpage_types = []

    featured_event = models.BooleanField(default=False)
    date_start = models.DateTimeField("Event start date and time",
                                      default=timezone.now)
    date_end = models.DateTimeField("Event end date and time",
                                    null=True,
                                    blank=True)
    location = models.TextField(null=True, blank=True)
    registration_link = models.URLField(max_length=255, null=True, blank=True)
    feed_image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text=
        'This is the image that will be displayed for the event in the page header and on the Events and Past Events list pages.'
    )

    additional_information = StreamField(IATIStreamBlock(required=False),
                                         null=True,
                                         blank=True)
    event_type = ParentalManyToManyField('events.EventType', blank=True)

    @property
    def event_type_concat(self):
        """Take all of the EventType snippets and concatenate them into a space separated one-liner."""
        event_types = self.event_type.values_list('name', flat=True)

        return " | ".join(event_types)

    translation_fields = AbstractContentPage.translation_fields + [
        "additional_information"
    ]

    multilingual_field_panels = [
        FieldPanel('featured_event'),
        FieldPanel('date_start'),
        FieldPanel('date_end'),
        FieldPanel('location'),
        FieldPanel('registration_link'),
        FieldPanel('event_type', widget=forms.CheckboxSelectMultiple),
        ImageChooserPanel('feed_image'),
    ]
class GuidanceGroupPage(AbstractContentPage):
    """A base for Guidance Group pages."""

    subpage_types = [
        'guidance_and_support.GuidanceGroupPage',
        'guidance_and_support.GuidancePage'
    ]

    section_image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text=
        'This is the image that will be displayed for this page on the main guidance and support page. Ignore if this page is being used as a sub-index page.'
    )

    section_summary = StreamField(
        IATIStreamBlock(required=False),
        null=True,
        blank=True,
        help_text=
        'A small amount of content to appear on the main page (e.g. bullet points). Ignore if this page is being used as a sub-index page.'
    )

    button_link_text = models.TextField(
        max_length=255,
        null=True,
        blank=True,
        help_text=
        'The text to appear on the button of the main guidance and support page. Ignore if this page is being used as a sub-index page.'
    )

    content_editor = StreamField(
        IATIStreamBlock(required=False),
        null=True,
        blank=True,
        help_text=
        'The content to appear on the page itself, as opposed to "section summary" which appears on the parent page.'
    )

    @property
    def guidance_groups(self):
        """Get all objects that are children of the instantiated GuidanceGroupPage.

        Note:
            These can be other guidance group pages or single guidance pages.

        """
        guidance_groups = Page.objects.child_of(self).specific().live()
        guidance_group_list = [{
            "page": page,
            "count": len(page.get_children())
        } for page in guidance_groups]
        return guidance_group_list

    translation_fields = AbstractContentPage.translation_fields + [
        "section_summary", "button_link_text"
    ]

    multilingual_field_panels = [
        ImageChooserPanel('section_image'),
    ]
Exemple #3
0
class StandardGuidanceIndexPage(DefaultPageHeaderImageMixin, AbstractIndexPage):
    """A model for standard guidance index page."""

    parent_page_types = ['guidance_and_support.GuidanceAndSupportPage']
    subpage_types = ['iati_standard.StandardGuidancePage']

    max_count = 1

    section_summary = models.TextField(
        blank=True,
        null=True,
        help_text='Summary seen on Guidance and Support page'
    )
    button_link_text = models.CharField(
        blank=True,
        null=True,
        max_length=255,
        help_text='Button text to be shown on Guidance and Support page',
    )

    content_editor = StreamField(IATIStreamBlock(required=False), null=True, blank=True)

    translation_fields = AbstractIndexPage.translation_fields + ["section_summary", "button_link_text", "content_editor"]

    def get_guidance(self, request, filter_dict=None, search_query=None):
        """Return a filtered list of guidance."""
        all_guidance = StandardGuidancePage.objects.live().descendant_of(self).order_by('title')
        if filter_dict:
            filtered_guidance = self.filter_children(all_guidance, filter_dict)
        else:
            filtered_guidance = all_guidance
        if search_query and filtered_guidance:
            queried_guidance = all_guidance.filter(
                id__in=filtered_guidance.values_list('id', flat=True)
            ).search(
                search_query,
                order_by_relevance=False
            )
        else:
            queried_guidance = filtered_guidance
        return queried_guidance

    def get_context(self, request, *args, **kwargs):
        """Overwrite the default wagtail get_context function to allow for filtering based on params.

        Use the functions built into the abstract index page class to dynamically filter the child pages.

        """
        filter_dict = {}

        search_query = request.GET.get('search', None)
        if search_query:
            query = Query.get(search_query)
            query.add_hit()

        guidance_type_organisation = request.GET.get('organisation', None)
        guidance_type_activity = request.GET.get('activity', None)
        guidance_type_list = list()
        if guidance_type_organisation:
            guidance_type_list.append("organisation")
        if guidance_type_activity:
            guidance_type_list.append("activity")
        if len(guidance_type_list):
            filter_dict["guidance_types__guidance_type__in"] = guidance_type_list

        context = super(StandardGuidanceIndexPage, self).get_context(request)
        context['guidance'] = self.get_guidance(request, filter_dict, search_query)
        return context