~timrchavez/+junk/offspring-python2.7

« back to all changes in this revision

Viewing changes to lib/offspring/web/queuemanager/forms.py

  • Committer: Mike Heald
  • Date: 2012-04-13 14:46:08 UTC
  • mfrom: (126.2.5 offspring-dga)
  • Revision ID: mike.heald@canonical.com-20120413144608-vb7ikhks98ntfcdy
Merge of lp:~mike-powerthroughwords/offspring/offspring-django-group-access [r=Cody]

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
from django.forms import (
5
5
    ModelChoiceField,
 
6
    ModelMultipleChoiceField,
6
7
    ModelForm,
7
8
    Textarea,
8
9
    TextInput,
9
10
)
10
11
from django.forms import fields
11
12
 
 
13
from django_group_access.middleware import get_access_control_user
 
14
from django_group_access.models import AccessGroup
 
15
 
12
16
from offspring.web.queuemanager.models import (
13
17
    Project,
14
18
    ProjectGroup,
21
25
class ProjectBaseForm(ModelForm):
22
26
    status = fields.CharField(max_length=200,
23
27
        widget=fields.Select(choices=Project.STATUS_CHOICES), required=True)
 
28
    access_groups = ModelMultipleChoiceField(
 
29
        queryset=AccessGroup.objects.all(), required=False,
 
30
        help_text='Restrict access to these groups. Selecting no groups here '
 
31
        'will make this a public project.')
 
32
 
 
33
    def __init__(self, *args, **kwargs):
 
34
        super(ProjectBaseForm, self).__init__(*args, **kwargs)
 
35
        logged_in_user = get_access_control_user()
 
36
        if logged_in_user and not logged_in_user.is_superuser:
 
37
            self.fields['access_groups'].queryset = \
 
38
                self.fields['access_groups'].queryset.filter(
 
39
                    members=logged_in_user)
24
40
 
25
41
    class Meta:
26
42
        model = Project
33
49
            'config_url': TextInput(attrs={'size': 50}),
34
50
            'notes' : Textarea(attrs={'cols': 73, 'rows' : 4}),
35
51
        }
 
52
        exclude = ('owner',)
36
53
 
37
54
    def clean_name(self):
38
55
        return self.cleaned_data['name'].lower()
43
60
 
44
61
class CreateProjectForm(ProjectBaseForm):
45
62
    class Meta(ProjectBaseForm.Meta):
46
 
        exclude = ('priority', 'is_active', 'suite')
 
63
        exclude = ('priority', 'is_active', 'suite', 'owner')
47
64
        widgets = {
48
65
            'project_group' : SelectWithAddNew(),
49
66
            'launchpad_project' : SelectWithAddNew(),
53
70
 
54
71
class EditProjectForm(ProjectBaseForm):
55
72
    class Meta(ProjectBaseForm.Meta):
56
 
        exclude = ('name', 'priority', 'is_active')
 
73
        exclude = ('name', 'priority', 'is_active', 'owner')
57
74
        widgets = {
58
75
            'project_group' : SelectWithAddNew(),
59
76
            'launchpad_project' : SelectWithAddNew(),