annotate gpp/weblinks/forms.py @ 216:fe900598f81c

Implement #85 - display who has posted from a post's IP address.
author Brian Neal <bgneal@gmail.com>
date Sun, 30 May 2010 20:51:41 +0000
parents b4305e18d3af
children 7e8d2dda99e3
rev   line source
gremmie@1 1 """
gremmie@1 2 Forms for the weblinks application.
gremmie@1 3 """
gremmie@1 4
gremmie@1 5 from django import forms
bgneal@204 6 from weblinks.models import PendingLink, Link
gremmie@1 7
gremmie@1 8 class SearchForm(forms.Form):
gremmie@1 9 '''Weblinks search form'''
gremmie@1 10 text = forms.CharField(max_length = 30)
gremmie@1 11
gremmie@1 12 def query(self):
gremmie@1 13 return self.cleaned_data['text']
gremmie@1 14
gremmie@1 15
gremmie@1 16 class AddLinkForm(forms.ModelForm):
gremmie@1 17 title = forms.CharField(widget = forms.TextInput(attrs = {'size': 52}))
gremmie@1 18 url = forms.CharField(widget = forms.TextInput(attrs = {'size': 52}))
gremmie@1 19
gremmie@1 20 def clean_url(self):
gremmie@1 21 new_url = self.cleaned_data['url']
gremmie@1 22 try:
gremmie@1 23 Link.objects.get(url__iexact = new_url)
gremmie@1 24 except Link.DoesNotExist:
gremmie@1 25 return new_url
gremmie@1 26 raise forms.ValidationError('That link already exists in our database.')
gremmie@1 27
gremmie@1 28 class Meta:
bgneal@204 29 model = PendingLink
bgneal@204 30 exclude = ('user', 'date_added')