]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/bpcms/content_val.py
update copyright years
[sommitrealweird.git] / sommitrealweird / bpcms / content_val.py
1 from django.core import validators
2 from django.conf import settings
3
4 def is_allowed_name(slug, all_data):
5     from bpcms.models import Document, Folder
6     folder = None
7     if all_data.has_key('folder'):
8         folder = all_data['folder']
9     elif all_data.has_key('parent'):
10         folder = all_data['parent']
11     if folder == u'':
12         folder = None
13     if folder == None:
14         # right - we're at the root.
15         if slug in settings.BPCMS_DISALLOWED_ROOT_DOC_NAMES \
16             or slug in ['cms-admin']:
17             raise validators.ValidationError(u'That slug is reserved')
18
19 def is_unique_name(slug, all_data):
20     from bpcms.models import Document, Folder
21     if all_data["folder"] != '' and all_data["id"] == '':
22         folder_id = int(all_data["folder"])
23         try:
24             doc = Document.objects.get(folder__exact=folder_id, slug__exact=slug)
25             raise validators.ValidationError(u'There is already a document with that name')
26         except:
27             pass
28
29         try:
30             folder = Folder.objects.get(slug__exact=slug, parent__exact=folder_id)
31             raise validators.ValidationError(u'There is already a folder with that name')
32         except:
33             pass