Commit 6c114617 authored by Clovis NZOUENDJOU's avatar Clovis NZOUENDJOU
Browse files

Fix flake 8

parent c95ee3522f0f
......@@ -16,8 +16,9 @@ class AnybusConsumerProcessImportCSV(osv.Model):
_columns = {
'process_id': fields.many2one('anybus.consumer.process',
'process', required=True, ondelete="cascade"),
'model_key': fields.char('Model key', size=64, help='Indicate the key in properties who give model'),
'process', required=True, ondelete="cascade"),
'model_key': fields.char('Model key', size=64,
help='Indicate the key in properties who give model'),
}
_defaults = {
......
......@@ -18,15 +18,15 @@ class AnybusConnection(osv.Model):
'publisher_ids': fields.one2many('anybus.publisher', 'connection_id',
'Publishers', readonly=True),
'pmessage_ids': fields.one2many('anybus.publisher.message',
'connection_id', 'Publishers message',
domain=[('state', '!=', 'done')], readonly=True),
'connection_id', 'Publishers message',
domain=[('state', '!=', 'done')], readonly=True),
'pprocess_ids': fields.function(_get_process,
method=True,
string='Outgoing process',
type='many2many',
relation='anybus.publisher.process',
readonly=True,
store=False),
method=True,
string='Outgoing process',
type='many2many',
relation='anybus.publisher.process',
readonly=True,
store=False),
}
## vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
......@@ -14,11 +14,12 @@ class AnybusPublisherMessage(osv.Model):
_columns = {
'publisher_id': fields.many2one('anybus.publisher', 'Publisher',
state={
'blocked': [('readonly', True)],
'done': [('readonly', True)],
}, required=True),
'exchange_id': fields.related('publisher_id', 'exchange_id', type='many2one', relation='anybus.entity.exchange', string='Exchange'),
state={
'blocked': [('readonly', True)],
'done': [('readonly', True)],
}, required=True),
'exchange_id': fields.related('publisher_id', 'exchange_id', type='many2one',
relation='anybus.entity.exchange', string='Exchange'),
}
_default_values_reads = [
......@@ -39,10 +40,10 @@ class AnybusPublisherMessage(osv.Model):
def _action_process_message(self, cr, uid, message, context=None):
self.pool.get('anybus.publisher').publish(cr, uid, message, context=context)
def action_process_messages(self, cr, uid, ids, context=None):
blocked_ids = self.search(cr, uid, [('state', '=', 'blocked')], context=context)
self.write(cr, uid, blocked_ids, {'state': 'draft'}, context=context)
return super(AnybusPublisherMessage, self).action_process_messages(cr, uid, ids, context=context)
return super(AnybusPublisherMessage, self).action_process_messages(cr, uid,
ids, context=context)
## vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
......@@ -11,7 +11,7 @@ class AnybusPublisherprocessNoop(osv.Model):
_columns = {
'process_id': fields.many2one('anybus.publisher.process',
'process', required=True, ondelete="cascade"),
'process', required=True, ondelete="cascade"),
}
def _process_process(self, cr, uid, id, model, model_ids, context=None):
......
......@@ -20,28 +20,30 @@ class AbstractAnybusPublisher(osv.AbstractModel):
def get_mimetypes(obj, cr, uid, context=None):
res = []
for ext, name in mimetypes.types_map.items():
res.append((name, '%s (%s)' %(name, ext)))
res.append((name, '%s (%s)' % (name, ext)))
for ext, name in mimetypes.common_types.items():
res.append((name, '%s (%s)' %(name, ext)))
res.append((name, '%s (%s)' % (name, ext)))
res.sort()
return [('none', 'Auto-detect')] + res
_columns = {
'select_routing_key': fields.selection([('binding', 'Binding'),
('fix', 'Fix'), ('none', 'None')], 'Select the routing key',
help="Binding: Use an define binding, Fix: write the routing key"),
('fix', 'Fix'), ('none', 'None')],
'Select the routing key',
help="Binding: Use an define binding,
Fix: write the routing key"),
'routing_key': fields.char('Routing key', size=255,
help='You can use user and context in quote to generate the \
help='You can use user and context in quote to generate the \
routing_key'),
'binding_id': fields.many2one('anybus.binding', 'Binding'),
#Message confuguration
'priority': fields.integer('Message priority', help='A number between \
0 and 9.'),
'content_type': fields.selection(get_mimetypes, 'Content type',
required=True),
required=True),
'content_encoding': fields.char('Content encoding', size=64),
'serializer': fields.selection([('json', 'json'), ('pickle', 'pickle'),
('yaml', 'yaml')], 'Serializer to use', required=True),
('yaml', 'yaml')], 'Serializer to use', required=True),
'compression': fields.selection(_get_aliases, 'Compression'),
}
......@@ -66,14 +68,14 @@ class AnybusPublisher(osv.Model):
'exchange_id': fields.many2one('anybus.entity.exchange', 'Exchange',
required=True),
'connection_id': fields.many2one('anybus.connection', 'Connection',
domain=[('state', '=', 'declared')], required=True),
domain=[('state', '=', 'declared')], required=True),
}
def action_publish(self, cr, uid, ids, context=None, properties={}, message="", **kwargs):
message_obj = self.pool.get('anybus.publisher.message')
for id in ids:
values = message_obj.on_change_defaut_values(cr, uid, None, id,
context=context).get('value')
context=context).get('value')
values.update({'publisher_id': id})
values.update(kwargs)
values['properties'] = str(properties)
......@@ -88,11 +90,12 @@ class AnybusPublisher(osv.Model):
raise osv.except_osv(_('Publisher error'),
_('The exchange must be declared'))
uri = self.pool.get('anybus.connection')._get_uri(cr, uid,
message.connection_id, context=context)
message.connection_id, context=context)
conn = Connection(uri)
conn.connect()
exchange = exchange_obj._get_entity(cr, uid,
message.publisher_id.exchange_id, conn.channel(), context=context)
message.publisher_id.exchange_id,
conn.channel(), context=context)
exchange.declare()
content_type = None
if message.content_type != 'none':
......@@ -102,7 +105,7 @@ class AnybusPublisher(osv.Model):
routing_key = message.routing_key
elif message.select_routing_key == 'binding':
routing_key = binding_obj._get_routing_key(cr, uid,
message.binding_id.id, context=context)
message.binding_id.id, context=context)
producer = Producer(
channel=conn.channel(),
......@@ -113,9 +116,9 @@ class AnybusPublisher(osv.Model):
)
param = {
'body': base64.decodestring(message.message or ""),
'delivery_mode':message.publisher_id.exchange_id.delivery_mode,
'priority':message.priority,
'content_encoding':message.content_encoding,
'delivery_mode': message.publisher_id.exchange_id.delivery_mode,
'priority': message.priority,
'content_encoding': message.content_encoding,
}
if content_type:
param['content_type'] = content_type
......
......@@ -2,6 +2,7 @@
from osv import osv, fields
class AnybusConnection(osv.Model):
_inherit = 'anybus.connection'
......@@ -10,12 +11,12 @@ class AnybusConnection(osv.Model):
_columns = {
'action_server_ids': fields.function(_get_action,
method=True,
string='Server trigger',
type='many2many',
relation='ir.actions.server',
readonly=True,
store=False),
method=True,
string='Server trigger',
type='many2many',
relation='ir.actions.server',
readonly=True,
store=False),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
......@@ -3,6 +3,7 @@
from osv import osv, fields, orm
import time
class AnybusIrActionServer(osv.Model):
_name = 'ir.actions.server'
_inherit = [
......@@ -19,7 +20,7 @@ class AnybusIrActionServer(osv.Model):
def __init__(self, pool, cr):
res = super(AnybusIrActionServer, self).__init__(pool, cr)
if 'anybus' not in [k for k, v in self._columns['state'].selection]:
self._columns['state'].selection.append(('anybus','Anybus'))
self._columns['state'].selection.append(('anybus', 'Anybus'))
def run(self, cr, uid, ids, context=None):
result = False
......@@ -30,12 +31,12 @@ class AnybusIrActionServer(osv.Model):
objs = obj_pool.browse(cr, uid, model_ids, context=context)
obj = objs[0] if objs else None
ctx = {
'context':context,
'context': context,
'object': obj,
'time':time,
'time': time,
'cr': cr,
'pool' : self.pool,
'uid' : uid
'pool': self.pool,
'uid': uid
}
expr = eval(str(action.condition), ctx)
if not expr:
......
......@@ -2,6 +2,7 @@
from osv import osv, fields
class AnybusConnection(osv.Model):
_inherit = 'anybus.connection'
......@@ -10,12 +11,12 @@ class AnybusConnection(osv.Model):
_columns = {
'action_user_ids': fields.function(_get_action,
method=True,
string='User trigger',
type='many2many',
relation='anybus.trigger.user',
readonly=True,
store=False),
method=True,
string='User trigger',
type='many2many',
relation='anybus.trigger.user',
readonly=True,
store=False),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
......@@ -4,6 +4,7 @@ from osv import osv, fields
import pooler
import thread
class AnybusTriggerUser(osv.Model):
_name = 'anybus.trigger.user'
_description = 'Anybus trigger user'
......@@ -68,11 +69,13 @@ class AnybusTriggerUser(osv.Model):
finally:
if not test_cursor:
cursor.close()
thread.start_new_thread(thread_post_action, (self, cr, uid, obj, method, model_ids, test_cursor))
thread.start_new_thread(thread_post_action, (self, cr, uid, obj,
method, model_ids, test_cursor))
openerp_execute = osv.object_proxy.execute
def execute(self, db, uid, obj, method, *args, **kw):
pool = pooler.get_pool(db)
cursor = pooler.get_db(db).cursor()
......
......@@ -2,6 +2,7 @@
from osv import osv, fields
class AnybusConnection(osv.Model):
_inherit = 'anybus.connection'
......@@ -10,12 +11,12 @@ class AnybusConnection(osv.Model):
_columns = {
'trigger_wizard_ids': fields.function(_get_action,
method=True,
string='User action',
type='many2many',
relation='anybus.trigger.wizard',
readonly=True,
store=False),
method=True,
string='User action',
type='many2many',
relation='anybus.trigger.wizard',
readonly=True,
store=False),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
......@@ -38,18 +38,19 @@ class AnybusTriggerWizard(osv.Model):
"domain": [],
"context": {'default_action_id': id},
"target": "new",
}, context=context)
}, context=context)
value_id = self.pool.get('ir.values').create(cr, uid, {
"name": values['name'],
"key": "action",
"key2": "client_action_multi",
"model": self.pool.get('ir.model').read(cr, uid, values['model_id'], ['model'], context=context)['model'],
"model": self.pool.get('ir.model').read(cr, uid, values['model_id'],
['model'], context=context)['model'],
"value": "ir.actions.act_window,%d" % action_id,
}, context=context)
}, context=context)
self.write(cr, uid, [id], {
'action_id': action_id,
'value_id': value_id,
}, context=context)
}, context=context)
return id
def write(self, cr, uid, ids, values, context=None):
......
Markdown is supported
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