Mercurial > public > sg101
comparison gpp/weblinks/forms.py @ 1:dbd703f7d63a
Initial import of sg101 stuff from private repository.
author | gremmie |
---|---|
date | Mon, 06 Apr 2009 02:43:12 +0000 |
parents | |
children | b4305e18d3af |
comparison
equal
deleted
inserted
replaced
0:900ba3c7b765 | 1:dbd703f7d63a |
---|---|
1 """ | |
2 Forms for the weblinks application. | |
3 """ | |
4 | |
5 from django import forms | |
6 from weblinks.models import Link | |
7 | |
8 class SearchForm(forms.Form): | |
9 '''Weblinks search form''' | |
10 text = forms.CharField(max_length = 30) | |
11 | |
12 def query(self): | |
13 return self.cleaned_data['text'] | |
14 | |
15 | |
16 class AddLinkForm(forms.ModelForm): | |
17 title = forms.CharField(widget = forms.TextInput(attrs = {'size': 52})) | |
18 url = forms.CharField(widget = forms.TextInput(attrs = {'size': 52})) | |
19 | |
20 def clean_url(self): | |
21 new_url = self.cleaned_data['url'] | |
22 try: | |
23 Link.objects.get(url__iexact = new_url) | |
24 except Link.DoesNotExist: | |
25 return new_url | |
26 raise forms.ValidationError('That link already exists in our database.') | |
27 | |
28 class Meta: | |
29 model = Link | |
30 exclude = ('user', 'date_added', 'hits', 'is_public') |