Created
August 13, 2012 19:50
-
-
Save DamianMullins/3343596 to your computer and use it in GitHub Desktop.
Check that submitted URL is unique and allowed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_url(self): | |
INVALID_URLS = ('about', 'admin', 'register') | |
url = self.cleaned_data['url'] | |
try: | |
post = Post.objects.get(url=url) | |
except Post.DoesNotExist: | |
pass | |
else: | |
raise forms.ValidationError(u'%s already exists' % post ) | |
if url in INVALID_URLS: | |
raise forms.ValidationError(u'%s is not a valid url' % url ) | |
return url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment