]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/bpcms/content_val.py
Small tweak to content block
[sommitrealweird.git] / sommitrealweird / bpcms / content_val.py
1 from django.core import validators
2
3 def is_unique_name(slug, all_data):
4     from bpcms.models import Document, Folder
5     if all_data["folder"] != '' and all_data["id"] == '':
6         folder_id = int(all_data["folder"])
7         try:
8             doc = Document.objects.get(folder__exact=folder_id, slug__exact=slug)
9             raise validators.ValidationError(u'There is already a document with that name')
10         except:
11             pass
12
13         try:
14             folder = Folder.objects.get(slug__exact=slug, parent__exact=folder_id)
15             raise validators.ValidationError(u'There is already a folder with that name')
16         except:
17             pass