Trees | Indices | Help |
|
---|
|
1 #!/usr/bin/env python 2 # 3 # 4 # 5 # Copyright (c) 2008 University of Dundee. 6 # 7 # This program is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU Affero General Public License as 9 # published by the Free Software Foundation, either version 3 of the 10 # License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU Affero General Public License for more details. 16 # 17 # You should have received a copy of the GNU Affero General Public License 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # 20 # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 21 # 22 # Version: 1.0 23 # 24 25 from django.conf import settings 26 from django import forms 27 from django.forms import ModelForm 28 from django.forms.widgets import Textarea 29 from django.forms.widgets import HiddenInput 30 31 from omeroweb.custom_forms import NonASCIIForm 32 33 from custom_forms import ServerModelChoiceField, \ 34 GroupModelChoiceField, GroupModelMultipleChoiceField, \ 35 ExperimenterModelChoiceField, ExperimenterModelMultipleChoiceField, \ 36 DefaultGroupField, OmeNameField 37 from custom_widgets import DefaultGroupRadioSelect 38 39 40 ################################################################# 41 # Non-model Form 42446146 super(LoginForm, self).__init__(*args, **kwargs) 47 g = settings.SERVER_LIST.all() 48 try: 49 if len(g) > 1: 50 self.fields['server'] = ServerModelChoiceField(g, empty_label=u"---------") 51 else: 52 self.fields['server'] = ServerModelChoiceField(g, empty_label=None) 53 except: 54 self.fields['server'] = ServerModelChoiceField(g, empty_label=u"---------") 55 56 self.fields.keyOrder = ['server', 'username', 'password', 'ssl']57 58 username = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'size':22})) 59 password = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={'size':22, 'autocomplete': 'off'})) 60 ssl = forms.BooleanField(required=False, help_text='<img src="/appmedia/omeroweb/images/nuvola_encrypted_grey16.png" title="Real-time encrypted data transfer can be turned on by checking the box, but it will slow down the data access. Turning it off does not affect the connection to the server which is always secure." alt="SSL"')63 64 server = ServerModelChoiceField(settings.SERVER_LIST.all(), empty_label=u"---------") 65 username = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'size':28, 'autocomplete': 'off'})) 66 email = forms.EmailField(widget=forms.TextInput(attrs={'size':28, 'autocomplete': 'off'}))676911971 super(ExperimenterForm, self).__init__(*args, **kwargs) 72 self.name_check=name_check 73 self.email_check=email_check 74 75 try: 76 self.fields['default_group'] = DefaultGroupField(choices=kwargs['initial']['default'], widget=DefaultGroupRadioSelect(), required=True, label="Groups") 77 self.fields['other_groups'] = GroupModelMultipleChoiceField(queryset=kwargs['initial']['others'], initial=kwargs['initial']['others'], required=False, widget=forms.SelectMultiple(attrs={'size':10})) 78 except: 79 self.fields['default_group'] = forms.ChoiceField(choices=list(), widget=forms.RadioSelect(), required=True, label="Groups") 80 self.fields['other_groups'] = GroupModelMultipleChoiceField(queryset=list(), required=False, widget=forms.SelectMultiple(attrs={'size':10})) 81 82 self.fields['available_groups'] = GroupModelMultipleChoiceField(queryset=kwargs['initial']['available'], required=False, widget=forms.SelectMultiple(attrs={'size':10})) 83 84 if kwargs['initial'].has_key('with_password') and kwargs['initial']['with_password']: 85 self.fields['password'] = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={'size':30, 'autocomplete': 'off'})) 86 self.fields['confirmation'] = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={'size':30, 'autocomplete': 'off'})) 87 88 self.fields.keyOrder = ['omename', 'first_name', 'middle_name', 'last_name', 'email', 'institution', 'administrator', 'active', 'password', 'confirmation', 'default_group', 'other_groups', 'available_groups'] 89 else: 90 self.fields.keyOrder = ['omename', 'first_name', 'middle_name', 'last_name', 'email', 'institution', 'administrator', 'active', 'default_group', 'other_groups', 'available_groups']91 92 omename = OmeNameField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'}), label="Username") 93 first_name = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'})) 94 middle_name = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'}), required=False) 95 last_name = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'})) 96 email = forms.EmailField(widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'}), required=False) 97 institution = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'}), required=False) 98 administrator = forms.CharField(widget=forms.CheckboxInput(), required=False) 99 active = forms.CharField(widget=forms.CheckboxInput(), required=False) 100102 if self.cleaned_data.get('password') or self.cleaned_data.get('confirmation'): 103 if len(self.cleaned_data.get('password')) < 3: 104 raise forms.ValidationError('Password must be at least 3 letters long') 105 if self.cleaned_data.get('password') != self.cleaned_data.get('confirmation'): 106 raise forms.ValidationError('Passwords do not match') 107 else: 108 return self.cleaned_data.get('password')109111 if self.name_check: 112 raise forms.ValidationError('This username already exist.') 113 return self.cleaned_data.get('omename')114121 122 PERMISSION_CHOICES = ( 123 ('0', 'Private'), 124 ('1', 'Collaborative '), 125 #('2', 'Public ') 126 ) 127147129 super(GroupForm, self).__init__(*args, **kwargs) 130 self.name_check=name_check 131 try: 132 if kwargs['initial']['owners']: pass 133 self.fields['owners'] = ExperimenterModelMultipleChoiceField(queryset=kwargs['initial']['experimenters'], initial=kwargs['initial']['owner'], required=False) 134 except: 135 self.fields['owners'] = ExperimenterModelMultipleChoiceField(queryset=kwargs['initial']['experimenters'], required=False) 136 self.fields.keyOrder = ['name', 'description', 'owners', 'permissions', 'readonly']137 138 name = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'size':25, 'autocomplete': 'off'})) 139 description = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':25, 'autocomplete': 'off'}), required=False) 140 permissions = forms.ChoiceField(choices=PERMISSION_CHOICES, widget=forms.RadioSelect(), required=True, label="Permissions", help_text="<div class=\"error\">WARNING: Changing Permissions will change permissions of all objects in a group. This will take some time for large groups and could break the server.</div>") 141 readonly = forms.BooleanField(required=False, label="(read-only)") 142149 150 PERMISSION_CHOICES = ( 151 ('0', 'Private'), 152 ('1', 'Collaborative '), 153 #('2', 'Public ') 154 ) 155 156 permissions = forms.ChoiceField(choices=PERMISSION_CHOICES, widget=forms.RadioSelect(), required=True, label="Permissions", help_text="<div class=\"error\">WARNING: Changing Permissions will change permissions of all objects in a group. This will take some time for large groups and could break the server.</div>") 157 readonly = forms.BooleanField(required=False, label="(read-only)")158160182 183162 super(MyAccountForm, self).__init__(*args, **kwargs) 163 self.email_check=email_check 164 try: 165 if kwargs['initial']['default_group']: pass 166 self.fields['default_group'] = GroupModelChoiceField(queryset=kwargs['initial']['groups'], initial=kwargs['initial']['default_group'], empty_label=None) 167 except: 168 self.fields['default_group'] = GroupModelChoiceField(queryset=kwargs['initial']['groups'], empty_label=None) 169 self.fields.keyOrder = ['omename', 'first_name', 'middle_name', 'last_name', 'email', 'institution', 'default_group']170 171 omename = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'onfocus':'this.blur()', 'size':30, 'autocomplete': 'off'}), label="Username") 172 first_name = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'})) 173 middle_name = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'}), required=False) 174 last_name = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'})) 175 email = forms.EmailField(widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'}), required=False) 176 institution = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30, 'autocomplete': 'off'}), required=False) 177185191 192187 super(ContainedExperimentersForm, self).__init__(*args, **kwargs) 188 self.fields['members'] = ExperimenterModelMultipleChoiceField(queryset=kwargs['initial']['members'], required=False, widget=forms.SelectMultiple(attrs={'size':25})) 189 self.fields['available'] = ExperimenterModelMultipleChoiceField(queryset=kwargs['initial']['available'], required=False, widget=forms.SelectMultiple(attrs={'size':25})) 190 self.fields.keyOrder = ['members', 'available']194 195 photo = forms.FileField(required=False) 196205198 if self.cleaned_data.get('photo') is None: 199 raise forms.ValidationError('No image selected. Supported image formats (file extensions allowed): jpeg, jpg, gif, png. The maximum image size allowed is 200KB.') 200 if not self.cleaned_data.get('photo').content_type.startswith("image"): 201 raise forms.ValidationError('Supported image formats (file extensions allowed): jpeg, jpg, gif, png.') 202 if self.cleaned_data.get('photo').size > 204800: 203 raise forms.ValidationError('The maximum image size allowed is 200KB.') 204 return self.cleaned_data.get('photo')207 208 password = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={'size':30, 'autocomplete': 'off'}), label="New password") 209 confirmation = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={'size':30, 'autocomplete': 'off'}), label="Confirm new password") 210 old_password = forms.CharField(max_length=50, widget=forms.PasswordInput(attrs={'size':30, 'autocomplete': 'off'}), label="Your current password") 211220 224 225213 if self.cleaned_data.get('password') or self.cleaned_data.get('confirmation'): 214 if len(self.cleaned_data.get('password')) < 3: 215 raise forms.ValidationError('Password must be at least 3 letters long') 216 if self.cleaned_data.get('password') != self.cleaned_data.get('confirmation'): 217 raise forms.ValidationError('Passwords do not match') 218 else: 219 return self.cleaned_data.get('password')227240229 super(EnumerationEntries, self).__init__(*args, **kwargs) 230 for i,e in enumerate(entries): 231 try: 232 if kwargs['initial']['entries']: 233 self.fields[str(e.id)] = forms.CharField(max_length=250, initial=e.value, widget=forms.TextInput(attrs={'size':30}), label=i+1) 234 else: 235 self.fields[str(e.id)] = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30}), label=i+1) 236 except: 237 self.fields[str(e.id)] = forms.CharField(max_length=250, widget=forms.TextInput(attrs={'size':30}), label=i+1) 238 239 self.fields.keyOrder = [str(k) for k in self.fields.keys()]
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Jan 24 19:49:21 2012 | http://epydoc.sourceforge.net |