def clean(self): if self._errors: return self.cleaned_data #raise forms.ValidationError() self.cleaned_data['name'] = name_from_title(self.cleaned_data['title']) self.cleaned_data['type_string'] = self.cleaned_data['create_iface'].split('Create')[1] cls = ContentType.objects.get(model=self.cleaned_data['type_string'].lower()).model_class() group = TgGroup.objects.get(id=self.cleaned_data['group']) try: obj = cls.objects.get(name=self.cleaned_data['name'], in_agent=group.get_ref(), stub=True) self._errors['title'] = _("There is already a %s in %s called %s. Please choose a different title.") %(self.cleaned_data['type_string'], group.display_name.capitalize(), self.cleaned_data['title']) except cls.DoesNotExist: pass return self.cleaned_data
if container.__class__.__name__ == 'User' : tags.append(container.username) tags.append(container.first_name) tags.append(container.last_name) user = container container = get_resources_group() if not container.has_member(user) : container.add_member(user) flag = True title = doc['title'] if len(title) > 80 : title = title[:80] #print "shortened %s" % title.encode('utf-8') name = name_from_title(title) pages = WikiPage.objects.filter(name=name) if not pages : page = create_page(container, user, tags, title=title, stub=False, license='not specified', content=doc['body'], in_agent=container.get_ref(), name=name, created_by=user) else : page = pages[0] related_dict[page.id] = (doc['uid'],doc['related']) if flag : container.remove_member(user) #print "made %s (%s) belonging to %s" % (page.title.encode('utf-8'), page.id, page.in_agent.obj)
def doc_name_from_title(title) : if len(title) > 80 : title = title[:80] return name_from_title(title)
def name_from_title(self): #if name changes (and this is not a stub) we should set up a permanent redirect from here self.name = name_from_title(self.title) return self.name
def doc_name_from_title(title): if len(title) > 80: title = title[:80] return name_from_title(title)