class MenuItem(LinkFields): menu_title_en = models.CharField(max_length=255) menu_title_de = models.CharField(max_length=255, blank=True) menu_title_it = models.CharField(max_length=255, blank=True) menu_title_fr = models.CharField(max_length=255, blank=True) menu_title_sv = models.CharField(max_length=255, blank=True) menu_title_sl = models.CharField(max_length=255, blank=True) menu_title_da = models.CharField(max_length=255, blank=True) menu_title_uk = models.CharField(max_length=255, blank=True) menu_title_el = models.CharField(max_length=255, blank=True) menu_title_ru = models.CharField(max_length=255, blank=True) menu_title_ka = models.CharField(max_length=255, blank=True) menu_title_mk = models.CharField(max_length=255, blank=True) menu_title_mt = models.CharField(max_length=255, blank=True) translated_menu_title = TranslatedField('menu_title') @property def url(self): return self.link def __str__(self): return self.title panels = [ edit_handlers.FieldPanel('menu_title_en'), edit_handlers.MultiFieldPanel([ edit_handlers.FieldPanel('menu_title_' + lang_code) for lang_code, _language in LANGUAGES ], heading="Translations", classname="collapsible collapsed") ] + LinkFields.panels
class RSSImport(models.Model): url = models.URLField(null=True, blank=True) rss_title_en = models.CharField(max_length=255) rss_title_de = models.CharField(max_length=255, blank=True) rss_title_it = models.CharField(max_length=255, blank=True) rss_title_fr = models.CharField(max_length=255, blank=True) rss_title_sv = models.CharField(max_length=255, blank=True) rss_title_sl = models.CharField(max_length=255, blank=True) rss_title_da = models.CharField(max_length=255, blank=True) rss_title_uk = models.CharField(max_length=255, blank=True) rss_title_el = models.CharField(max_length=255, blank=True) rss_title_ru = models.CharField(max_length=255, blank=True) rss_title_ka = models.CharField(max_length=255, blank=True) rss_title_mk = models.CharField(max_length=255, blank=True) rss_title_mt = models.CharField(max_length=255, blank=True) translated_rss_title = TranslatedField('rss_title') panels = [ edit_handlers.FieldPanel('url'), edit_handlers.MultiFieldPanel([ edit_handlers.FieldPanel('rss_title_' + lang_code) for lang_code, _language in LANGUAGES ], heading="Translations", classname="collapsible collapsed") ] def __str__(self): return self.rss_title_en
class ContactPage(ANSPage): company_name = models.CharField(max_length=100) line1 = models.CharField("First line", max_length=50) line2 = models.CharField("Second line", max_length=50, blank=True) town = models.CharField(max_length=50) county = models.CharField(max_length=50) postcode = models.CharField(max_length=10) country = models.CharField(max_length=50) phone_number = models.CharField(max_length=20) email_address = models.EmailField(max_length=254) parent_page_types = [HomePage] content_panels = ANSPage.content_panels + [ panels.MultiFieldPanel([ panels.FieldPanel('company_name'), panels.FieldPanel('line1'), panels.FieldPanel('line2'), panels.FieldPanel('town'), panels.FieldPanel('county'), panels.FieldPanel('postcode'), panels.FieldPanel('country'), ], "Address"), panels.FieldPanel('phone_number'), panels.FieldPanel('email_address'), ]
def __new__(cls, name, bases, namespace): panels = namespace['panels'] blueprint_names = namespace['blueprint_names'] for member in blueprint_names: namespace[member.name] = models.ForeignKey( 'a4projects.Project', on_delete=models.SET_NULL, null=True, blank=True, related_name='example_project_{}'.format(member.name), help_text='Please select an exemplary {} project.'.format( member.value), ) panels += [edit_handlers.FieldPanel(member.name)] return super().__new__(cls, name, bases, namespace)
class LinkFields(models.Model): link_page = models.ForeignKey('wagtailcore.Page', related_name='+', blank=True, null=True) allowed_views = ((org_urls, 'organisation-list', _('List of Organisations')), ) link_view = models.CharField( max_length=100, blank=True, choices=[(name, title) for urlconfig, name, title in allowed_views if name in map(attrgetter('name'), urlconfig.urlpatterns)]) def clean(self): if self.link_page and self.link_view: msg = _('Can only either link a view or a page.') raise ValidationError({ 'link_view': msg, 'link_page': msg, }) if not self.link_page and not self.link_view: msg = _('Specify either a link to a view or a page.') raise ValidationError({ 'link_view': msg, 'link_page': msg, }) @property def link(self): if self.link_page: return self.link_page.url else: return reverse(self.link_view) panels = [ edit_handlers.PageChooserPanel('link_page'), edit_handlers.FieldPanel('link_view'), ] class Meta: abstract = True
class ANSPage(Page): main_image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', ) intro = models.TextField(max_length=255, blank=True) content_panels = Page.content_panels + [ ImageChooserPanel('main_image'), panels.FieldPanel('intro'), ] is_abstract = True class Meta: abstract = True
class ManualsSectionPage(Page): # Title translated_title = TranslatedField('title') title_en = models.CharField(max_length=150, blank=True, verbose_name="Title") title_de = models.CharField(max_length=150, blank=True, verbose_name="Title") title_it = models.CharField(max_length=150, blank=True, verbose_name="Title") title_fr = models.CharField(max_length=150, blank=True, verbose_name="Title") title_sv = models.CharField(max_length=150, blank=True, verbose_name="Title") title_sl = models.CharField(max_length=150, blank=True, verbose_name="Title") title_da = models.CharField(max_length=150, blank=True, verbose_name="Title") title_uk = models.CharField(max_length=150, blank=True, verbose_name="Title") title_el = models.CharField(max_length=150, blank=True, verbose_name="Title") title_ru = models.CharField(max_length=150, blank=True, verbose_name="Title") title_ka = models.CharField(max_length=150, blank=True, verbose_name="Title") title_mk = models.CharField(max_length=150, blank=True, verbose_name="Title") title_mt = models.CharField(max_length=150, blank=True, verbose_name="Title") description = TranslatedField('description') description_en = models.CharField(max_length=260, blank=True, verbose_name="Description") description_de = models.CharField(max_length=260, blank=True, verbose_name="Description") description_it = models.CharField(max_length=260, blank=True, verbose_name="Description") description_fr = models.CharField(max_length=260, blank=True, verbose_name="Description") description_sv = models.CharField(max_length=260, blank=True, verbose_name="Description") description_sl = models.CharField(max_length=260, blank=True, verbose_name="Description") description_da = models.CharField(max_length=260, blank=True, verbose_name="Description") description_uk = models.CharField(max_length=260, blank=True, verbose_name="Description") description_el = models.CharField(max_length=260, blank=True, verbose_name="Description") description_ru = models.CharField(max_length=260, blank=True, verbose_name="Description") description_ka = models.CharField(max_length=260, blank=True, verbose_name="Description") description_mk = models.CharField(max_length=260, blank=True, verbose_name="Description") description_mt = models.CharField(max_length=260, blank=True, verbose_name="Description") body = StreamField([ ('snippet', snippet_blocks.SnippetChooserBlock( required=False, target_model=PageCollection, template='home/blocks/page_collection_block.html')) ]) image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') colors = ( ('blue', 'Blue'), ('orange', 'Orange'), ('turquoise', 'Turquoise'), ('pink', 'Pink'), ('purple', 'Purple'), ) color = models.CharField(choices=colors, max_length=9, blank=False, default='blue') general_panels = [ edit_handlers.FieldPanel('title', classname='title'), edit_handlers.FieldPanel('slug'), edit_handlers.FieldPanel('color'), ImageChooserPanel('image'), ] content_panels = [ edit_handlers.StreamFieldPanel('body'), ] + [ edit_handlers.MultiFieldPanel([ edit_handlers.FieldPanel('title_' + lang_code), edit_handlers.FieldPanel('description_' + lang_code), ], heading=lang, classname="collapsible collapsed") for lang_code, lang in LANGUAGES ] edit_handler = edit_handlers.TabbedInterface([ edit_handlers.ObjectList(content_panels, heading='Content'), edit_handlers.ObjectList(general_panels, heading='General') ]) parent_page_types = ['home.ManualsIndex'] subpage_types = ['home.ManualsDetailPage']
class ManualsIndex(Page): translated_title = TranslatedField('title') title_en = models.CharField(max_length=150, blank=True, verbose_name="Title") title_de = models.CharField(max_length=150, blank=True, verbose_name="Title") title_it = models.CharField(max_length=150, blank=True, verbose_name="Title") title_fr = models.CharField(max_length=150, blank=True, verbose_name="Title") title_sv = models.CharField(max_length=150, blank=True, verbose_name="Title") title_sl = models.CharField(max_length=150, blank=True, verbose_name="Title") title_da = models.CharField(max_length=150, blank=True, verbose_name="Title") title_uk = models.CharField(max_length=150, blank=True, verbose_name="Title") title_el = models.CharField(max_length=150, blank=True, verbose_name="Title") title_ru = models.CharField(max_length=150, blank=True, verbose_name="Title") title_ka = models.CharField(max_length=150, blank=True, verbose_name="Title") title_mk = models.CharField(max_length=150, blank=True, verbose_name="Title") title_mt = models.CharField(max_length=150, blank=True, verbose_name="Title") block_types = [ ('heading', core_blocks.CharBlock(classname="full title", icon="title")), ('paragraph', core_blocks.TextBlock(icon="pilcrow")), ('rich_text', core_blocks.RichTextBlock(icon="pilcrow")), ('info_block', InfoBlock()), ('image', image_blocks.ImageChooserBlock(icon="image")), ('wide_image', WideImageBlock(icon="image")), ('images', InlineImagesBlock(icon="image")), ('image_text_block_list', ImageTextBlockList()), ] body = TranslatedField('body') body_en = StreamField(block_types, null=True, blank=True, verbose_name="body") body_de = StreamField(block_types, null=True, blank=True, verbose_name="body") body_it = StreamField(block_types, null=True, blank=True, verbose_name="body") body_fr = StreamField(block_types, null=True, blank=True, verbose_name="body") body_sv = StreamField(block_types, null=True, blank=True, verbose_name="body") body_sl = StreamField(block_types, null=True, blank=True, verbose_name="body") body_da = StreamField(block_types, null=True, blank=True, verbose_name="body") body_uk = StreamField(block_types, null=True, blank=True, verbose_name="body") body_el = StreamField(block_types, null=True, blank=True, verbose_name="body") body_ru = StreamField(block_types, null=True, blank=True, verbose_name="body") body_ka = StreamField(block_types, null=True, blank=True, verbose_name="body") body_mk = StreamField(block_types, null=True, blank=True, verbose_name="body") body_mt = StreamField(block_types, null=True, blank=True, verbose_name="body") subpage_types = ['home.ManualsSectionPage', 'home.ManualsDetailPage'] content_panels = [ edit_handlers.MultiFieldPanel([ edit_handlers.FieldPanel('title_' + lang_code), ], heading=lang, classname="collapsible collapsed") for lang_code, lang in LANGUAGES ] general_panels = [ edit_handlers.FieldPanel('title', classname='title'), edit_handlers.FieldPanel('slug'), ] edit_handler = edit_handlers.TabbedInterface([ edit_handlers.ObjectList(content_panels, heading='Content'), edit_handlers.ObjectList(general_panels, heading='General') ]) @property def subpages(self): return self.get_children().live().specific()
class SimplePage(Page): # Title title_en = models.CharField(max_length=255, blank=True, verbose_name="Title") title_de = models.CharField(max_length=255, blank=True, verbose_name="Title") title_it = models.CharField(max_length=255, blank=True, verbose_name="Title") title_fr = models.CharField(max_length=255, blank=True, verbose_name="Title") title_sv = models.CharField(max_length=255, blank=True, verbose_name="Title") title_sl = models.CharField(max_length=255, blank=True, verbose_name="Title") title_da = models.CharField(max_length=255, blank=True, verbose_name="Title") title_uk = models.CharField(max_length=255, blank=True, verbose_name="Title") title_el = models.CharField(max_length=255, blank=True, verbose_name="Title") title_ru = models.CharField(max_length=255, blank=True, verbose_name="Title") title_ka = models.CharField(max_length=255, blank=True, verbose_name="Title") title_mk = models.CharField(max_length=255, blank=True, verbose_name="Title") title_mt = models.CharField(max_length=255, blank=True, verbose_name="Title") intro_en = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_de = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_it = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_fr = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_sv = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_sl = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_da = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_uk = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_el = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_ru = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_ka = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_mk = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_mt = models.CharField(max_length=255, blank=True, verbose_name="Subtitle") intro_image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') # Body block_types = [ ('heading', core_blocks.CharBlock(classname="full title", icon="title")), ('paragraph', core_blocks.TextBlock(icon="pilcrow")), ('rich_text', core_blocks.RichTextBlock(icon="pilcrow")), ('info_block', InfoBlock()), ('image', image_blocks.ImageChooserBlock(icon="image")), ('wide_image', WideImageBlock(icon="image")), ('images', InlineImagesBlock(icon="image")), ('contact_block', ContactBlock(icon="form")), ('accordion_block', AccordionBlock(icon="collapse-down")), ('image_text_block_list', ImageTextBlockList()), ('rss_feed', RSSImportBlock()), ] body_en = StreamField(block_types, null=True, blank=True, verbose_name="body") body_de = StreamField(block_types, null=True, blank=True, verbose_name="body") body_it = StreamField(block_types, null=True, blank=True, verbose_name="body") body_fr = StreamField(block_types, null=True, blank=True, verbose_name="body") body_sv = StreamField(block_types, null=True, blank=True, verbose_name="body") body_sl = StreamField(block_types, null=True, blank=True, verbose_name="body") body_da = StreamField(block_types, null=True, blank=True, verbose_name="body") body_uk = StreamField(block_types, null=True, blank=True, verbose_name="body") body_el = StreamField(block_types, null=True, blank=True, verbose_name="body") body_ru = StreamField(block_types, null=True, blank=True, verbose_name="body") body_ka = StreamField(block_types, null=True, blank=True, verbose_name="body") body_mk = StreamField(block_types, null=True, blank=True, verbose_name="body") body_mt = StreamField(block_types, null=True, blank=True, verbose_name="body") translated_title = TranslatedField('title') translated_intro = TranslatedField('intro') body = TranslatedField('body') general_panels = [ edit_handlers.FieldPanel('title', classname='title'), edit_handlers.FieldPanel('slug'), ImageChooserPanel('intro_image') ] content_panels = [ edit_handlers.MultiFieldPanel([ edit_handlers.FieldPanel('title_' + lang_code), edit_handlers.FieldPanel('intro_' + lang_code), edit_handlers.StreamFieldPanel('body_' + lang_code) ], heading=lang, classname="collapsible collapsed") for lang_code, lang in LANGUAGES ] edit_handler = edit_handlers.TabbedInterface([ edit_handlers.ObjectList(content_panels, heading='Content'), edit_handlers.ObjectList(general_panels, heading='General') ])
class HomePage(Page): # Title title_en = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_de = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_it = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_fr = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_sv = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_sl = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_da = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_uk = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_el = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_ru = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_ka = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_mk = models.CharField(max_length=255, blank=True, verbose_name="Header Title") title_mt = models.CharField(max_length=255, blank=True, verbose_name="Header Title") default_subtitle = ( "Ever wondered how to get young people involved in politics online?" "OPIN, a European toolbox for youth eParticipation projects, shows " "you how.") intro_en = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_de = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_it = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_fr = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_sv = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_sl = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_da = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_uk = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_el = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_ru = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_ka = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_mk = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) intro_mt = models.CharField(max_length=255, blank=True, verbose_name="Subtitle", default=default_subtitle) image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', verbose_name="Header Image", help_text="The Image that is shown on top of the page") videoplayer_url = models.URLField() # Body block_types = [ ('image', image_blocks.ImageChooserBlock(icon="image")), ('info_block', InfoBlock()), ('video_block', VideoBlock()), ('news_block', NewsBlock()), ('rss_feed', RSSImportBlock()), ('column_block', ColumnBlock()), ] body_en = StreamField(block_types, null=True) body_de = StreamField(block_types, null=True, blank=True) body_it = StreamField(block_types, null=True, blank=True) body_fr = StreamField(block_types, null=True, blank=True) body_sv = StreamField(block_types, null=True, blank=True) body_sl = StreamField(block_types, null=True, blank=True) body_da = StreamField(block_types, null=True, blank=True) body_uk = StreamField(block_types, null=True, blank=True) body_el = StreamField(block_types, null=True, blank=True) body_ru = StreamField(block_types, null=True, blank=True) body_ka = StreamField(block_types, null=True, blank=True) body_mk = StreamField(block_types, null=True, blank=True) body_mt = StreamField(block_types, null=True, blank=True) body = TranslatedField('body') translated_title = TranslatedField('title') translated_intro = TranslatedField('intro') class Meta: verbose_name = "Homepage" general_panels = [ edit_handlers.FieldPanel('title', classname='title'), edit_handlers.FieldPanel('slug'), ImageChooserPanel('image'), edit_handlers.FieldPanel('videoplayer_url'), ] content_panels = [ edit_handlers.MultiFieldPanel([ edit_handlers.FieldPanel('title_' + lang_code), edit_handlers.FieldPanel('intro_' + lang_code), edit_handlers.StreamFieldPanel('body_' + lang_code) ], heading=lang, classname="collapsible collapsed") for lang_code, lang in LANGUAGES ] edit_handler = edit_handlers.TabbedInterface([ edit_handlers.ObjectList(content_panels, heading='Content'), edit_handlers.ObjectList(general_panels, heading='General') ]) parent_page_types = [] subpage_types = ['home.SimplePage', 'home.ManualsIndex'] @property def featured_projects(self): return prj_models.Project.objects.featured()
class PageCollection(models.Model): title = TranslatedField('title') title_en = models.CharField(max_length=80) title_de = models.CharField(max_length=80, blank=True) title_it = models.CharField(max_length=80, blank=True) title_fr = models.CharField(max_length=80, blank=True) title_sv = models.CharField(max_length=80, blank=True) title_sl = models.CharField(max_length=80, blank=True) title_da = models.CharField(max_length=80, blank=True) title_uk = models.CharField(max_length=80, blank=True) title_el = models.CharField(max_length=80, blank=True) title_ru = models.CharField(max_length=80, blank=True) title_ka = models.CharField(max_length=80, blank=True) title_mk = models.CharField(max_length=80, blank=True) title_mt = models.CharField(max_length=80, blank=True) image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+', help_text='The Image that is shown on top of the page') intro_text = models.CharField(max_length=250, blank=True) args = { 'on_delete': models.SET_NULL, 'null': True, 'blank': True, 'related_name': '+' } page_1 = models.ForeignKey('wagtailcore.Page', **args) page_2 = models.ForeignKey('wagtailcore.Page', **args) page_3 = models.ForeignKey('wagtailcore.Page', **args) page_4 = models.ForeignKey('wagtailcore.Page', **args) page_5 = models.ForeignKey('wagtailcore.Page', **args) page_6 = models.ForeignKey('wagtailcore.Page', **args) page_7 = models.ForeignKey('wagtailcore.Page', **args) page_8 = models.ForeignKey('wagtailcore.Page', **args) panels = [ edit_handlers.MultiFieldPanel( [ edit_handlers.FieldPanel('title_{}'.format(lang_code)) for lang_code, lang in LANGUAGES ], heading="Title", ), edit_handlers.FieldPanel('intro_text'), edit_handlers.MultiFieldPanel( [ edit_handlers.PageChooserPanel('page_{}'.format(x)) for x in range(1, 8) ], classname="collapsible collapsed", heading="Pages", ), ImageChooserPanel('image'), ] def __str__(self): return self.title @property def pages(self): return [ self.page_1, self.page_2, self.page_3, self.page_4, self.page_5, self.page_6, self.page_7, self.page_8 ]
class ManualsDetailPage(Page): subpage_types = [] parent_page_types = ['home.ManualsSectionPage', 'home.ManualsIndex'] # Title translated_title = TranslatedField('title') title_en = models.CharField(max_length=150, blank=True, verbose_name="Title") title_de = models.CharField(max_length=150, blank=True, verbose_name="Title") title_it = models.CharField(max_length=150, blank=True, verbose_name="Title") title_fr = models.CharField(max_length=150, blank=True, verbose_name="Title") title_sv = models.CharField(max_length=150, blank=True, verbose_name="Title") title_sl = models.CharField(max_length=150, blank=True, verbose_name="Title") title_da = models.CharField(max_length=150, blank=True, verbose_name="Title") title_uk = models.CharField(max_length=150, blank=True, verbose_name="Title") title_el = models.CharField(max_length=150, blank=True, verbose_name="Title") title_ru = models.CharField(max_length=150, blank=True, verbose_name="Title") title_ka = models.CharField(max_length=150, blank=True, verbose_name="Title") title_mk = models.CharField(max_length=150, blank=True, verbose_name="Title") title_mt = models.CharField(max_length=150, blank=True, verbose_name="Title") # Subtitle (Field named description as in ManualsSectionPage) description = TranslatedField('description') description_en = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_de = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_it = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_fr = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_sv = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_sl = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_da = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_uk = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_el = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_ru = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_ka = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_mk = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") description_mt = models.CharField(max_length=260, blank=True, verbose_name="Subtitle") # Body body = TranslatedField('body') block_types = [ ('heading', core_blocks.CharBlock(classname="full title", icon="title")), ('paragraph', core_blocks.TextBlock(icon="pilcrow")), ('rich_text', core_blocks.RichTextBlock(icon="pilcrow")), ('video_block', VideoBlock()), ('image', image_blocks.ImageChooserBlock(icon="image")), ('accordion_block', AccordionBlock(icon="collapse-down")), ] body_en = StreamField(block_types, null=True, blank=True, verbose_name="body") body_de = StreamField(block_types, null=True, blank=True, verbose_name="body") body_it = StreamField(block_types, null=True, blank=True, verbose_name="body") body_fr = StreamField(block_types, null=True, blank=True, verbose_name="body") body_sv = StreamField(block_types, null=True, blank=True, verbose_name="body") body_sl = StreamField(block_types, null=True, blank=True, verbose_name="body") body_da = StreamField(block_types, null=True, blank=True, verbose_name="body") body_uk = StreamField(block_types, null=True, blank=True, verbose_name="body") body_el = StreamField(block_types, null=True, blank=True, verbose_name="body") body_ru = StreamField(block_types, null=True, blank=True, verbose_name="body") body_ka = StreamField(block_types, null=True, blank=True, verbose_name="body") body_mk = StreamField(block_types, null=True, blank=True, verbose_name="body") body_mt = StreamField(block_types, null=True, blank=True, verbose_name="body") content_panels = [ edit_handlers.MultiFieldPanel([ edit_handlers.FieldPanel('title_' + lang_code), edit_handlers.FieldPanel('description_' + lang_code), edit_handlers.StreamFieldPanel('body_' + lang_code), ], heading=lang, classname="collapsible collapsed") for lang_code, lang in LANGUAGES ] image = models.ForeignKey('wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') colors = ( ('blue', 'Blue'), ('orange', 'Orange'), ('turquoise', 'Turquoise'), ('pink', 'Pink'), ('purple', 'Purple'), ) color = models.CharField(choices=colors, max_length=9, blank=True, default='blue') general_panels = [ edit_handlers.FieldPanel('title', classname='title'), edit_handlers.FieldPanel('slug'), edit_handlers.FieldPanel('color'), ImageChooserPanel('image'), ] edit_handler = edit_handlers.TabbedInterface([ edit_handlers.ObjectList(content_panels, heading='Content'), edit_handlers.ObjectList(general_panels, heading='General') ]) def get_template(self, request, **kwargs): # only render detail page with sidebar if there's a section if self.parent_page.__class__.__name__ == 'ManualsSectionPage': return 'home/manuals_detail_page_sections.html' else: return 'home/manuals_detail_page.html' @property def parent_page(self): return self.get_ancestors().live().specific().last()
class NavigationMenuItem(Orderable, MenuItem): parent = ParentalKey('home.NavigationMenu', related_name='menu_items') class NavigationMenu(ClusterableModel): menu_name = models.CharField(max_length=255, null=False, blank=False) def __str__(self): return self.menu_name NavigationMenu.panels = [ edit_handlers.FieldPanel('menu_name', classname='full title'), edit_handlers.InlinePanel('menu_items', label="Menu Items") ] class PageCollection(models.Model): title = TranslatedField('title') title_en = models.CharField(max_length=80) title_de = models.CharField(max_length=80, blank=True) title_it = models.CharField(max_length=80, blank=True) title_fr = models.CharField(max_length=80, blank=True) title_sv = models.CharField(max_length=80, blank=True) title_sl = models.CharField(max_length=80, blank=True) title_da = models.CharField(max_length=80, blank=True) title_uk = models.CharField(max_length=80, blank=True) title_el = models.CharField(max_length=80, blank=True)
class GradingMethod(models.Model): """ Describes a valid grading method. """ class Meta: unique_together = [('name', 'owner')] VALID_NAMES = { 'best': _('The final grade is equal to the best response.'), 'worst': _('The final grade is equal to the worst response.'), 'first': _('Only the first response is considered.'), 'last': _('Only the last response is considered.'), 'average': _('Take the average over all responses.'), } VALID_FAMILIES = [] name = models.CharField(max_length=20) description = models.TextField(blank=True) family = models.CharField(max_length=20, blank=True) data = models.TextField() owner = models.ForeignKey( models.User, blank=True, null=True, related_name='private_grading_methods', ) data_as_json = property(lambda x: json.loads(x.data)) def __str__(self): return self.name # Alternative constructors best = mk_grading_constructor('best') worst = mk_grading_constructor('worst') first = mk_grading_constructor('first') last = mk_grading_constructor('last') average = mk_grading_constructor('average') @classmethod def from_name(cls, name, user=None): """ Return the grading method with the given name for the given user. """ if name in self.VALID_NAMES: return getattr(self, name)() elif user: return cls.objects.get(name=name, user=user) else: raise cls.DoesNotExist def save(self, *args, **kwargs): self.validate() super().save(*args, **kwargs) def is_valid(self): """ Return true if name, family and data fields are valid. """ if self.name in self.VALID_NAMES: return self.family == '' and self.data == '' elif self.name == '': if self.family: try: self.parse_data() return True except ValueError: return False else: return False else: return False def validate(self): """ Validate the name, family and data fields. """ if not self.is_valid(): raise ValueError('invalid grading method') def parse_data(self): """ Return an usable representation of data for the given family of grading methods. """ if self.name or not self.family: raise ValueError else: try: method = getattr(self, '_parse_data_' + self.family_attribute) except AttributeError: raise ValueError else: return method() # Implements grading methods def grade(self, responses): """ Grade the given sequence of responses using the grading method. """ responses = list(self._filter_valid_responses(responses)) name = self.name if name in ['best', 'worst']: func = max if name == 'best' else min if responses: return func(x.final_grade for x in responses) else: return ZERO elif name in ['first', 'last']: if responses: responses = sorted(responses, key=response.created) return response[0 if name == 'first' else -1] return ZERO elif name == 'average': if responses: return sum(x.final_grade for x in responses) / len(responses) else: return ZERO if self.name in self.VALID_NAMES: method = getattr(self, '_grade_' + self.name) return method(responses) else: raise NotImplementedError def _filter_valid_responses(self, responses): for response in responses: if response.status == response.STATUS_PENDING: response.autograde_response() if response.status == response.STATUS_DONE: yield response # Wagtail admin panels = [ panel.FieldPanel('name'), panel.FieldPanel('description'), ]