gremmie@1: """ gremmie@1: Forms for the weblinks application. gremmie@1: """ gremmie@1: gremmie@1: from django import forms gremmie@1: from weblinks.models import Link gremmie@1: gremmie@1: class SearchForm(forms.Form): gremmie@1: '''Weblinks search form''' gremmie@1: text = forms.CharField(max_length = 30) gremmie@1: gremmie@1: def query(self): gremmie@1: return self.cleaned_data['text'] gremmie@1: gremmie@1: gremmie@1: class AddLinkForm(forms.ModelForm): gremmie@1: title = forms.CharField(widget = forms.TextInput(attrs = {'size': 52})) gremmie@1: url = forms.CharField(widget = forms.TextInput(attrs = {'size': 52})) gremmie@1: gremmie@1: def clean_url(self): gremmie@1: new_url = self.cleaned_data['url'] gremmie@1: try: gremmie@1: Link.objects.get(url__iexact = new_url) gremmie@1: except Link.DoesNotExist: gremmie@1: return new_url gremmie@1: raise forms.ValidationError('That link already exists in our database.') gremmie@1: gremmie@1: class Meta: gremmie@1: model = Link gremmie@1: exclude = ('user', 'date_added', 'hits', 'is_public')