예제 #1
0
파일: models.py 프로젝트: BlinkenOSA/FEC
class HomePage(Page):
    hero_video_url = models.CharField(max_length=100)
    hero_text_top = models.CharField(max_length=100, blank=True)
    hero_text_title = models.CharField(max_length=100)
    hero_text_motto = models.CharField(max_length=100, blank=True)
    about_text = RichTextField(blank=True, null=True, editor='tinymce')

    content_panels = Page.content_panels + [
        FieldPanel('hero_video_url'),
        FieldPanel('hero_text_top'),
        FieldPanel('hero_text_title'),
        FieldPanel('hero_text_motto'),
        FieldPanel('about_text', classname='full'),
        CondensedInlinePanel('counters',
                             label="Counters",
                             card_header_from_field="counter_text"),
        CondensedInlinePanel('badges',
                             label="Badges",
                             card_header_from_field="badge_header_text")
    ]

    def get_context(self, request, *args, **kwargs):
        context = super(HomePage, self).get_context(request)
        context['counter_blocks'] = self.counters.all()
        context['counter_blocks_count'] = self.counters.count()
        context['badge_blocks'] = self.badges.all()
        context['badge_blocks_count'] = self.badges.count()
        return context
예제 #2
0
class FAQPage(KochergaPage):
    summary = models.TextField('Короткое описание', blank=True)

    parent_page_types = ['pages.FrontPage', 'faq.FAQPage']
    subpage_types = ['faq.FAQPage']

    @property
    def prev_page(self):
        result = self.get_prev_siblings().type(self.__class__).live().first()
        return result.specific if result else None

    @property
    def next_page(self):
        result = self.get_next_siblings().type(self.__class__).live().first()
        return result.specific if result else None

    @property
    def subpages(self):
        return [
            page.specific
            for page in self.get_children().type(self.__class__).live()
        ]

    content_panels = KochergaPage.content_panels + [
        FieldPanel('summary'),
        CondensedInlinePanel('entries', label="Вопросы и ответы"),
    ]

    graphql_type = 'FaqPage'
예제 #3
0
class AboutPage(Page):
    main_image = models.ForeignKey('core.CMSImage',
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   verbose_name=_('Main image'))
    heading = models.TextField(_('Heading'), blank=True)
    # intro = models.TextField(_('Introduction'), blank=True)
    body = RichTextField(_('Body'))
    # involvement_title = models.TextField(_('Involvement title'), blank=True)

    content_panels = [
        FieldPanel('title', classname='full title'),
        ImageChooserPanel('main_image'),
        FieldPanel('heading', classname='full'),
        # FieldPanel('intro', classname='full'),
        FieldPanel('body', classname='full'),
        CondensedInlinePanel('content_blocks', label=_('Content blocks')),
        CondensedInlinePanel('related_link_buttons',
                             label=_('Header buttons')),
        CondensedInlinePanel('offices', label=_('Offices')),
        # FieldPanel('involvement_title'),
    ]
예제 #4
0
파일: models.py 프로젝트: BlinkenOSA/FEC
class TimelinePage(Page):
    header_image = models.ForeignKey('wagtailimages.Image',
                                     related_name='+',
                                     on_delete=models.PROTECT)

    content_panels = Page.content_panels + [
        ImageChooserPanel('header_image'),
        CondensedInlinePanel('timeline_items',
                             label='Timeline Items',
                             card_header_from_field='title')
    ]

    def get_context(self, request, *args, **kwargs):
        context = super(TimelinePage, self).get_context(request)
        context['timeline_blocks'] = self.timeline_items.all()
        return context
예제 #5
0
파일: models.py 프로젝트: BlinkenOSA/FEC
class GraphPage(Page):
    header_image = models.ForeignKey('wagtailimages.Image',
                                     related_name='+',
                                     on_delete=models.PROTECT)
    upper_text = RichTextField(blank=True, null=True, editor='tinymce')
    graph_slider_text = RichTextField(blank=True, null=True, editor='tinymce')

    content_panels = Page.content_panels + [
        ImageChooserPanel('header_image'),
        FieldPanel('upper_text', classname='full'),
        FieldPanel('graph_slider_text', classname='full'),
        CondensedInlinePanel('slider_images', label="Slider Images")
    ]

    def get_context(self, request, *args, **kwargs):
        context = super(GraphPage, self).get_context(request)
        context['slider_graphs'] = self.slider_images.all()
        return context
예제 #6
0
파일: models.py 프로젝트: BlinkenOSA/FEC
class FaqPage(Page):
    header_image = models.ForeignKey('wagtailimages.Image',
                                     related_name='+',
                                     on_delete=models.PROTECT)
    body_title = models.CharField(max_length=100, blank=True, null=True)
    body_text = RichTextField(blank=True, null=True, editor='tinymce')

    content_panels = Page.content_panels + [
        ImageChooserPanel('header_image'),
        FieldPanel('body_title'),
        FieldPanel('body_text', classname='full'),
        CondensedInlinePanel(
            'faq_items', label='FAQ Items', card_header_from_field='question')
    ]

    def get_context(self, request, *args, **kwargs):
        context = super(FaqPage, self).get_context(request)
        context['faq_blocks'] = self.faq_items.all()
        context['faq_blocks_count'] = self.faq_items.count()
        return context
예제 #7
0
파일: models.py 프로젝트: xr-web-de/xr-web
class EventPage(XrPage):
    template = "xr_events/pages/event_detail.html"
    content = StreamField(
        ContentBlock,
        blank=True,
        help_text=_("The content is only visible on the detail page."),
    )
    location = models.CharField(
        max_length=255,
        blank=True,
        help_text=_(
            "Some city or address, like you would enter in GMaps or OpenStreetMap, "
            'e.g. "Berlin", "Somestreet 84, 12345 Samplecity".'),
    )
    group = models.ForeignKey(LocalGroup,
                              on_delete=models.PROTECT,
                              editable=False,
                              related_name="events")
    start_date = models.DateTimeField(null=True, blank=True)
    end_date = models.DateTimeField(null=True, blank=True)

    content_panels = XrPage.content_panels + [
        CondensedInlinePanel("dates", label=_("Dates")),
        FieldPanel("location"),
        CondensedInlinePanel("further_organisers",
                             label=_("Further organisers")),
        StreamFieldPanel("content"),
    ]

    parent_page_types = ["EventGroupPage"]

    objects = EventPageManager()

    is_event_page = True

    class Meta:
        verbose_name = _("Event")
        verbose_name_plural = _("Events")

    def route(self, request, path_components, redirect_self=None):
        if path_components:
            event_date_id = None
            try:
                event_date_id = int(path_components[0])
            except (ValueError, TypeError):
                pass
            return RouteResult(
                self,
                kwargs={
                    "event_date_id": event_date_id,
                    "redirect_self": redirect_self
                },
            )
        else:
            # request is for this very page
            if self.live:
                return RouteResult(self,
                                   kwargs={"redirect_self": redirect_self})
            else:
                raise Http404

    def serve(self, request, event_date_id=None, redirect_self=False):
        if redirect_self:
            return redirect("{}{}/".format(self.url, event_date_id))

        request.is_preview = getattr(request, "is_preview", False)
        event_date = None

        if event_date_id:
            try:
                event_date = (EventDate.objects.filter(
                    id=event_date_id).select_related("event_page").first())
                if event_date and event_date.event_page != self:
                    return redirect("{}{}/".format(event_date.event_page.url,
                                                   event_date_id))
            except EventDate.DoesNotExist:
                pass

        if not event_date:
            event_date = self.get_next_date()

        context = self.get_context(request)
        context.update({"event": self, "event_date": event_date})

        return TemplateResponse(request, self.get_template(request), context)

    def get_next_date(self):
        next_date = None
        try:
            next_date = (self.dates.filter(
                start__date__gte=localdate()).order_by("start").first())
        except EventDate.DoesNotExist:
            pass
        return next_date

    def get_image(self):
        if self.image:
            return self.image
        event_group_page = EventGroupPage.objects.ancestor_of(self).last()
        if event_group_page.default_event_image:
            return event_group_page.default_event_image
        event_list_page = EventListPage.objects.ancestor_of(self).last()
        if event_list_page.default_event_image:
            return event_list_page.default_event_image
        return None

    @property
    def organiser(self):
        return self.group

    def get_all_organisers(self):
        all_organisers = [self.group]
        shadow_qs = self.shadow_events.live().filter(original_event=self)
        if shadow_qs.exists():
            all_organisers += [shadow.specific.group for shadow in shadow_qs]
        if hasattr(self,
                   "further_organisers") and self.further_organisers.exists():
            all_organisers += list(self.further_organisers.all())
        return all_organisers

    @property
    def all_organiser_names(self):
        return ", ".join(
            [organiser.name for organiser in self.get_all_organisers()])

    def save(self, *args, **kwargs):
        if not hasattr(self, "group"):
            self.group = self.get_parent().specific.group

        if self.dates.exists():
            all_dates = []
            for date in self.dates.all():
                all_dates.append(date.start)
                if date.end:
                    all_dates.append(date.end)
            all_dates = sorted(all_dates)
            self.start_date = all_dates[0]
            self.end_date = all_dates[-1]

        super().save(*args, **kwargs)
예제 #8
0
class EventPage(XrPage):
    template = "xr_events/pages/event_detail.html"
    content = StreamField(
        ContentBlock,
        blank=True,
        help_text=_("The content is only visible on the detail page."),
    )
    location = models.CharField(
        max_length=255,
        blank=True,
        help_text=_(
            "Some city or address, like you would enter in GMaps or OpenStreetMap, "
            'e.g. "Berlin", "Somestreet 84, 12345 Samplecity".'),
    )
    group = models.ForeignKey(LocalGroup,
                              on_delete=models.PROTECT,
                              editable=False,
                              related_name="events")
    start_date = models.DateTimeField(null=True, blank=True)
    end_date = models.DateTimeField(null=True, blank=True)

    content_panels = XrPage.content_panels + [
        CondensedInlinePanel("dates", label=_("Dates")),
        FieldPanel("location"),
        CondensedInlinePanel("further_organisers",
                             label=_("Further organisers")),
        StreamFieldPanel("content"),
    ]

    parent_page_types = ["EventGroupPage"]

    objects = EventPageManager()

    is_event_page = True

    class Meta:
        verbose_name = _("Event")
        verbose_name_plural = _("Events")

    def get_context(self, request, *args, **kwargs):
        context = super().get_context(request, *args, **kwargs)
        context["event"] = self
        return context

    def get_image(self):
        if self.image:
            return self.image
        event_group_page = EventGroupPage.objects.ancestor_of(self).last()
        if event_group_page.default_event_image:
            return event_group_page.default_event_image
        event_list_page = EventListPage.objects.ancestor_of(self).last()
        if event_list_page.default_event_image:
            return event_list_page.default_event_image
        return None

    @property
    def organiser(self):
        return self.group

    def save(self, *args, **kwargs):
        if not hasattr(self, "group"):
            self.group = self.get_parent().specific.group

        if self.dates.exists():
            all_dates = []
            for date in self.dates.all():
                all_dates.append(date.start)
                if date.end:
                    all_dates.append(date.end)
            all_dates = sorted(all_dates)
            self.start_date = all_dates[0]
            self.end_date = all_dates[-1]

        super().save(*args, **kwargs)