gremmie@1: """ gremmie@1: Forms for the weblinks application. gremmie@1: """ gremmie@1: gremmie@1: from django import forms bgneal@204: from weblinks.models import PendingLink, Link 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: bgneal@204: model = PendingLink bgneal@1148: fields = ['category', 'title', 'url', 'description']