def clean_related_film(self): related = [] related_film_form_data = self.cleaned_data['related_film'] if isinstance(related_film_form_data, (list, tuple)): return related_film_form_data if len(related_film_form_data) ==0: self.cleaned_data['related_film'] == "" return self.cleaned_data['related_film'] else: for related_film in comma_split(related_film_form_data): related_permalink = slughifi(related_film) search_helper = Search_Helper() search_results = search_helper.search_film(title=related_film) best_results = list(search_results['best_results']) other_results = list(search_results['results']) films = best_results + other_results def match_film(film): localized_title = film.get_localized_title() return related_film in [film.title, localized_title, u"%s [%d]"%(film.title, film.release_year), u"%s [%d]"%(localized_title, film.release_year)] if films: matches = filter(match_film, films) if not matches or len(matches)>1: msg = [] if not matches: msg.append(_('Movie') + " " + related_film + " " + _('is not present in the database!')) msg.append(_('Maybe you were looking for these movies') + ": ") msg.extend(u"%s [%d]"%(unicode(f), f.release_year) for f in films) self._errors["related_film"] = ErrorList(msg) else: related.append(matches[0]) else: msg = _('Movie') +" "+ related_film +" "+ _('is not present in the database') self._errors["related_film"] = ErrorList([msg]) return related
def clean_related_film(self): related = [] related_film_form_data = self.cleaned_data['related_film'] if isinstance(related_film_form_data, (list, tuple)): return related_film_form_data if len(related_film_form_data) ==0: self.cleaned_data['related_film'] == "" return self.cleaned_data['related_film'] else: from re import compile year_pattern = compile( r'\[(\d+)\]$' ) for related_film in comma_split(related_film_form_data): films = search_film( year_pattern.sub( '', related_film ) ) def match_film(film): localized_title = film.get_localized_title() return related_film in [film.title, localized_title, u"%s [%d]"%(film.title, film.release_year), u"%s [%d]"%(localized_title, film.release_year)] if films: matches = filter(match_film, films) if not matches or len(matches)>1: msg = [] if not matches: msg.append(_('Movie') + " " + related_film + " " + _('is not present in the database!')) msg.append(_('Maybe you were looking for these movies') + ": ") msg.extend(u"%s [%d]"%(unicode(f), f.release_year) for f in films) self._errors["related_film"] = ErrorList(msg) else: related.append(matches[0]) else: msg = _('Movie') +" "+ related_film +" "+ _('is not present in the database') self._errors["related_film"] = ErrorList([msg]) return related