class CollectionChooserBlock(SectionBlock): import wagtail.core.models register_snippet(wagtail.core.models.Collection) collection = SnippetChooserBlock(wagtail.core.models.Collection) class Meta: icon = 'snippet' template = 'blocks/image_chooser_block.html'
from django.db import models from django.utils.encoding import python_2_unicode_compatible from wagtail.snippets.models import register_snippet @python_2_unicode_compatible class Interactive(models.Model): name = models.TextField() template = models.TextField() def __str__(self): return self.name register_snippet(Interactive)
url = models.URLField(null=True, blank=True) text = models.CharField(max_length=255) tags = TaggableManager(through=AdvertTag, blank=True) panels = [ FieldPanel('url'), FieldPanel('text'), FieldPanel('tags'), ] def __str__(self): return self.text register_snippet(Advert) class AdvertWithTabbedInterface(models.Model): url = models.URLField(null=True, blank=True) text = models.CharField(max_length=255) something_else = models.CharField(max_length=255) advert_panels = [ FieldPanel('url'), FieldPanel('text'), ] other_panels = [ FieldPanel('something_else'), ]
except: # noqa result = None if result and result.json and "lat" in result.json and "lng" in result.json: lnglat = "{lng},{lat}".format(lng=result.json["lng"], lat=result.json["lat"]) self.lnglat = lnglat else: self.lnglat = "" super().save(*args, **kwargs) def __str__(self): return self.name register_snippet(LocalGroup) class LocalGroupListPage(XrPage): template = "xr_pages/pages/local_group_list.html" content = StreamField(ContentBlock, blank=True) group = models.OneToOneField(LocalGroup, editable=False, on_delete=models.PROTECT) content_panels = XrPage.content_panels + [StreamFieldPanel("content")] parent_page_types = [] is_creatable = False class Meta:
def setUp(self): register_snippet(ZuluSnippet) register_snippet(AlphaSnippet)
on_delete=models.SET_NULL, related_name='+' ) embed_url = models.URLField("Embed URL", blank=True) caption = models.CharField(max_length=255, blank=True) content_panels = [ ImageChooserPanel('image'), FieldPanel('embed_url'), FieldPanel('caption'), ] class Meta: abstract = True register_snippet(CarouselItem) class HomePageCarouselItem(Orderable, CarouselItem): page = ParentalKey('HomePage', related_name='carousel_items') class TranslatablePageMixin(models.Model): # One link for each alternative language # These should only be used on the main language page (english) fi_link = models.ForeignKey(Page, null=True, on_delete=models.SET_NULL, blank=True, related_name='+') se_link = models.ForeignKey(Page, null=True, on_delete=models.SET_NULL, blank=True, related_name='+') panels = [ PageChooserPanel('fi_link'), PageChooserPanel('se_link'), ]
class ProductListSnippet(ClusterableModel): title = models.CharField(max_length=255) code = models.CharField(max_length=100, unique=True) panels = [ FieldPanel('title'), FieldPanel('code'), ] def __unicode__(self): return self.title class ProductListItem(Orderable): parent = ParentalKey(to=ProductListSnippet, related_name='items') product = models.ForeignKey('catalogue.Product', related_name='+', on_delete=models.CASCADE) panels = [ ProductChooserPanel('product'), ] ProductListSnippet.panels += [ InlinePanel('items', label=_("Products")) ] register_snippet(ProductListSnippet)
FieldPanel('description'), ] class Meta: verbose_name = _("Answer Category") verbose_name_plural = _("Answer Categories") ordering = ['name'] def __str__(self): return self.name def get_prefiltered_search_params(self): return "?{}=".format(self.name) register_snippet(AnswerCategory) class Answer(Page): template = 'cms/answer_detail.html' # Determines type and whether its highlighted in overview list type = models.CharField( choices=[('answer', 'Antwoord'), ('column', 'Column')], max_length=100, default='answer', help_text= _('Choose between answer or discussion piece with a more prominent look' )) featured = models.BooleanField(default=False)
panels = [ FieldPanel("name"), FieldPanel("slug"), ] class Meta: verbose_name = "Tour Category" verbose_name_plural = "Tour Categories" ordering = ["name"] def __str__(self): return self.name register_snippet(TourCategory) class TourDestinationOrderable(Orderable): page = ParentalKey("tours.TourPage", related_name="tour_destinations") destination_pages = models.ForeignKey("destinations.DestinationPage", null=True, blank=True, on_delete=models.SET_NULL, related_name="+") def __str__(self): return self.page.title
tags = TaggableManager(through=CraftPostCategoryTag, blank=True) panels = [ FieldPanel('name'), FieldPanel('tags'), ] def __str__(self): return "{}".format(self.name) class Meta: verbose_name = "Craftbox Category" verbose_name_plural = "craftbox Categories" register_snippet(CraftboxCategory) class CraftPost(Page): author = models.CharField(max_length=255, blank=True, null=True) date = models.DateField("Post date") featured = models.BooleanField(default=False) body = StreamField([ ('content', blocks.RichTextBlock()), ('quote', blocks.BlockQuoteBlock()), ('image', ImageChooserBlock(template="frontend/craftbox/blocks/image.html")), ('embed', EmbedBlock()), ('code', CodeBlock()) ]) cover_image = models.ForeignKey( 'wagtailimages.Image',
null=False, help_text="location tag") panels = [ FieldPanel("tag"), ] def __str__(self): return self.tag class Meta: verbose_name = "Location Tag" verbose_name_plural = "Location Tags" register_snippet(LocationTag) class TripType(models.Model): trip_type = models.CharField(max_length=100, blank=False, null=False, help_text="location tag") panels = [ FieldPanel("trip_type"), ] def __str__(self): return self.trip_type
url = models.URLField(null=True, blank=True) text = models.CharField(max_length=255) tags = TaggableManager(through=AdvertTag, blank=True) panels = [ FieldPanel('url'), FieldPanel('text'), FieldPanel('tags'), ] def __str__(self): return self.text register_snippet(Advert) class AdvertWithTabbedInterface(models.Model): url = models.URLField(null=True, blank=True) text = models.CharField(max_length=255) something_else = models.CharField(max_length=255) advert_panels = [ FieldPanel('url'), FieldPanel('text'), ] other_panels = [ FieldPanel('something_else'), ]
FieldPanel("currency"), FieldPanel("ingredients"), FieldPanel("price") ], heading="Dish") ] def __str__(self): return self.name class Meta: verbose_name = "Dish" verbose_name_plural = "Dishes" register_snippet(Dish) class RestaurantPage(Page): template = 'restaurant/restaurant_page.html' content = StreamField( [("category_block", blocks.CategoryBlock()), ("logo_block", blocks.LogoBlock()), ("title_dish_block", blocks.TitleDish())], null=True, blank=True, ) address = models.CharField(max_length=100, null=True, blank=True) restaurant = models.ForeignKey(Restaurant, null=True,
feature_style=style, image_overlay_opacity=opacity, ) @python_2_unicode_compatible class SiteDefaults(models.Model): site = models.OneToOneField('wagtailcore.Site', related_name='default_settings', unique=True, on_delete=models.CASCADE) default_external_article_source_logo = models.ForeignKey( 'images.AttributedImage', related_name='+', on_delete=models.CASCADE ) contact_email = models.EmailField(blank=True, default="") def __str__(self): return "{}".format(self.site) class Meta: verbose_name_plural = "Site Defaults" panels = [ FieldPanel('site'), ImageChooserPanel('default_external_article_source_logo'), FieldPanel('contact_email'), ] register_snippet(SiteDefaults)
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 __str__(self): return u"{0}[{1}]".format(self.title, self.slug) register_snippet(ContentBlock) class Testimonial(LinkFields): page = models.ForeignKey(Page, related_name='testimonials', null=True, blank=True, on_delete=models.SET_NULL) name = models.CharField(max_length=150) photo = models.ForeignKey(Image, null=True, blank=True, on_delete=models.SET_NULL) text = RichTextField(blank=True)
def setUp(self): register_snippet(ZuluSnippet) register_snippet(AlphaSnippet)
notes = RichTextField("Bookmark notes", null=True, blank=True) date_read = models.DateField() tags = TaggableManager(through=BookmarkTag, blank=True) panels = [ FieldPanel('url'), FieldPanel('title'), FieldPanel('notes'), FieldPanel('date_read'), FieldPanel('tags'), ] def __str__(self): return self.title.encode("utf8") register_snippet(Bookmark) class BookmarkPlacement(models.Model): page = ParentalKey('wagtailcore.Page', related_name='bookmark_placements') quote = models.ForeignKey('blog.Bookmark', related_name='+', on_delete=models.CASCADE) # -- End snippets -- # class BlogPageTag(TaggedItemBase): content_object = ParentalKey('blog.BlogPage', related_name='tagged_items') class CodeBlock(StructBlock): """ Code Highlighting Block """
panels = [ MultiFieldPanel([ FieldPanel('name', heading='Nome do Site'), FieldPanel('link', heading='Link'), FieldPanel('social_icon', heading='ID icone FontAwesome 5'), ], heading="Contato/Redes Social", classname="collapsible") ] def __str__(self): return self.name register_snippet(ContactButton) class TechIcon(models.Model): name = models.CharField(null=True, blank=False, max_length=20) tech_icon = models.CharField(null=True, blank=False, max_length=40) panels = [ MultiFieldPanel([ FieldPanel('name', heading='Nome da Habilidade/Tecnologia'), FieldPanel('tech_icon', heading='ID icone FontAwesome 5'), ], heading="Habilidade/Tecnologia", classname="collapsible") ]
heading="Categories"), StreamFieldPanel("content"), ] class ProjectCategory(models.Model): """Category for Projects in Snippets.""" name = models.CharField(max_length=255) slug = models.SlugField( verbose_name="slug", allow_unicode=True, max_length=255, help_text='A slug to identify projects by this category') panels = {MultiFieldPanel([ FieldPanel("name"), FieldPanel("slug"), ])} class Meta: #noqa verbose_name = "Project Category" verbose_name_plural = "Project Categories" ordering = ["name"] def __str__(self): return self.name register_snippet(ProjectCategory)
from django.db import models from django.utils.encoding import python_2_unicode_compatible from wagtail.snippets.models import register_snippet @python_2_unicode_compatible class Interactive(models.Model): name = models.TextField() template = models.TextField() def __str__(self): return self.name register_snippet(Interactive)
return self.owner.get_full_name() or self.owner.get_username() return None @property def index(self) -> IndexPage: return self.get_ancestors().type(IndexPage).last() promote_panels = BasePage.promote_panels + [ FieldPanel("guest_authors"), FieldPanel("tags"), ] register_snippet(Person) class BiographyPage(BaseRichTextPage): person = models.ForeignKey( Person, blank=True, null=True, on_delete=models.SET_NULL, related_name="biographies", ) content_panels = BasePage.content_panels + [ SnippetChooserPanel("person"), FieldPanel("body", classname="full"), ]
description = models.CharField(max_length=124) image = models.ImageField(null=True, blank=True) panels = [ MultiFieldPanel([ FieldPanel('name'), FieldPanel('sub_title'), FieldPanel('description'), ImageChooserPanel('image') ]) ] def __str__(self): return f"{self.name} -- {self.sub_title}" register_snippet(NPC) class NPCChooser(AdminChooser): choose_one_text = _('Choose an NPC') choose_another_text = _('Choose another NPC') link_to_chosen_text = _('Edit this NPC') model = NPC choose_modal_url_name = 'npc_chooser:choose' def get_edit_item_url(self, item): return reverse('wagtailsnippets:edit', args=('npcs', 'npc', quote(item.pk))) class NPCBlogRelationship(Orderable):
@python_2_unicode_compatible class Organization(models.Model): name = models.CharField(max_length=100) website = models.URLField(max_length=255) logo = models.ForeignKey('images.AttributedImage', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') def __str__(self): return self.name register_snippet(Organization) Organization.panels = [ FieldPanel('name'), FieldPanel('website'), ImageChooserPanel('logo'), ] class EventListPage(PaginatedListPageMixin, ThemeablePage): subpage_types = ['EventPage'] events_per_page = models.IntegerField(default=20) counter_field_name = 'events_per_page' counter_context_name = 'events'
FieldPanel("website"), ], heading="Links" ) ] def __str__(self): """String repr of this class.""" return self.name class Meta: verbose_name = "Blog Author" verbose_name_plural = "Blog Authors" register_snippet(BlogAuthor) class BlogListingPage(Page): """Listing page lists all the Blog Detail Pages.""" template = "blog/blog_listing_page.html" custom_title = models.CharField( max_length=100, blank=True, null=True, help_text='Overwrites the default title', ) content_panels = Page.content_panels + [
from wagtail.snippets.models import register_snippet from .categories import Category from .navigation_menus import NavigationMenu register_snippet(Category) register_snippet(NavigationMenu)
date_read = models.DateField() tags = TaggableManager(through=BookmarkTag, blank=True) panels = [ FieldPanel('url'), FieldPanel('title'), FieldPanel('notes'), FieldPanel('date_read'), FieldPanel('tags'), ] def __str__(self): return self.title.encode("utf8") register_snippet(Bookmark) class BookmarkPlacement(models.Model): page = ParentalKey('wagtailcore.Page', related_name='bookmark_placements') quote = models.ForeignKey('blog.Bookmark', related_name='+') # -- End snippets -- # class BlogPageTag(TaggedItemBase): content_object = ParentalKey('blog.BlogPage', related_name='tagged_items') class CodeBlock(StructBlock):
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) register_snippet(ContentBlock) class Client(LinkFields): name = models.CharField(max_length=225, default="") logo = models.ForeignKey('wagtailimages.Image', blank=True, null=True, on_delete=models.CASCADE, related_name='+') moto = models.CharField(max_length=100, blank=True, null=True) summary = RichTextField(blank=True, null=True) panels = [ FieldPanel('name'), ImageChooserPanel('logo'),
related_name='form_fields') # class ContactPage(AbstractEmailForm): class ContactPage(WagtailCaptchaEmailForm): parent_page_types = ['home.HomePage'] subpage_types = [] template = "contact/contact_page.html" intro = RichTextField(blank=True) thank_you_text = RichTextField(blank=True) content_panels = AbstractEmailForm.content_panels + [ FieldPanel('intro'), InlinePanel('form_fields', label='Form Fields'), FieldPanel('thank_you_text'), MultiFieldPanel([ FieldRowPanel([ FieldPanel('from_address', classname="col6"), FieldPanel('to_address', classname="col6") ]), FieldPanel("subject"), ], heading="Email Settings"), ] register_snippet(ContactPage)
name = models.CharField(max_length=255) contact_email = models.EmailField(blank=True, null=True, help_text="Only provide if this should be different from the site default email contact address.") panels = [ FieldPanel('name'), FieldPanel('contact_email'), InlinePanel('block_links', label="Content Blocks"), InlinePanel('follow_links', label="Follow Links"), InlinePanel('logo_links', label="Logos"), ] def __str__(self): return self.name register_snippet(ThemeContent) @python_2_unicode_compatible class Theme(models.Model): name = models.CharField(max_length=1024) folder = models.CharField(max_length=1024, default="themes/default") is_default = models.BooleanField(default=False) content = models.ForeignKey( ThemeContent, null=True, on_delete=models.SET_NULL ) def __str__(self): return self.name
url = models.URLField(null=True, blank=True) text = models.CharField(max_length=255) tags = TaggableManager(through=AdvertTag, blank=True) panels = [ FieldPanel('url'), FieldPanel('text'), FieldPanel('tags'), ] def __str__(self): return self.text register_snippet(Advert) class AdvertWithCustomPrimaryKey(ClusterableModel): advert_id = models.CharField(max_length=255, primary_key=True) url = models.URLField(null=True, blank=True) text = models.CharField(max_length=255) panels = [ FieldPanel('url'), FieldPanel('text'), ] def __str__(self): return self.text
from oscar_wagtail.edit_handlers import ProductChooserPanel class ProductListSnippet(ClusterableModel): title = models.CharField(max_length=255) code = models.CharField(max_length=100, unique=True) panels = [ FieldPanel('title'), FieldPanel('code'), ] def __unicode__(self): return self.title class ProductListItem(Orderable): parent = ParentalKey(to=ProductListSnippet, related_name='items') product = models.ForeignKey('catalogue.Product', related_name='+', on_delete=models.CASCADE) panels = [ ProductChooserPanel('product'), ] ProductListSnippet.panels += [InlinePanel('items', label=_("Products"))] register_snippet(ProductListSnippet)
# ZuluSnippet is registered during TestSnippetOrdering class ZuluSnippet(models.Model): text = models.CharField(max_length=255) def __str__(self): return self.text # Register model as snippet using register_snippet as both a function and a decorator class RegisterFunction(models.Model): pass register_snippet(RegisterFunction) @register_snippet class RegisterDecorator(models.Model): pass # A snippet model that inherits from index.Indexed can be searched on @register_snippet class SearchableSnippet(index.Indexed, models.Model): text = models.CharField(max_length=255) search_fields = [ index.SearchField('text'),
class LinkGroupSnippet(ClusterableModel): name = models.CharField( max_length=255, help_text="The name of the menu for internal identification e.g 'Primary', 'Footer'.", ) panels = [FieldPanel("name"), InlinePanel("links", label="Links")] def __str__(self): return self.name class Meta: verbose_name = "Link group" ordering = ["name"] register_snippet(LinkGroupSnippet) class MenuSnippetLink(Orderable, models.Model): snippet = ParentalKey("MenuSnippet", related_name="links") link_page = models.ForeignKey( "wagtailcore.Page", models.SET_NULL, null=True, blank=True, related_name="+", help_text="Choose a page to which to link", ) link_text = models.TextField( blank=True, help_text="Optional. Override title text for chosen link page" )
MultiFieldPanel( [ FieldPanel("website"), ], heading="Links" ) ] def __str__(self): return self.name class Meta: verbose_name= "Blog Author" verbose_name_plural = "Blog Authors" register_snippet(BlogAuthor) class BlogCategory(models.Model): name = models.CharField(max_length=255) slug = models.SlugField( verbose_name="slug", allow_unicode=True, max_length=255, help_text="A slug to identify posts by this category", ) panels = [ FieldPanel("name"), FieldPanel("slug"), ]
InlinePanel("place_images", min_num=1), ], heading="Images"), FieldPanel('trip_types', widget=forms.CheckboxSelectMultiple), FieldPanel('location_tags', widget=forms.CheckboxSelectMultiple), ] search_fields = [ index.SearchField('name', partial_match=True), ] def __str__(self): return self.name register_snippet(Place) class PlaceImages(Orderable): place = ParentalKey('Place', related_name="place_images", null=False, blank=False) image = models.ForeignKey("wagtailimages.Image", null=True, blank=False, on_delete=models.CASCADE, related_name="+") panels = [ ImageChooserPanel("image"),
related_name='adverts' ) url = models.URLField(null=True, blank=True) text = models.CharField(max_length=255) panels = [ PageChooserPanel('page'), FieldPanel('url'), FieldPanel('text'), ] def __str__(self): return self.text register_snippet(Advert) # Custom image class TorchboxImage(AbstractImage): credit = models.CharField(max_length=255, blank=True) admin_form_fields = Image.admin_form_fields + ( 'credit', ) @property def credit_text(self): return self.credit
class FixtureStatus(models.Model): """ Snippet to limited status for Match """ fixture_status = models.CharField(max_length=100) #fixture_video_url = models.URLField(blank=True, null=True) panels = [FieldPanel("fixture_status")] def __str__(self): return self.fixture_status class Meta: verbose_name = "Fixture Status" verbose_name_plural = "Fixture Statuses" register_snippet(FixtureStatus) class FixtureListingPage(RoutablePageMixin, Page): """Listing page lists all the Fixture Detail Pages.""" template = "fixture/fixture_listing_page.html" subpage_types = ['fixture.FixtureDetailPage'] max_count = 1 custom_title = models.CharField( max_length=100, blank=False, null=False, help_text='Overwrites the default title', )
# ZuluSnippet is registered during TestSnippetOrdering class ZuluSnippet(models.Model): text = models.CharField(max_length=255) def __str__(self): return self.text # Register model as snippet using register_snippet as both a function and a decorator class RegisterFunction(models.Model): pass register_snippet(RegisterFunction) @register_snippet class RegisterDecorator(models.Model): pass # A snippet model that inherits from index.Indexed can be searched on @register_snippet class SearchableSnippet(index.Indexed, models.Model): text = models.CharField(max_length=255) search_fields = [
return sorted(chain(article_list, series_list), key=lambda x: x.first_published_at, reverse=True) class Meta: ordering = ["name", ] search_fields = [ index.SearchField('name', partial_match=True), ] panels = [ FieldPanel("name"), ] register_snippet(Topic) class TopicListPage(RoutablePageMixin, ThemeablePage): articles_per_page = models.IntegerField(default=20) @property def topics(self): popular_topics = Topic.objects.annotate( num_articles=Count('article_links') + Count('articles') + Count('series')).order_by("-num_articles")[:25] return sorted(popular_topics, key=lambda x: x.name) @route(r'^$', name="topic_list") def topics_list(self, request): context = { "self": self,