示例#1
0
 def doRemoveSuppliers(self, *args, **kwargs):
     """
     Action method.
     """
     current_suppliers = contactsdb.suppliers()
     desired_suppliers = settings.getSuppliersNumberDesired()
     if len(current_suppliers) < desired_suppliers:
         lg.warn('must have more suppliers %d<%d' % (
             len(current_suppliers), desired_suppliers))
     removed_suppliers = []
     for supplier_idurl in self.dismiss_list:
         if supplier_idurl not in current_suppliers:
             lg.warn('%s not a supplier' % supplier_idurl)
             continue
         pos = current_suppliers.index(supplier_idurl)
         # current_suppliers.remove(supplier_idurl)
         current_suppliers[pos] = ''
         removed_suppliers.append((pos, supplier_idurl,))
         misc.writeSupplierData(
             supplier_idurl,
             'disconnected',
             time.strftime('%d-%m-%Y %H:%M:%S'),
             my_id.getLocalID(),
         )
     current_suppliers = current_suppliers[:desired_suppliers]
     contactsdb.update_suppliers(current_suppliers)
     contactsdb.save_suppliers()
     from main import control
     control.on_suppliers_changed(current_suppliers)
     for position, supplier_idurl in removed_suppliers:
         events.send('supplier-modified', dict(
             new_idurl=None, old_idurl=supplier_idurl, position=position,
         ))
     lg.out(2, '!!!!!!!!!!! REMOVE SUPPLIERS : %d' % len(self.dismiss_list))
示例#2
0
 def doRemoveSuppliers(self, arg):
     """
     Action method.
     """
     current_suppliers = contactsdb.suppliers()
     desired_suppliers = settings.getSuppliersNumberDesired()
     if len(current_suppliers) < desired_suppliers:
         lg.warn('must have more suppliers %d<%d' % (
             len(current_suppliers), desired_suppliers))
     for supplier_idurl in self.dismiss_list:
         if supplier_idurl not in current_suppliers:
             lg.warn('%s not a supplier' % supplier_idurl)
             continue
         pos = current_suppliers.index(supplier_idurl)
         # current_suppliers.remove(supplier_idurl)
         current_suppliers[pos] = ''
         misc.writeSupplierData(
             supplier_idurl,
             'disconnected',
             time.strftime('%d-%m-%Y %H:%M:%S'))
     current_suppliers = current_suppliers[:desired_suppliers]
     contactsdb.update_suppliers(current_suppliers)
     contactsdb.save_suppliers()
     if settings.NewWebGUI():
         from web import control
         control.on_suppliers_changed(current_suppliers)
     else:
         from web import webcontrol
         webcontrol.OnListSuppliers()
     lg.out(2, '!!!!!!!!!!! REMOVE SUPPLIERS : %d' % len(self.dismiss_list))
示例#3
0
 def doSubstituteSupplier(self, arg):
     """
     Action method.
     """
     new_idurl = arg
     current_suppliers = list(contactsdb.suppliers())
     if new_idurl in current_suppliers:
         raise Exception('%s is already supplier' % new_idurl)
     position = -1
     old_idurl = None
     for i in range(len(current_suppliers)):
         if current_suppliers[i].strip() == '':
             position = i
             break
         if current_suppliers[i] in self.dismiss_list:
             # self.dismiss_list.remove(current_suppliers[i])
             position = i
             old_idurl = current_suppliers[i]
             break
     lg.out(10, 'fire_hire.doSubstituteSupplier position=%d' % position)
     if position < 0:
         current_suppliers.append(new_idurl)
     else:
         current_suppliers[position] = new_idurl
     contactsdb.update_suppliers(current_suppliers)
     contactsdb.save_suppliers()
     misc.writeSupplierData(
         new_idurl,
         'connected',
         time.strftime('%d-%m-%Y %H:%M:%S'),
         my_id.getLocalID(),
     )
     if settings.NewWebGUI():
         from web import control
         control.on_suppliers_changed(current_suppliers)
     else:
         from web import webcontrol
         webcontrol.OnListSuppliers()
     if position < 0:
         lg.out(2, '!!!!!!!!!!! ADDED NEW SUPPLIER : %s' % (new_idurl))
         events.send('supplier-modified', dict(
             new_idurl=new_idurl, old_idurl=None, position=(len(current_suppliers) - 1),
         ))
     else:
         if old_idurl:
             lg.out(2, '!!!!!!!!!!! SUBSTITUTE EXISTING SUPPLIER %d : %s->%s' % (position, old_idurl, new_idurl))
             events.send('supplier-modified', dict(
                 new_idurl=new_idurl, old_idurl=old_idurl, position=position,
             ))
         else:
             lg.out(2, '!!!!!!!!!!! REPLACE EMPTY SUPPLIER %d : %s' % (position, new_idurl))
             events.send('supplier-modified', dict(
                 new_idurl=new_idurl, old_idurl=None, position=position,
             ))
     self.restart_interval = 1.0
示例#4
0
 def doSubstituteSupplier(self, arg):
     """
     Action method.
     """
     new_idurl = arg
     current_suppliers = list(contactsdb.suppliers())
     if new_idurl in current_suppliers:
         raise Exception('%s is already supplier' % new_idurl)
     position = -1
     old_idurl = None
     for i in range(len(current_suppliers)):
         if current_suppliers[i].strip() == '':
             position = i
             break
         if current_suppliers[i] in self.dismiss_list:
             # self.dismiss_list.remove(current_suppliers[i])
             position = i
             old_idurl = current_suppliers[i]
             break
     lg.out(10, 'fire_hire.doSubstituteSupplier position=%d' % position)
     if position < 0:
         current_suppliers.append(new_idurl)
     else:
         current_suppliers[position] = new_idurl
     contactsdb.update_suppliers(current_suppliers)
     contactsdb.save_suppliers()
     misc.writeSupplierData(
         new_idurl,
         'connected',
         time.strftime('%d-%m-%Y %H:%M:%S'))
     if settings.NewWebGUI():
         from web import control
         # control.on_suppliers_changed(current_suppliers)
     else:
         from web import webcontrol
         webcontrol.OnListSuppliers()
     if position < 0:
         lg.out(2, '!!!!!!!!!!! ADD SUPPLIER : %s' % (new_idurl))
     else:
         if old_idurl:
             lg.out(
                 2, '!!!!!!!!!!! SUBSTITUTE SUPPLIER %d : %s->%s' %
                 (position, old_idurl, new_idurl))
         else:
             lg.out(
                 2, '!!!!!!!!!!! REPLACE EMPTY SUPPLIER %d : %s' %
                 (position, new_idurl))
     self.restart_interval = 1.0
示例#5
0
 def doRemoveSuppliers(self, *args, **kwargs):
     """
     Action method.
     """
     current_suppliers = contactsdb.suppliers()
     desired_suppliers = settings.getSuppliersNumberDesired()
     if len(current_suppliers) < desired_suppliers:
         lg.warn('must have more suppliers %d<%d' %
                 (len(current_suppliers), desired_suppliers))
     removed_suppliers = []
     for supplier_idurl in self.dismiss_list:
         if id_url.is_not_in(supplier_idurl,
                             current_suppliers,
                             as_field=False):
             lg.warn('%s not a supplier' % supplier_idurl)
             continue
         pos = current_suppliers.index(id_url.field(supplier_idurl))
         current_suppliers[pos] = ''
         removed_suppliers.append((
             pos,
             supplier_idurl,
         ))
         misc.writeSupplierData(
             supplier_idurl,
             'disconnected',
             time.strftime('%d-%m-%Y %H:%M:%S'),
             my_id.getLocalID(),
         )
     current_suppliers = current_suppliers[:desired_suppliers]
     contactsdb.update_suppliers(current_suppliers)
     contactsdb.save_suppliers()
     from main import control
     control.on_suppliers_changed(current_suppliers)
     for position, supplier_idurl in removed_suppliers:
         events.send(
             'supplier-modified',
             dict(
                 new_idurl=None,
                 old_idurl=supplier_idurl,
                 position=position,
             ))
     lg.info(
         'removed some suppliers : %d  desired_suppliers=%d current_suppliers=%d'
         % (len(self.dismiss_list), desired_suppliers,
            len(contactsdb.suppliers())))
     if _Debug:
         lg.out(_DebugLevel,
                '    my current suppliers: %r' % contactsdb.suppliers())