Beispiel #1
0
class NewsRelatedPage(Orderable):
    page = ParentalKey(NewsPage, related_name='related_pages')
    related_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
    )
    name = models.CharField(blank=True, max_length=250)

    panels = [
        FieldPanel('name'),
        PageChooserPanel('related_page', "news.NewsPage"),
    ]

    @property
    def link(self):
        if self.related_page:
            return self.related_page.url
class ContentBlock(LinkFields):
    page = models.ForeignKey(Page,
                             related_name='contentblocks',
                             null=True,
                             blank=True)
    title = models.CharField(max_length=255)
    body = RichTextField()
    summary = RichTextField(blank=True)
    slug = models.SlugField()
    panels = [
        PageChooserPanel('page'),
        FieldPanel('title'),
        FieldPanel('summary'),
        FieldPanel('body', classname="full"),
        FieldPanel('slug'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

    def __unicode__(self):
        return u"{0}[{1}]".format(self.title, self.slug)
Beispiel #3
0
class FeaturedPage(models.Model):
    featured_page = models.ForeignKey('wagtailcore.Page',
                                      verbose_name="page to feature",
                                      on_delete=models.CASCADE,
                                      related_name='+')

    title = models.CharField(max_length=255,
                             blank=True,
                             help_text="Leave blank to use page title.")

    subtitle = models.CharField(max_length=255)

    panels = [
        PageChooserPanel('featured_page'),
        FieldPanel('title'),
        FieldPanel('subtitle'),
    ]

    class Meta:
        abstract = True
Beispiel #4
0
    def test_override_page_type(self):
        # Model has a foreign key to Page, but we specify EventPage in the PageChooserPanel
        # to restrict the chooser to that page type
        MyPageObjectList = ObjectList([
            PageChooserPanel('page', 'tests.EventPage')
        ]).bind_to_model(EventPageChooserModel)
        MyPageChooserPanel = MyPageObjectList.children[0]
        PageChooserForm = MyPageObjectList.get_form_class(
            EventPageChooserModel)
        form = PageChooserForm(instance=self.test_instance)
        page_chooser_panel = MyPageChooserPanel(instance=self.test_instance,
                                                form=form)

        result = page_chooser_panel.render_as_field()
        expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, false);'.format(
            id="id_page",
            model="tests.eventpage",
            parent=self.events_index_page.id)

        self.assertIn(expected_js, result)
Beispiel #5
0
class NewsletterEventLink(Orderable, models.Model):
    event = models.ForeignKey("events.EventPage",
                              null=True,
                              blank=True,
                              on_delete=models.SET_NULL,
                              related_name='+',
                              help_text="Link to an event")
    override_text = RichTextField(blank=True,
                                  default="",
                                  help_text="Text to describe this event.")

    newsletter = ParentalKey("NewsletterPage", related_name='event_links')

    def __str__(self):
        return "{}".format(self.event.title)

    panels = [
        PageChooserPanel("event", 'events.EventPage'),
        FieldPanel("override_text"),
    ]
Beispiel #6
0
    def setUp(self):
        model = PageChooserModel  # a model with a foreign key to Page which we want to render as a page chooser

        # a PageChooserPanel class that works on PageChooserModel's 'page' field
        self.MyPageChooserPanel = PageChooserPanel(
            'page', 'tests.EventPage').bind_to_model(PageChooserModel)

        # build a form class containing the fields that MyPageChooserPanel wants
        self.PageChooserForm = self.MyPageChooserPanel.get_form_class(
            PageChooserModel)

        # a test instance of PageChooserModel, pointing to the 'christmas' page
        self.christmas_page = Page.objects.get(slug='christmas')
        self.events_index_page = Page.objects.get(slug='events')
        self.test_instance = model.objects.create(page=self.christmas_page)

        self.form = self.PageChooserForm(instance=self.test_instance)
        # self.form.errors['page'] = self.form.error_class(['errors'])  # FIXME: wat
        self.page_chooser_panel = self.MyPageChooserPanel(
            instance=self.test_instance, form=self.form)
Beispiel #7
0
    def setUp(self):
        model = PageChooserModel  # a model with a foreign key to Page which we want to render as a page chooser

        # a PageChooserPanel class that works on PageChooserModel's 'page' field
        self.EditHandler = ObjectList([PageChooserPanel('page')
                                       ]).bind_to_model(PageChooserModel)
        self.MyPageChooserPanel = self.EditHandler.children[0]

        # build a form class containing the fields that MyPageChooserPanel wants
        self.PageChooserForm = self.EditHandler.get_form_class(
            PageChooserModel)

        # a test instance of PageChooserModel, pointing to the 'christmas' page
        self.christmas_page = Page.objects.get(slug='christmas')
        self.events_index_page = Page.objects.get(slug='events')
        self.test_instance = model.objects.create(page=self.christmas_page)

        self.form = self.PageChooserForm(instance=self.test_instance)
        self.page_chooser_panel = self.MyPageChooserPanel(
            instance=self.test_instance, form=self.form)
Beispiel #8
0
class HomePageHighlight(Orderable):
    homepage = ParentalKey('website.HomePage', related_name='highlights')
    title = models.CharField("Title", max_length=80, blank=True)
    blurb = RichTextField(default='', blank=True)
    image = models.ForeignKey('website.WebImage',
                              null=True,
                              blank=True,
                              on_delete=models.SET_NULL,
                              related_name='+')
    page = models.ForeignKey('wagtailcore.Page',
                             null=True,
                             blank=True,
                             related_name='+')

    panels = [
        FieldPanel('title', classname="full title"),
        FieldPanel('blurb', classname="full"),
        ImageChooserPanel('image'),
        PageChooserPanel('page'),
    ]
Beispiel #9
0
class FooterLink(Orderable, models.Model):
    footer = ParentalKey(FooterLinks, related_name='footer_links')
    target = models.ForeignKey('wagtailcore.Page')
    anchor = models.CharField(max_length=500,
                              null=True,
                              blank=True,
                              help_text='A specific anchor to scroll to.')
    _name = models.CharField(
        max_length=255,
        null=True,
        blank=True,
        verbose_name='Alt. name',
        help_text='If left empty, the target\'s title will be used.')
    name = property(lambda self: self._name or self.target.title)

    panels = [
        PageChooserPanel('target'),
        FieldPanel('anchor'),
        FieldPanel('_name'),
    ]
Beispiel #10
0
class Advert(models.Model):
    page = models.ForeignKey(
        'wagtailcore.Page',
        related_name='adverts',
        null=True,
        blank=True
    )
    url = models.URLField(null=True, blank=True)
    text = models.CharField(max_length=255)

    panels = [
        PageChooserPanel('page'),
        FieldPanel('url'),
        FieldPanel('text'),
    ]

    api_fields = ['page', 'url', 'text']

    def __str__(self):
        return self.text
Beispiel #11
0
class GlobalAnnouncementSettings(BaseSetting):
    is_enabled = models.BooleanField(default=False)

    content = models.TextField(help_text='Content of announcement')

    link_page = models.ForeignKey('wagtailcore.Page',
                                  null=True,
                                  on_delete=models.SET_NULL,
                                  related_name='+')

    show_dismiss = models.BooleanField(default=True)
    dismiss_key = models.CharField(max_length=12)

    panels = [
        FieldPanel('is_enabled'),
        FieldPanel('content'),
        FieldPanel('show_dismiss'),
        FieldPanel('dismiss_key'),
        PageChooserPanel('link_page')
    ]
Beispiel #12
0
class HomePageGalleryItem(Orderable):
    image = models.ForeignKey('wagtailimages.Image',
                              null=True,
                              blank=True,
                              on_delete=models.SET_NULL,
                              related_name='+')
    link_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        related_name='+',
        help_text='Add if you want this item to link to a page on this site.')
    caption = models.CharField(max_length=255, blank=True)
    page = ParentalKey('home.HomePage', related_name='banner_items')

    panels = [
        ImageChooserPanel('image'),
        FieldPanel('caption'),
        PageChooserPanel('link_page'),
    ]
Beispiel #13
0
class Portfolio(Page):
    name = models.TextField(max_length=255, default='')
    portfolio_category = models.ForeignKey(PortfolioCategory,
                                           on_delete=models.SET_NULL,
                                           null=True,
                                           blank=True,
                                           related_name='+')
    image = models.ForeignKey('wagtailimages.Image',
                              related_name='+',
                              on_delete=models.SET_NULL,
                              null=True,
                              blank=True)

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('name'),
            ImageChooserPanel('image'),
        ], 'Portfolio'),
        PageChooserPanel('portfolio_category'),
    ]
Beispiel #14
0
class Panel(models.Model):
    title = models.CharField(max_length=255, help_text="Panel Title")
    content = models.TextField(help_text="Panel Body")
    link_page = models.ForeignKey('wagtailcore.page',
                                  null=True,
                                  blank=True,
                                  related_name='+')
    link_text = models.CharField(max_length=255,
                                 help_text="Link Text",
                                 blank=True)

    panels = [
        FieldPanel('title'),
        FieldPanel('content', classname="full"),
        PageChooserPanel('link_page'),
        FieldPanel('link_text'),
    ]

    class Meta:
        abstract = True
Beispiel #15
0
class HeaderSettings(ClusterableModel, BaseSetting):
    banner_first_intro = RichTextField(null=True, blank=True)
    banner_second_intro = RichTextField(null=True, blank=True)
    banner_image = models.ForeignKey('wagtailimages.Image',
                                     null=True,
                                     blank=True,
                                     on_delete=models.SET_NULL,
                                     related_name='+')

    show_participate = models.BooleanField(default=False)
    participate_target = models.ForeignKey('wagtailcore.Page',
                                           null=True,
                                           blank=True)
    participate_alt_name = models.CharField(
        max_length=255,
        null=True,
        blank=True,
        verbose_name='Alt. name',
        help_text='If left empty, the target\'s title will be used.')
    participate_name = property(lambda self: self.participate_alt_name or self.
                                participate_target.title)

    panels = [
        MultiFieldPanel(
            [
                FieldPanel('banner_first_intro'),
                FieldPanel('banner_second_intro'),
                ImageChooserPanel('banner_image'),
            ],
            heading="Banner",
        ),
        InlinePanel('header_links', label="Link", classname="collapsed"),
        MultiFieldPanel(
            [
                FieldPanel('show_participate'),
                FieldPanel('participate_alt_name'),
                PageChooserPanel('participate_target'),
            ],
            heading="Participate",
        ),
    ]
Beispiel #16
0
class LinkFields(models.Model):
    link_external = models.URLField(
        "External link",
        blank=True,
        help_text=
        'Add if you want this item to link to an external url. Add only one of External Link, Link Page, or Link Document.'
    )
    link_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        related_name='+',
        help_text=
        'Add if you want this item to link to a page on this site. Add only one of External Link, Link Page, or Link Document.'
    )
    link_document = models.ForeignKey(
        'wagtaildocs.Document',
        null=True,
        blank=True,
        related_name='+',
        help_text=
        'Add if you want this item to link to a document. Add only one of External Link, Link Page, or Link Document.'
    )

    @property
    def link(self):
        if self.link_page:
            return self.link_page.url
        elif self.link_document:
            return self.link_document.url
        else:
            return self.link_external

    panels = [
        FieldPanel('link_external'),
        PageChooserPanel('link_page'),
        DocumentChooserPanel('link_document'),
    ]

    class Meta:
        abstract = True
Beispiel #17
0
    def test_render_js_init_with_can_choose_root_true(self):
        # construct an alternative page chooser panel object, with can_choose_root=True

        MyPageObjectList = ObjectList([
            PageChooserPanel('page', can_choose_root=True)
        ]).bind_to_model(PageChooserModel)
        MyPageChooserPanel = MyPageObjectList.children[0]
        PageChooserForm = MyPageObjectList.get_form_class(
            EventPageChooserModel)

        form = PageChooserForm(instance=self.test_instance)
        page_chooser_panel = MyPageChooserPanel(instance=self.test_instance,
                                                form=form)
        result = page_chooser_panel.render_as_field()

        # the canChooseRoot flag on createPageChooser should now be true
        expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, true);'.format(
            id="id_page",
            model="wagtailcore.page",
            parent=self.events_index_page.id)
        self.assertIn(expected_js, result)
Beispiel #18
0
class LinkFields(models.Model):
    link_external = models.URLField("External link", blank=True)
    link_page = models.ForeignKey('wagtailcore.Page',
                                  null=True,
                                  blank=True,
                                  related_name='+')

    @property
    def link(self):
        if self.link_page:
            return self.link_page.url
        else:
            return self.link_external

    panels = [
        FieldPanel('link_external'),
        PageChooserPanel('link_page'),
    ]

    class Meta:
        abstract = True
Beispiel #19
0
class Advert(LinkFields):
    page = models.ForeignKey(
        Page,
        related_name='adverts',
        null=True,
        blank=True
    )
    title = models.CharField(max_length=150, null=True)
    image = models.ForeignKey(Image, null=True, blank=True, on_delete=models.SET_NULL)
    text = RichTextField(blank=True)

    panels = [
        PageChooserPanel('page'),
        FieldPanel('title'),
        ImageChooserPanel('image'),
        FieldPanel('text'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

    def __unicode__(self):
        return self.title
Beispiel #20
0
class HomePageGalleryItem(Orderable):
    THEME_CHOICES = (
        ('dark', 'Dark'),
        ('light', 'Light'),
    )
    
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text="Minimum 1920px wide"
    )
    link_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        related_name='+',
        help_text='Add if you want this item to link to a page on this site.'
    )

    video_hd_url = models.URLField(blank=True,
        help_text='High Definition URL from a video streaming service such as Vimeo.')
    video_sd_url = models.URLField(blank=True,
        help_text='Standard Definition URL from a video streaming service such as Vimeo.')
    caption = RichTextField(features=['bold', 'italic'])
    theme = models.CharField(max_length=255, choices=THEME_CHOICES, default='light')
    page = ParentalKey('home.HomePage', related_name='slideshow_images')

    panels = [
        ImageChooserPanel('image'),
        MultiFieldPanel([
            FieldPanel('video_hd_url'),
            FieldPanel('video_sd_url'),
        ], heading="Video"),
        FieldPanel('caption'),
        FieldPanel('theme'),
        PageChooserPanel('link_page'),
    ]
Beispiel #21
0
class HeaderLink(Orderable, models.Model):
    header = ParentalKey(HeaderLinks, related_name='header_links')
    target = models.ForeignKey('wagtailcore.Page')
    _name = models.CharField(
        max_length=255,
        null=True,
        blank=True,
        verbose_name='Alt. name',
        help_text='If left empty, the target\'s title will be used.')
    name = property(lambda self: self._name or self.target.title)
    menu_items = StreamField([
        ('jump_link', JumpLinkBlock()),
        ('page_link', PageLinkBlock()),
    ],
                             null=True,
                             blank=True)

    panels = [
        PageChooserPanel('target'),
        FieldPanel('_name'),
        StreamFieldPanel('menu_items'),
    ]
Beispiel #22
0
class Teaser(models.Model):
    page = ParentalKey('pages.AboutPage', related_name='teasers')
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
    )
    title = models.CharField(max_length=100)
    subtitle = models.CharField(max_length=100)
    link = models.ForeignKey('wagtailcore.Page',
                             null=True,
                             blank=True,
                             related_name='+')

    panels = [
        ImageChooserPanel('image'),
        FieldPanel('title'),
        FieldPanel('subtitle'),
        PageChooserPanel('link'),
    ]
Beispiel #23
0
class HomePage(Page):
    parent_page_types = []

    body = RichTextField(blank=True)
    featured_article = models.ForeignKey(ArticlePage,
                                         null=True,
                                         blank=True,
                                         on_delete=models.SET_NULL)

    content_panels = Page.content_panels + [
        FieldPanel('body', classname="full"),
        PageChooserPanel('featured_article'),
        InlinePanel('preview_articles', label='Previewed Articles'),
    ]

    class Meta:
        verbose_name = "Homepage"

    def latest_articles(self):
        articles = ArticlePage.objects.live()
        articles = articles.order_by('-date')
        return articles[0:5]
Beispiel #24
0
class LinkFields(models.Model):
    """
    Adds fields for internal and external links with some methods to simplify the rendering:

    {% if page.link_page %}
        <a href="{% pageurl page.link_page %}">{{ page.get_link_text }}</a>
    {% elif page.link_url  %}
        <a href="{{ page.link_url }}">{{ page.get_link_text }}</a>
    {% endif %}
    """

    link_page = models.ForeignKey(
        Page,
        blank=True,
        null=True,
        on_delete=models.SET_NULL,
    )
    link_url = models.URLField(blank=True)
    link_text = models.CharField(blank=True, max_length=255)

    class Meta:
        abstract = True

    def get_link_text(self):
        if self.link_text:
            return self.link_text

        if self.link_page:
            return self.link_page.title

        return ''

    content_panels = [
        MultiFieldPanel([
            PageChooserPanel('link_page'),
            FieldPanel('link_url'),
            FieldPanel('link_text'),
        ], 'Link'),
    ]
Beispiel #25
0
class NewsletterExternalArticleLink(Orderable, models.Model):
    external_article = models.ForeignKey(
        "articles.ExternalArticlePage",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text="Link to an external article")
    override_text = RichTextField(blank=True,
                                  default="",
                                  help_text="Text to describe article.")

    newsletter = ParentalKey("NewsletterPage",
                             related_name='external_article_links')

    def __str__(self):
        return "{}".format(self.external_article.title)

    panels = [
        PageChooserPanel("external_article", 'articles.ExternalArticlePage'),
        FieldPanel("override_text"),
    ]
class Testimonial(LinkFields):
    page = models.ForeignKey(Page,
                             related_name='testimonials',
                             null=True,
                             blank=True)
    name = models.CharField(max_length=150)
    photo = models.ForeignKey(Image,
                              null=True,
                              blank=True,
                              on_delete=models.SET_NULL)
    text = models.CharField(max_length=255)

    panels = [
        PageChooserPanel('page'),
        FieldPanel('name'),
        ImageChooserPanel('photo'),
        FieldPanel('text'),
        MultiFieldPanel(LinkFields.panels, "Link"),
    ]

    def __unicode__(self):
        return self.name
Beispiel #27
0
class IndexLink(models.Model):
    link_page = models.ForeignKey('wagtailcore.Page',
                                  null=True,
                                  blank=True,
                                  related_name='+')
    button_text = models.CharField(max_length=255,
                                   help_text="Button title",
                                   null=True,
                                   blank=True,
                                   default="button")

    @property
    def link(self):
        if self.link_page:
            return self.link_page.url
        else:
            return self.link_external

    panels = [
        PageChooserPanel('link_page'),
        FieldPanel('button_text'),
    ]
Beispiel #28
0
class CustomFormPage(CustomPage):
    redirect_page = models.ForeignKey('wagtailcore.Page',
                                      null=True,
                                      blank=True,
                                      on_delete=models.SET_NULL,
                                      related_name='+')

    def serve(self, request):
        fb = GeoKitFormBuilder(self.form_fields.all())
        form_class = fb.get_form_class()

        if request.method == "POST":
            form = form_class(request.POST)

            if form.is_valid():
                # Save form variables
                for var, value in form.cleaned_data.items():
                    # Currently, this saves model instances (such as Features)
                    # serialized using their unicode representations. Maybe this
                    # should be less hacky?
                    var = FormVariable(name=var,
                                       value=value,
                                       user=request.user)
                    var.save()

                return redirect(self.redirect_page.url)
        else:
            form = form_class()

        return render(request, self.template, {
            'self': self,
            'form': form,
        })

    content_panels = CustomPage.content_panels + [
        InlinePanel('form_fields', label="Form fields"),
        PageChooserPanel('redirect_page'),
    ]
Beispiel #29
0
class ArtworkPage(Page):
    description = RichTextField(blank=True, null=True)
    date = models.DateField("Post date", default=datetime.date.today)
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    video = models.ForeignKey(
        'wagtaildocs.Document',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )

    content_panels = Page.content_panels + [
        FieldPanel('description'),
        FieldPanel('date'),
        ImageChooserPanel('image'),
        DocumentChooserPanel('video'),
        InlinePanel('artworkartistlink', label="Artist Attributes",
            panels = [
                PageChooserPanel('artist', 'artists.ArtistProfilePage'),
            ]
        ),
    ]

    api_fields = ['slug', 'title', 'description', 'date', 'image', 'video', 'artwork_preview_url']

    subpage_types = []

    @property
    def artwork_preview_url(self):
        if self.image:
            return generate_image_url(self.image, 'width-800')
Beispiel #30
0
class CookieBannerSettings(BaseSetting):

    is_active = models.BooleanField("Active", default=False)
    title = models.CharField(blank=True, max_length=100)
    text = RichTextField(blank=True)
    policy_page = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        on_delete=models.SET_NULL,
    )

    updated_at = models.DateTimeField(auto_now=True)

    panels = [
        FieldPanel('is_active'),
        FieldPanel('title'),
        FieldPanel('text', classname='full'),
        PageChooserPanel('policy_page'),
    ]

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        purge_esi()