def clean(self): NewsAndEventsForm.warnings = [] NewsAndEventsForm.info = [] # 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"] # if this item has an external url, we need to do all kinds of things with it self.info, self.warnings, self.cleaned_data["external_url"]= validate_and_get_messages( 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("subtitle"), # link description self.info, self.warnings, ) if not self.cleaned_data["hosted_by"] and not self.cleaned_data["external_url"]: raise forms.ValidationError("A Host is required except for items on external websites - please provide either a Host or an External URL") #must have content or url in order to be published if not (self.cleaned_data["external_url"] or self.cleaned_data["content"] or self.cleaned_data["body"]): # Note for Stefan: # to give the user warnings, we do this: self.warnings.append("This will not be published until either an external URL or Plugin has been added. Perhaps you ought to do that now.")
def clean(self): self.warnings = [] self.info = [] # if this person has an external url, we need to do all kinds of things with it title = self.cleaned_data["title"] or "" link_title = " ".join(name_part for name_part in [str(title), self.cleaned_data["given_name"], self.cleaned_data["surname"]] if name_part) self.info, self.warnings, self.cleaned_data["external_url"]= validate_and_get_messages( self.cleaned_data.get("input_url", None), # a manually entered url self.cleaned_data.get("external_url", None), # a url chosen with autocomplete link_title, # link title "", # link description self.info, self.warnings, ) return self.cleaned_data