X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/a2883504e45a556b06e76f023395e879e01ae03c..56b2cdf3569443cf4504fe085de9db0466dcd09f:/sommitrealweird/bpcms/content_val.py diff --git a/sommitrealweird/bpcms/content_val.py b/sommitrealweird/bpcms/content_val.py new file mode 100644 index 0000000..0e62150 --- /dev/null +++ b/sommitrealweird/bpcms/content_val.py @@ -0,0 +1,17 @@ +from django.core import validators + +def is_unique_name(slug, all_data): + from bpcms.models import Document, Folder + if all_data["folder"] != '' and all_data["id"] == '': + folder_id = int(all_data["folder"]) + try: + doc = Document.objects.get(folder__exact=folder_id, slug__exact=slug) + raise validators.ValidationError(u'There is already a document with that name') + except: + pass + + try: + folder = Folder.objects.get(slug__exact=slug, parent__exact=folder_id) + raise validators.ValidationError(u'There is already a folder with that name') + except: + pass