def test_render_with_event(self): event = Event.objects.get(title='Test event') instance = GallerySelect(event=event) # add some pictures with open(self.main_image) as fp: Picture.objects.create( file=File(fp), notes='Some notes' ) pic2 = Picture.objects.create( file=File(fp), notes='Other notes', event=event ) Picture.objects.create( file=File(fp), notes='Inactive Notes', is_active=False, ) html = instance.render('picture', None, None) ok_('Some notes' in html) ok_('Other notes' in html) ok_('Inactive notes' not in html) # now with a value html = instance.render('picture', pic2.id, None) # one of them should have a class "selected" ok_('class="selected' in html) ok_('Inactive notes' not in html)
def test_render_without_event(self): instance = GallerySelect() # add some pictures event = Event.objects.get(title='Test event') with open(self.main_image) as fp: pic1 = Picture.objects.create( file=File(fp), notes='Some notes' ) Picture.objects.create( file=File(fp), notes='Other notes', event=event ) Picture.objects.create( file=File(fp), notes='Inactive notes', is_active=False ) html = instance.render('picture', None, None) ok_('Some notes' in html) ok_('data-picture-id="%s"' % pic1.id in html) ok_('Other notes' not in html) # belongs to an event ok_('Inactive notes' not in html) # not active
def __init__(self, *args, **kwargs): self.event = kwargs.pop('event', None) super(EventEditForm, self).__init__(*args, **kwargs) self.fields['channels'].queryset = ( Channel.objects .filter(Q(never_show=False) | Q(id__in=self.event.channels.all())) ) self.fields['placeholder_img'].required = False self.fields['placeholder_img'].label = ( 'Upload a picture from your computer' ) self.fields['channels'].help_text = "" self.fields['recruitmentmessage'].label = 'Recruitment message' self.fields['recruitmentmessage'].required = False self.fields['recruitmentmessage'].queryset = ( RecruitmentMessage.objects.filter(active=True) ) self.fields['picture'].widget = GallerySelect(event=self.event) self.fields['picture'].label = ( 'Select an existing picture from the gallery' ) if not (self.event.is_upcoming() or self.event.is_live()): del self.fields['call_info']
def test_render_with_event_picture_inactive(self): event = Event.objects.get(title='Test event') with open(self.main_image) as fp: picture = Picture.objects.create(file=File(fp), notes='Inactive notes', is_active=False) event.picture = picture event.save() instance = GallerySelect(event=event) html = instance.render('picture', None, None) ok_('Inactive notes' in html) html = instance.render('picture', picture.id, None) ok_('Inactive notes' in html) ok_('value="{}"'.format(picture.id) in html) ok_('value="None"' not in html)
def test_render_with_event_picture_inactive(self): event = Event.objects.get(title='Test event') with open(self.main_image) as fp: picture = Picture.objects.create( file=File(fp), notes='Inactive notes', is_active=False ) event.picture = picture event.save() instance = GallerySelect(event=event) html = instance.render('picture', None, None) ok_('Inactive notes' in html) html = instance.render('picture', picture.id, None) ok_('Inactive notes' in html)
def test_render_with_event(self): event = Event.objects.get(title='Test event') instance = GallerySelect(event=event) # add some pictures with open(self.main_image) as fp: Picture.objects.create(file=File(fp), notes="Some notes") pic2 = Picture.objects.create(file=File(fp), notes="Other notes", event=event) html = instance.render('picture', None, None) ok_('Some notes' in html) ok_('Other notes' in html) # now with a value html = instance.render('picture', pic2.id, None) # one of them should have a class "selected" ok_('class="selected' in html)
def test_render_without_event(self): instance = GallerySelect() # add some pictures event = Event.objects.get(title='Test event') with open(self.main_image) as fp: pic1 = Picture.objects.create(file=File(fp), notes='Some notes') Picture.objects.create(file=File(fp), notes='Other notes', event=event) Picture.objects.create(file=File(fp), notes='Inactive notes', is_active=False) html = instance.render('picture', None, None) ok_('Some notes' in html) ok_('data-picture-id="%s"' % pic1.id in html) ok_('Other notes' not in html) # belongs to an event ok_('Inactive notes' not in html) # not active ok_('value="None"' not in html)
def __init__(self, *args, **kwargs): super(PlaceholderForm, self).__init__(*args, **kwargs) self.fields['placeholder_img'].label = ( 'Upload a picture from your computer') self.fields['placeholder_img'].help_text = ( "We need a placeholder image for your event. <br>" "A recent head-shot of the speaker is preferred. <br>" "Placeholder images should be 200 x 200 px or larger.") self.fields['picture'].widget = GallerySelect() self.fields['picture'].label = ( 'Select an existing picture from the gallery')
def test_render_with_name(self): instance = GallerySelect() html = instance.render('picky', None, None) ok_('id="id_picky"' in html) ok_('name="picky"' in html)