Example #1
0
class CoursePage(Page):
    course_image = models.ForeignKey('wagtailimages.Image',
                                     null=True,
                                     blank=True,
                                     on_delete=models.SET_NULL,
                                     related_name='+')

    author = models.CharField(max_length=255)
    date = models.DateField("Post date")
    description = RichTextField("Description", blank=True)
    forwhom = RichTextField("For Whom?", blank=True)
    objectives = RichTextField("Learning Objectives", blank=True)
    software = RichTextField("Software", blank=True)
    books = RichTextField("Books", blank=True)
    lecturer = RichTextField("Lecturer", blank=True)
    acknowledgements = RichTextField("Acknowledgements", blank=True)
    shortcourses = RichTextField("Short Courses", blank=True)
    schedule = RichTextField("Schedule", blank=True)
    document = models.ForeignKey(
        'wagtaildocs.Document',
        null=True,
        blank=True,
        related_name='+',
        on_delete=models.SET_NULL,
    )
    slides = RichTextField("Slides of Lectures", blank=True)
    thanks = RichTextField("Thanks", blank=True)
    training = RichTextField("Tailor Made Trainings", blank=True)

    category = models.ForeignKey('knowledgeplatform.CourseCategoryPage',
                                 null=True,
                                 blank=True,
                                 related_name='+',
                                 on_delete=models.SET_NULL)

    body = StreamField([
        ('paragraph', blocks.RichTextBlock()),
        ('urls', blocks.URLBlock()),
        ('image', ImageChooserBlock()),
        ('document', DocumentChooserBlock()),
        ('embed', EmbedBlock()),
    ])

    @property
    def categories(self):
        # Get list of live news pages that are descendants of this page
        categories = CourseCategoryPage.objects.live()
        return categories

    def get_context(self, request):
        courses = CoursePage.objects.live().descendant_of(self.get_parent())

        category = request.GET.get('category')
        page = request.GET.get('page')

        if category:
            filtered_courses = get_courses_by_category(category, courses, page)
        else:
            filtered_courses = courses
        context = super(CoursePage, self).get_context(request)
        context['courses'] = filtered_courses
        return context

    content_panels = Page.content_panels + [
        FieldPanel('author'),
        FieldPanel('date'),
        ImageChooserPanel('course_image'),
        FieldPanel('description', classname="full"),
        FieldPanel('forwhom', classname="full"),
        FieldPanel('objectives', classname="full"),
        FieldPanel('software', classname="full"),
        FieldPanel('books', classname="full"),
        FieldPanel('lecturer', classname="full"),
        FieldPanel('acknowledgements', classname="full"),
        FieldPanel('shortcourses', classname="full"),
        FieldPanel('slides', classname="full"),
        FieldPanel('thanks', classname="full"),
        FieldPanel('training', classname="full"),
        FieldPanel('category'),
    ]
Example #2
0
class StoryPage(Page):
    date = models.DateField("Post date")

    intro = models.CharField(max_length=250)
    # intro = models.CharField(max_length=250, help_text="Listen up buddy This thing is non editable Yeah!")

    author = models.CharField(max_length=250, default="Anonymous")

    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('images',
         blocks.StructBlock(
             [
                 ('image', ImageChooserBlock()),
                 ('caption',
                  blocks.CharBlock(blank=True, required=False, null=True)),
             ],
             icon='image',
         )),
        ('gist',
         blocks.TextBlock(
             help_text=
             "Go to gist.github.com to write code and copy the embed Link.")),
        ('Link',
         blocks.StructBlock(
             [
                 ('URL', blocks.URLBlock()),
                 ('Text', blocks.CharBlock()),
             ],
             icon='site',
         )),
        ('Quote',
         blocks.StructBlock([
             ('quote', blocks.BlockQuoteBlock()),
             ('Author', blocks.TextBlock(max_length=50)),
         ],
                            icon='quote')),
        ('embed', EmbedBlock()),
    ])

    tags = ClusterTaggableManager(through=StoryPageTag, blank=True)

    categories = ParentalManyToManyField('story.StoryCategory', blank=True)

    search_fields = Page.search_fields + [
        index.SearchField('intro'),
        index.SearchField('body'),
    ]

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('date'),
            FieldPanel('author'),
            FieldPanel('tags'),
            FieldPanel('categories', widget=forms.CheckboxSelectMultiple),
        ],
                        heading="Information About Story"),
        FieldPanel('intro'),
        StreamFieldPanel('body'),
    ]
Example #3
0
 class LinkBlock(blocks.StructBlock):
     title = blocks.CharBlock()
     link = blocks.URLBlock()
Example #4
0
class ReadMoreBlock(StructBlock):
    name = blocks.CharBlock(required=False)
    page = PageChooserBlock(
        required=False,
        help_text='Links to the original page (in "{}") will automatically '
        'point to translated pages (if they exist) in other '
        'languages. Links to a translation will always point to that '
        'translated page, in all languages.'.format(
            TranslatablePageMixin.original_lang_code))
    link = blocks.URLBlock(required=False)
    button = blocks.BooleanBlock(required=False)
    alignment = ChoiceBlock(
        choices=[
            ('left', 'Left'),
            ('center', 'Center'),
            ('right', 'Right'),
        ],
        required=False,
    )

    def __init__(self, required=True, local_blocks=None, **kwargs):
        super().__init__(local_blocks=local_blocks, **kwargs)
        self._required = required

    @property
    def required(self):
        return self._required

    def get_context(self, value, parent_context=None):
        context = super().get_context(value, parent_context)
        page = value.get('page')
        if page is not None:
            page = TranslatablePageMixin.get_translated_page(page.specific)
        link = value.get('link')
        context.update({
            'href': page.url if page else link,
            'external': not bool(page),
            'text': value.get('name') or _('Read more'),
            'align': value.get('alignment'),
            'button': value.get('button'),
        })
        return context

    def clean(self, value):
        at_lest_one_field_required_fields = ['page', 'link']
        if self.required and not any([
                bool(value.get(field))
                for field in at_lest_one_field_required_fields
        ]):
            error_message = 'At least one of {} is required'.format(
                at_lest_one_field_required_fields)
            errors = {
                field: ErrorList([error_message])
                for field in at_lest_one_field_required_fields
            }
            raise ValidationError(error_message, params=errors)
        return super().clean(value)

    class Meta:
        icon = 'link'
        label = _('Read more')
        template = 'widgets/read-more-link.html'
        help_text = 'Choose either a page or an external link'
Example #5
0
 class LinkBlock(blocks.StructBlock):
     title = blocks.CharBlock(default="Github")
     link = blocks.URLBlock(default="http://www.github.com")
Example #6
0
 class LinkBlock(blocks.StructBlock):
     title = CharBlockWithDeclarations(default="Torchbox")
     link = blocks.URLBlock(default="http://www.torchbox.com")
Example #7
0
 class LinkBlock(blocks.StructBlock):
     title = ScriptedCharBlock(default="Torchbox")
     link = blocks.URLBlock(default="http://www.torchbox.com")
Example #8
0
class UniversalStreamPage(Page, BaseFieldsMixin):
    content = StreamField([
        ('teaser_area',
         blocks.StructBlock([
             ('headline', blocks.CharBlock()),
             ('content', blocks.RichTextBlock()),
         ],
                            template='core/blocks/teaser_area.html')),
        ('quotation',
         blocks.StructBlock([
             ('image', ImageChooserBlock()),
             ('text',
              blocks.TextBlock(
                  help_text=
                  "quotation marks (“...”) will be added automatically")),
             ('name', blocks.RichTextBlock()),
             ('second_image', ImageChooserBlock(required=False)),
             ('second_text',
              blocks.TextBlock(
                  required=False,
                  help_text=
                  "quotation marks (“...”) will be added automatically")),
             ('second_name', blocks.RichTextBlock(required=False)),
         ],
                            template='core/blocks/quotation.html')),
        ('one_column_text',
         blocks.StructBlock([
             ('content', blocks.RichTextBlock()),
         ],
                            template='core/blocks/one_column_text.html')),
        ('two_column_50_50_text',
         blocks.StructBlock(
             [
                 ('left_content', blocks.RichTextBlock()),
                 ('right_content', blocks.RichTextBlock()),
             ],
             template='core/blocks/two_column_50_50_text.html')),
        ('two_column_66_33_text',
         blocks.StructBlock(
             [
                 ('left_content', blocks.RichTextBlock()),
                 ('right_content', blocks.RichTextBlock()),
             ],
             template='core/blocks/two_column_66_33_text.html')),
        ('three_column_33_33_33_text',
         blocks.StructBlock(
             [
                 ('left_content', blocks.RichTextBlock()),
                 ('center_content', blocks.RichTextBlock()),
                 ('right_content', blocks.RichTextBlock()),
             ],
             template='core/blocks/three_column_33_33_33_text.html')),
        ('four_column_text',
         blocks.StructBlock([
             ('col1_content', blocks.RichTextBlock()),
             ('col2_content', blocks.RichTextBlock()),
             ('col3_content', blocks.RichTextBlock()),
             ('col4_content', blocks.RichTextBlock()),
         ],
                            template='core/blocks/four_column_text.html')),
        ('six_column_text',
         blocks.StructBlock([
             ('col1_content', blocks.RichTextBlock()),
             ('col2_content', blocks.RichTextBlock()),
             ('col3_content', blocks.RichTextBlock()),
             ('col4_content', blocks.RichTextBlock()),
             ('col5_content', blocks.RichTextBlock()),
             ('col6_content', blocks.RichTextBlock()),
         ],
                            template='core/blocks/six_column_text.html')),
        ('call_to_action_area',
         blocks.StructBlock([
             ('title', blocks.CharBlock(required=False)),
             ('button_label', blocks.CharBlock()),
             ('button_link', blocks.URLBlock()),
             ('button2_label', blocks.CharBlock(required=False)),
             ('button2_link', blocks.URLBlock(required=False)),
         ],
                            template='core/blocks/call_to_action_area.html')),
        ('raw_html',
         blocks.StructBlock([
             ('html', blocks.RawHTMLBlock()),
         ],
                            template='core/blocks/raw_html.html')),
    ])

    settings_panels = BaseFieldsMixin.settings_panels
    content_panels = BaseFieldsMixin.content_panels + [
        StreamFieldPanel('content'),
    ]

    class Meta:
        verbose_name = 'Flexible content page'
Example #9
0
class FooterItemBlock(blocks.StructBlock):
    icon = ImageChooserBlock(required=True)
    url_name = blocks.CharBlock(max_length=255,
                                required=True,
                                help_text='Add the name of the link.')
    url = blocks.URLBlock(required=True)