diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py index 6aefe163..927b2ea4 100644 --- a/applications/admin/controllers/default.py +++ b/applications/admin/controllers/default.py @@ -11,9 +11,11 @@ import re from gluon.admin import * from gluon.fileutils import abspath, read_file, write_file from gluon.utils import web2py_uuid +from gluon.tools import Config from glob import glob import shutil import platform + try: import git if git.__version__ < '0.3.1': @@ -559,6 +561,10 @@ def edit(): """ File edit handler """ # Load json only if it is ajax edited... app = get_app(request.vars.app) + app_path = apath(app, r=request) + editor_defaults={'theme':'web2py'} + config = Config(os.path.join(app_path, 'settings.cfg'), section='editor', default_values=editor_defaults) + preferences = config.read() if not(request.ajax): # return the scaffolding, the rest will be through ajax requests @@ -572,7 +578,21 @@ def edit(): for key in editarea_preferences: if key in globals(): editarea_preferences[key] = globals()[key] - return response.render ('default/edit.html', dict(app=request.args[0], editarea_preferences=editarea_preferences)) + return response.render ('default/edit.html', dict(app=request.args[0], editor_settings=preferences, editarea_preferences=editarea_preferences)) + + # show settings tab and save prefernces + if 'settings' in request.vars: + if request.post_vars: #save new preferences + if config.save(request.post_vars.items()): + response.headers["web2py-component-flash"] = T('Preferences saved correctly') + else: + response.headers["web2py-component-flash"] = T('Preferences saved on session only') + response.headers["web2py-component-command"] = "update_theme('%s'); jQuery('a[href=#editor_settings] button.close').click();" % config.read()['theme'] + return + else: + details = {'filename':'settings', 'id':'editor_settings', 'force': False} + details['plain_html'] = response.render('default/editor_settings.html', {'editor_settings':preferences}) + return response.json(details) """ File edit handler """ # Load json only if it is ajax edited... diff --git a/applications/admin/static/css/typeahead.js-bootstrap.css b/applications/admin/static/css/typeahead.js-bootstrap.css index 630ee5c5..f9e5c71b 100644 --- a/applications/admin/static/css/typeahead.js-bootstrap.css +++ b/applications/admin/static/css/typeahead.js-bootstrap.css @@ -1,3 +1,7 @@ +.twitter-typeahead { + width: 100%; +} + .twitter-typeahead .tt-query, .twitter-typeahead .tt-hint { margin-bottom: 0px; diff --git a/applications/admin/views/default/edit.html b/applications/admin/views/default/edit.html index 3edaeca0..35ff2865 100644 --- a/applications/admin/views/default/edit.html +++ b/applications/admin/views/default/edit.html @@ -16,7 +16,7 @@ }} {{cm=URL('static','codemirror')}} - + @@ -42,7 +42,7 @@ diff --git a/gluon/tools.py b/gluon/tools.py index 4f0eba7a..ee5b91d2 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -22,6 +22,7 @@ import urllib import urllib2 import Cookie import cStringIO +import ConfigParser from email import MIMEBase, MIMEMultipart, MIMEText, Encoders, Header, message_from_string, Charset from gluon.contenttype import contenttype @@ -5852,6 +5853,37 @@ class Wiki(object): request.post_vars.render = None return render(request.post_vars) +class Config(object): + def __init__( + self, + filename, + section, + default_values={} + ): + self.config = ConfigParser.ConfigParser(default_values) + self.config.read(filename) + if not self.config.has_section(section): + self.config.add_section(section) + self.section = section + self.filename = filename + + def read(self): + if not( isinstance(current.session['settings_%s' % self.section], dict) ): + settings = dict(self.config.items(self.section)) + else: + settings = current.session['settings_%s' % self.section] + return settings + + def save(self, options): + for option, value in options: + self.config.set(self.section, option, value) + try: + self.config.write(open(self.filename, 'w')) + result = True + except: + current.session['settings_%s' % self.section] = dict(self.config.items(self.section)) + result = False + return result if __name__ == '__main__': import doctest