summaryrefslogtreecommitdiff
path: root/coip/apps/name/forms.py
blob: d1fed9031ec61b87714eebaef3ca6c36c891d225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'''
Created on Jun 24, 2010

@author: leifj
'''
from django import forms
from coip.apps.name.models import Name, Attribute, NameLink
from django.forms import fields
from django.forms.widgets import HiddenInput, CheckboxSelectMultiple, TextInput
from form_utils.forms import BetterModelForm, BetterForm
    
class NameForm(forms.ModelForm):
    class Meta:
        model = Name
        
class AttributeForm(forms.ModelForm):
    class Meta:
        model = Attribute

class NameEditForm(BetterModelForm):
    error_css_class = 'error'
    required_css_class = 'required'
    class Meta:
        model = Name
        fields = ['short','description','format']
        widgets = {'description': forms.Textarea(attrs={'cols': 62, 'rows': 6}),
                   'short':  forms.TextInput(attrs={'size': 40})}
        fieldsets = [('step1', {'fields': ['short', 'description'],
                                'legend': 'Step 1: Describe your group',
                                'classes': ['step'], 
                                'description': 'Provide a short and (optionally) longer description of your group.'}),
                     ('step2', {'fields': ['format'],
                                'legend': 'Step 2: (optional): Advanced options',
                                'classes': ['step','submit_step'],
                                'description': 'Only change these settings if you know what you are doing.'})            
                    ]

class NewNameForm(BetterModelForm):
    error_css_class = 'error'
    required_css_class = 'required'
    value = forms.CharField(label="Name")
    #error_css_class = 'error'
    #required_css_class = 'required'
    class Meta:
        model = Name
        fields = ['value','short','description','type','format']
        widgets = {'description': forms.Textarea(attrs={'cols': 60, 'rows': 6}),
                   'short':  forms.TextInput(attrs={'size': 40})}
        fieldsets = [('step1', {'fields': ['value'], 
                                'legend': 'Step 1: Name your group',
                                'classes': ['step'],
                                'description': 'Provide a short identifier for your groups. Spaces are not allowed here.'}),
                     ('step2', {'fields': ['short', 'description'],
                                'legend': 'Step 2: Describe your group',
                                'classes': ['step'], 
                                'description': 'Provide a short and (optionally) longer description of your group.'}),
                     ('step3', {'fields': ['type','format'],
                                'legend': 'Step 3 (optional): Advanced options',
                                'classes': ['step','submit_step'],
                                'description': 'Only change these settings if you know what you are doing...'})]
        
class NameDeleteForm(BetterForm):
    recursive = fields.BooleanField(label="Also delete everything below this name?",required=False)
    class Meta:
        fieldsets = [('step1', {'fields': ['recursive'], 
                                'legend': 'Confirm deletion of your group',
                                'classes': ['step'],
                                'description': 'This is a destructive operation - there is no way to recover your group once it has been deleted!'})]
    
class NameLinkForm(forms.ModelForm):
    class Meta:
        model = NameLink
        fields = ['dst','type','data']

class NameLinkDeleteForm(forms.Form):
    confirm = fields.BooleanField(label="Confirm")
    
class PermissionForm(BetterForm):
    dst = fields.IntegerField(widget=HiddenInput)
    subject = fields.CharField(max_length=1024,label="Group",widget=TextInput(attrs={'size': 40}))
    permissions = fields.MultipleChoiceField(widget=CheckboxSelectMultiple,
                                             choices=[('r','read'),
                                                      ('w','write'),
                                                      ('l','list members and groups'),
                                                      ('i','manage members'),
                                                      ('d','delete'),
                                                      ('a','manage access')])
    class Meta:
        fieldsets = [('subject',{'fields': ['dst','subject'],
                               'legend': 'Step 1: Select a group',
                               'classes': ['step'],
                               'description': 'Start typing in the textfield to find the group you want.'}),
                     ('permission',{'fields': ['permissions'],
                                    'legend': 'Step 2: Set permissions',
                                    'classes': ['step','submit_step'],
                                    'description': 'Select the rights that members of the group should have.'})]