class PagesStreamBlock(StreamBlock): content_centered = RichTextBlock(icon="pilcrow", label=u"居中内容") page_title = PageTitle(icon="pilcrow", label=u"大小标题模块") underline_title = PageTitle(icon="pilcrow", label=u"下划线标题模块") html_paragraph = RawHTMLBlock(icon="code", label=u'HTML段落') html_quote = RawHTMLBlock(icon = "openquote", label=u'HTML引用') right_aligned_quote = TextBlock(icon = "openquote", label=u'右对齐引用') paragraph = RichTextBlock(icon="pilcrow", label=u'段落') image_with_caption = ImageBlock(icon="image", label=u'带标题图片') image_list = ImageListBlock(icon="image", label=u'图片列表') html = RawHTMLBlock(icon="code", label=u'HTML代码')
class HomePage(Page): main_image = models.ForeignKey('base.CustomImage', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') heading = models.CharField(max_length=50, default="Omar Rahman") intro = models.CharField(max_length=255, default="Web Developer, Designer, Illustrator") body = RichTextField(blank=True) customMarkup = StreamField([ ('markup', RawHTMLBlock()), ], blank=True, null=True) content_panels = Page.content_panels + [ FieldPanel('body', classname="hero-content"), ImageChooserPanel('main_image'), FieldPanel('heading'), FieldPanel('intro'), StreamFieldPanel('customMarkup') ] def get_context(self, request): context = super(HomePage, self).get_context(request) context['homePageSection'] = HomePageSection.objects.all() return context
class HomePage(Page, MeetupMixin, SponsorMixin): subpage_types = [ 'HomePage', 'SimplePage', 'speakers.SpeakersPage', 'speakers.TalksPage' ] body = StreamField([('heading', blocks.CharBlock(icon="home", classname="full title")), ('paragraph', blocks.RichTextBlock(icon="edit")), ('video', EmbedBlock(icon="media")), ('image', ImageChooserBlock(icon="image")), ('slide', EmbedBlock(icon="media")), ('html', RawHTMLBlock(icon="code"))]) sponsors = models.ManyToManyField(Sponsor, through=HomePageSponsorRelationship, null=True, blank=True) def __str__(self): return self.title content_panels = Page.content_panels + [ StreamFieldPanel('body'), ] settings_panels = Page.settings_panels + MeetupMixin.settings_panels + SponsorMixin.settings_panels + [ InlinePanel('homepage_segments', label='Homepage Segment'), ]
class Footer(Model): title = CharField(default='untitled', max_length=255) content = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', RichTextBlock()), ('image', ImageChooserBlock()), ('columns', RowBlock()), ('raw_html', RawHTMLBlock( help_text= 'With great power comes great responsibility. This HTML is unescaped. Be careful!' )), ('google_map', GoogleMapBlock()), ('twitter_feed', TwitterBlock()), ('photo_stream', COSPhotoStreamBlock()), ('centered_text', CenteredTextBlock()), ], null=True, blank=True) class Meta: verbose_name = "Footer" verbose_name_plural = "Footers" panels = [ FieldPanel('title'), StreamFieldPanel('content'), ] def __str__(self): return self.title
class AlignedHTMLBlock(StructBlock): html = RawHTMLBlock( help_text="Use to embed code/widgets from external sites") alignment = HTMLAlignmentChoiceBlock() class Meta: icon = "code"
class HomePage(Page): tagline = models.CharField(max_length=255, null=True, blank=True) body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('embeded_content', EmbedBlock()), ('raw_HTML', RawHTMLBlock()), ])
class ParagraphWithRawEmbedBlock(blocks.StructBlock): embed = RawHTMLBlock(help_text="Embed HTML code(an iframe)") embed_caption = RichTextMiniBlock(required=False) embed_align = blocks.ChoiceBlock(choices=ALIGNMENT_CHOICES, default=ALIGNMENT_CHOICES[0][0]) content = PargraphBlockWithOptionalContent(required=False) class Meta: icon = 'media' label = 'Raw embed with text' template = 'article/blocks/paragraph_with_raw_embed.html'
class HomePagesStreamBlock(StreamBlock): paragraph = RichTextBlock(icon="pilcrow", label=u'段落') image_list_4 = FourColImageListBlock(icon="image", label=u"四列图片") image_list_3 = ThreeColImageListBlock(icon="image", label=u"三列图片") image_list_2 = TwoColImageListBlock(icon="image", label=u"两列图片") link_list = LinkList(icon="link", label=u"链接列表") html = RawHTMLBlock(icon="code", label=u'HTML代码') overlap = OverlapDesign(icon="pilcrow", label=u"大小标题模块") quote = TextBlock(icon = "openquote", label=u'引用') image_list_5 = HPFiveColImageListBlock(icon="image", label=u"主页五列图片") carousel = Carousel(icon="image", label=u"幻灯片图片")
class HomePageSection(Page): main_image = models.ForeignKey(CustomImage, null=True, blank=True, on_delete=models.SET_NULL, related_name='+') orientation = models.CharField(max_length=50, choices=(('left', 'LEFT'), ('right', 'RIGHT'), ('centre', 'CENTRE'), ('freeform', 'FREEFORM')), default='left') link_page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') button_text = models.CharField(max_length=255, help_text="Button title", null=True, blank=True, default="button") sectionClassName = models.SlugField(max_length=100, help_text="no spaces", default="homepage-section") body = RichTextField(blank=True) streamBody = StreamField([ ('heading', blocks.CharBlock(classname="full-title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('markup', RawHTMLBlock()), ], null=True, blank=True) sectionBackgroundSelector = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') content_panels = Page.content_panels + [ FieldPanel('orientation'), FieldPanel('sectionClassName'), MultiFieldPanel(IndexLink.panels, "Related index page"), ImageChooserPanel('main_image'), DocumentChooserPanel('sectionBackgroundSelector'), FieldPanel('body', classname="section-body"), StreamFieldPanel('streamBody'), InlinePanel('related_links', label="Section link items"), ] def get_context(self, request): context = super(HomePageSection, self).get_context(request) return context
class BodyStreamBlock(StreamBlock): heading = HeadingBlock() paragraph = CustomRichTextBlock( features=['bold', 'italic', 'ol', 'ul', 'hr', 'link', 'document-link']) image = ImageBlock() blockquote = BlockQuoteBlock() embed = EmbedBlock() document = DocumentChooserBlock() code = CodeBlock() raw_html = RawHTMLBlock() table = TableBlock()
class StoryBlock(StreamBlock): h2 = CharBlock(icon="title", classname="h2 title") h3 = CharBlock(icon="title", classname="h3 title") h4 = CharBlock(icon="title", classname="h4 title") paragraph = StoryTextBlock(icon="pilcrow") image = ImageBlock(label="image") pullquote = PullQuoteBlock() raw_html = RawHTMLBlock(label='Raw HTML', icon="code") embed = EmbedBlock(icon="code") class Meta: template = "blog/blocks/storyblock.html"
class StoryBlock(StreamBlock): h2 = CharBlock(icon="title", classname="title") h3 = CharBlock(icon="title", classname="title") h4 = CharBlock(icon="title", classname="title") intro = RichTextBlock(icon="pilcrow") paragraph = RichTextBlock(icon="pilcrow") aligned_image = ImageBlock(label="Aligned image") wide_image = WideImage(label="Wide image") bustout = BustoutBlock() pullquote = PullQuoteBlock() raw_html = RawHTMLBlock(label='Raw HTML', icon="code") embed = EmbedBlock(icon="code")
class IframeBlock(Accessible, StructBlock): iframe_url = URLBlock(required=True, icon="arrow-right") iframe_width = CharBlock(required=False) iframe_height = CharBlock(required=False) iframe_id = CharBlock(required=False) iframe_html = RawHTMLBlock(required=False) fallback_image = ImageBlock() class Meta: icon = "site" template = 'longform/blocks/html.html' accessible_template = "longform/blocks/accessible_html.html"
class BaseStreamBlock(StreamBlock): """ Define the custom blocks that `StreamField` will utilize """ heading_block = HeadingBlock(label="标题", heading_text="请选择字号") paragraph_block = RichTextBlock(icon="pilcrow", template="blocks/paragraph_block.html", label=u"段落") image_block = ImageBlock(label=u"图片", icon="image") block_quote = BlockQuote(label=u"引用", ) table_block = TableBlock(label=u"表格", ) raw_html = RawHTMLBlock(icon="code", label='Raw HTML')
class HomePage(Page): body = StreamField([('heading', blocks.CharBlock(classname='full title')), ('paragraph', blocks.RichTextBlock(classname='full')), ('image', ImageChooserBlock()), ('html', RawHTMLBlock()), ('embed', EmbedBlock()), ('jumbotron', JumbotronBlock())]) search_fields = Page.search_fields + (index.SearchField('body'), ) content_panels = Page.content_panels + [ StreamFieldPanel('body'), InlinePanel('related_links', label="Related links"), ]
class Job(ClusterableModel, index.Indexed): title = CharField(max_length=255, unique=True) background = RichTextField(blank=True) responsibilities = RichTextField(blank=True) skills = RichTextField(blank=True) notes = RichTextField(blank=True) location = RichTextField(blank=True) benefits = RichTextField(blank=True) applying = StreamField([ ('raw_html', RawHTMLBlock( help_text= 'To add Google Analytics to your link, use this template: ' '<a href="www.example.com" onclick="trackOutboundLink("www.example.com"); return false;">link</a>.' ' With great power comes great responsibility. ' 'This HTML is unescaped. Be careful!')), ('rich_text', RichTextBlock()), ], null=True, blank=True) core_technologies = RichTextField(blank=True) referrals = RichTextField(blank=True) preferred = RichTextField(blank=True) qualifications = RichTextField(blank=True) experience_we_need = RichTextField(blank=True) panels = [ MultiFieldPanel([ FieldPanel('title'), FieldPanel('background'), FieldPanel('responsibilities'), FieldPanel('skills'), FieldPanel('notes'), FieldPanel('location'), FieldPanel('core_technologies'), FieldPanel('qualifications'), FieldPanel('experience_we_need'), FieldPanel('preferred'), FieldPanel('referrals'), FieldPanel('benefits'), StreamFieldPanel('applying'), ]), ] class Meta: ordering = ['title'] def __str__(self): return '{self.title}'.format(self=self)
class Give(Page): touchnet_form = RawHTMLBlock() content_panels = [ FieldPanel('title', classname="full title"), #FieldPanel('touchnet_form'), ] promote_panels = [ FieldPanel('slug'), FieldPanel('seo_title'), FieldPanel('search_description'), ] parent_page_types = ['pages.HomePage']
class BaseStreamBlock(StreamBlock): heading_block = HeadingBlock() button_block = ButtonBlock() image_block = ImageBlock() accordion_block = AccordionBlock() embed_block = EmbedBlock() unorderd_list_block = ListBlock( (RichTextBlock(label="Unordered list item")), template="blocks/unorderd_list_block.html", icon="list-ul") orderd_list_block = ListBlock((RichTextBlock(label="Ordered list item")), template="blocks/orderd_list_block.html", icon="list-ol") rich_text_block = RichTextBlock() raw_html_block = RawHTMLBlock()
class BlogBodyBlock(StreamBlock): heading = CharBlock(classname="full title", icon='title', template='blog/blocks/heading.html') quote = QuoteBlock() paragraph = RichTextBlock(icon='doc-full', label="Rich Text") image = ImageChooserBlock(icon='image') embed = EmbedBlock(icon='media') caption = CaptionBlock() raw_html = RawHTMLBlock( icon='code', label="Raw HTML", help_text=format_html( '<ul class="messages"><li class="error">Please mind that ' 'using raw HTML can break site rendering and/or compromise ' 'site security.</li></ul>'), )
class SimplePage(Page, MeetupMixin, SponsorMixin): """ allowed url to embed listed in lib/python3.4/site-packages/wagtail/wagtailembeds/oembed_providers.py """ body = StreamField([('heading', blocks.CharBlock(icon="home", classname="full title")), ('paragraph', blocks.RichTextBlock(icon="edit")), ('video', EmbedBlock(icon="media")), ('image', ImageChooserBlock(icon="image")), ('slide', EmbedBlock(icon="media")), ('html', RawHTMLBlock(icon="code"))]) content_panels = Page.content_panels + [ StreamFieldPanel('body'), ] settings_panels = Page.settings_panels + MeetupMixin.settings_panels + SponsorMixin.settings_panels
class GeneralPage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('tagline', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('multicolumn', blocks.StreamBlock([ ('column', ColumnBlock()), ], icon='placeholder')), ('html', RawHTMLBlock()), ]) api_fields = ( 'title', 'body', 'slug', 'seo_title', 'search_description', ) content_panels = [ FieldPanel('title'), StreamFieldPanel('body'), ] promote_panels = [ FieldPanel('slug'), FieldPanel('seo_title'), FieldPanel('search_description'), ] def serve(self, request, *args, **kwargs): data = { 'title': self.title, 'slug': self.slug, 'seo_title': self.seo_title, 'search_description': self.search_description, 'body': self.body, } return JsonResponse(data)
class GeneralPage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('html', RawHTMLBlock()), ]) api_fields = ( 'title', 'body', ) content_panels = [ FieldPanel('title'), StreamFieldPanel('body'), ] promote_panels = [ FieldPanel('slug'), FieldPanel('seo_title'), FieldPanel('search_description'), ]
class BlogPage(Page): main_image = models.ForeignKey(ExtendedImage, null=True, blank=True, on_delete=models.SET_NULL, related_name='+') date = models.DateField('Post Date') intro = models.CharField(max_length=250) body = StreamField([ ('heading', blocks.CharBlock(classname='full title')), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()), ('html', RawHTMLBlock()), ('embed', EmbedBlock()), ]) search_fields = Page.search_fields + ( index.SearchField('intro'), index.SearchField('body'), ) def get_absolute_url(self): return self.full_url @property def blog_index(self): return self.get_ancestors().type(BlogIndexPage).last() content_panels = Page.content_panels + [ FieldPanel('date'), ImageChooserPanel('main_image'), FieldPanel('intro'), StreamFieldPanel('body'), InlinePanel('related_links', label='Related Links') ]
class CustomPage(Page, index.Indexed): footer = ForeignKey('common.Footer', default=DEFAULT_FOOTER_ID, null=True, blank=True, on_delete=SET_NULL, related_name='+') content = StreamField([ ('appeal', StructBlock([ ('icon', ChoiceBlock(required=True, choices=[ ('none', 'none'), ('flask', 'flask'), ('group', 'group'), ('laptop', 'laptop'), ('sitemap', 'sitemap'), ('user', 'user'), ('book', 'book'), ('download', 'download'), ])), ('topic', CharBlock(required=True, max_length=35)), ('content', RichTextBlock(required=True)), ], classname='appeal', icon='tick', template='common/blocks/appeal.html')), ('heading', CharBlock(classname="full title")), ('statement', CharBlock()), ('paragraph', RichTextBlock()), ('imagechooser', ImageChooserBlock()), ('column', RowBlock()), ('tabs', TabsBlock()), ('image', ImageBlock()), ('customImage', CustomImageBlock()), ('rich_text', RichTextBlock()), ('raw_html', RawHTMLBlock( help_text= 'With great power comes great responsibility. This HTML is unescaped. Be careful!' )), ('people_block', PeopleBlock()), ('centered_text', CenteredTextBlock()), ('hero_block', HeroBlock()), ('spotlight_block', SpotlightBlock()), ('job_whole_block', JobsWholeBlock()), ('embed_block', EmbedBlock()), ('whitespaceblock', WhitespaceBlock()), ('clear_fixblock', ClearfixBlock()), ('code_block', CodeBlock()), ('table_block', CustomTableBlock()), ('calender_block', GoogleCalendarBlock()), ('journal_block', JournalsTabBlock()), ('render_file', MfrBlock()), ('sponsor_partner_block', SponsorPartnerBlock()), ('collapse_block', CollapseBoxBlock()), ('button', ButtonBlock()), ], null=True, blank=True) custom_url = CharField(max_length=256, default='', null=True, blank=True) menu_order = IntegerField( blank=True, default=1, help_text=( 'The order this page should appear in the menu. ' 'The lower the number, the more left the page will appear. ' 'This is required for all pages where "Show in menus" is checked.' )) search_fields = [ index.SearchField('content', partial_match=True), ] content_panels = Page.content_panels + [ StreamFieldPanel('content'), SnippetChooserPanel('footer'), ] promote_panels = Page.promote_panels + [ FieldPanel('custom_url'), FieldPanel('menu_order'), InlinePanel('versioned_redirects', label='URL Versioning'), ] def serve(self, request): return render( request, self.template, { 'page': self, 'people': Person.objects.all(), 'jobs': Job.objects.all(), 'journals': Journal.objects.all(), 'organizations': Organization.objects.all(), 'donations': Donation.objects.all(), 'inkinddonations': InkindDonation.objects.all(), }) @transaction.atomic # only commit when all descendants are properly updated def move(self, target, pos=None): """ Extension to the treebeard 'move' method to ensure that url_path is updated too. """ old_url_path = Page.objects.get(id=self.id).url_path super(Page, self).move(target, pos=pos) # treebeard's move method doesn't actually update the in-memory instance, so we need to work # with a freshly loaded one now new_self = Page.objects.get(id=self.id) new_url_path = new_self.set_url_path(new_self.get_parent()) new_self.save() new_self._update_descendant_url_paths(old_url_path, new_url_path) new_redirect = new_self.versioned_redirects.create() redirect_url = ('/' + '/'.join(old_url_path.split('/')[2:]))[:-1] new_redirect.old_path = redirect_url new_redirect.redirect_page = new_self new_redirect.site = new_self.get_site() new_redirect.save() new_self.redirect_set.add(new_redirect) # Log logger.info("Page moved: \"%s\" id=%d path=%s", self.title, self.id, new_url_path) @transaction.atomic # ensure that changes are only committed when we have updated all descendant URL paths, to preserve consistency def save(self, *args, **kwargs): self.full_clean() update_descendant_url_paths = False is_new = self.id is None if is_new: # we are creating a record. If we're doing things properly, this should happen # through a treebeard method like add_child, in which case the 'path' field # has been set and so we can safely call get_parent self.set_url_path(self.get_parent()) else: # Check that we are committing the slug to the database # Basically: If update_fields has been specified, and slug is not included, skip this step if not ('update_fields' in kwargs and 'slug' not in kwargs['update_fields']): # see if the slug has changed from the record in the db, in which case we need to # update url_path of self and all descendants old_record = Page.objects.get(id=self.id) if old_record.slug != self.slug: self.set_url_path(self.get_parent()) update_descendant_url_paths = True old_url_path = old_record.url_path new_url_path = self.url_path new_redirect = self.versioned_redirects.create() redirect_url = ('/' + '/'.join(old_url_path.split('/')[2:]))[:-1] new_redirect.old_path = redirect_url new_redirect.redirect_page = self new_redirect.site = self.get_site() new_redirect.save() self.redirect_set.add(new_redirect) for redirect in self.versioned_redirects.all(): redirect.versioned_redirect_page = self redirect.redirect_page = self redirect.save() result = super(Page, self).save(*args, **kwargs) if update_descendant_url_paths: self._update_descendant_url_paths(old_url_path, new_url_path) # Check if this is a root page of any sites and clear the 'wagtail_site_root_paths' key if so if Site.objects.filter(root_page=self).exists(): cache.delete('wagtail_site_root_paths') # Log if is_new: cls = type(self) logger.info( "Page created: \"%s\" id=%d content_type=%s.%s path=%s", self.title, self.id, cls._meta.app_label, cls.__name__, self.url_path) return result
class AlignedHTMLBlock(StructBlock): html = RawHTMLBlock() alignment = HTMLAlignmentChoiceBlock() class Meta: icon = "code"
context['images'] = images return context class Meta: icon = 'fa fa-th' label = 'Gallery' template = 'widgets/gallery.html' #FIXME: Move blocks to blocks.py CONTENT_BLOCKS = [ #('heading', blocks.CharBlock(classname="full title", icon="title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock(icon="image")), ('media', EmbedBlock(icon="media")), ('html', RawHTMLBlock(icon="code")), ('link', LinkBlock(icon="link")), ('gallery', GalleryBlock()), ('slider', SliderBlock()), ('section_divider', SectionDivider()), ] class CountryRegionStructBlock(StructBlock): country = None region = None def __init__(self, *args, **kwargs): self.country = kwargs.pop('country', None) self.region = kwargs.pop('region', None) return super(CountryRegionStructBlock, self).__init__(*args, **kwargs)
class ProgrammePage(Page): ### Model Fields ###################################### short_description = models.CharField( blank=True, null=True, max_length=1000, help_text="Short Description to be displayed at the top of the page" ) body = StreamField( [ ('paragraph', RichTextBlock(features=[ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'bold', 'italic', 'link', 'ol', 'ul', 'hr'])), ('captioned_image', CaptionedImageBlock(label="Image")), ('authored_block_quote', AuthoredBlockQuoteBlock( label="Block Quote")), ('embed', EmbedBlock()), ('raw_html', RawHTMLBlock(label="Raw HTML")), ('clearfix', ClearfixBlock()) ], null=True ) host = models.CharField( blank=True, null=True, max_length=200, ) genre = models.CharField( blank=True, null=True, max_length=200, ) air_time = models.CharField( blank=True, null=True, max_length=200, help_text='Duration of Each Episode', ) tv_rating = models.CharField( blank=True, null=True, max_length=50, help_text='Malaysian Standard: U, P13, 18', ) banner = models.ForeignKey( 'wagtailimages.Image', blank=True, null=True, on_delete=models.SET_NULL, related_name='programme_banner' ) thumbnail = models.ForeignKey( 'wagtailimages.Image', blank=True, null=True, on_delete=models.SET_NULL, related_name='programme_thumbnail' ) ### Methods ########################################### def episodes(self): return [n.episode_ID for n in self.youtube_episode.all()] def thumbnail_url(self): if(self.thumbnail): return get_wagtail_image_url(self.thumbnail) def banner_url(self): if(self.banner): return get_wagtail_image_url(self.banner) # Render Stream object to sensible HTML data, then replace # <img> tags with the correct src location def body_rendered(self): text = self.body.render_as_block() text = html_replace_img(text) return text ### CMS and API Exposure ############################## # Content panels - What shows up on the CMS dashboard content_panels = Page.content_panels + [ FieldPanel('short_description'), StreamFieldPanel('body'), MultiFieldPanel( [ FieldPanel('genre'), FieldPanel('host'), FieldPanel('air_time'), FieldPanel('tv_rating') ], heading="Programme Info", ), InlinePanel('youtube_episode', label="Youtube Episodes"), ImageChooserPanel('banner'), ImageChooserPanel('thumbnail'), ] # API fields - What will be returned from API call api_fields = [ APIField('short_description'), APIField('body_rendered'), APIField('genre'), APIField('host'), APIField('air_time'), APIField('tv_rating'), APIField('episodes'), APIField('banner_url'), APIField('thumbnail_url'), ] subpage_types = [] parent_page_types = ['ProgrammeIndexPage']
class AlignedHTMLBlock(StructBlock): html = RawHTMLBlock()
class HTMLBlock(StreamBlock): raw_html = RawHTMLBlock() rich_text = RichTextBlock()
class RedTwitBlock(StreamBlock): twitter = EmbedBlock(icon="site") reddit = RawHTMLBlock(icon="code")