class LinkFields(models.Model): link_external = models.URLField("External link", blank=True) link_page = models.ForeignKey( "wagtailcore.Page", null=True, blank=True, related_name="+", on_delete=models.CASCADE, ) link_document = models.ForeignKey( "wagtaildocs.Document", null=True, blank=True, related_name="+", on_delete=models.CASCADE, ) @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
class PublicationPage(ArticlePage): author_list = StreamField([('author', AuthorBlock())], blank=True) date = models.DateField(blank=True, null=True) abstract = RichTextField(blank=True, null=True) journal = models.CharField(blank=True, null=True, max_length=250) pdf = models.ForeignKey( 'wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) link = models.URLField(null=True, blank=True) search_fields = Page.search_fields + [ index.SearchField('author_list'), index.SearchField('abstract'), index.SearchField('journal'), ] content_panels = Page.content_panels + [ StreamFieldPanel('author_list'), FieldPanel('date'), FieldPanel('abstract', classname="full"), FieldPanel('journal'), DocumentChooserPanel('pdf'), FieldPanel('link'), ] index_entry_template = 'articles/fragments/publication_index_entry.html' citation_template = 'articles/fragments/publication_citation.html' def print_author_list(self): names = [author.value['name'] for author in self.author_list] return ', '.join(names)
class SliderItem(Orderable): page = ParentalKey('HomePage', related_name='slider_items', null=True) title = models.CharField(max_length=255, verbose_name="Tytuł") description = RichTextField(verbose_name="Opis") link = models.TextField(null=True, blank=True, verbose_name="Link zewnętrzny") related_page = models.ForeignKey( 'wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', ) image = models.ForeignKey('wagtailimages.Image', related_name='+', verbose_name="Obrazek", on_delete=models.SET_NULL, null=True, blank=True) file = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') panels = [ FieldPanel('title', classname="full"), FieldPanel('description', classname="full"), FieldPanel('link', classname="full"), PageChooserPanel('related_page'), ImageChooserPanel('image'), DocumentChooserPanel('file'), ]
class PlantCollections(Orderable): page = ParentalKey(PlantCollectionsPage, blank=True, null=True, on_delete=models.SET_NULL, related_name="plant_collections") image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') collection_doc = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') title = models.CharField(max_length=255) text = RichTextField() slideshow_link = models.URLField() panels = [ ImageChooserPanel('image'), FieldPanel('title'), FieldPanel('text'), MultiFieldPanel([ FieldPanel('slideshow_link'), DocumentChooserPanel('collection_doc') ], heading=_('Info for Collection buttons')), ]
class BeerContainer(AbstractBaseModel): name = models.CharField(max_length=255, verbose_name='Container name') volume = models.IntegerField(default=0, verbose_name='Volume in cl') svg_icon = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') panels = [ FieldRowPanel([ FieldPanel('name', classname='col4'), FieldPanel('volume', classname='col4'), DocumentChooserPanel('svg_icon', classname='col4'), ]), ] + AbstractBaseModel.panels class Meta: ordering = [ 'sort_order', 'name', ] verbose_name = 'Beer Container' verbose_name_plural = 'Beer Containers' app_label = 'beer' def __str__(self): return self.name def get_svg_icon_content(self): return get_svg_content(self.svg_icon)
class DashboardPageCarouselVideos(Orderable): '''Between 1 and 5 imagges for the home carousel ''' page = ParentalKey("dashboard.DashboardPage", related_name="carousel_media") carousel_video = models.ForeignKey("wagtailvideos.Video", null=True, blank=True, on_delete=models.CASCADE, related_name="+", unique=True) carousel_document = models.ForeignKey("documents.CustomDocument", null=True, blank=True, on_delete=models.CASCADE, related_name="+", unique=True) carousel_image = models.ForeignKey("documents.CustomImage", null=True, blank=True, on_delete=models.CASCADE, related_name="+", unique=True) panels = [ VideoChooserPanel("carousel_video"), DocumentChooserPanel("carousel_document"), ImageChooserPanel("carousel_image") ]
class LinkFields(models.Model): link_external = models.URLField("External link", blank=True) link_page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, related_name='+', on_delete=models.SET_NULL) link_document = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, related_name='+', on_delete=models.SET_NULL) @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
class PublicationDownload(index.Indexed, BaseDownload): language = models.ForeignKey( 'Language', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) panels = [ DocumentChooserPanel('file'), FieldPanel('title'), FieldPanel('language', widget=forms.RadioSelect), ] search_fields = [ index.SearchField('title', partial_match=True), ] def __str__(self): if self.language: return '%s | %s' % (self.title, self.language.title) return self.title def save(self, *args, **kwargs): self.title = self.title if self.title else self.file.title super(PublicationDownload, self).save(*args, **kwargs)
class CookieNotice(models.Model): heading = models.CharField(max_length=255, blank=True, null=True) body = models.TextField(blank=True, null=True) download_link_caption = models.CharField(max_length=255, blank=True, null=True, verbose_name='Link Caption') cookie_policy = models.ForeignKey( 'wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name='Policy Doc' ) panels = [ FieldPanel('heading'), FieldPanel('body'), MultiFieldPanel([ FieldPanel('download_link_caption'), DocumentChooserPanel('cookie_policy'), ], heading='Download Link'), ] def __str__(self): return self.heading or self.body or 'Blank Notice' class Meta(): verbose_name = "Cookie Notice" verbose_name_plural = "Cookie Notices"
class IGGuidance(BasePage): subpage_types = ["publications.PublicationPage"] topic = models.ForeignKey( IGGuidanceTopic, on_delete=models.PROTECT, related_name="+" ) tags = ParentalManyToManyField("IGGuidanceTag", blank=False) summary = models.TextField() featured_image = models.ForeignKey( settings.WAGTAILIMAGES_IMAGE_MODEL, null=True, blank=True, on_delete=models.SET_NULL, related_name="+", ) download = models.ForeignKey( settings.WAGTAILDOCS_DOCUMENT_MODEL, null=True, blank=True, on_delete=models.SET_NULL, related_name="+", ) content_panels = Page.content_panels + [ FieldPanel("topic", widget=forms.Select), FieldPanel("tags", widget=forms.CheckboxSelectMultiple), FieldPanel("summary"), ImageChooserPanel("featured_image"), DocumentChooserPanel("download"), ] class Meta: abstract = True
class Archive(FileContent): address = models.CharField(max_length=256, blank=True, verbose_name="Dirección") panels = [ FieldPanel('title', classname='title'), FieldPanel('body', classname="full"), ImageChooserPanel('image', heading='heading'), DocumentChooserPanel('file', heading='heading'), FieldPanel('publish_at', classname="full"), FieldPanel('address', classname="full"), FieldPanel('published', classname="full"), FieldPanel('pinned', classname="full"), ] api_fields = [ APIField('title'), APIField('body', serializer=RichTextRendereableField()), APIField('image'), APIField('file'), APIField('publish_at'), APIField('address'), APIField('published'), APIField('pinned'), ] class Meta: verbose_name = 'Archivo' verbose_name_plural = 'Archivos'
class FileContent(RawContent): file = models.ForeignKey('wagtaildocs.Document', on_delete=models.DO_NOTHING, related_name='+', verbose_name="Documento") publish_at = models.DateTimeField( 'Fecha de publicación', default=now, help_text='Fecha de publicación del documento.') search_fields = [] panels = [ FieldPanel('title', classname='title'), FieldPanel('body', classname="full"), ImageChooserPanel('image', heading='heading'), DocumentChooserPanel('file', heading='heading'), FieldPanel('publish_at', classname="full"), FieldPanel('published', classname="full"), FieldPanel('pinned', classname="full"), ] api_fields = [ APIField('title'), APIField('body', serializer=RichTextRendereableField()), APIField('image'), APIField('file'), APIField('published'), APIField('publish_at'), APIField('pinned'), ] class Meta: abstract = True
class OfficialDocumentPageOfficialDocument(Orderable): page = ParentalKey(OfficialDocumentPage, related_name='official_documents') date = models.DateField(verbose_name="Document date", null=True) title = models.CharField(verbose_name="Document title", max_length=DEFAULT_MAX_LENGTH) authoring_office = models.CharField( verbose_name="Authoring office of document", max_length=DEFAULT_MAX_LENGTH) summary = models.TextField(verbose_name="Document summary") name = models.CharField(verbose_name="Name of Document", max_length=DEFAULT_MAX_LENGTH) document = models.ForeignKey(Document, null=True, blank=False, on_delete=models.SET_NULL, related_name='+') panels = [ FieldPanel('date'), FieldPanel('title', widget=countMe), FieldPanel('authoring_office', widget=countMe), FieldPanel('summary', widget=widgets.CountableWidget( attrs={ 'data-count': 'characters', 'data-max-count': AUTHOR_LIMITS['document_summary'], 'data-count-direction': 'down' })), FieldPanel('name', widget=countMe), DocumentChooserPanel('document') ] class Meta: indexes = [models.Index(fields=['-date'])]
class RelatedDocOrderable(Orderable): page = ParentalKey("legislation.LawPage", related_name='related_docs') related_doc = models.ForeignKey("base.CustomDocument", null=True, blank=True, on_delete=models.SET_NULL, related_name='+') @property def title(self): return self.related_doc.title @property def filename(self): return self.related_doc.filename @property def file_size(self): return self.related_doc.get_file_size() @property def file_extension(self): return self.related_doc.file_extension panels = [DocumentChooserPanel('related_doc')] api_fields = [ APIField('title'), APIField('related_doc'), APIField('filename'), APIField('file_size'), APIField('file_extension') ]
def ReportDownloadPanel(): return MultiFieldPanel([ FieldPanel('download_report_title'), FieldPanel('download_report_body'), ImageChooserPanel('download_report_cover'), DocumentChooserPanel('report_download') ], heading='Report download section')
class DirectorySettings(BaseSetting): # Contact new_instance_alert_group = models.OneToOneField( Group, blank=True, null=True, help_text= 'Users in this group will get an email alert when a new SecureDrop instance is submitted', on_delete=models.CASCADE, ) contact_email = models.EmailField( default='*****@*****.**', help_text='People should contact this email address about inaccuracies ' 'or potential attacks in the directory') contact_gpg = models.ForeignKey( 'wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name='Contact email GPG', help_text='Public key for email communication') # Messages grade_text = models.CharField(max_length=100, default='Security Grade') no_results_text = RichTextField( default='Results could not be calculated.', help_text= 'Text displayed when there are no results for a results group.') # Feature flags allow_directory_management = models.BooleanField( default=False, help_text='Allow directory instance submission/management by ' 'site visitors') show_scan_results = models.BooleanField( default=False, help_text='Show directory instance scan results on public site') panels = [ MultiFieldPanel([ FieldPanel('grade_text'), FieldPanel('no_results_text'), ], 'Messages'), MultiFieldPanel([ FieldPanel('allow_directory_management'), FieldPanel('show_scan_results'), ], 'Feature Flags'), MultiFieldPanel([ FieldPanel('new_instance_alert_group'), FieldPanel('contact_email'), DocumentChooserPanel('contact_gpg'), ], 'Contact'), ] class Meta: verbose_name = 'Directory Settings'
class MyPageDocumentLink(Orderable): page = ParentalKey(BreadPage, related_name='documents') document = models.ForeignKey('wagtaildocs.Document', on_delete=models.CASCADE, related_name='+') panels = [ DocumentChooserPanel('document'), ]
class NewsIndex(Page): intro = RichTextField(blank=True) press_kit = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') promote_image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') @property def articles(self): articles = NewsArticle.objects.live().child_of(self) article_data = {} for article in articles: article_data['{}'.format(article.slug)] = { 'detail_url': '/apps/cms/api/v2/pages/{}/'.format(article.pk), 'date': article.date, 'heading': article.heading, 'subheading': article.subheading, 'body_blurb': article.first_paragraph, 'pin_to_top': article.pin_to_top, 'article_image': article.article_image, 'article_image_alt': article.featured_image_alt_text, 'author': article.author, 'tags': [tag.name for tag in article.tags.all()], } return article_data content_panels = Page.content_panels + [ FieldPanel('intro', classname="full"), DocumentChooserPanel('press_kit'), ] promote_panels = [ FieldPanel('slug'), FieldPanel('seo_title'), FieldPanel('search_description'), ImageChooserPanel('promote_image') ] api_fields = [ APIField('intro'), APIField('press_kit'), APIField('articles'), APIField('slug'), APIField('seo_title'), APIField('search_description'), APIField('promote_image') ] subpage_types = ['news.NewsArticle'] parent_page_types = ['pages.HomePage'] max_count = 1
class MenuItem(Orderable): text = models.CharField(max_length=255) link_page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') link_document = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') link_url = models.CharField( blank=True, max_length=255, help_text='A URL or path for this menu item to link to.') html_title = models.CharField( blank=True, max_length=255, help_text='Value for the HTML title attribute') html_classes = models.CharField( blank=True, max_length=255, help_text='HTML classes to be added to this menu item') menu = ParentalKey(Menu, related_name='menu_items') panels = [ FieldPanel('text'), MultiFieldPanel(( PageChooserPanel('link_page'), DocumentChooserPanel('link_document'), FieldPanel('link_url'), ), 'Destination'), MultiFieldPanel(( FieldPanel('html_title'), FieldPanel('html_classes'), ), 'HTML') ] indexes = [ models.Index( fields=['sort_order']), # Defined in wagtail.models.Orderable models.Index(fields=['menu']), ] @property def url(self): """ Return an available url in this order of priority: page, document, raw url. """ if self.link_page: return self.link_page.url if self.link_document: return self.link_document.url return self.link_url
class HomePage(Page): short_description = RichTextField( verbose_name=_('Short description'), null=True, validators=[ProhibitBlankRichTextValidator()]) image = models.ForeignKey( 'wagtailimages.Image', null=True, on_delete=models.SET_NULL, related_name='+', verbose_name=_('Background image'), ) related_page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name=_('Blog page')) book_file = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name=_('Document')) # Meta tags meta_key_words = models.TextField(blank=True, max_length=255, verbose_name=_('SEO keywords')) Page.content_panels[0].classname = 'class-fix-panels' content_panels = [ MultiFieldPanel(Page.content_panels + [ FieldPanel('short_description'), ImageChooserPanel('image'), PageChooserPanel('related_page', 'blog.BlogInnerPage'), DocumentChooserPanel('book_file'), ], heading=_('Home')) ] promote_panels = [ MultiFieldPanel(Page.promote_panels + [ FieldPanel('meta_key_words'), ], _('Common page configuration')) ] # Maximum number of pages created max_count = 1 class Meta: verbose_name = _('Home')
class LinkFields(models.Model): """ An object which will be a link in every page. """ link_external = models.URLField(_('External Link'), blank=True) link_page = models.ForeignKey( 'wagtailcore.Page', null=True, blank=True, related_name='+', verbose_name=_("Page's Link"), on_delete=models.SET_NULL, ) link_document = models.ForeignKey( 'wagtaildocs.Document', null=True, blank=True, related_name='+', verbose_name=_("File's link"), on_delete=models.SET_NULL, ) link_email = models.EmailField( _("E-mail's link"), blank=True, null=True, ) link_phone = models.CharField( _("Phone's link"), max_length=20, blank=True, null=True, ) @property def link(self): if self.link_page: return self.link_page.url elif self.link_document: return self.link_document.url elif self.link_email: return 'mailto:%s' % self.link_email elif self.link_phone: return 'tel:%s' % self.link_phone.strip() else: return self.link_external panels = [ FieldPanel('link_external'), PageChooserPanel('link_page'), DocumentChooserPanel('link_document'), FieldPanel('link_email'), FieldPanel('link_phone'), ] class Meta: abstract = True
class NewsPageAttach(Orderable): page = ParentalKey(NewsPage, on_delete=models.CASCADE, related_name='news_attach') attach = models.ForeignKey( 'wagtaildocs.Document', on_delete=models.CASCADE, related_name='+', verbose_name="附件", ) panels = [ DocumentChooserPanel('attach'), ]
class BookPage(Page): book_file = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') content_panels = Page.content_panels + [ DocumentChooserPanel('book_file'), ]
class BlogPage(GrapplePageMixin, Page): author = models.CharField(max_length=255) date = models.DateField("Post date") advert = models.ForeignKey('home.Advert', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') cover = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') book_file = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') featured_media = models.ForeignKey('wagtailmedia.Media', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') body = StreamField([ ("heading", blocks.CharBlock(classname="full title")), ("paraagraph", blocks.RichTextBlock()), ("image", ImageChooserBlock()), ("decimal", blocks.DecimalBlock()), ("date", blocks.DateBlock()), ("datetime", blocks.DateTimeBlock()), ]) content_panels = Page.content_panels + [ FieldPanel("author"), FieldPanel("date"), ImageChooserPanel('cover'), StreamFieldPanel("body"), InlinePanel('related_links', label="Related links"), SnippetChooserPanel('advert'), DocumentChooserPanel('book_file'), MediaChooserPanel('featured_media'), ] graphql_fields = [ GraphQLString("heading"), GraphQLString("date"), GraphQLString("author"), GraphQLStreamfield("body"), GraphQLForeignKey("related_links", "home.blogpagerelatedlink", True), GraphQLSnippet('advert', 'home.Advert'), GraphQLImage('cover'), GraphQLDocument('book_file'), GraphQLMedia('featured_media'), ]
class ServicePageDocumentLink(Orderable): page = ParentalKey(ServicePage, related_name="documents") document = models.ForeignKey(Document, on_delete=models.CASCADE, related_name="+") include_in_email = models.BooleanField(default=True) panels = [ DocumentChooserPanel("document"), FieldPanel("include_in_email"), ]
class RegularPage(Page): body = RichTextField(blank=True) book_file = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') content_panels = Page.content_panels + [ FieldPanel('body', classname="full"), DocumentChooserPanel('book_file'), ]
class ThesisFinishedPage(Page): body = get_standard_streamfield() about_author = RichTextField() pdf_thesis = models.ForeignKey( "wagtaildocs.Document", null=True, blank=True, on_delete=models.SET_NULL, related_name="+", ) pdf_thumbnail = models.ForeignKey( "wagtailimages.Image", null=True, blank=False, on_delete=models.SET_NULL, related_name="+", ) author_pic = models.ForeignKey( "wagtailimages.Image", null=True, blank=False, on_delete=models.SET_NULL, related_name="+", ) content_panels = Page.content_panels + [ DocumentChooserPanel("pdf_thesis"), ImageChooserPanel("pdf_thumbnail"), ImageChooserPanel("author_pic"), FieldPanel("about_author"), StreamFieldPanel("body"), ] parent_page_types = ["theses.ThesisFinishedIndexPage"] def prev(self): prev_sibling = self.get_prev_sibling() if prev_sibling: if prev_sibling.live: return prev_sibling else: return prev_sibling.prev() def next(self): next_sibling = self.get_next_sibling() if next_sibling: if next_sibling.live: return next_sibling else: return next_sibling.next()
class AbstractLinkFields(models.Model): link_external = models.URLField('External link', blank=True) link_page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') link_document = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') link_text = models.CharField( max_length=255, null=True, blank=True, help_text= "Provide the text to use for an external link, or override the internal link text." ) @property def anchor_url(self): """ The link. """ if self.link_page: return self.link_page.url elif self.link_document: return self.link_document.url else: return self.link_external @property def anchor_text(self): """ The text to display for the menu item. """ if self.link_text: return self.link_text elif self.link_page: return self.link_page.title elif self.link_document: return self.link_document.title else: return self.link_external panels = [ FieldPanel('link_external'), PageChooserPanel('link_page'), DocumentChooserPanel('link_document'), FieldPanel('link_text'), ] class Meta: abstract = True
class AbstractRelatedDocument(Orderable): document = models.ForeignKey(Document, on_delete=models.CASCADE, related_name='+', verbose_name=_('document')) title_en = models.CharField(max_length=64) title_de = models.CharField(max_length=64) TranslatedField('title') panels = [DocumentChooserPanel('document')] class Meta: abstract = True
class DocumentList(Orderable): page = ParentalKey("document.DocumentPage", related_name="related_documents") related_document = models.ForeignKey( "wagtaildocs.Document", null=True, blank=False, on_delete=models.SET_NULL, related_name="+", ) panels = [DocumentChooserPanel("related_document")]