class VideoPlayer(blocks.StructBlock): YOUTUBE_ID_HELP_TEXT = ( 'Enter the YouTube video ID, which is located at the end of the video ' 'URL, after "v=". For example, the video ID for ' 'https://www.youtube.com/watch?v=1V0Ax9OIc84 is 1V0Ax9OIc84.') video_id = blocks.RegexBlock( label='YouTube video ID', # Set required=False to allow for non-required VideoPlayers. # See https://github.com/wagtail/wagtail/issues/2665. required=False, # This is a reasonable but not official regex for YouTube video IDs. # https://webapps.stackexchange.com/a/54448 regex=r'^[\w-]{11}$', error_messages={ 'invalid': "The YouTube video ID is in the wrong format.", }, help_text=YOUTUBE_ID_HELP_TEXT) thumbnail_image = images_blocks.ImageChooserBlock( required=False, help_text=mark_safe( 'Optional thumbnail image to show before and after the video ' 'plays. If the thumbnail image is not set here, the video player ' 'will default to showing the thumbnail that was set in (or ' 'automatically chosen by) YouTube.')) def clean(self, value): cleaned = super().clean(value) errors = {} if not cleaned['video_id']: if getattr(self.meta, 'required', True): errors['video_id'] = ErrorList([ ValidationError('This field is required.'), ]) elif cleaned['thumbnail_image']: errors['thumbnail_image'] = ErrorList([ ValidationError( 'This field should not be used if YouTube video ID is ' 'not set.') ]) if errors: raise ValidationError('Validation error in VideoPlayer', params=errors) return cleaned class Meta: icon = 'media' template = '_includes/organisms/video-player.html' value_class = VideoPlayerStructValue class Media: js = ['video-player.js']
class CategoriesListBlock(blocks.StructBlock): title = blocks.CharBlock(label=_('模块标题'), default=_('课程分类')) categorieslist = blocks.ListBlock(blocks.StructBlock([ ('categories_name', blocks.RegexBlock(regex=r'^[\u4e00-\u9fa5a-zA-Z]{2,10}$', error_messages={'invalid': _('只允许输入2到10位中英文字符')}, required=True, label=_('分类名称'))), ('categories_link', blocks.URLBlock(required=True, label=_('分类链接'))), ('img_for_app', ImageChooserBlock(required=False, label=_('app显示图标'))), ]), label=_('课程分类')) class Meta: template = 'home/blocks/categorieslist.html' label = "课程分类" icon = 'grip'
class _S_BigBlock(blocks.StructBlock): integerblock = blocks.IntegerBlock() floatblock = blocks.FloatBlock() decimalblock = blocks.DecimalBlock() regexblock = blocks.RegexBlock(regex="") urlblock = blocks.URLBlock() booleanblock = blocks.BooleanBlock() dateblock = blocks.DateBlock() graphql_fields = [ GraphQLInt("integerblock"), GraphQLFloat("floatblock"), GraphQLFloat("decimalblock"), GraphQLString("regexblock"), GraphQLString("urlblock"), GraphQLBoolean("booleanblock"), GraphQLString("dateblock"), ]
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 VideoPlayer(blocks.StructBlock): video_url = blocks.RegexBlock( label='YouTube Embed URL', default='https://www.youtube.com/embed/', required=True, regex=r'^https:\/\/www\.youtube\.com\/embed\/.+$', error_messages={ 'required': 'The YouTube URL field is required for video players.', 'invalid': "The YouTube URL is in the wrong format. " "You must use the embed URL " "(https://www.youtube.com/embed/video_id), " "which can be obtained by clicking Share > Embed " "on the YouTube video page.", }) class Meta: icon = 'media' template = '_includes/organisms/video-player.html' class Media: js = ['video-player.js']
class ConferenceRegistrationForm(AbstractFormBlock): govdelivery_code = blocks.CharBlock( label='GovDelivery code', help_text=( 'Conference registrants will be subscribed to this GovDelivery ' 'topic.')) govdelivery_question_id = blocks.RegexBlock( required=False, regex=r'^\d{5,}$', error_messages={ 'invalid': 'GovDelivery question ID must be 5 digits.' }, label='GovDelivery question ID', help_text=mark_safe( 'Enter the ID of the question in GovDelivery that is being used ' 'to track registration for this conference. It is the number in ' 'the question URL, e.g., the <code>12345</code> in ' '<code>https://admin.govdelivery.com/questions/12345/edit</code>.') ) govdelivery_answer_id = blocks.RegexBlock( required=False, regex=r'^\d{5,}$', error_messages={'invalid': 'GovDelivery answer ID must be 5 digits.'}, label='GovDelivery answer ID', help_text=mark_safe( 'Enter the ID of the affirmative answer for the above question. ' 'To find it, right-click on the answer in the listing on a page ' 'like <code>https://admin.govdelivery.com/questions/12345/answers' '</code>, inspect the element, and look around in the source for ' 'a five-digit ID associated with that answer. <strong>Required ' 'if Govdelivery question ID is set.</strong>')) capacity = blocks.IntegerBlock(help_text=( 'Enter the (physical) conference attendance limit as a number.')) success_message = blocks.RichTextBlock(help_text=( 'Enter a message that will be shown on successful registration.')) at_capacity_message = blocks.RichTextBlock(help_text=( 'Enter a message that will be shown when the event is at capacity.')) failure_message = blocks.RichTextBlock( help_text=('Enter a message that will be shown if the GovDelivery ' 'subscription fails.')) def clean(self, value): cleaned = super(ConferenceRegistrationForm, self).clean(value) question = cleaned.get('govdelivery_question_id') answer = cleaned.get('govdelivery_answer_id') # Question and answer values must both exist or neither exist if question and not answer: raise ValidationError( 'Validation error in Conference Registration Form: ' 'GovDelivery question ID requires answer ID, and vice versa.', params={ 'govdelivery_answer_id': ErrorList( ['Required if a GovDelivery question ID is entered.']) }) if answer and not question: raise ValidationError( 'Validation error in Conference Registration Form: ' 'GovDelivery question ID requires answer ID, and vice versa.', params={ 'govdelivery_question_id': ErrorList( ['Required if a GovDelivery answer ID is entered.']) }) return cleaned class Meta: handler = 'data_research.handlers.ConferenceRegistrationHandler' template = 'data_research/conference-registration-form.html'
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'), ]