Mercurial > public > sg101
annotate gpp/weblinks/forms.py @ 12:f408971657b9
Changed the shoutbox: posts are now made by Ajax. The smiley farm is loaded only on demand. jQuery is now in the base template. May add scrolling later.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 15 Apr 2009 01:13:17 +0000 |
parents | dbd703f7d63a |
children | b4305e18d3af |
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 |
gremmie@1 | 6 from weblinks.models import 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: |
gremmie@1 | 29 model = Link |
gremmie@1 | 30 exclude = ('user', 'date_added', 'hits', 'is_public') |