rename 'content' to 'bpcms'
[sommitrealweird.git] / sommitrealweird / bpcms / content_val.py
diff --git a/sommitrealweird/bpcms/content_val.py b/sommitrealweird/bpcms/content_val.py
new file mode 100644 (file)
index 0000000..0e62150
--- /dev/null
@@ -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