wip: replacing "/static/" occurences with something more flexible.

This commit is contained in:
tonio
2010-08-05 17:49:29 +02:00
parent 01fda22180
commit cc7da3f5d6
12 changed files with 72 additions and 57 deletions
+12 -12
View File
@@ -3,7 +3,7 @@ from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from modoboa import admin
from modoboa.lib import events
from modoboa.lib import events, static_url
register = template.Library()
@@ -17,16 +17,16 @@ def domain_menu(domain_id, selection, user):
{"name" : "",
"url" : reverse(admin.views.newmailbox, args=[domain_id]),
"label" : _("New mailbox"),
"img" : "/static/pics/add.png",
"img" : static_url("pics/add.png"),
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:300,y:280}}"},
{"name" : "mailboxes",
"url" : reverse(admin.views.mailboxes, args=[domain_id]),
"img" : "/static/pics/mailbox.png",
"img" : static_url("pics/mailbox.png"),
"label" : _("Mailboxes")},
{"name" : "aliases",
"url" : reverse("full-aliases", args=[domain_id]),
"img" : "/static/pics/alias.png",
"img" : static_url("/pics/alias.png"),
"label" : _("Aliases")},
]
@@ -35,7 +35,7 @@ def domain_menu(domain_id, selection, user):
{"name" : "",
"url" : reverse(admin.views.editdomain, args=[domain_id]),
"label" : _("Properties"),
"img" : "/static/pics/edit.png",
"img" : static_url("pics/edit.png"),
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:300,y:180}}"}
]
@@ -51,16 +51,16 @@ def settings_menu(selection, user):
{"name" : "permissions",
"url" : reverse(admin.views.settings),
"label" : _("Permissions"),
"img" : "/static/pics/permissions.png"},
"img" : static_url("pics/permissions.png"}),
{"name" : "addperm",
"url" : reverse(admin.views.addpermission),
"img" : "/static/pics/add.png",
"img" : static_url("pics/add.png"),
"label" : _("Add permission"),
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:320,y:210}}"},
{"name" : "parameters",
"url" : reverse(admin.views.viewparameters),
"img" : "/static/pics/domains.png",
"img" : static_url("pics/domains.png"),
"label" : _("Parameters")},
]
return render_to_string('common/menu.html',
@@ -73,13 +73,13 @@ def domains_menu(selection, user):
{"name" : "newdomain",
"url" : reverse(admin.views.newdomain),
"label" : _("New domain"),
"img" : "/static/pics/add.png",
"img" : static_url("pics/add.png"),
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:300,y:200}}"},
{"name" : "domains",
"url" : reverse(admin.views.domains),
"label" : _("Domains"),
"img" : "/static/pics/domains.png"}
"img" : static_url("pics/domains.png")}
]
entries += events.raiseQueryEvent("AdminMenuDisplay", target="admin_menu_box",
user=user)
@@ -131,8 +131,8 @@ def param(app, definition):
if definition.has_key("help"):
result += """
<a href='%s' onclick='return false;' class='Tips' title='%s'>
<img src='/static/pics/info.png' border='0' />
</a>""" % (definition["help"], _("Help"))
<img src='%s' border='0' />
</a>""" % (definition["help"], _("Help"), static_url("pics/info.png"))
result += """
</div>
"""
+2 -2
View File
@@ -5,7 +5,7 @@
from django.conf.urls.defaults import *
from django.utils.translation import ugettext as _, ungettext
from django.core.urlresolvers import reverse
from modoboa.lib import events, parameters
from modoboa.lib import events, parameters, static_url
def infos():
return {
@@ -49,7 +49,7 @@ def menu(**kwargs):
{"name" : "quarantine",
"label" : _("Quarantine"),
"url" : reverse(views.index),
"img" : "/static/pics/quarantine.png"}
"img" : static_url("pics/quarantine.png")}
]
return []
@@ -2,6 +2,8 @@ from django import template
from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from django.conf import settings
from modoboa.lib import static_url
from modoboa.extensions import amavis_quarantine
register = template.Library()
@@ -23,27 +25,27 @@ def viewm_menu(selection, backurl, mail_id, perms):
entries = [
{"name" : "back",
"url" : backurl,
"img" : "/static/pics/back.png",
"img" : static_url("pics/back.png"),
"label" : _("Back to list")},
{"name" : "headers",
"url" : reverse(amavis_quarantine.views.viewheaders, args=[mail_id]),
"img" : "/static/pics/add.png",
"img" : static_url("pics/add.png"),
"label" : _("View full headers"),
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:600,y:500}}"},
{"name" : "release",
"url" : reverse(amavis_quarantine.views.release, args=[mail_id]),
"img" : "/static/pics/release.png",
"img" : static_url("pics/release.png"),
"label" : _("Release"),
"confirm" : _("Release this message?")},
{"name" : "delete",
"url" : reverse(amavis_quarantine.views.delete, args=[mail_id]),
"img" : "/static/pics/remove.png",
"img" : static_url("pics/remove.png"),
"label" : _("Delete"),
"confirm" : _("Delete this message?")},
{"name" : "options",
"label" : _("Options"),
"img" : "/static/pics/settings.png",
"img" : static_url("pics/settings.png"),
"class" : "menubardropdown",
"menu" : options_menu}
]
@@ -57,15 +59,15 @@ def quar_menu(selection, perms):
entries = [
{"name" : "release",
"url" : "",
"img" : "/static/pics/release.png",
"img" : static_url("pics/release.png"),
"label" : _("Release")},
{"name" : "delete",
"url" : "",
"img" : "/static/pics/remove.png",
"img" : static_url("pics/remove.png"),
"label" : _("Delete")},
{"name" : "select",
"url" : "",
"img" : "/static/pics/domains.png",
"img" : static_url("pics/domains.png"),
"label" : _("Select"),
"class" : "menubardropdown",
"menu" : [
@@ -88,5 +90,7 @@ def quar_menu(selection, perms):
menu = render_to_string('common/menu.html',
{"selection" : selection, "entries" : entries,
"perms" : perms})
searchbar = render_to_string('common/email_searchbar.html', {})
searchbar = render_to_string('common/email_searchbar.html', {
"MEDIA_URL" : settings.MEDIA_URL
})
return menu + searchbar
+2 -2
View File
@@ -10,7 +10,7 @@ functionality into Postfix.
from django.conf.urls.defaults import include
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from modoboa.lib import events, parameters
from modoboa.lib import events, parameters, static_url
from models import *
def infos():
@@ -53,7 +53,7 @@ def menu(**kwargs):
return [
{"name" : "autoreply",
"url" : reverse(views.autoreply),
"img" : "/static/pics/auto-reply.png",
"img" : static_url("pics/auto-reply.png"),
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:440,y:400}}",
"label" : _("Auto-reply message")}
+3 -3
View File
@@ -10,7 +10,7 @@ sent, received, bounced, rejected
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from django.conf.urls.defaults import *
from modoboa.lib import events, parameters
from modoboa.lib import events, parameters, static_url
def infos():
return {
@@ -45,13 +45,13 @@ def menu(**kwargs):
{"label" : _("Statistics"),
"name" : "stats",
"url" : reverse('domindex', args=[domain_id]),
"img" : "/static/pics/graph.png"}
"img" : static_url("pics/graph.png")}
]
if kwargs["target"] == "admin_menu_box":
return [
{"name" : "stats",
"label" : _("Statistics"),
"url" : reverse('fullindex'),
"img" : "/static/pics/graph.png"}
"img" : static_url("pics/graph.png")}
]
return []
+2 -2
View File
@@ -16,7 +16,7 @@ from django.utils.translation import ugettext as _
from django.conf import settings
from modoboa.lib import decode, tables, imap_utf7, Singleton
from modoboa.lib.email_listing import MBconnector, EmailListing, Email
from modoboa.lib import tables, imap_utf7, parameters
from modoboa.lib import tables, imap_utf7, parameters, static_url
class WMtable(tables.Table):
@@ -369,7 +369,7 @@ class IMAPconnector(object):
if not "\\Seen" in flags:
msg["class"] = "unseen"
if "\\Answered" in flags:
msg["img_flags"] = "/static/pics/answered.png"
msg["img_flags"] = static_url("pics/answered.png")
tmpdict[imapid] = msg
for id in submessages:
result += [tmpdict[id]]
+2 -2
View File
@@ -2,7 +2,7 @@
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from django.conf.urls.defaults import include
from modoboa.lib import events, parameters
from modoboa.lib import events, parameters, static_url
def init():
events.register("UserMenuDisplay", menu)
@@ -69,7 +69,7 @@ def menu(**kwargs):
{"name" : "webmail",
"label" : _("Webmail"),
"url" : reverse(views.index),
"img" : "/static/pics/webmail.png"}
"img" : static_url("pics/webmail.png")}
]
def userlogin(**kwargs):
+4 -4
View File
@@ -40,7 +40,7 @@
item.removeClass("hidden");
item.addClass("visible");
$$("li[name=" + item.get("name") + "]").each(function(item) {
item.setStyle("background", "url('/static/pics/folder-open.png') no-repeat");
item.setStyle("background", "url('{{ MEDIA_URL }}pics/folder-open.png') no-repeat");
});
});
}
@@ -157,10 +157,10 @@
$$("li[class*=clickable]").addEvent("click", function(evt) {
$$("ul[name=" + evt.target.get("name") + "]").each(function(item) {
if (item.hasClass("hidden")) {
evt.target.setStyle("background", "url('/static/pics/folder-open.png') no-repeat");
evt.target.setStyle("background", "url('{{ MEDIA_URL }}pics/folder-open.png') no-repeat");
item.removeClass("hidden").addClass("visible");
} else {
evt.target.setStyle("background", "url('/static/pics/subfolders.png') no-repeat");
evt.target.setStyle("background", "url('{{ MEDIA_URL }}pics/subfolders.png') no-repeat");
item.removeClass("visible").addClass("hidden");
}
});
@@ -170,7 +170,7 @@
if (navparams.has("order")) {
src = navparams.get("order").charAt(0) == "-" ? "down_arrow.png" : "up_arrow.png";
th = $$("th[id=" + navparams.get("order").substring(1) + "]");
th.getElement("img").set("src", "/static/pics/" + src);
th.getElement("img").set("src", "{{ MEDIA_URL }}pics/" + src);
th.getElement("img").setStyle("display", "block");
th.addClass("selected");
}
+17 -14
View File
@@ -2,9 +2,10 @@ from django import template
from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from django.conf import settings
from modoboa.extensions import webmail
from modoboa.extensions.webmail.lib import IMAPheader
from modoboa.lib import parameters
from modoboa.lib import parameters, static_url
register = template.Library()
@@ -13,22 +14,22 @@ def viewm_menu(selection, backurl, folder, mail_id, user):
entries = [
{"name" : "back",
"url" : backurl,
"img" : "/static/pics/back.png",
"img" : static_url("pics/back.png"),
"label" : _("Back")},
{"name" : "reply",
"url" : "reply/",
"img" : "/static/pics/reply.png",
"img" : static_url("pics/reply.png"),
"label" : _("Reply")},
{"name" : "replyall",
"url" : "reply/",
"img" : "/static/pics/reply-all.png",
"img" : static_url("pics/reply-all.png"),
"label" : _("Reply all")},
{"name" : "forward",
"url" : "forward/",
"img" : "/static/pics/alias.png",
"img" : static_url("pics/alias.png"),
"label" : _("Forward")},
{"name" : "delete",
"img" : "/static/pics/remove.png",
"img" : static_url("pics/remove.png"),
"url" : reverse(webmail.views.delete, args=[folder, mail_id]),
"label" : _("Delete")},
]
@@ -42,11 +43,11 @@ def compose_menu(selection, backurl, user):
entries = [
{"name" : "back",
"url" : backurl,
"img" : "/static/pics/back.png",
"img" : static_url("pics/back.png"),
"label" : _("Back")},
{"name" : "sendmail",
"url" : "",
"img" : "/static/pics/send-receive.png",
"img" : static_url("pics/send-receive.png"),
"label" : _("Send")},
]
return render_to_string('common/menu.html',
@@ -58,10 +59,10 @@ def listing_menu(selection, folder, user):
entries = [
{"name" : "compose",
"url" : reverse(webmail.views.compose),
"img" : "/static/pics/edit.png",
"img" : static_url("pics/edit.png"),
"label" : _("New message")},
{"name" : "mark",
"img" : "/static/pics/domains.png",
"img" : static_url("pics/domains.png"),
"label" : _("Mark messages"),
"class" : "menubardropdown",
"menu" : [
@@ -74,14 +75,14 @@ def listing_menu(selection, folder, user):
]
},
{"name" : "actions",
"img" : "/static/pics/settings.png",
"img" : static_url("pics/settings.png"),
"label" : _("Actions"),
"class" : "menubardropdown",
"width" : "150",
"menu" : [
{"name" : "fdaction",
"label" : _("Compress folder"),
"img" : "/static/pics/compress.png",
"img" : static_url("pics/compress.png"),
"url" : "compact/%s/" % folder},
]
}
@@ -90,13 +91,15 @@ def listing_menu(selection, folder, user):
entries[2]["menu"] += [
{"name" : "fdaction",
"label" : _("Empty folder"),
"img" : "/static/pics/clear.png",
"img" : static_url("pics/clear.png"),
"url" : reverse(webmail.views.empty, args=[folder])}
]
menu = render_to_string("common/menu.html",
{"selection" : selection, "entries" : entries,
"user" : user})
searchbar = render_to_string("common/email_searchbar.html", {})
searchbar = render_to_string("common/email_searchbar.html", {
"MEDIA_URL" : settings.MEDIA_URL
})
return menu + searchbar
@register.simple_tag
+10
View File
@@ -2,6 +2,7 @@
import os
import sys
import time
from django.conf import settings
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.template.loader import render_to_string
@@ -37,6 +38,15 @@ def _ctx_ok(url):
def _ctx_ko(tpl, ctx):
return {"status" : "ko", "content" : render_to_string(tpl, ctx)}
def static_url(path):
"""Returns the correct static url for a given file
:param path: the targeted static media
"""
if path.startswith("/"):
path = path[1:]
return "%s%s" % (settings.MEDIA_URL, path)
def getctx(status, level=1, callback=None, **kwargs):
if not callback:
callername = sys._getframe(level).f_code.co_name
+2 -4
View File
@@ -4,9 +4,9 @@ import re
import os
import time, random, hashlib
from email.header import decode_header
import lxml
import lxml.html
from lxml import etree
from django.conf import settings
from django.template.loader import render_to_string
from django.template import Template, Context
from django.utils.translation import ugettext as _
@@ -103,7 +103,7 @@ class EmailListing:
def render_navbar(self, page):
if page is None:
return ""
context = {"page" : page}
context = {"page" : page, "MEDIA_URL" : settings.MEDIA_URL}
return render_to_string("common/navbar.html", context)
def fetch(self, request, id_start, id_stop):
@@ -213,8 +213,6 @@ class Email(object):
:param fname: the image associated filename
:param part: the email part that contains the image payload
"""
from django.conf import settings
if re.search("\.\.", fname):
return None
path = "/static/tmp/" + fname
+3 -3
View File
@@ -6,9 +6,9 @@
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modoboa - {%block pagetitle %}{% endblock %}</title>
<link rel="icon" type="image/png" href="/static/css/logo-icon.png" />
<link rel="stylesheet" type="text/css" href="/static/css/default.css" />
<link rel="stylesheet" type="text/css" href="/static/css/SqueezeBox.css" />
<link rel="icon" type="image/png" href="{{ MEDIA_URL }}css/logo-icon.png" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/default.css" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/SqueezeBox.css" />
<script src="{{ MEDIA_URL }}js/mootools.js" type="text/javascript"></script>
<script src="{{ MEDIA_URL }}js/mootools-more.js" type="text/javascript"></script>
<script src="{{ MEDIA_URL }}js/SqueezeBox.js" type="text/javascript"></script>