class PostcardUploadForm(forms.ModelForm): postcard_image = forms.IntegerField( label='Postcard image', required=False, help_text= "Image will be used to print a set of postcards with your contact details, for you to use during the Show. The image will not appear in your Show online catalogue. Image must be A6 plus 2mm 'bleed' on each edge (1795 x 1287px, ie. 152 x 109mm @ 300 dpi). This must be uploaded at the correct size and before the deadline for postcards to be printed.", widget=ImageInput, ) photographer = forms.CharField( max_length=255, required=False, help_text=help_text('rca.RcaImage', 'photographer'), ) permission = forms.CharField( max_length=255, required=False, help_text=help_text('rca.RcaImage', 'permission'), ) def clean_postcard_image(self): try: return RcaImage.objects.get( id=self.cleaned_data.get('postcard_image')) except RcaImage.DoesNotExist: return None def __init__(self, *args, **kwargs): if 'instance' in kwargs: page = kwargs.get('instance') if page.postcard_image is not None: initial_update = { 'permission': page.postcard_image.permission, 'photographer': page.postcard_image.photographer, } initial = kwargs.get('initial', {}) initial.update(initial_update) kwargs['initial'] = initial super(PostcardUploadForm, self).__init__(*args, **kwargs) def save(self, *args, **kwargs): res = super(PostcardUploadForm, self).save(*args, **kwargs) # now also save the photographer and permission fields # ignoring whether commit is True or False, we save these fields right away, because the user will not save them pci = self.cleaned_data.get('postcard_image') if pci is not None: pci.photographer = self.cleaned_data.get('photographer') pci.permission = self.cleaned_data.get('permission') pci.save() return res class Meta: model = NewStudentPage fields = [ 'postcard_image', ]
class PhDSupervisorForm(forms.ModelForm): supervisor_type = forms.ChoiceField(label='Type', choices=( ('internal', 'Internal'), ('other', 'Other'), )) supervisor = forms.ModelChoiceField( queryset=StaffPage.objects.all().order_by('last_name'), required=False, help_text=help_text( 'rca.NewStudentPagePhDSupervisor', 'supervisor', default= "Please select your RCA supervisor's profile page or enter the name of an external supervisor." ), widget=forms.Select(attrs={ 'width': '100%', 'class': 'supervisor-select' }), ) class Meta: model = NewStudentPagePhDSupervisor fields = ['supervisor', 'supervisor_other']
class PhDForm(forms.ModelForm): phd_programme = forms.ModelChoiceField( label="Programme", help_text=help_text('rca.NewStudentPage', 'phd_programme'), queryset=Programme.objects.filter(disabled=False), required=True, ) phd_start_year = forms.IntegerField( label='Start year', min_value=1950, max_value=2050, required=False, help_text=help_text('rca.NewStudentPage', 'phd_start_year'), ) phd_graduation_year = forms.IntegerField( label='Graduation year', min_value=1950, max_value=2050, required=False, help_text='If unknown, enter current year') def clean_phd_start_year(self): if self.cleaned_data['phd_start_year']: return self.cleaned_data['phd_start_year'] else: return '' def clean_phd_graduation_year(self): if self.cleaned_data['phd_graduation_year']: return self.cleaned_data['phd_graduation_year'] else: return '' class Meta: model = NewStudentPage fields = [ 'phd_in_show', 'phd_programme', 'phd_start_year', 'phd_graduation_year', 'phd_status', 'phd_degree_type', ]
class EmailForm(forms.Form): #saves to NewStudentPageContactsEmail email = forms.EmailField( max_length=255, required=False, # because we'll only save those that are there anyway help_text=help_text( 'rca.NewStudentPageContactsEmail', 'email', default= "Students can use personal email as well as [email protected]" ))
class PhoneForm(forms.Form): #saves to NewStudentPageContactsPhone phone = PhoneNumberField( max_length=255, required=False, # because we'll only save those that are there anyway help_text=help_text( 'rca.NewStudentPageContactsPhone', 'phone', default= "UK mobile e.g. 07XXX XXXXXX or overseas landline, e.g. +33 (1) XXXXXXX" ))
class AwardsForm(forms.Form): #saves to NewStudentPageAward award = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPageAward', 'award', default= "Please include prize, award title and year, separated by commas"), )
class ExperienceForm(forms.Form): experience = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPageExperience', 'experience', default= "Please include job title, company name, city and year(s), separated by commas" ), )
class MASponsorForm(forms.Form): #saves to NewStudentPageShowSponsor name = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPageShowSponsor', 'name', default= "Please list companies and individuals that have provided financial or in kind sponsorship for your final project, separated by commas" ), )
class MACollaboratorForm(forms.Form): #saves to NewStudentPageShowCollaborator name = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPageShowCollaborator', 'name', default= "Please include collaborator's name and programme (if RCA), separated by commas" ), )
class ConferencesForm(forms.Form): #saves to NewStudentPageConference name = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPageConference', 'name', default= "Please include paper, title of conference, institution, date, separated by commas" ), )
class PublicationsForm(forms.Form): #saves to NewStudentPagePublication name = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPagePublication', 'name', default= "Please include author (if not you), title of article, title of publication, issue number, year, pages, separated by commas" ), )
class ExhibitionForm(forms.Form): #saves to NewStudentPageExhibition exhibition = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPageExhibition', 'exhibition', default= "Please include exhibition title, gallery, city and year, separated by commas" ), )
class PreviousDegreeForm(forms.Form): #saves to NewStudentPagePreviousDegree degree = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPagePreviousDegree', 'degree', default= "Please include the degree level, subject, institution name and year of graduation, separated by commas" ), )
class ProfileBasicForm(forms.ModelForm): title = forms.CharField( max_length=255, required=True, label='Full Name', help_text= "Your name in full, as you'd like it to be seen by the public, e.g, Joe Smith", ) profile_image = forms.IntegerField( required=True, help_text=help_text('rca.NewStudentPage', 'profile_image', default="Self-portrait image, 500x500px"), widget=ImageInput, ) def clean_profile_image(self): if self.cleaned_data['profile_image']: return RcaImage.objects.get(id=self.cleaned_data['profile_image']) return None def clean_twitter_handle(self): if self.cleaned_data.get('twitter_handle'): handle = self.cleaned_data.get('twitter_handle', '') if handle.startswith('@'): return handle[1:] else: return handle else: return '' class Meta: model = NewStudentPage fields = [ 'title', 'first_name', 'last_name', 'twitter_handle', 'profile_image', 'statement' ]
class MADetailsForm(forms.ModelForm): ma_in_show = forms.BooleanField( label='In show', required=False, help_text="Please tick only if you're in the Show this academic year.", ) ma_graduation_year = forms.IntegerField( label='Graduation year', min_value=1950, max_value=2050, required=False, help_text=help_text('rca.NewStudentPage', 'ma_graduation_year'), ) ma_programme = forms.ModelChoiceField( label="Programme", queryset=Programme.objects.filter(disabled=False), required=True, ) def clean_ma_graduation_year(self): if self.cleaned_data['ma_graduation_year']: return self.cleaned_data['ma_graduation_year'] else: return '' class Meta: model = NewStudentPage fields = [ 'ma_in_show', 'ma_programme', 'ma_graduation_year', 'ma_specialism', ]
'tags', ] class RelatedLinkForm(forms.Form): link = forms.URLField( required=False, # because we'll only save those that are there anyway error_messages={'invalid': 'Please enter a full URL, including the ‘http://’!'}, widget=forms.TextInput, ) def clean_link(self): link = self.cleaned_data.get('link') if not link: return None if not link.startswith('http://') or link.startswith('https://'): return 'http://' + link else: return link RelatedLinkFormset = formset_factory(RelatedLinkForm, extra=1, formset=OrderedFormset) RelatedLinkFormset.title = 'Web links' RelatedLinkFormset.help_text = 'Paste in the URL of the website in full, including the ‘http://’' class AreaForm(forms.Form): area = forms.ModelChoiceField(queryset=Area.objects.all()) AreaFormSet = formset_factory(AreaForm, extra=1, formset=OrderedFormset) AreaFormSet.title = 'Areas' AreaFormSet.help_text = help_text=help_text('rca.RcaNowPageArea', 'area')
award = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPageAward', 'award', default= "Please include prize, award title and year, separated by commas"), ) AwardsFormset = make_formset( AwardsForm, 'Awards', help_text( 'rca.NewStudentPageAward', 'award', default= "Please include prize, award title and year, separated by commas")) class PublicationsForm(forms.Form): #saves to NewStudentPagePublication name = forms.CharField( max_length=255, required=False, help_text=help_text( 'rca.NewStudentPagePublication', 'name', default= "Please include author (if not you), title of article, title of publication, issue number, year, pages, separated by commas" ),
class MAShowCarouselItemForm(forms.Form): item_type = forms.ChoiceField(choices=( ( 'image', 'Image' ), # if you change these values, you must also change the values in the javascript and in the views! ('video', 'Video'), )) image_id = forms.IntegerField( # name is _id because that's what's going to be saved label='Image', required=False, help_text=help_text( 'rca.CarouselItemFields', 'image', default= 'Landscape images will display better within the carousel than portrait images. Consider sizing all your images to the same dimension - ideally 2000 x 1125 pixels.' ), widget=ImageInput, ) # image type fields (there are a lot of them!) title = forms.CharField( max_length=255, required=False, label='Title', ) title.half = True creator = forms.CharField( max_length=255, required=False, help_text=help_text('rca.RcaImage', 'creator') + 'If this work was a collaboration with others, list them here after your own name in brackets.', ) creator.half = True year = forms.CharField( max_length=255, required=False, help_text=help_text('rca.RcaImage', 'year'), ) year.half = True medium = forms.CharField( max_length=255, required=False, help_text=help_text('rca.RcaImage', 'medium', default='e.g. Bronze, copper wire and plaster'), ) medium.half = True dimensions = forms.CharField( max_length=255, required=False, help_text=help_text('rca.RcaImage', 'dimensions', default='e.g. 100 cm x 145 cm'), ) dimensions.half = True photographer = forms.CharField( max_length=255, required=False, help_text=help_text('rca.RcaImage', 'photographer'), ) photographer.half = True embedly_url = forms.URLField( label='Vimeo URL', required=False, help_text= 'Video content must first be uploaded to a Vimeo account. Then simply cut and paste the Vimeo URL in full, e.g. http://vimeo.com/117377525', ) poster_image_id = forms.IntegerField( label='Poster image', required=False, help_text= 'Add a still image as a placeholder for your video when it is not playing.', widget=ImageInput, ) def clean_image_id(self): if self.cleaned_data.get( 'item_type' ) == 'image' and not self.cleaned_data.get('image_id'): raise forms.ValidationError('This field is required.') else: return self.cleaned_data.get('image_id') def clean_title(self): if self.cleaned_data.get( 'item_type') == 'image' and self.cleaned_data.get( 'image_id') and not self.cleaned_data.get('title'): raise forms.ValidationError('This field is required.') else: return self.cleaned_data.get('title', '') def clean_embedly_url(self): if self.cleaned_data.get( 'item_type' ) == 'video' and not self.cleaned_data.get('embedly_url'): raise forms.ValidationError('This field is required.') else: return self.cleaned_data.get('embedly_url')
class ExperienceForm(forms.Form): experience = forms.CharField( max_length=255, required=False, help_text=help_text('rca.NewStudentPageExperience', 'experience', default="Please include job title, company name, city and year(s), separated by commas"), ) ExperiencesFormset = make_formset(ExperienceForm, 'Experience', u'Relevant professional experience. Include job title, company name, city and year(s), separated by commas') class AwardsForm(forms.Form): #saves to NewStudentPageAward award = forms.CharField( max_length=255, required=False, help_text=help_text('rca.NewStudentPageAward', 'award', default="Please include prize, award title and year, separated by commas"), ) AwardsFormset = make_formset(AwardsForm, 'Awards', help_text('rca.NewStudentPageAward', 'award', default="Please include prize, award title and year, separated by commas")) class PublicationsForm(forms.Form): #saves to NewStudentPagePublication name = forms.CharField( max_length=255, required=False, help_text=help_text('rca.NewStudentPagePublication', 'name', default="Please include author (if not you), title of article, title of publication, issue number, year, pages, separated by commas"), ) PublicationsFormset = make_formset(PublicationsForm, 'Publications', u'Include author (if not you), article title, journal title, issue number, year, pages, separated by commas') class ConferencesForm(forms.Form): #saves to NewStudentPageConference name = forms.CharField( max_length=255, required=False,