]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/content/content_val.py
a7ba5827c43b2e0ced9678c3be8a7b2c0dee05b2
[sommitrealweird.git] / sommitrealweird / content / content_val.py
1 from django.core import validators
2
3 def is_unique_name(slug, all_data):
4     from content.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.object.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.object.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