Commit 6eacc277 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

cw 3.8/3.9 api update

parent 56dfc62f3f1c
......@@ -10,24 +10,15 @@ import re
from logilab.common import umessage
from cubicweb.interfaces import ITree
from cubicweb.mixins import TreeMixIn
from cubicweb.entities import AnyEntity, fetch_config
from cubicweb.entities import AnyEntity, fetch_config, adapters
from cubicweb.selectors import is_instance
from import parse_body
class Email(TreeMixIn, AnyEntity):
class Email(AnyEntity):
"""customized class for Email entities"""
__regid__ = 'Email'
fetch_attrs, fetch_order = fetch_config(['subject'])
__implements__ = AnyEntity.__implements__ + (ITree,)
tree_attribute = 'reply_to'
def parent(self):
"""for breadcrumbs"""
return self.thread
def dc_title(self):
return self.subject
......@@ -98,6 +89,7 @@ class Email(TreeMixIn, AnyEntity):
return umessage.message_from_string(headers + '\n\n')
class EmailPart(AnyEntity):
"""customized class for EmailPart entities"""
__regid__ = 'EmailPart'
......@@ -131,3 +123,9 @@ class EmailThread(AnyEntity):
def dc_title(self):
return self.title
class EmailITreeAdapter(adapters.ITreeAdapter):
__select__ = is_instance('Email')
tree_relation = 'reply_to'
......@@ -5,7 +5,7 @@
linking information are found
:organization: Logilab
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: --
__docformat__ = "restructuredtext en"
......@@ -14,7 +14,7 @@ from logilab.mtconverter import TransformError
from cubicweb import UnknownEid, typed_eid
from cubicweb.mail import parse_message_id
from cubicweb.selectors import implements
from cubicweb.selectors import is_instance
from cubicweb.server import hook
......@@ -23,10 +23,10 @@ def fix_ownership(session, eid, email):
if (sender and sender.e_schema == 'CWUser' and
sender.eid != session.actual_session().user.eid):
# match a user which is not the session's user, set owned_by / created_by
session.unsafe_execute('SET X owned_by U WHERE X eid %(x)s, U eid %(u)s',
{'x': eid, 'u': sender.eid}, 'x')
session.unsafe_execute('SET X created_by U WHERE X eid %(x)s, U eid %(u)s',
{'x': eid, 'u': sender.eid}, 'x')
session.execute('SET X owned_by U WHERE X eid %(x)s, U eid %(u)s',
{'x': eid, 'u': sender.eid})
session.execute('SET X created_by U WHERE X eid %(x)s, U eid %(u)s',
{'x': eid, 'u': sender.eid})
class ExtractEmailInformation(hook.Operation):
......@@ -42,7 +42,7 @@ class ExtractEmailInformation(hook.Operation):
except UnknownEid:
self.error('email %s is referencing an unknown eid %s',
email.messageid, origeid)
if origetype in self.session.vreg.schema['comments'].objects('Comment'):
part = email.parts_in_order(prefered_mime_type='text/plain')[0]
......@@ -56,12 +56,12 @@ class ExtractEmailInformation(hook.Operation):
origeid, email)
def insert_comment(self, eid, emailpart):
com = self.session.unsafe_execute(
com = self.session.execute(
'INSERT Comment C: C content %(content)s, '
'C content_format %(format)s, C comments X, C generated_by E '
'WHERE X eid %(x)s, E eid %(e)s',
{'x': eid, 'e':, 'format': u'text/plain',
'content': emailpart.actual_content()}, 'x')
'content': emailpart.actual_content()})
fix_ownership(self.session, com[0][0],
......@@ -89,7 +89,7 @@ class AddEmailHook(hook.Hook):
"""an email has been added, check if associated content should be created
__regid__ = 'extractmailcontent'
__select__ = hook.Hook.__select__ & implements('Email')
__select__ = hook.Hook.__select__ & is_instance('Email')
events = ('after_add_entity',)
def __call__(self):
from cubicweb.selectors import is_instance
from cubicweb.web import uicfg
from cubicweb.web.views import ibreadcrumbs
_pvs = uicfg.primaryview_section
_pvs.tag_object_of(('Email', 'in_thread', 'EmailThread'), 'hidden')
......@@ -14,3 +16,8 @@ _afs.tag_object_of(('*', 'sender', 'EmailAddress'), 'main', 'hidden')
_afs.tag_object_of(('*', 'recipients', 'EmailAddress'), 'main', 'hidden')
_afs.tag_object_of(('*', 'cc', 'EmailAddress'), 'main', 'hidden')
_afs.tag_subject_of(('*', 'generated_by', 'Email'), 'main', 'hidden')
class EmailPartIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
__select__ = is_instance('EmailPart')
def parent_entity(self):
return self.entity.thread
"""Specific views for email related entities
:organization: Logilab
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: --
__docformat__ = "restructuredtext en"
......@@ -9,9 +9,8 @@ _ = unicode
from logilab.mtconverter import xml_escape
from cubicweb.selectors import implements
from cubicweb.selectors import is_instance
from cubicweb.uilib import soup2xhtml
from cubicweb.mixins import TreeViewMixIn
from cubicweb.web import uicfg, formwidgets
from cubicweb.web.views import baseviews, primary
......@@ -38,7 +37,7 @@ def formated_sender(email):
return email._cw._('unknown sender')
class EmailPrimaryView(primary.PrimaryView):
__select__ = implements('Email')
__select__ = is_instance('Email')
def render_entity_attributes(self, entity):
self.w(u'<div class="emailheader"><table>')
......@@ -75,7 +74,7 @@ class EmailPrimaryView(primary.PrimaryView):
class EmailHeadersView(baseviews.EntityView):
"""display email's headers"""
__regid__ = 'headers'
__select__ = implements('Email')
__select__ = is_instance('Email')
title = _('headers')
templatable = False
content_type = 'text/plain'
......@@ -89,7 +88,7 @@ class EmailOneLineView(baseviews.OneLineView):
"""short view usable in the context of the email sender/recipient (in which
case the caller should specify its context eid) or outside any context
__select__ = implements('Email')
__select__ = is_instance('Email')
title = _('oneline')
def cell_call(self, row, col, contexteid=None):
......@@ -120,25 +119,20 @@ class EmailInContextView(EmailOneLineView):
"""short view inside the context of the email"""
__regid__ = 'incontext'
class EmailTreeItemView(EmailOutOfContextView):
__regid__ = 'treeitem'
title = None
class EmailPartOutOfContextView(baseviews.OutOfContextView):
"""out of context an email part is redirecting to related email view"""
__select__ = implements('EmailPart')
__select__ = is_instance('EmailPart')
def cell_call(self, row, col):
entity = self.cw_rset.get_entity(row, col)
entity.reverse_parts[0].view('outofcontext', w=self.w)
class EmailThreadView(TreeViewMixIn, baseviews.ListView):
"""display email's headers"""
__select__ = implements('Email')
title = _('thread view')
item_vid = 'outofcontext'
class EmailThreadPrimaryView(primary.PrimaryView):
__select__ = implements('EmailThread')
__select__ = is_instance('EmailThread')
def cell_call(self, row, col):
entity = self.cw_rset.complete_entity(row, col)
......@@ -158,7 +152,7 @@ class EmailThreadPrimaryView(primary.PrimaryView):
rset = self._cw.execute('DISTINCT Any X,D ORDERBY D '
'WHERE X date D, X in_thread E, '
'NOT X reply_to Y, E eid %(x)s',
{'x': entity.eid}, 'x')
{'x': entity.eid})
if rset:
self.w(u'\n'.join(email.view('tree') for email in rset.entities()))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment