[IMP] wip

bzr revid: nicolas.vanhoren@openerp.com-20101126131811-rmgjiy7i7tsu2pim
This commit is contained in:
nvi-openerp 2010-11-26 14:18:11 +01:00
parent d778be3341
commit 6cd96a7742
6 changed files with 42 additions and 43 deletions

View File

@ -116,7 +116,7 @@ class publisher_warranty_contract(osv.osv):
def check_validity(self, cr, uid, ids, context={}):
"""
Check the validity of a publisher warranty contract. This method just call send_ping() but checks
Check the validity of a publisher warranty contract. This method just call get_logs() but checks
some more things, so it can be called from a user interface.
"""
contract_id = ids[0]
@ -124,7 +124,7 @@ class publisher_warranty_contract(osv.osv):
state = contract.state
validated = state != "unvalidated"
self.send_ping(cr, uid, ids, cron_mode=False, context=context)
self.get_logs(cr, uid, ids, cron_mode=False, context=context)
contract = self.browse(cr, uid, contract_id)
validated2 = contract.state != "unvalidated"
@ -132,7 +132,7 @@ class publisher_warranty_contract(osv.osv):
raise osv.except_osv(_("Contract validation error"),
_("Please check your publisher warranty contract name and validity."))
def send_ping(self, cr, uid, ids, cron_mode=True, context={}):
def get_logs(self, cr, uid, ids, cron_mode=True, context={}):
"""
Send a message to OpenERP's publisher warranty server to check the validity of
the contracts, get notifications, etc...
@ -142,9 +142,9 @@ class publisher_warranty_contract(osv.osv):
"""
try:
try:
result = send_ping(cr, uid)
result = get_sys_logs(cr, uid)
except:
_logger.debug("Exception while sending a ping", exc_info=1)
_logger.debug("Exception while sending a get logs messages", exc_info=1)
raise osv.except_osv(_("Error"), _("Error during communication with the publisher warranty server."))
contracts = result["contracts"]
@ -161,16 +161,14 @@ class publisher_warranty_contract(osv.osv):
limit_date = (datetime.datetime.now() - _PREVIOUS_LOG_CHECK).strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT)
for message in result["messages"]:
content = message if isinstance(message, str) or \
isinstance(message, unicode) else message[0]
ids = self.pool.get("res.log").search(cr, uid, [("res_model", "=", "publisher_warranty.contract"),
("create_date", ">=", limit_date),
("name", "=", content)])
("name", "=", message)])
if ids:
continue
self.pool.get('res.log').create(cr, uid,
{
'name': content,
'name': message,
'res_model': "publisher_warranty.contract",
"read": True,
"user_id": False,
@ -178,7 +176,7 @@ class publisher_warranty_contract(osv.osv):
context=context
)
except:
_logger.debug("Exception while interpreting the result of a ping", exc_info=1)
_logger.debug("Exception while interpreting the result of a logs message", exc_info=1)
if cron_mode:
return False # same as before
else:
@ -186,19 +184,27 @@ class publisher_warranty_contract(osv.osv):
return True
def get_last_user_message(self, cr, uid, context={}):
def get_last_user_messages(self, cr, uid, limit, context={}):
"""
Get the message to be written in the web client.
@return: An html message, can be False instead.
@rtype: string
Get the messages to be written in the web client.
@return: A list of html messages with ids, can be False or empty.
@rtype: list of tuples(int,string)
"""
ids = self.pool.get('res.log').search(cr, uid, [("res_model", "=", "publisher_warranty.contract")]
, order="create_date desc", limit=1)
, order="create_date desc", limit=limit)
if not ids:
return False
message = self.pool.get('res.log').browse(cr, uid, ids[0]).name
return []
messages = [(x.id, x.name) for x in self.pool.get('res.log').browse(cr, uid, ids)]
return message
return messages
def del_user_message(self, cr, uid, id, context={}):
"""
Delete a message.
"""
self.pool.get('res.log').unlink(cr, uid, [id])
return True
_columns = {
'name' : fields.char('Contract Name', size=384, required=True),
@ -273,9 +279,9 @@ class publisher_warranty_contract_wizard(osv.osv_memory):
publisher_warranty_contract_wizard()
def send_ping(cr, uid):
def get_sys_logs(cr, uid):
"""
Utility method to send a publisher warranty ping.
Utility method to send a publisher warranty get logs messages.
"""
pool = pooler.get_pool(cr.dbname)
@ -284,6 +290,7 @@ def send_ping(cr, uid):
nbr_users = pool.get("res.users").search(cr, uid, [], count=True)
contractosv = pool.get('publisher_warranty.contract')
contracts = contractosv.browse(cr, uid, contractosv.search(cr, uid, []))
user = pool.get("res.users").browse(cr, uid, uid)
msg = {
"dbuuid": dbuuid,
"nbr_users": nbr_users,
@ -291,6 +298,7 @@ def send_ping(cr, uid):
"db_create_date": db_create_date,
"version": release.version,
"contracts": [c.name for c in contracts],
"language": user.context_lang,
}
uo = urllib.urlopen(config.get("publisher_warranty_url"),

View File

@ -3,7 +3,7 @@
<data>
<record id="ir_cron_ping_scheduler" model="ir.cron">
<field name="name">Update Data Scheduler</field>
<field name="name">Update System Logs</field>
<field eval="True" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
@ -11,7 +11,7 @@
<field name="numbercall">-1</field>
<field eval="True" name="doall" />
<field eval="'publisher_warranty.contract'" name="model" />
<field eval="'send_ping'" name="function" />
<field eval="'get_logs'" name="function" />
<field eval="'(None,)'" name="args" />
</record>

View File

@ -7,7 +7,7 @@
<field name="model">publisher_warranty.contract</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Publisher Warranty Contract">
<tree string="Publisher Warranty Contracts">
<field name="name"/>
<field name="date_start"/>
<field name="date_stop"/>
@ -71,7 +71,7 @@
</record>
<record id="action_publisher_warranty_contract_form" model="ir.actions.act_window">
<field name="name">Publisher Warranty Contracts</field>
<field name="name">Contracts</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">publisher_warranty.contract</field>
<field name="view_type">form</field>
@ -82,7 +82,8 @@
<menuitem name="Publisher Warranty" id="publisher_warranty"
parent="base.menu_administration" groups="base.group_extended"/>
<menuitem action="action_publisher_warranty_contract_form" id="menu_publisher_warranty_contract" parent="publisher_warranty"/>
<menuitem action="action_publisher_warranty_contract_form" id="menu_publisher_warranty_contract"
parent="publisher_warranty" sequence="2"/>
<record id="publisher_warranty_contract_add_wizard" model="ir.ui.view">
@ -113,7 +114,7 @@
</record>
<record id="action_publisher_warranty_contract_add_wizard" model="ir.actions.act_window">
<field name="name">Add Publisher Warranty Contract</field>
<field name="name">Register a contract</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">publisher_warranty.contract.wizard</field>
<field name="view_type">form</field>
@ -124,20 +125,7 @@
<menuitem
action="action_publisher_warranty_contract_add_wizard"
id="menu_publisher_warranty_contract_add"
parent="publisher_warranty" />
<record id="publisher_warranty_res_log_act_window" model="ir.actions.act_window">
<field name="name">Notifications</field>
<field name="res_model">res.log</field>
<field name="view_type">form</field>
<field name="context">{}</field>
<field name="domain">[('res_model','=','publisher_warranty.contract')]</field>
</record>
<menuitem
action="publisher_warranty_res_log_act_window"
id="menu_publisher_warranty_res_log"
parent="publisher_warranty"/>
parent="publisher_warranty" sequence="1"/>
</data>
</openerp>

View File

@ -24,13 +24,13 @@ from osv import fields, osv
class res_log(osv.osv):
_name = 'res.log'
_columns = {
'name': fields.char('Message', size=128, help='The logging message.', required=True),
'name': fields.char('Message', size=250, help='The logging message.', required=True, select=1),
'user_id': fields.many2one('res.users','User'),
'res_model': fields.char('Object', size=128),
'res_model': fields.char('Object', size=128, select=1),
'context': fields.char('Context', size=250),
'res_id': fields.integer('Object ID'),
'secondary': fields.boolean('Secondary Log', help='Do not display this log if it belongs to the same object the user is working on'),
'create_date': fields.datetime('Created Date', readonly=True),
'create_date': fields.datetime('Created Date', readonly=True, select=1),
'read': fields.boolean('Read', help="If this log item has been read, get() should not send it to the client"),
}
_defaults = {

View File

@ -11,6 +11,8 @@
<filter icon="terp-stock_align_left_24" string="Unread" domain="[('read','&lt;&gt;',True)]" name="unread"/>
<separator orientation="vertical"/>
<filter icon="terp-stock_align_left_24" string="My Logs" domain="[('user_id','=',uid)]" name="my"/>
<filter icon="terp-stock_align_left_24" string="System Logs"
domain="[('res_model','=','publisher_warranty.contract')]" name="sys"/>
<separator orientation="vertical"/>
<field name="name"/>
<field name="user_id"/>

View File

@ -490,6 +490,7 @@ class OpenERPDispatcher:
self.log('result', result, channel=logging.DEBUG_RPC_ANSWER, depth=(logger.isEnabledFor(logging.DEBUG_SQL) and 5 or 3))
return result
except Exception, e:
logging.getLogger(__name__).exception("Dispatcher error")
self.log('exception', tools.exception_to_unicode(e))
tb = getattr(e, 'traceback', sys.exc_info())
tb_s = "".join(traceback.format_exception(*tb))