146 from django.utils.safestring import mark_safe |
146 from django.utils.safestring import mark_safe |
147 |
147 |
148 class SettingsForm(forms.Form): |
148 class SettingsForm(forms.Form): |
149 workspace_name = forms.CharField(label=ugettext_lazy("Workspace name"), |
149 workspace_name = forms.CharField(label=ugettext_lazy("Workspace name"), |
150 widget=forms.TextInput, |
150 widget=forms.TextInput, |
151 required=True, |
151 required=False, |
152 ) |
152 ) |
153 |
153 |
154 workspace_tagline = forms.CharField(label=ugettext_lazy("Workspace tagline"), |
154 workspace_tagline = forms.CharField(label=ugettext_lazy("Workspace tagline"), |
155 widget=forms.TextInput, |
155 widget=forms.TextInput, |
156 required=False, |
156 required=False, |
157 ) |
157 ) |
|
158 |
|
159 workspace_logo_file = forms.FileField(label=ugettext_lazy("Workspace logo"),required=False) |
158 |
160 |
159 workspace_registration = forms.BooleanField(label=ugettext_lazy("Workspace registration"), |
161 workspace_registration = forms.BooleanField(label=ugettext_lazy("Workspace registration"), |
160 help_text=ugettext_lazy("Can users register themselves into the workspace? (if not, only invitations by managers can create new users)"), |
162 help_text=ugettext_lazy("Can users register themselves into the workspace? (if not, only invitations by managers can create new users)"), |
161 required=False, |
163 required=False, |
162 ) |
164 ) |
169 workspace_role_model = forms.ChoiceField(label=ugettext_lazy("Role model"), |
171 workspace_role_model = forms.ChoiceField(label=ugettext_lazy("Role model"), |
170 help_text=(ugettext_lazy("Change the roles available in the workspace")), |
172 help_text=(ugettext_lazy("Change the roles available in the workspace")), |
171 choices=role_models_choices, |
173 choices=role_models_choices, |
172 required=False, |
174 required=False, |
173 ) |
175 ) |
|
176 |
|
177 |
174 # fields to save in the Configuration objects |
178 # fields to save in the Configuration objects |
175 conf_fields = ['workspace_name', 'workspace_tagline', 'workspace_registration', 'workspace_registration_moderation', 'workspace_role_model'] |
179 conf_fields = ['workspace_name', 'workspace_tagline', 'workspace_registration', 'workspace_registration_moderation', 'workspace_role_model'] |
176 |
180 |
177 def __init__(self, data=None, initial=None): |
181 def __init__(self, data=None, initial=None): |
178 forms.Form.__init__(self, data=data, initial=initial) |
182 forms.Form.__init__(self, data=data, initial=initial) |
183 def save(self): |
187 def save(self): |
184 for field in self.fields: |
188 for field in self.fields: |
185 if field in self.conf_fields: |
189 if field in self.conf_fields: |
186 val = self.cleaned_data[field] |
190 val = self.cleaned_data[field] |
187 Configuration.objects.set_key(field, val) |
191 Configuration.objects.set_key(field, val) |
|
192 #handle_uploaded_file() |
|
193 def save_file(self, logo_file): |
|
194 attach = Attachment.objects.create_attachment(filename='wp_logo', data=logo_file.read(), text_version=None) |
|
195 Configuration.objects.set_key('workspace_logo_file_key', attach.key) |
|
196 print attach.key |
188 |
197 |
189 @has_global_perm('can_manage_workspace') |
198 @has_global_perm('can_manage_workspace') |
190 def settingss(request): |
199 def settingss(request): |
191 if request.method == 'POST': |
200 if request.method == 'POST': |
192 form = SettingsForm(data=request.POST) |
201 if 'delete_logo' in request.POST: |
193 if form.is_valid() : |
202 Configuration.objects.del_key('workspace_logo_file_key') |
194 form.save() |
|
195 display_message(request, _(u'Settings saved')) |
203 display_message(request, _(u'Settings saved')) |
196 return HttpResponseRedirect(reverse('index')) |
204 return HttpResponseRedirect(reverse('index')) |
|
205 else: |
|
206 form = SettingsForm(data=request.POST) |
|
207 if form.is_valid() : |
|
208 form.save() |
|
209 logo_file = request.FILES.get('workspace_logo_file',None) |
|
210 if logo_file: |
|
211 form.save_file(logo_file) |
|
212 display_message(request, _(u'Settings saved')) |
|
213 return HttpResponseRedirect(reverse('index')) |
197 else: |
214 else: |
198 form = SettingsForm() |
215 form = SettingsForm() |
199 |
216 |
200 return render_to_response('site/settings.html', {'form' : form, 'help_links' : {'workspace_role_model':'role_model'}}, context_instance=RequestContext(request)) |
217 return render_to_response('site/settings.html', {'form' : form, 'help_links' : {'workspace_role_model':'role_model'}}, context_instance=RequestContext(request)) |
201 |
218 |