From f77232740c48be9e2641890414db2775ae6fc0ec Mon Sep 17 00:00:00 2001 From: spametki Date: Sun, 20 Oct 2013 08:38:07 -0300 Subject: [PATCH] imap: return to common field type for attachment and content plus appadmin imap support --- applications/admin/languages/es.py | 3 ++ applications/welcome/controllers/appadmin.py | 29 ++++++++++++++++---- applications/welcome/views/appadmin.html | 4 +-- gluon/dal.py | 28 +++++++++---------- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/applications/admin/languages/es.py b/applications/admin/languages/es.py index e5ca7602..39875970 100644 --- a/applications/admin/languages/es.py +++ b/applications/admin/languages/es.py @@ -35,6 +35,7 @@ 'application "%s" uninstalled': 'aplicación "%s" desinstalada', 'application %(appname)s installed with md5sum: %(digest)s': 'application %(appname)s installed with md5sum: %(digest)s', 'application compiled': 'aplicación compilada', +'Application exists already': 'Application exists already', 'application is compiled and cannot be designed': 'la aplicación está compilada y no puede ser modificada', 'Application name:': 'Nombre de la aplicación:', 'are not used': 'are not used', @@ -63,6 +64,7 @@ 'cache': 'cache', 'cache, errors and sessions cleaned': 'cache, errores y sesiones eliminados', 'can be a git repo': 'puede ser un repositorio git', +'Cancel': 'Cancel', 'Cannot be empty': 'No puede estar vacío', 'Cannot compile: there are errors in your app. Debug it, correct errors and try again.': 'No se puede compilar: hay errores en su aplicación. Depure, corrija errores y vuelva a intentarlo.', 'Cannot compile: there are errors in your app:': 'No se puede compilar: hay errores en su aplicación:', @@ -161,6 +163,7 @@ 'Error snapshot': 'Error snapshot', 'Error ticket': 'Error ticket', 'Errors': 'errores', +'Errors in form, please check it out.': 'Errors in form, please check it out.', 'Exception instance attributes': 'Atributos de la instancia de Excepción', 'Exit Fullscreen': 'Exit Fullscreen', 'Expand Abbreviation': 'Expand Abbreviation', diff --git a/applications/welcome/controllers/appadmin.py b/applications/welcome/controllers/appadmin.py index 7a9fb58e..44efa2d5 100644 --- a/applications/welcome/controllers/appadmin.py +++ b/applications/welcome/controllers/appadmin.py @@ -186,6 +186,10 @@ def select(): import re db = get_database(request) dbname = request.args[0] + try: + is_imap = db._uri.startswith("imap://") + except (KeyError, AttributeError, TypeError): + is_imap = False regex = re.compile('(?P\w+)\.(?P\w+)=(?P\d+)') if len(request.args) > 1 and hasattr(db[request.args[1]], '_primarykey'): regex = re.compile('(?P
\w+)\.(?P\w+)=(?P.+)') @@ -203,7 +207,15 @@ def select(): else: start = 0 nrows = 0 - stop = start + 100 + + step = 100 + fields = [] + + if is_imap: + step = 3 + + stop = start + step + table = None rows = [] orderby = request.vars.orderby @@ -244,12 +256,18 @@ def select(): db(query, ignore_common_filters=True).delete() response.flash = T('%s %%{row} deleted', nrows) nrows = db(query, ignore_common_filters=True).count() + + if is_imap: + fields = [db[table][name] for name in + ("id", "uid", "created", "to", + "sender", "subject")] if orderby: - rows = db(query, ignore_common_filters=True).select(limitby=( - start, stop), orderby=eval_in_global_env(orderby)) + rows = db(query, ignore_common_filters=True).select( + *fields, limitby=(start, stop), + orderby=eval_in_global_env(orderby)) else: rows = db(query, ignore_common_filters=True).select( - limitby=(start, stop)) + *fields, limitby=(start, stop)) except Exception, e: import traceback tb = traceback.format_exc() @@ -278,11 +296,12 @@ def select(): table=table, start=start, stop=stop, + step=step, nrows=nrows, rows=rows, query=request.vars.query, formcsv=formcsv, - tb=tb, + tb=tb ) diff --git a/applications/welcome/views/appadmin.html b/applications/welcome/views/appadmin.html index 617daeeb..054efd49 100644 --- a/applications/welcome/views/appadmin.html +++ b/applications/welcome/views/appadmin.html @@ -62,8 +62,8 @@ {{=T('"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN')}}



{{=T("%s selected", nrows)}}

- {{if start>0:}}{{=A(T('previous 100 rows'),_href=URL('select',args=request.args[0],vars=dict(start=start-100)),_class="btn")}}{{pass}} - {{if stop0:}}{{=A(T('previous %s rows') % step,_href=URL('select',args=request.args[0],vars=dict(start=start-step)),_class="btn")}}{{pass}} + {{if stop {{linkto = lambda f, t, r: URL('update', args=[request.args[0], r, f]) if f else "#"}} diff --git a/gluon/dal.py b/gluon/dal.py index 990cf99a..77f4bc43 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -6281,25 +6281,25 @@ class IMAPAdapter(NoSQLAdapter): for name in names: self.db.define_table("%s" % name, - Field("uid", "string", writable=False), - Field("answered", "boolean"), + Field("uid", writable=False), Field("created", "datetime", writable=False), - Field("content", list, writable=False), - Field("to", "string", writable=False), - Field("cc", "string", writable=False), - Field("bcc", "string", writable=False), + Field("content", "text", writable=False), + Field("to", writable=False), + Field("cc", writable=False), + Field("bcc", writable=False), + Field("sender", writable=False), Field("size", "integer", writable=False), + Field("subject", writable=False), + Field("mime", writable=False), + Field("email", "text", writable=False, readable=False), + Field("attachments", "text", writable=False, readable=False), + Field("encoding", writable=False), + Field("answered", "boolean"), Field("deleted", "boolean"), Field("draft", "boolean"), Field("flagged", "boolean"), - Field("sender", "string", writable=False), Field("recent", "boolean", writable=False), - Field("seen", "boolean"), - Field("subject", "string", writable=False), - Field("mime", "string", writable=False), - Field("email", "string", writable=False, readable=False), - Field("attachments", list, writable=False, readable=False), - Field("encoding", writable=False) + Field("seen", "boolean") ) # Set a special _mailbox attribute for storing @@ -6562,7 +6562,7 @@ class IMAPAdapter(NoSQLAdapter): mailbox = table.mailbox d = dict(((k.name, v) for k, v in fields)) - date_time = d.get("created", datetime.datetime.now()) + date_time = d.get("created") or datetime.datetime.now() struct_time = date_time.timetuple() if len(d) > 0: message = d.get("email", None)