本文整理汇总了Python中models.Contact.add_nuvius_resource方法的典型用法代码示例。如果您正苦于以下问题:Python Contact.add_nuvius_resource方法的具体用法?Python Contact.add_nuvius_resource怎么用?Python Contact.add_nuvius_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Contact
的用法示例。
在下文中一共展示了Contact.add_nuvius_resource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_sync
# 需要导入模块: from models import Contact [as 别名]
# 或者: from models.Contact import add_nuvius_resource [as 别名]
def _do_sync(data, user):
"Run updates"
resource_id = data.info.application.id.raw
contact_type = _get_contact_type(user)
for item in data.result:
item_id = None
if 'id' in item.raw:
item_id = item.id.raw
dups = _find_duplicates(resource_id, item, user)
if dups:
for contact in dups:
transaction.commit()
try:
fields = contact.contact_type.fields
contact.add_nuvius_resource(resource_id, item_id)
if item.name.raw:
contact.name = item.name.raw
if item.email:
fs = fields.filter(field_type='email')
if fs:
for iemail in item.email:
values = contact.contactvalue_set.filter(
field__in=fs, value=iemail.raw)
if not values:
value = ContactValue(
contact=contact, field=fs[0], value=iemail.raw)
value.save()
if item.phone:
fs = fields.filter(field_type='phone')
if fs:
for iphone in item.phone:
values = contact.contactvalue_set.filter(
field__in=fs, value=iphone.raw)
if not values:
value = ContactValue(
contact=contact, field=fs[0], value=iphone.raw)
value.save()
if item.address:
fs = fields.filter(name='address')
if fs:
for iaddress in item.address:
values = contact.contactvalue_set.filter(
field__in=fs, value__icontains=iaddress.raw)
if not values:
value = ContactValue(
contact=contact, field=fs[0], value=iaddress.raw)
value.save()
if item.website:
fs = fields.filter(name='website')
if fs:
for iwebsite in item.website:
values = contact.contactvalue_set.filter(
field__in=fs, value__icontains=iwebsite.raw)
if not values:
value = ContactValue(
contact=contact, field=fs[0], value=iwebsite.raw)
value.save()
contact.auto_notify = False
contact.save()
transaction.commit()
except KeyboardInterrupt:
transaction.rollback()
break
except:
transaction.rollback()
else:
if contact_type and item.name.raw:
transaction.commit()
try:
contact = Contact(contact_type=contact_type)
contact.add_nuvius_resource(resource_id, item_id)
contact.name = item.name.raw
contact.auto_notify = False
contact.set_user(user)
contact.save()
fields = contact_type.fields
if item.email:
fs = fields.filter(field_type='email')
if fs:
for iemail in item.email:
value = ContactValue(
contact=contact, field=fs[0], value=iemail.raw)
value.save()
if item.phone:
fs = fields.filter(field_type='phone')
if fs:
for iphone in item.phone:
value = ContactValue(
contact=contact, field=fs[0], value=iphone.raw)
value.save()
if item.address:
fs = fields.filter(name='address')
if fs:
for iaddress in item.address:
value = ContactValue(
contact=contact, field=fs[0], value=iaddress.raw)
#.........这里部分代码省略.........