class AbstractCarouselItem(AbstractLinkFields): image = models.ForeignKey( 'tuiuiuimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) embed_url = models.URLField("Embed URL", blank=True) caption = models.CharField(max_length=255, blank=True) api_fields = ( 'image', 'embed_url', 'caption', ) + AbstractLinkFields.api_fields panels = [ ImageChooserPanel('image'), FieldPanel('embed_url'), FieldPanel('caption'), MultiFieldPanel(AbstractLinkFields.panels, "Link"), ] class Meta: abstract = True
def test_no_thousand_separators_in_js(self): """ Test that the USE_THOUSAND_SEPARATOR setting does not screw up the rendering of numbers (specifically maxForms=1000) in the JS initializer: https://github.com/tuiuiu/tuiuiu/pull/2699 https://github.com/tuiuiu/tuiuiu/issues/3227 """ SpeakerObjectList = ObjectList([ InlinePanel('speakers', label="Speakers", panels=[ FieldPanel('first_name', widget=forms.Textarea), ImageChooserPanel('image'), ]), ]).bind_to_model(EventPage) SpeakerInlinePanel = SpeakerObjectList.children[0] EventPageForm = SpeakerObjectList.get_form_class(EventPage) event_page = EventPage.objects.get(slug='christmas') form = EventPageForm(instance=event_page) panel = SpeakerInlinePanel(instance=event_page, form=form) self.assertIn('maxForms: 1000', panel.render_js_init())
class EventPageSpeaker(Orderable, LinkFields): page = ParentalKey('tests.EventPage', related_name='speakers', on_delete=models.CASCADE) first_name = models.CharField("Name", max_length=255, blank=True) last_name = models.CharField("Surname", max_length=255, blank=True) image = models.ForeignKey('tuiuiuimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+') @property def name_display(self): return self.first_name + " " + self.last_name panels = [ FieldPanel('first_name'), FieldPanel('last_name'), ImageChooserPanel('image'), MultiFieldPanel(LinkFields.panels, "Link"), ]
class EventPageSpeaker(Orderable, AbstractLinkFields): page = ParentalKey('EventPage', related_name='speakers', on_delete=models.CASCADE) first_name = models.CharField("Name", max_length=255, blank=True) last_name = models.CharField("Surname", max_length=255, blank=True) image = models.ForeignKey( 'tuiuiuimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) api_fields = ( 'first_name', 'last_name', 'image', ) panels = [ FieldPanel('first_name'), FieldPanel('last_name'), ImageChooserPanel('image'), MultiFieldPanel(AbstractLinkFields.panels, "Link"), ]
def test_render_with_panel_overrides(self): """ Check that inline panel renders the panels listed in the InlinePanel definition where one is specified """ SpeakerObjectList = ObjectList([ InlinePanel('speakers', label="Speakers", panels=[ FieldPanel('first_name', widget=forms.Textarea), ImageChooserPanel('image'), ]), ]).bind_to_model(EventPage) SpeakerInlinePanel = SpeakerObjectList.children[0] EventPageForm = SpeakerObjectList.get_form_class(EventPage) # SpeakerInlinePanel should instruct the form class to include a 'speakers' formset self.assertEqual(['speakers'], list(EventPageForm.formsets.keys())) event_page = EventPage.objects.get(slug='christmas') form = EventPageForm(instance=event_page) panel = SpeakerInlinePanel(instance=event_page, form=form) result = panel.render_as_field() # rendered panel should contain first_name rendered as a text area, but no last_name field self.assertIn('<label for="id_speakers-0-first_name">Name:</label>', result) self.assertIn('Father</textarea>', result) self.assertNotIn( '<label for="id_speakers-0-last_name">Surname:</label>', result) # test for #338: surname field should not be rendered as a 'stray' label-less field self.assertTagInHTML('<input id="id_speakers-0-last_name">', result, count=0, allow_extra_attrs=True) self.assertIn('<label for="id_speakers-0-image">Image:</label>', result) self.assertIn('Choose an image', result) # rendered panel must also contain hidden fields for id, DELETE and ORDER self.assertTagInHTML( '<input id="id_speakers-0-id" name="speakers-0-id" type="hidden">', result, allow_extra_attrs=True) self.assertTagInHTML( '<input id="id_speakers-0-DELETE" name="speakers-0-DELETE" type="hidden">', result, allow_extra_attrs=True) self.assertTagInHTML( '<input id="id_speakers-0-ORDER" name="speakers-0-ORDER" type="hidden">', result, allow_extra_attrs=True) # rendered panel must contain maintenance form for the formset self.assertTagInHTML( '<input id="id_speakers-TOTAL_FORMS" name="speakers-TOTAL_FORMS" type="hidden">', result, allow_extra_attrs=True) # render_js_init must provide the JS initializer self.assertIn('var panel = InlinePanel({', panel.render_js_init())
FieldPanel('time_from'), FieldPanel('time_to'), FieldPanel('location'), FieldPanel('audience'), FieldPanel('cost'), FieldPanel('signup_link'), InlinePanel('carousel_items', label="Carousel items"), FieldPanel('body', classname="full"), InlinePanel('speakers', label="Speakers"), InlinePanel('related_links', label="Related links"), FieldPanel('categories'), ] EventPage.promote_panels = [ MultiFieldPanel(COMMON_PANELS, "Common page configuration"), ImageChooserPanel('feed_image'), ] # Just to be able to test multi table inheritance class SingleEventPage(EventPage): excerpt = models.TextField( max_length=255, blank=True, null=True, help_text="Short text to describe what is this action about") # Give this page model a custom URL routing scheme def get_url_parts(self): url_parts = super(SingleEventPage, self).get_url_parts() if url_parts is None: