~ubuntu-wanted-dev/ubuntu-wanted/wanted-django

« back to all changes in this revision

Viewing changes to uwanted/forms.py

  • Committer: Sense Hofstede
  • Date: 2010-01-30 16:21:50 UTC
  • Revision ID: sense@qense.nl-20100130162150-lmybw4zaza9xgdp7
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.forms import ModelForm, ValidationError
 
2
from wanted.uwanted.models import Project, Team, is_valid_launchpad_project, is_valid_launchpad_team
 
3
 
 
4
class ProjectForm(ModelForm):
 
5
    def clean(self):
 
6
        cleaned_data = self.cleaned_data
 
7
 
 
8
        if not is_valid_launchpad_project(cleaned_data['slug']):
 
9
            raise ("The project '%s' doesn't exist on Launchpad, please provide a valid Launchpad project." % cleaned_data['slug'])
 
10
            
 
11
        return cleaned_data
 
12
 
 
13
    class Meta:
 
14
        model = Project
 
15
 
 
16
class TeamForm(ModelForm):
 
17
    def clean(self):
 
18
        cleaned_data = self.cleaned_data
 
19
 
 
20
        if not is_valid_launchpad_team(cleaned_data['slug']):
 
21
            raise ValidationError("The team '%s' doesn't exist on Launchpad, please provide a valid Launchpad project." % cleaned_data['slug'])
 
22
        
 
23
        return cleaned_data
 
24
 
 
25
    class Meta:
 
26
        model = Team