class FooterGroup(blocks.StructBlock): title = blocks.CharBlock() items = blocks.StreamBlock([ ('item', NavigationItem()), ('blank', blocks.StaticBlock()), ('text', blocks.StaticBlock()), ('social', SocialButtons()), ('field_form', FooterForm()), ])
class _S_LightBlock(blocks.StructBlock): documentchooserblock = docblocks.DocumentChooserBlock() imagechooserblock = ImageChooserBlock() snippetchooserblock = SnippetChooserBlock(target_model="utils.Button") embedblock = EmbedBlock() staticblock = blocks.StaticBlock() graphql_fields = [ GraphQLDocument("documentchooserblock"), GraphQLImage("imagechooserblock"), GraphQLSnippet("snippetchooserblock", snippet_model="utils.Button"), GraphQLEmbed("embedblock"), GraphQLString("staticblock"), ]
class NotebookBlock(blocks.StructBlock): show_code = blocks.BooleanBlock(default=True) url = blocks.URLBlock(required=False) ipynb = blocks.StaticBlock() class Meta: label = 'Jupyter Notebook' icon = 'link-external' value_class = NotebookStructValue def clean(self, value): for name, val in value.items(): if name == 'url': req = requests.get(val) value['ipynb'] = req.text return super().clean(value)
class StandardPage(Page): section = StreamField([ ('heading', HeadingBlock()), ('paragraph', blocks.RichTextBlock()), ('quote', blocks.BlockQuoteBlock()), ('image', ImageChooserBlock()), ('document', DocumentChooserBlock()), ('embed', EmbedBlock()), ('table', TableBlock()), ('person', SnippetChooserBlock(Person)), ('event', blocks.StaticBlock(admin_text='Latest events: no configuration needed.', template='')), ], blank=True) person = models.ForeignKey( 'Person', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) # event = models.ForeignKey( # 'Event', # null=True, # blank=True, # on_delete=models.SET_NULL, # related_name='+' # ) content_panels = Page.content_panels + [ StreamFieldPanel('section'), InlinePanel('person_placements', label="people"), # SnippetChooserPanel('event'), ]
class PromoPage(Page): body = StreamField([ ('heroes', blocks.StaticBlock( admin_text='Heroes block: no configuration needed.', template='heroes.html')), ('index', blocks.RichTextBlock()), ('text_plus_screenshot', blocks.StreamBlock([ ('screenshot', ImageChooserBlock()), ('text', blocks.RichTextBlock()) ], template='text_plus_screenshot.html')) ]) content_panels = Page.content_panels + [ StreamFieldPanel('body'), ] def get_context(self, request, *args, **kwargs): context = super().get_context(request) context['promotion'] = kwargs.get('promotion') return context def serve(self, request, *args, **kwargs): return TemplateResponse( request, self.get_template(request, *args, **kwargs), self.get_context(request, *args, **kwargs) ) def get_site(self): return {'site_name': '8fit'} @property def url(self): return '/demo/%s' % self.slug @property def full_url(self): return self.url
class CustomBlock1(blocks.StructBlock): field_char = blocks.CharBlock(required=False) field_text = blocks.TextBlock(required=False) field_email = blocks.EmailBlock(required=False) field_int = blocks.IntegerBlock(required=False) field_float = blocks.FloatBlock(required=False) field_decimal = blocks.DecimalBlock(required=False) field_regex = blocks.RegexBlock(regex=r'^[0-9]{3}$', required=False) field_url = blocks.URLBlock(required=False) field_bool = blocks.BooleanBlock(required=False) field_date = blocks.DateBlock(required=False) field_time = blocks.TimeBlock(required=False) field_datetime = blocks.DateTimeBlock(required=False) field_rich = blocks.RichTextBlock(required=False) field_raw = blocks.RawHTMLBlock(required=False) field_quote = blocks.BlockQuoteBlock(required=False) field_choice = blocks.ChoiceBlock(choices=[('tea', 'Tea'), ('coffee', 'Coffee')], icon='cup', required=False) field_static = blocks.StaticBlock(required=False) field_list = blocks.ListBlock(blocks.CharBlock, required=False) field_list_2 = blocks.ListBlock(CustomBlockInner, required=False)
class LatestProfileList(blocks.StructBlock): max_number_of_results = blocks.IntegerBlock( min_value=1, max_value=48, default=12, required=True, help_text='Pick up to 48 profiles.', ) advanced_filter_header = blocks.StaticBlock( label=' ', admin_text= '-------- ADVANCED FILTERS: OPTIONS TO DISPLAY FEWER, MORE TARGETED RESULTS. --------', ) profile_type = blocks.CharBlock(required=False, default='', help_text='Example: Fellow.') program_type = blocks.CharBlock(required=False, default='', help_text='Example: Tech Policy.') year = blocks.CharBlock(required=False, default='') def get_context(self, value, parent_context=None, no_limit=False, initial_year=False, ordering=False): context = super().get_context(value, parent_context=parent_context) query_args = { 'limit': value['max_number_of_results'], 'profile_type': value['profile_type'], 'program_type': value['program_type'], 'program_year': initial_year if initial_year else value['year'], 'ordering': ordering if ordering else '-id', 'is_active': 'true', 'format': 'json', } # Removing after the fact is actually easier than # conditionally adding and then filtering the list. if no_limit: query_args.pop('limit') # Filter out emptish values query_args = {k: v for k, v in query_args.items() if v} url = "{pulse_api}/api/pulse/v2/profiles/?{query}".format( pulse_api=settings.FRONTEND['PULSE_API_DOMAIN'], query=parse.urlencode(query_args)) data = [] try: response = request.urlopen(url) response_data = response.read() data = json.loads(response_data) for profile in data: profile['created_entries'] = False profile['published_entries'] = False profile['entry_count'] = False profile['user_bio_long'] = False except (IOError, ValueError) as exception: print(str(exception)) pass context['profiles'] = data context['profile_type'] = value['profile_type'] context['program_type'] = value['program_type'] context['program_year'] = value['year'] return context class Meta: template = 'wagtailpages/blocks/profile_blocks.html' icon = 'group' value_class = LatestProfileQueryValue
class PulseProjectList(blocks.StructBlock): search_terms = blocks.CharBlock( help_text='Test your search at mozillapulse.org/search', label='Search', required=False, ) max_number_of_results = blocks.IntegerBlock( min_value=0, max_value=12, default=6, required=True, help_text= 'Choose 1-12. If you want visitors to see more, link to a search or tag on Pulse.', ) only_featured_entries = blocks.BooleanBlock( default=False, label='Display only featured entries', help_text='Featured items are selected by Pulse moderators.', required=False, ) newest_first = blocks.ChoiceBlock( choices=[ ('True', 'Show newer entries first'), ('False', 'Show older entries first'), ], required=True, label='Sort', default='True', ) advanced_filter_header = blocks.StaticBlock( label=' ', admin_text= '-------- ADVANCED FILTERS: OPTIONS TO DISPLAY FEWER, MORE TARGETED RESULTS. --------', ) issues = blocks.ChoiceBlock(choices=[ ('all', 'All'), ('Decentralization', 'Decentralization'), ('Digital Inclusion', 'Digital Inclusion'), ('Online Privacy & Security', 'Online Privacy & Security'), ('Open Innovation', 'Open Innovation'), ('Web Literacy', 'Web Literacy'), ], required=True, default='all') help = blocks.ChoiceBlock( choices=[ ('all', 'All'), ('Attend', 'Attend'), ('Create content', 'Create content'), ('Code', 'Code'), ('Design', 'Design'), ('Fundraise', 'Fundraise'), ('Join community', 'Join community'), ('Localize & translate', 'Localize & translate'), ('Mentor', 'Mentor'), ('Plan & organize', 'Plan & organize'), ('Promote', 'Promote'), ('Take action', 'Take action'), ('Test & feedback', 'Test & feedback'), ('Write documentation', 'Write documentation'), ], required=True, default='all', label='Type of help needed', ) direct_link = blocks.BooleanBlock( default=False, label='Direct link', help_text= 'Checked: user goes to project link. Unchecked: user goes to pulse entry', required=False, ) class Meta: template = 'wagtailpages/blocks/pulse_project_list.html' icon = 'site' value_class = PulseProjectQueryValue
class LatestProfileList(blocks.StructBlock): max_number_of_results = blocks.IntegerBlock( min_value=1, max_value=48, default=12, required=True, help_text='Pick up to 48 profiles.', ) advanced_filter_header = blocks.StaticBlock( label=' ', admin_text= '-------- ADVANCED FILTERS: OPTIONS TO DISPLAY FEWER, MORE TARGETED RESULTS. --------', ) profile_type = blocks.CharBlock(required=False, default='', help_text='Example: Fellow.') program_type = blocks.CharBlock(required=False, default='', help_text='Example: Tech Policy.') year = blocks.CharBlock(required=False, default='') def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context=parent_context) query_args = { 'limit': context['block'].value['max_number_of_results'], 'profile_type': context['block'].value['profile_type'], 'program_type': context['block'].value['program_type'], 'program_year': context['block'].value['year'], 'ordering': '-id', 'is_active': 'true', 'format': 'json', } # filter out emptish values query_args = {k: v for k, v in query_args.items() if v} # FIXME: the protocol should be part of the pulse api variable. # see: https://github.com/mozilla/foundation.mozilla.org/issues/1824 url = "{pulse_api}/api/pulse/v2/profiles/?{query}".format( pulse_api=settings.FRONTEND['PULSE_API_DOMAIN'], query=parse.urlencode(query_args)) try: response = request.urlopen(url) response_data = response.read() data = json.loads(response_data) for profile in data: profile['created_entries'] = False profile['published_entries'] = False profile['entry_count'] = False profile['user_bio_long'] = False except (IOError, ValueError) as exception: print(str(exception)) pass context['profiles'] = data return context class Meta: template = 'wagtailpages/blocks/profile_blocks.html' icon = 'group' value_class = LatestProfileQueryValue
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='+') body = StreamField([ ("heading", blocks.CharBlock(classname="full title")), ("paraagraph", blocks.RichTextBlock()), ("image", ImageChooserBlock()), ("decimal", blocks.DecimalBlock()), ("date", blocks.DateBlock()), ("datetime", blocks.DateTimeBlock()), ("quote", blocks.BlockQuoteBlock()), ( "drink", blocks.ChoiceBlock(choices=[("tea", "Tea"), ("coffee", "Coffee")], icon="time"), ), ("somepage", blocks.PageChooserBlock()), ( "static", blocks.StaticBlock( admin_text="Latest posts: no configuration needed."), ), ( "person", blocks.StructBlock( [ ("first_name", blocks.CharBlock()), ("surname", blocks.CharBlock()), ("photo", ImageChooserBlock(required=False)), ("biography", blocks.RichTextBlock()), ], icon="user", ), ), ("video", EmbedBlock()), ( "carousel", blocks.StreamBlock( [ ("image", ImageChooserBlock()), ( "quotation", blocks.StructBlock([ ("text", blocks.TextBlock()), ("author", blocks.CharBlock()), ]), ), ], icon="cogs", ), ), ("doc", DocumentChooserBlock()), ( "ingredients_list", blocks.ListBlock( blocks.StructBlock([ ("ingredient", blocks.CharBlock()), ("amount", blocks.CharBlock(required=False)), ])), ), ]) content_panels = Page.content_panels + [ FieldPanel("author"), FieldPanel("date"), StreamFieldPanel("body"), InlinePanel('related_links', label="Related links"), SnippetChooserPanel('advert') ] graphql_fields = [ GraphQLString("heading"), GraphQLString("date"), GraphQLString("author"), GraphQLStreamfield("body"), GraphQLForeignKey("related_links", "home.blogpagerelatedlink", True), GraphQLSnippet('advert', 'home.Advert'), ]
class PageTypeA(Page): streamfield = StreamField([ ('h1', blocks.CharBlock(icon="title", classname="title")), ('h2', blocks.CharBlock(icon="subtitle", classname="subtitle")), ('n1', blocks.IntegerBlock(icon="subtitle", classname="subtitle")), ], null=True, blank=True) another = StreamField([ ('h3', blocks.CharBlock(icon="title", classname="title")), ('h4', blocks.CharBlock(icon="subtitle", classname="subtitle")), ('n2', blocks.IntegerBlock(icon="subtitle", classname="subtitle")), ], null=True, blank=True) third = StreamField([ ('char', blocks.CharBlock()), ('text', blocks.TextBlock()), ('email', blocks.EmailBlock()), ('int', blocks.IntegerBlock()), ('float', blocks.FloatBlock()), ('decimal', blocks.DecimalBlock()), ('regex', blocks.RegexBlock(regex=r'^[0-9]{3}$')), ('url', blocks.URLBlock()), ('bool', blocks.BooleanBlock()), ('date', blocks.DateBlock()), ('time', blocks.TimeBlock()), ('datetime', blocks.DateTimeBlock()), ('rich', blocks.RichTextBlock()), ('raw', blocks.RawHTMLBlock()), ('quote', blocks.BlockQuoteBlock()), ('choice', blocks.ChoiceBlock(choices=[('tea', 'Tea'), ('coffee', 'Coffee')], icon='cup')), ('static', blocks.StaticBlock()), ], null=True) links = StreamField([ ('image', ImageChooserBlock()), ('page', PageChooserBlock()), ('snippet', SnippetChooserBlock(target_model=App2Snippet)), ], null=True) lists = StreamField([ ('char', blocks.ListBlock(blocks.CharBlock())), ('text', blocks.ListBlock(blocks.TextBlock())), ('int', blocks.ListBlock(blocks.IntegerBlock())), ('float', blocks.ListBlock(blocks.FloatBlock())), ('decimal', blocks.ListBlock(blocks.DecimalBlock())), ('date', blocks.ListBlock(blocks.DateBlock())), ('time', blocks.ListBlock(blocks.TimeBlock())), ('datetime', blocks.ListBlock(blocks.DateTimeBlock())), ], null=True) links_list = StreamField([ ('image', blocks.ListBlock(ImageChooserBlock())), ('page', blocks.ListBlock(PageChooserBlock())), ('snippet', blocks.ListBlock(SnippetChooserBlock(target_model=App2Snippet))), ], null=True) custom = StreamField([ ('custom1', CustomBlock1()), ('custom2', CustomBlock2()), ], null=True) another_custom = StreamField([ ('custom1', CustomBlock1()), ('custom2', CustomBlock2()), ], null=True) custom_lists = StreamField([ ('custom1', blocks.ListBlock(CustomBlock1())), ('custom2', blocks.ListBlock(CustomBlock2())), ], null=True) content_panels = [ FieldPanel('title', classname="full title"), StreamFieldPanel('streamfield'), StreamFieldPanel('another'), StreamFieldPanel('third'), StreamFieldPanel('links'), StreamFieldPanel('custom'), StreamFieldPanel('another_custom'), StreamFieldPanel('lists'), StreamFieldPanel('links_list'), StreamFieldPanel('custom_lists'), ]
class BlogPage(RoutablePageMixin, Page): description = models.CharField( max_length=255, blank=True, ) herocarrousel = StreamField([ ('academic', HeroAcademic()), ('mini_photo', HeroWithMiniFoto()), ('solo_text', HeroSoloText()), ('photo_or_letters', HeroWithFotoOrLetter()), ], null=True, blank=True) herobanner = StreamField([ ('large_banner', Banner()), ('circle_banner', blocks.StaticBlock(label="Middle Circle Apply", icon="site")), ('circle_banner_half', blocks.StaticBlock(label="Middle Circle Apply Half", icon="site")), ('mini_banner', blocks.StaticBlock(label="Mini Circle Apply", icon="site")), ('only_text', HeroBannerCircText(label="Only Text Circle", icon="site")), ('circle_talk', blocks.StaticBlock(label="Middle Circle Talk", icon="site")), ('circle_talk_half', blocks.StaticBlock(label="Middle Circle Talk Half", icon="site")), ], null=True, blank=True) content_panels = Page.content_panels + [ FieldPanel('description', classname="full"), MultiFieldPanel([ StreamFieldPanel('herocarrousel'), StreamFieldPanel('herobanner'), ], heading="Hero", classname="collapsible collapsed"), ] def get_posts(self): return PostPage.objects.descendant_of(self).live().order_by('-date') def use_paginator(self, request, post_t): page_n = request.GET.get('page') if not page_n: page_n = "1" #post_t = PostPage.objects.descendant_of(self).live().order_by('-date') paginator = Paginator(post_t, 6) posts_page = paginator.get_page(page_n) return posts_page def get_context(self, request, *args, **kwargs): context = super(BlogPage, self).get_context(request, *args, **kwargs) context['posts'] = self.posts #context['posts'] = self.get_posts #context['posts'] = PostPage.objects.descendant_of(self).live() context['blog_page'] = self context['showing_all'] = self.showing_all return context @route(r'^view_all/') def view_all(self, request, *args, **kwargs): self.posts = self.get_posts() self.showing_all = True return Page.serve(self, request, *args, **kwargs) @route(r'^tag/(?P<tag>[-\w]+)/$') def post_by_tag(self, request, tag, *args, **kwargs): self.showing_all = False self.search_type = 'tag' self.search_term = tag posts_p = self.get_posts().filter(tags__slug=tag) self.posts = self.use_paginator(request, posts_p) return Page.serve(self, request, *args, **kwargs) @route(r'^category/(?P<category>[-\w]+)/$') def post_by_category(self, request, category, *args, **kwargs): self.showing_all = False self.search_type = 'category' self.search_term = category posts_p = self.get_posts().filter(categories__slug=category) self.posts = self.use_paginator(request, posts_p) return Page.serve(self, request, *args, **kwargs) @route(r'^author/(?P<author>[-\w]+)/$') def post_by_author(self, request, author, *args, **kwargs): self.showing_all = False self.search_type = 'author' self.search_term = author posts_p = self.get_posts().filter(author__slug=author) self.posts = self.use_paginator(request, posts_p) #self.posts = self.get_posts() return Page.serve(self, request, *args, **kwargs) @route(r'^(\d{4})/$') @route(r'^(\d{4})/(\d{2})/$') @route(r'^(\d{4})/(\d{2})/(\d{2})/$') def post_by_date(self, request, year, month=None, day=None, *args, **kwargs): self.showing_all = False self.posts = self.get_posts().filter(date__year=year) if month: self.posts = self.posts.filter(date__month=month) df = DateFormat(date(int(year), int(month), 1)) self.search_term = df.format('F Y') if day: self.posts = self.posts.filter(date__day=day) self.search_term = date_format( date(int(year), int(month), int(day))) return Page.serve(self, request, *args, **kwargs) @route(r'^(\d{4})/(\d{2})/(\d{2})/(.+)/$') def post_by_date_slug(self, request, year, month, day, slug, *args, **kwargs): post_page = self.get_posts().filter(slug=slug).first() self.showing_all = False if not post_page: raise Http404 return Page.serve(post_page, request, *args, **kwargs) @route(r'^$') def post_list(self, request, *args, **kwargs): #page_n = request.GET.get('page') #if not page_n: # page_n = "1" #post_t = self.get_posts() #paginator = Paginator(post_t, 3) #posts_page = paginator.get_page(page_n) #self.posts = posts_page #self.posts = self.get_posts() self.showing_all = False posts_p = self.get_posts() self.posts = self.use_paginator(request, posts_p) return Page.serve(self, request, *args, **kwargs)
class _S_ShopBlock(blocks.StructBlock): shop = blocks.StaticBlock(admin_text=mark_safe( 'Insert this block in order to display the shop on your website.'), null=True, blank=True, icon='fa-shopping-basket')
( 'section_header', blocks.StructBlock( [ ('header', blocks.CharBlock()), ('text', SafeRichTextBlock(required=False)), ], group='basic', label='Заголовок секции', icon='title', ), ), ( 'hr', blocks.StaticBlock(group='basic', label='Горизонтальная линия', icon='horizontalrule'), ), ( 'anchor', blocks.CharBlock( group='basic', label='Якорь', icon='tag', validators=[validators.validate_slug], ), ), ], ) registry.register_list(
class FooterColumn(blocks.StructBlock): size = blocks.IntegerBlock(label="grid based, total must be 12") content = blocks.StreamBlock([ ('group', FooterGroup()), ('blank', blocks.StaticBlock()), ])
class NavigationDropdown(blocks.StructBlock): title = blocks.CharBlock() items = blocks.StreamBlock([ ('item', NavigationItem()), ('separator', blocks.StaticBlock()), ])