mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-19 05:58:34 +02:00
Quarantine plugin refactoring. It is now working like the webmail plugin, ie with an anchor based ajax navigation. What is broken for the moment:
* search functionality, * headers do not appear while displaying a mail. New message system. (see infobox.js)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import popen2
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from django.conf import settings
|
||||
from django.template import RequestContext
|
||||
@@ -67,6 +68,16 @@ def _ctx_ok(url):
|
||||
def _ctx_ko(tpl, ctx):
|
||||
return {"status" : "ko", "content" : render_to_string(tpl, ctx)}
|
||||
|
||||
def getctx(status, level=1, callback=None, **kwargs):
|
||||
if not callback:
|
||||
callername = sys._getframe(level).f_code.co_name
|
||||
else:
|
||||
callername = callback
|
||||
ctx = {"status" : status, "callback" : callername}
|
||||
for kw, v in kwargs.iteritems():
|
||||
ctx[kw] = v
|
||||
return ctx
|
||||
|
||||
def decode(s, encodings=('utf8', 'latin1', 'windows-1252', 'ascii')):
|
||||
for encoding in encodings:
|
||||
try:
|
||||
|
||||
+16
-8
@@ -83,16 +83,23 @@ class Paginator(object):
|
||||
return p
|
||||
|
||||
class EmailListing:
|
||||
def __init__(self, folder=None, elems_per_page=40, navparams={}, **kwargs):
|
||||
def __init__(self, baseurl=None, folder=None, elems_per_page=40,
|
||||
navparams={}, **kwargs):
|
||||
self.folder = folder
|
||||
self.elems_per_page = elems_per_page
|
||||
self.navparams = navparams
|
||||
order = "order" in kwargs.keys() and kwargs["order"] or None
|
||||
self.paginator = Paginator(self.mbc.messages_count(folder=self.folder,
|
||||
order=order),
|
||||
elems_per_page)
|
||||
self.empty = "empty" in kwargs.keys() and kwargs["empty"] or False
|
||||
if not self.empty:
|
||||
self.paginator = Paginator(self.mbc.messages_count(folder=self.folder,
|
||||
order=order),
|
||||
elems_per_page)
|
||||
if baseurl:
|
||||
self.paginator.baseurl = baseurl
|
||||
|
||||
def render_navbar(self, page):
|
||||
if page is None:
|
||||
return ""
|
||||
return render_to_string("common/navbar.html", {
|
||||
"page" : page
|
||||
})
|
||||
@@ -110,9 +117,10 @@ class EmailListing:
|
||||
return tpl.render(Context({"table" : table.render(request)}))
|
||||
|
||||
def render(self, request, pageid=1, **kwargs):
|
||||
page = self.paginator.getpage(pageid)
|
||||
thead = listing = ""
|
||||
if "empty" in kwargs.keys() and not kwargs["empty"]:
|
||||
listing = ""
|
||||
page = None
|
||||
if not self.empty:
|
||||
page = self.paginator.getpage(pageid)
|
||||
if not page:
|
||||
listing = "Empty folder"
|
||||
else:
|
||||
@@ -125,7 +133,7 @@ class EmailListing:
|
||||
"folders" : self.getfolders(),
|
||||
"selection" : self.folder,
|
||||
"navparams" : self.navparams,
|
||||
"current_page" : pageid
|
||||
"deflocation" : self.deflocation, "defcallback" : self.defcallback
|
||||
})
|
||||
|
||||
class Email(object):
|
||||
|
||||
+14
-10
@@ -55,16 +55,21 @@ class Table(object):
|
||||
for row in rows:
|
||||
nrow = {"id" : row[self.idkey], "cols" : []}
|
||||
for c in self.columns:
|
||||
newcol = {}
|
||||
try:
|
||||
newcol["width"] = getattr(c, "width")
|
||||
except AttributeError:
|
||||
pass
|
||||
if isinstance(c, SelectionColumn):
|
||||
nrow["cols"] += [{"value" : c.render(row[self.idkey]), "safe" : True}]
|
||||
continue
|
||||
newcol["value"] = c.render(row[self.idkey])
|
||||
newcol["safe"] = True
|
||||
|
||||
if isinstance(c, ImgColumn):
|
||||
key = "img_%s" % c.name
|
||||
if key in row.keys():
|
||||
nrow["cols"] += [{"value" : c.render(row[key]), "safe" : True, "width" : c.width}]
|
||||
else:
|
||||
nrow["cols"] += [{"width" : c.width}]
|
||||
continue
|
||||
newcol["value"] = c.render(row[key])
|
||||
newcol["safe"] = True
|
||||
|
||||
if row.has_key(c.name):
|
||||
try:
|
||||
cssclass = getattr(c, "cssclass")
|
||||
@@ -72,10 +77,9 @@ class Table(object):
|
||||
cssclass = ""
|
||||
if "class" in row.keys():
|
||||
cssclass += (cssclass != "") and ", %s" % row["class"] or row["class"]
|
||||
|
||||
nrow["cols"] += [{"value" : self.parse(c.name, row[c.name]),
|
||||
"class" : cssclass,
|
||||
"width" : c.width}]
|
||||
newcol["value"] = self.parse(c.name, row[c.name])
|
||||
newcol["class"] = cssclass
|
||||
nrow["cols"] += [newcol]
|
||||
self.rows += [nrow]
|
||||
|
||||
def render(self, request):
|
||||
|
||||
Reference in New Issue
Block a user