add design customisation option
authorraph
Fri, 12 Feb 2010 11:48:23 +0100
changeset 164 cc217bd00476
parent 163 c3329d4d6ef5
child 165 f6509416da19
add design customisation option
src/cm/templates/site/layout/base.html
src/cm/templates/site/settings.html
src/cm/templates/site/settings_design.html
src/cm/urls.py
src/cm/views/site.py
--- a/src/cm/templates/site/layout/base.html	Thu Feb 11 19:48:16 2010 +0100
+++ b/src/cm/templates/site/layout/base.html	Fri Feb 12 11:48:23 2010 +0100
@@ -44,6 +44,12 @@
       -->
       </script>
   
+    {% if CONF.workspace_code %}
+    	{% autoescape off %}
+    	{{ CONF.workspace_code }}
+    	{% endautoescape %}
+    {% endif %}
+    	
     {% block head_base %}
     {% endblock %}
     {% block head %}
--- a/src/cm/templates/site/settings.html	Thu Feb 11 19:48:16 2010 +0100
+++ b/src/cm/templates/site/settings.html	Fri Feb 12 11:48:23 2010 +0100
@@ -17,12 +17,16 @@
 
 <div id="settings" class="tab-meta">   
 
+<ul class="sub_list">
+    <li class="active_sub">{% blocktrans %}General{% endblocktrans %}</li>
+    <li> / </li>
+    <li><a href="{% url settings-design %}">{% blocktrans %}Appearance{% endblocktrans %}</a></li>
+</ul>
+
 {% endblock %}
 
 {% block buttons %}
     <input name="cancel" type="button" id="cancel_button" value="{% blocktrans %}Cancel{% endblocktrans %}"/>
-    &nbsp;|&nbsp; 
-    <input name="delete_logo" type="submit" id="delete_logo_button" value="{% blocktrans %}Delete logo{% endblocktrans %}"/>
     <script type="text/javascript">
     <!--
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cm/templates/site/settings_design.html	Fri Feb 12 11:48:23 2010 +0100
@@ -0,0 +1,58 @@
+{% extends "site/layout/base_workspace_form.html" %}
+{% load i18n %}
+{% load com %}
+
+{% block title %}{% blocktrans %}Settings{% endblocktrans %}{% endblock %}
+
+{% block head %}
+{% endblock %}
+
+{% block pre_form %}
+
+<script type="text/javascript">
+<!--
+tb_conf['current_tab'] = 'settings';
+-->
+</script>
+
+<div id="settings" class="tab-meta">   
+
+<ul class="sub_list">
+    <li><a href="{% url settings %}">{% blocktrans %}General{% endblocktrans %}</a></li>
+    <li> / </li>
+    <li class="active_sub">{% blocktrans %}Design{% endblocktrans %}</li>
+</ul>
+
+{% endblock %}
+
+{% block buttons %}
+    <input name="cancel" type="button" id="cancel_button" value="{% blocktrans %}Cancel{% endblocktrans %}"/>
+    &nbsp;|&nbsp; 
+    <input name="delete_logo" type="submit" id="delete_logo_button" value="{% blocktrans %}Delete logo{% endblocktrans %}"/>
+    <script type="text/javascript">
+    <!--
+
+    
+    $(document).ready(function(){
+        old_state = $("#id_workspace_role_model").attr('value');
+        
+        $("#id_workspace_role_model").change(function (e) { 
+            question = "{% blocktrans %}Are you sure you want to change the role model? All roles (except managers) will be resetted!{% endblocktrans %}";
+            if (!confirm(question)) {
+            	$("#id_workspace_role_model").attr('value',old_state);
+            }
+          });
+        
+        $("#cancel_button").click(function (e) { 
+            window.location = "{% url index %}";
+            e.stopPropagation(); 
+          });                
+    }) ;
+    -->
+    </script>
+{% endblock %}
+
+{% block post_form %}
+</div>
+{% endblock %}
+
--- a/src/cm/urls.py	Thu Feb 11 19:48:16 2010 +0100
+++ b/src/cm/urls.py	Fri Feb 12 11:48:23 2010 +0100
@@ -21,6 +21,7 @@
      url(r'^$', dashboard, name="index"),
      url(r'^text/$', text_list, name="text"),
      url(r'^settings/$', settingss, name="settings"),
+     url(r'^settings/design/$', settings_design, name="settings-design"),
 
      # system pages
      url(r'^i18n/setlang/(?P<lang_code>\w+)/$', i18n.set_language, name="setlang"),
--- a/src/cm/views/site.py	Thu Feb 11 19:48:16 2010 +0100
+++ b/src/cm/views/site.py	Fri Feb 12 11:48:23 2010 +0100
@@ -145,7 +145,22 @@
 from cm.role_models import role_models_choices
 from django.utils.safestring import mark_safe
 
-class SettingsForm(forms.Form):
+class BaseSettingsForm(forms.Form):
+    def __init__(self, data=None, initial=None):
+        forms.Form.__init__(self, data=data, initial=initial)
+        for field in self.fields:
+            if field in self.conf_fields:
+                self.fields[field].initial = Configuration.objects.get_key(field)
+                
+                self.fields[field].initial = Configuration.objects.get_key(field)
+    
+    def save(self):
+        for field in self.fields:
+            if field in self.conf_fields:
+                val = self.cleaned_data[field]
+                Configuration.objects.set_key(field, val)
+                                    
+class SettingsForm(BaseSettingsForm):
     workspace_name = forms.CharField(label=ugettext_lazy("Workspace name"),
                                      widget=forms.TextInput,
                                      required=False,
@@ -156,8 +171,6 @@
                                         required=False,
                                         )
 
-    workspace_logo_file  = forms.FileField(label=ugettext_lazy("Workspace logo"),required=False)
-
     workspace_registration = forms.BooleanField(label=ugettext_lazy("Workspace registration"),
                                                 help_text=ugettext_lazy("Can users register themselves into the workspace? (if not, only invitations by managers can create new users)"),
                                                 required=False,
@@ -178,22 +191,7 @@
     # fields to save in the Configuration objects
     conf_fields = ['workspace_name', 'workspace_tagline', 'workspace_registration', 'workspace_registration_moderation', 'workspace_role_model']
 
-    def __init__(self, data=None, initial=None):
-        forms.Form.__init__(self, data=data, initial=initial)
-        for field in self.fields:
-            if field in self.conf_fields:
-                self.fields[field].initial = Configuration.objects.get_key(field)
-    
-    def save(self):
-        for field in self.fields:
-            if field in self.conf_fields:
-                val = self.cleaned_data[field]
-                Configuration.objects.set_key(field, val)
-        #handle_uploaded_file()
-    def save_file(self, logo_file):
-        attach = Attachment.objects.create_attachment(filename='wp_logo', data=logo_file.read(), text_version=None)
-        Configuration.objects.set_key('workspace_logo_file_key', attach.key)
-        
+
 @has_global_perm('can_manage_workspace')
 def settingss(request):
     if request.method == 'POST':
@@ -205,9 +203,6 @@
             form = SettingsForm(data=request.POST)
             if form.is_valid() :
                 form.save()
-                logo_file = request.FILES.get('workspace_logo_file',None)
-                if logo_file:
-                    form.save_file(logo_file)
                 display_message(request, _(u'Settings saved'))
                 return HttpResponseRedirect(reverse('index'))
     else:
@@ -215,6 +210,43 @@
     
     return render_to_response('site/settings.html', {'form' : form, 'help_links' : {'workspace_role_model':'role_model'}}, context_instance=RequestContext(request))
 
+class SettingsDesignForm(BaseSettingsForm):
+    workspace_logo_file  = forms.FileField(label=ugettext_lazy("Workspace logo"),required=False)
+    
+    workspace_code = forms.CharField(label=ugettext_lazy("Workspace html code"),
+                                     help_text=(ugettext_lazy("Add stylesheets etc. Warning: this code will be added to the workspace code, make sure you know what you're doing before adding something here.")),
+                                     widget=forms.Textarea,
+                                     required=False,
+                                     )
+
+    conf_fields = ['workspace_code']
+    
+    def save_file(self, logo_file):
+        attach = Attachment.objects.create_attachment(filename='wp_logo', data=logo_file.read(), text_version=None)
+        Configuration.objects.set_key('workspace_logo_file_key', attach.key)
+        
+    
+@has_global_perm('can_manage_workspace')
+def settings_design(request):
+    if request.method == 'POST':
+        if 'delete_logo' in request.POST:
+            Configuration.objects.del_key('workspace_logo_file_key')
+            display_message(request, _(u'Settings saved'))
+            return HttpResponseRedirect(reverse('index'))            
+        else:
+            form = SettingsDesignForm(data=request.POST)
+            if form.is_valid() :
+                form.save()
+                logo_file = request.FILES.get('workspace_logo_file',None)
+                if logo_file:
+                    form.save_file(logo_file)
+                display_message(request, _(u'Settings saved'))
+                return HttpResponseRedirect(reverse('index'))
+    else:
+        form = SettingsDesignForm()
+    
+    return render_to_response('site/settings_design.html', {'form' : form}, context_instance=RequestContext(request))
+    
 def help(request):
     return render_to_response('site/help.html', context_instance=RequestContext(request))