def clean(self): super(NewsAndEventsForm, self).clean() # create the short_title automatically if necessary if not self.cleaned_data["short_title"] and self.cleaned_data.get("title"): if len(self.cleaned_data["title"]) > 70: raise forms.ValidationError("Please provide a short (less than 70 characters) version of the Title for the Short title field.") else: self.cleaned_data["short_title"] = self.cleaned_data["title"] # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link(self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("title"), # link title self.cleaned_data.get("summary"), # link description ) # misc checks if not self.cleaned_data["external_url"]: if not self.cleaned_data["hosted_by"]: raise forms.ValidationError("A Host is required except for items on external websites - please provide either a Host or an External URL") # must have body or url in order to be published if not self.instance and self.instance.body.cmsplugin_set.all(): # if not self.cleaned_data["body"]: message = u"This will not be published until either an external URL or Plugin has been added. Perhaps you ought to do that now." messages.add_message(self.request, messages.WARNING, message)
def clean(self): # create the short_title automatically if necessary if not self.cleaned_data["short_title"] and self.cleaned_data.get("title"): if len(self.cleaned_data["title"]) > 70: raise forms.ValidationError("Please provide a short (less than 70 characters) version of the Title for the Short title field.") else: self.cleaned_data["short_title"] = self.cleaned_data["title"] # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link(self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("title"), # link title self.cleaned_data.get("summary"), # link description ) # misc checks if not self.cleaned_data["external_url"]: if not self.cleaned_data["hosted_by"]: raise forms.ValidationError("A Host is required except for items on external websites - please provide either a Host or an External URL") # must have body or url in order to be published if not self.instance and self.instance.body.cmsplugin_set.all(): # if not self.cleaned_data["body"]: message = u"This will not be published until either an external URL or Plugin has been added. Perhaps you ought to do that now." messages.add_message(self.request, messages.WARNING, message)
def clean(self): # create the short_title automatically if necessary if not self.cleaned_data["short_title"] and self.cleaned_data.get("title"): if len(self.cleaned_data["title"]) > 70: raise forms.ValidationError("Please provide a short (less than 70 characters) version of the Title for the Short title field.") else: self.cleaned_data["short_title"] = self.cleaned_data["title"] # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link(self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("title"), # link title self.cleaned_data.get("summary"), # link description ) # misc checks if not self.cleaned_data["external_url"]: if not self.cleaned_data["hosted_by"]: message = "This vacancy is not Hosted by and Entity and has no External URL. Are you sure you want to do that?" messages.add_message(self.request, messages.WARNING, message) # must have content or url in order to be published # not currently working, because self.cleaned_data["body"] = None # if not self.cleaned_data["body"]: # message = "This will not be published until either an external URL or Plugin has been added. Perhaps you ought to do that now." # messages.add_message(self.request, messages.WARNING, message) return self.cleaned_data
def clean(self): super(EntityForm, self).clean() if self.cleaned_data["website"]: try: # does an instance exist in the database with the same website? entity = models.Entity.objects.get( website=self.cleaned_data["website"]) except: # nothing matched, so we can safely go ahead with this one pass else: # one existed already - if it's this one that's OK if not self.instance.pk == entity.pk: raise forms.ValidationError( 'Another entity (%s) already has the same home page (%s).' % (entity, self.cleaned_data["website"])) # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link( self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("name"), # link title "", # link description ) if not self.cleaned_data["website"] and not self.cleaned_data[ "external_url"]: message = "This entity has neither a home page nor an External URL. Are you sure you want to do that?" messages.add_message(self.request, messages.WARNING, message) if not self.cleaned_data["short_name"]: self.cleaned_data["short_name"] = self.cleaned_data["name"] return self.cleaned_data
def clean(self): super(EntityForm, self).clean() if self.cleaned_data["website"]: try: # does an instance exist in the database with the same website? entity = models.Entity.objects.get(website=self.cleaned_data["website"]) except: # nothing matched, so we can safely go ahead with this one pass else: # one existed already - if it's this one that's OK if not self.instance.pk == entity.pk: raise forms.ValidationError('Another entity (%s) already has the same home page (%s).' % (entity, self.cleaned_data["website"])) # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link(self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("name"), # link title "", # link description ) if not self.cleaned_data["website"] and not self.cleaned_data["external_url"]: message = "This entity has neither a home page nor an External URL. Are you sure you want to do that?" messages.add_message(self.request, messages.WARNING, message) if not self.cleaned_data["short_name"]: self.cleaned_data["short_name"] = self.cleaned_data["name"] return self.cleaned_data
def clean(self): super(VacancyStudentshipForm, self).clean() # create the short_title automatically if necessary if not self.cleaned_data["short_title"] and self.cleaned_data.get("title"): if len(self.cleaned_data["title"]) > 70: raise forms.ValidationError("Please provide a short (less than 70 characters) version of the Title for the Short title field.") else: self.cleaned_data["short_title"] = self.cleaned_data["title"] # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link(self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("title"), # link title self.cleaned_data.get("summary"), # link description ) # misc checks if not self.cleaned_data["external_url"]: if not self.cleaned_data["hosted_by"]: message = "This vacancy is not Hosted by and Entity and has no External URL. Are you sure you want to do that?" messages.add_message(self.request, messages.WARNING, message) # must have content or url in order to be published # not currently working, because self.cleaned_data["body"] = None # if not self.cleaned_data["body"]: # message = "This will not be published until either an external URL or Plugin has been added. Perhaps you ought to do that now." # messages.add_message(self.request, messages.WARNING, message) return self.cleaned_data
def clean(self): # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link(self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("name"), # link title "", # link description ) if not self.cleaned_data["website"] and not self.cleaned_data["external_url"]: message = "This entity has neither a home page nor an External URL. Are you sure you want to do that?" messages.add_message(self.request, messages.WARNING, message) if not self.cleaned_data["short_name"]: self.cleaned_data["short_name"] = self.cleaned_data["name"] return self.cleaned_data
def clean(self): # set the title title = self.cleaned_data["title"] or "" link_title = u" ".join(name_part for name_part in [unicode(title), self.cleaned_data["given_name"], self.cleaned_data["surname"]] if name_part) # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link(self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("link_title"), # link title "", # link description ) return self.cleaned_data
def clean(self): super(PersonForm, self).clean() # set the title title = self.cleaned_data["title"] or "" link_title = u" ".join(name_part for name_part in [ unicode(title), self.cleaned_data["given_name"], self.cleaned_data["surname"] ] if name_part) # check ExternalLink-related issues self.cleaned_data["external_url"] = get_or_create_external_link( self.request, self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete self.cleaned_data.get("link_title"), # link title "", # link description ) return self.cleaned_data