本文整理汇总了Python中treeio.identities.models.Contact.set_user方法的典型用法代码示例。如果您正苦于以下问题:Python Contact.set_user方法的具体用法?Python Contact.set_user怎么用?Python Contact.set_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treeio.identities.models.Contact
的用法示例。
在下文中一共展示了Contact.set_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MessagingApiTest
# 需要导入模块: from treeio.identities.models import Contact [as 别名]
# 或者: from treeio.identities.models.Contact import set_user [as 别名]
class MessagingApiTest(TestCase):
"Messaging functional tests for api"
username = "api_test"
password = "api_password"
prepared = False
authentication_headers ={"CONTENT_TYPE": "application/json",
"HTTP_AUTHORIZATION" : "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk" }
content_type ='application/json'
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
# Create objects
try:
self.group = Group.objects.get(name='test')
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name='test')
self.group.save()
try:
self.user = DjangoUser.objects.get(username=self.username)
self.user.set_password(self.password)
try:
self.profile = self.user.get_profile()
except Exception:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
except DjangoUser.DoesNotExist:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
try:
perspective = Perspective.objects.get(name='default')
except Perspective.DoesNotExist:
Perspective.objects.all().delete()
perspective = Perspective(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.user_contact = Contact(name='test', related_user=self.user.get_profile(), contact_type=self.contact_type)
self.user_contact.set_user(self.user)
self.user_contact.save()
self.stream = MessageStream(name='test')
self.stream.set_default_user()
self.stream.save()
self.mlist = MailingList(name='test', from_contact=self.contact)
self.mlist.set_default_user()
self.mlist.save()
self.message = Message(title='test', body='test', author=self.contact, stream=self.stream)
self.message.set_default_user()
self.message.save()
self.client = Client()
self.prepared = True
def test_unauthenticated_access(self):
"Test index page at /api/messaging/mlist"
response = self.client.get('/api/messaging/mlist')
# Redirects as unauthenticated
self.assertEquals(response.status_code, 401)
def test_get_mlist(self):
""" Test index page api/messaging/mlist """
response = self.client.get(path=reverse('api_messaging_mlist'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
def test_get_one_mlist(self):
response = self.client.get(path=reverse('api_messaging_mlist', kwargs={'object_ptr': self.mlist.id}), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
def test_update_mlist(self):
updates = {"name": "API mailing list", "description": "API description update", "from_contact": self.contact.id,
"members": [self.contact.id,]}
response = self.client.put(path=reverse('api_messaging_mlist', kwargs={'object_ptr': self.mlist.id}),
content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
#.........这里部分代码省略.........
示例2: _do_sync
# 需要导入模块: from treeio.identities.models import Contact [as 别名]
# 或者: from treeio.identities.models.Contact import set_user [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)
#.........这里部分代码省略.........