class Location(models.Model): zip_code = models.CharField(max_length=255, null=True, blank=True) # city = models.CharField(max_length=255, null=True, blank=True) # country = models.CharField(max_length=255, null=True, blank=True) city = models.ForeignKey('City', verbose_name=_('Ciudad'), null=True, blank=True, on_delete=models.SET_NULL, related_name="+") region = models.ForeignKey('Region', verbose_name=_('Region'), null=True, blank=True, on_delete=models.SET_NULL, related_name="+") country = models.ForeignKey('Country', verbose_name=_('Pais'), null=True, blank=True, on_delete=models.SET_NULL, related_name="+") panels = [ FieldPanel('zip_code'), SnippetChooserPanel('city'), SnippetChooserPanel('region'), SnippetChooserPanel('country'), ]
class CommitteePageFlag(Orderable): source_page = ParentalKey('rec.CommitteePage', related_name='committee_flags') committee_flag = models.ForeignKey('rec.CommitteeFlag', related_name='+') panels = [ SnippetChooserPanel('committee_flag') ]
class CommitteePageType(Orderable): source_page = ParentalKey('rec.CommitteePage', related_name='committee_types') committee_type = models.ForeignKey('rec.CommitteeType', related_name='+') panels = [ SnippetChooserPanel('committee_type') ]
class BasicBlockPlacement(Orderable, models.Model): page = ParentalKey('wagtailcore.Page', related_name='blocks') block = models.ForeignKey('basic_site.BasicBlock', related_name='+') panels = [ SnippetChooserPanel('block', BasicBlock), ]
class TechnologySection(Orderable): page = ParentalKey(ServicesPage, related_name='technologies') technology = models.ForeignKey(Technology) panels = [ SnippetChooserPanel('technology'), ]
class EventYoutubeRelationship(Orderable, models.Model): page = ParentalKey('EventPage', related_name='event_youtube_relationship') youtube = models.ForeignKey('base.YoutubeChannel', related_name='youtube_event_relationship') panels = [SnippetChooserPanel('youtube')]
class EventTwitchRelationship(Orderable, models.Model): page = ParentalKey('EventPage', related_name='event_twitch_relationship') twitch = models.ForeignKey('base.TwitchChannel', related_name='twitch_event_relationship') panels = [SnippetChooserPanel('twitch')]
class FacultyResources(models.Model): resource = models.ForeignKey( Resource, null=True, help_text="Manage resources through snippets.", related_name='+') link_external = models.URLField("External link", blank=True) link_page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, related_name='+') link_document = models.ForeignKey('wagtaildocs.Document', null=True, blank=True, related_name='+') api_fields = ( 'resource', 'link_external', 'link_page', 'link_document', ) panels = [ SnippetChooserPanel('resource', Resource), FieldPanel('link_external'), PageChooserPanel('link_page'), DocumentChooserPanel('link_document'), ]
class HomePage(Page): template = 'home/home_page.pug' headline = models.TextField() intro = RichTextField() intro_image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) specials = models.ForeignKey( 'MenuSection', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) reservation = RichTextField() content_panels = Page.content_panels + [ FieldPanel('headline'), FieldPanel('intro'), ImageChooserPanel('intro_image'), SnippetChooserPanel('specials'), FieldPanel('reservation'), ]
def test_target_content_type_nonexistent_type(self): result = SnippetChooserPanel( 'advert', 'snowman.lorry' ).bind_to_model(SnippetChooserModel) self.assertRaises(ImproperlyConfigured, result.target_content_type)
class Trend(DriverOfChange): parent_page_types = ['pages.StaticIndex'] trend_type = models.IntegerField(choices=TREND_TYPES, default=1) content_panels2 = DriverOfChange.content_panels + [ SnippetChooserPanel('trend_type') ]
class AboutPage(Page, CossBaseModel): """About page for Open source clubs.""" about = models.ForeignKey('home.AboutSnippet', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') opengraph_image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name='Open Graph Image') logo = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name='Logo') featured = models.BooleanField(default=False) content_panels = Page.content_panels + [ SnippetChooserPanel('about'), FieldPanel('opengraph_image'), FieldPanel('logo'), FieldPanel('featured') ]
class AboutPage(Page): body = RichTextField() image = models.ForeignKey('wagtailimages.Image', on_delete=SET_NULL, related_name='+', blank=True, null=True) testimonial = models.ForeignKey(Client, blank=True, null=True, on_delete=SET_NULL, related_name='+') teams = ParentalManyToManyField('blog.Profile', blank=True) ##clientblock = models.ForeignKey('ClientPageBlock', blank=True, null=True, ## on_delete=SET_NULL, related_name='+') #clients = ParentalManyToManyField(Client, blank=True) search_fields = Page.search_fields + [SearchField('body')] content_panels = Page.content_panels + [ FieldPanel('body', classname='full'), ImageChooserPanel('image'), FieldPanel("teams", widget=forms.CheckboxSelectMultiple), #FieldPanel("clientblock"), SnippetChooserPanel('testimonial'), InlinePanel("clients", label="Our Clients"), ]
class Contact(ClusterableModel): name = models.CharField(max_length=DEFAULT_MAX_LENGTH) email = models.EmailField() phone = models.CharField(max_length=DEFAULT_MAX_LENGTH) location = models.ForeignKey(Location, null=True, blank=True, related_name='+') api_fields = [ 'name', 'email', 'phone', 'location', 'hours', ] panels = [ FieldPanel('name'), FieldPanel('email'), FieldPanel('phone'), SnippetChooserPanel('location'), InlinePanel('hours', label='Hours'), ] def __str__(self): return self.name
class BusinessContact(ContactField): rnc = models.CharField(verbose_name=_('RNC'), blank=True, max_length=255, null=False) mobile = models.CharField(verbose_name=_('Celular'), blank=True, max_length=255, null=True) website = models.CharField(verbose_name=_('Sitio Web'), blank=True, null=True, max_length=255) notes = RichTextField(verbose_name=_('Notas'), blank=True, null=True) fis_position = models.ForeignKey('contacts.FiscalPosition', verbose_name=_('Posición Fiscal'), null=True, blank=True, default=1 or None, on_delete=models.SET_NULL, related_name="+") panels = [ FieldPanel('rnc', classname='nic-field'), # SnippetChooserPanel('fiscal_position'), MultiFieldPanel([SnippetChooserPanel('fis_position')], classname='fiscal-position'), FieldPanel('phone', classname='phone-field'), FieldPanel('mobile', classname='mobile-field'), FieldPanel('email', classname='email-field'), FieldPanel('website', classname='site-field'), # FieldPanel('address'), FieldPanel('notes', classname='notes-field'), ]
class ExternalArticlePage(Page, FeatureStyleFields, Promotable): body = RichTextField() website_link = models.URLField(max_length=255) main_image = models.ForeignKey('images.AttributedImage', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') source = models.ForeignKey('Source', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') def __str__(self): return "{}".format(self.title) search_fields = Page.search_fields + [ index.SearchField('body', partial_match=True), index.SearchField('source', partial_match=True), ] def get_source_name(self): if self.source: return self.source.name else: return "" content_panels = Page.content_panels + [ FieldPanel("body"), FieldPanel("website_link"), SnippetChooserPanel('source'), ImageChooserPanel('main_image'), ]
class ArticlePageCategory(models.Model): page = ParentalKey('articles.ArticlePage', related_name='categories') category = models.ForeignKey('articles.ArticleCategory', related_name='+', on_delete=models.CASCADE) panels = [SnippetChooserPanel('category')]
class TopLevelPage(Page): """Render a top-level page. Useful for things like FAQ/About Us/etc. """ body = StreamField([ ('banner_image', common_blocks.BannerImage()), ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', common_blocks.CaptionImageBlock()), ('h1', common_blocks.HeaderH1(classname="full title")), ('subhead', common_blocks.Subhead(classname="full title")), ('block_quote', common_blocks.BlockQuote()), ('call_to_action', common_blocks.CallToAction()), ('small_call_to_action', common_blocks.CTAButton()), ('embed_code', common_blocks.EmbedCode()), ]) page_date = models.DateField() fundraising_snippet = models.ForeignKey(EmbedCodeSnippet, null=True, blank=True, on_delete=models.SET_NULL, related_name='+') search_fields = Page.search_fields + [ index.SearchField('body'), ] content_panels = Page.content_panels + [ FieldPanel('page_date'), StreamFieldPanel('body'), SnippetChooserPanel('fundraising_snippet') ]
class SubGenreClassAlbumRelationship(Orderable, models.Model): page = ParentalKey('Album', related_name='subgenre_album_relationship') subgenre = models.ForeignKey('genre.SubgenreClass', related_name="+") panels = [ # We need this for the inlinepanel on the Feature Content Page to grab hold of SnippetChooserPanel('subgenre') ]
class EventPage(Page): date = models.DateTimeField("Event Date") location = models.CharField(max_length=255) event_link = models.URLField(max_length=255) body = RichTextField() organization = models.ForeignKey('Organization', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') def __str__(self): return "{}".format(self.title) content_panels = [ FieldPanel("title"), FieldPanel("date"), FieldPanel("location"), FieldPanel("event_link"), FieldPanel("body"), SnippetChooserPanel('organization'), ] edit_handler = TabbedInterface([ ObjectList(content_panels, heading='Content'), ObjectList(Page.promote_panels, heading='Promote'), ObjectList(Page.settings_panels, heading='Settings', classname="settings"), ])
class HomePage(OpenGraphMixin, Page): """Controls rendering of PhillyDSA home page. This is the first page that you see hosted at / """ body = StreamField([ ('banner_image', common_blocks.BannerImage()), ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', common_blocks.CaptionImageBlock()), ('h1', common_blocks.HeaderH1(classname="full title")), ('subhead', common_blocks.Subhead(classname="full title")), ('block_quote', common_blocks.BlockQuote()), ('call_to_action', common_blocks.CallToAction()), ('small_call_to_action', common_blocks.CTAButton()), ('embed_code', common_blocks.EmbedCode()), ]) fundraising_snippet = models.ForeignKey(EmbedCodeSnippet, null=True, blank=True, on_delete=models.SET_NULL, related_name='+') search_fields = Page.search_fields + [ index.SearchField('body'), ] content_panels = Page.content_panels + [ StreamFieldPanel('body'), SnippetChooserPanel('fundraising_snippet') ]
class NewsPageCategory(models.Model): page = ParentalKey('news.NewsPage', related_name='category_relationships') category = models.ForeignKey('categories.Category', related_name='+', on_delete=models.CASCADE) panels = [SnippetChooserPanel('category')]
class ThemeablePage(Page): ''' Abstract model class to inherit from for themable pages ''' is_creatable = False class Meta: abstract = True theme = models.ForeignKey( Theme, on_delete=models.SET_NULL, blank=True, null=True, ) def get_template(self, request, *args, **kwargs): original_template = super(ThemeablePage, self).get_template(request, *args, **kwargs) if self.theme is None: return original_template custom_template = utils.get_themed_template_name( self.theme, original_template) if utils.template_exists(custom_template): return custom_template return original_template style_panels = [ MultiFieldPanel([ SnippetChooserPanel('theme'), ], heading="Theme"), ]
def test_target_model_from_model(self): # RemovedInWagtail16Warning: snippet_type argument with self.ignore_deprecation_warnings(): result = SnippetChooserPanel( 'advert', Advert).bind_to_model(SnippetChooserModel).target_model() self.assertIs(result, Advert)
class TechStudentRelationship(models.Model): tech = ParentalKey(Tech, related_name='students') student = models.ForeignKey('students.Student') panels = [ SnippetChooserPanel('student'), ]
class PersonIndexPage(Page, HeroImageFields): introduction = RichTextField( null=True, blank=True, features=['bold', 'italic', 'link', 'justify']) call_to_action = models.ForeignKey('utils.CallToActionSnippet', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') subpage_types = ['PersonPage'] content_panels = Page.content_panels + HeroImageFields.content_panels + [ MultiFieldPanel([ FieldPanel('introduction'), InlinePanel('introduction_customisation', label="Introduction Customisation", max_num=1), ], 'Introduction'), MultiFieldPanel([ InlinePanel('category_relationships', label="Person Index Categories"), InlinePanel('people_customisation', label="People Section Customisation", max_num=1), ], 'People'), SnippetChooserPanel('call_to_action') ] def introduction_customisations(self): return self.introduction_customisation.first() @cached_property def people_customisations(self): return self.people_customisation.first() @cached_property def people(self): return self.get_children().specific().live().public() @cached_property def categories(self): return [ related.category for related in self.category_relationships.all() ] def get_context(self, request, *args, **kwargs): page_number = request.GET.get('page') paginator = Paginator(self.people, settings.DEFAULT_PER_PAGE) try: people = paginator.page(page_number) except PageNotAnInteger: people = paginator.page(1) except EmptyPage: people = paginator.page(paginator.num_pages) context = super().get_context(request, *args, **kwargs) context.update(people=people) return context
class ArticleIndexPage(Page): subpage_types = ['ArticlePage'] subject = models.OneToOneField( SubjectSnippet, blank=True, null=True, on_delete=models.SET_NULL, related_name="+") intro = models.TextField( blank=True, help_text='This text will be formatted with markdown.') content_panels = Page.content_panels + [ FieldPanel('intro', classname="full"), SnippetChooserPanel('subject', SubjectSnippet), #InlinePanel('related_links', label="Related links"), ] class Meta: verbose_name = 'Article Index' def get_context(self, request, *args, **kwargs): context = super(ArticleIndexPage, self).get_context( request, *args, **kwargs) articles = self.articles() # Pagination page = request.GET.get('page') page_size = 10 from home.models import GeneralSettings if GeneralSettings.for_site(request.site).pagination_count: page_size = GeneralSettings.for_site(request.site).pagination_count if page_size is not None: paginator = Paginator(articles, page_size) try: articles = paginator.page(page) except PageNotAnInteger: articles = paginator.page(1) except EmptyPage: articles = paginator.page(paginator.num_pages) context['articles'] = articles return context def articles(self, subject_filter=None): """ Return all articles if no subject specified, otherwise only those from that Subject :param subject_filter: Subject :return: QuerySet of Articles (I think) """ articles = ArticlePage.objects.live().descendant_of(self) if subject_filter is not None: articles = articles.filter(subject=subject_filter) articles = articles.order_by('-date') return articles
class SnippetChooserModel(models.Model): advert = models.ForeignKey(Advert, help_text='help text', on_delete=models.CASCADE) panels = [ SnippetChooserPanel('advert'), ]
class TourArtistRelationship(Orderable, models.Model): page = ParentalKey('TourPage', related_name='tour_artist_relationship') artists = models.ForeignKey( 'artist.Artist', # app.class related_name="artist_tour_relationship", help_text='The artist(s) who made this album') panels = [SnippetChooserPanel('artists')]
class EventPageEventType(models.Model): event_type = models.ForeignKey('events.EventType', on_delete=models.CASCADE) page = ParentalKey('events.EventPage', related_name='event_types') panels = [ SnippetChooserPanel('event_type'), ]