Commits

Zhang Huangbin committed 2afd257

Code cleanup.

Comments (0)

Files changed (9)

+= 0.2.0 =
+
 = 0.1.1 =
     * Add run-time language switch support.
     * Add enabledService={pop3secured,imapsecured,managesievesecured}.
 
 web.iredconfig['rootdir'] = rootdir
 
-# init urls
+backend = cfg.general.get('backend', 'ldap')
+skin = cfg.general.get('skin', 'default')
+
+# Import urls from backend.
 if cfg.general.get('backend') == 'ldap':
-    from controllers.ldap.urls import urls
+    from controllers.ldap.urls import urls as backendUrls
 else:
-    from controllers.mysql.urls import urls
+    from controllers.mysql.urls import urls as backendUrls
+
+# Merge urls.
+urls = tuple(list(backendUrls))
 
 # init app
 app = web.application(urls, globals(), autoreload=True)
 web.config._session = session
 
 # Use JinJa2 template.
-tmpldir = rootdir + '/templates/' + \
-        cfg.general.get('skin', 'default') +  '/' + \
-        cfg.general.get('backend')
+ldap_tmpldir = rootdir + 'templates/' + skin + '/' + backend
 
 # Object used to stored all translations.
 cfg.allTranslations = web.storage()
 import iredutils
 
 # Load i18n hook.
-app.add_processor(web.loadhook(iredutils.i18n_loadhook))
+app.add_processor(web.loadhook(iredutils.hook_i18n))
 
 # init render
 render = render_jinja(
-        tmpldir,                           # template dir.
-        encoding = 'utf-8',                 # Encoding.
+        ldap_tmpldir,           # template dir.
+        encoding = 'utf-8',     # Encoding.
         )
 
-# Add/override global functions.
-render._lookup.globals.update(
-        skin=cfg.general.get('skin', 'default'), # Used for static files.
-        session=web.config._session,  # Used for session.
-        ctx=web.ctx,                  # Used to get 'homepath'.
-        _=iredutils.ired_gettext,     # Override _() which provided by Jinja2.
-        #gettext=iredutils.ired_gettext,
-        #ngettext=iredutils.ired_gettext,
-        )
+# Custom Jinja2 global functions.
+render_globals = {
+        'skin': skin, # Used for static files.
+        'session': web.config._session,  # Used for session.
+        'ctx': web.ctx,                  # Used to get 'homepath'.
+        '_': iredutils.ired_gettext,     # Override _() which provided by Jinja2.
+        #'gettext': iredutils.ired_gettext,
+        #'ngettext': iredutils.ired_gettext,
+        }
 
-# Add/override custom Jinja filters.
-render._lookup.filters.update(
-        filesizeformat=iredutils.filesizeformat,
-        )
+# Custom Jinja filters.
+render_filters = {
+        'filesizeformat': iredutils.filesizeformat,
+        }
+
+# Add/Override Jinja2 global functions, filters.
+render._lookup.globals.update(render_globals)
+render._lookup.filters.update(render_filters)
+web.render = render
 
 def notfound():
     return web.notfound(render.error404())
 
 app.notfound = notfound
-web.render = render
         return "%d MB" % (bytes / (base * base))
     return "%.1f GB" % (bytes / (base * base * base))
 
-def i18n_loadhook():
+def hook_i18n():
     web.ctx.lang = web.input(lang=None, _method="GET").lang or session.get('lang')
 
 def get_translations(lang='en_US'):

static/default/css/iredadmin.css

 }
 */
 
+.brd .add {
+    background-image: url(../images/add.png);
+    background-repeat: no-repeat;
+    background-position: left center;
+    padding-left: 1.5em;
+}
+
 .brd #footer {
     text-align: center;
     margin-top: 20px;

templates/default/ldap/admins.html

 {% endblock id_welcome %}
 
 {% block id_visit_links %}
-<span><a href="{{ctx.homepath}}/create/admin">{{ _('Create new mail admin') }}</a></span>
+<span><a href="{{ctx.homepath}}/create/admin" class="add" >{{ _('Create new mail admin') }}</a></span>
 {% endblock id_visit_links %}
 
 {% block main %}

templates/default/ldap/dashboard.html

     <div class="ct-group">
         <div class="ct-set group-item1">
             <div class="ct-box">
-                <h3 class="ct-legend hn"><span>{{ _('Create new') }}</span></h3>
+                <h3 class="ct-legend hn"><span class="add" >{{ _('Create new') }}</span></h3>
                 <p>
                     {% if session.get('domainGlobalAdmin') == 'yes' %}
                     <span><a href="{{ctx.homepath}}/create/domain">{{ _('Mail Domain') }}</a></span>&nbsp;

templates/default/ldap/domains.html

 
 {% block id_visit_links %}
 {% if session.get('domainGlobalAdmin') == 'yes' %}
-<span><a href="{{ctx.homepath}}/create/domain">{{ _('Create new mail domain') }}</a></span>
+<span><a href="{{ctx.homepath}}/create/domain" class="add" >{{ _('Create new mail domain') }}</a></span>
 {% endif %}
 {% endblock id_visit_links %}
 

templates/default/ldap/error404.html

 {% block main %}
 <div class="ct-box info-box">
     <div class="error">
-        <span class="important"><strong>{{ _('Error:') }}</strong> {{ _('Page not found.') }} ({{ctx.fullpath}})</span>
+        <span class="important"><strong>{{ _('Error:') }}</strong> {{ _('Page not found.') }} ({{ctx.fullpath}}) {% if ctx.env.get('HTTP_REFERER') is not sameas none %}<a href="{{ ctx.env.get('HTTP_REFERER') }}">{{ _('Go back.') }}</a>{% endif %}</span>
     </div>
 </div>
 {% endblock main %}

templates/default/ldap/users.html

 {% endblock id_welcome %}
 
 {% block id_visit_links %}
-<span><a href="{{ctx.homepath}}/create/user/{{cur_domain}}">{{ _('Create new mail user') }}</a></span>
+<span><a href="{{ctx.homepath}}/create/user/{{cur_domain}}" class="add" >{{ _('Create new mail user') }}</a></span>
 {% if cur_domain is defined %}
 <span><a href="{{ctx.homepath}}/profile/domain/general/{{cur_domain}}">{{ _('View/Update domain profile') }}</a></span>
 {% endif %}