本文整理汇总了Python中treeio.identities.models.Contact类的典型用法代码示例。如果您正苦于以下问题:Python Contact类的具体用法?Python Contact怎么用?Python Contact使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Contact类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_model_liability
def test_model_liability(self):
"Test liability model"
contact_type = ContactType(name='test')
contact_type.save()
contact = Contact(name='test', contact_type=contact_type)
contact.save()
currency = Currency(code="GBP",
name="Pounds",
symbol="L",
is_default=True)
currency.save()
account = Account(
name='test', owner=contact, balance_currency=currency)
account.save()
obj = Liability(name='test',
source=contact,
target=contact,
account=account,
value=10,
value_currency=currency)
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
示例2: test_model_contact
def test_model_contact(self):
"Test Contact model"
type = ContactType(name='Test', slug='test')
type.save()
obj = Contact(name='Test', contact_type=type)
obj.save()
self.assertEquals('Test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
示例3: test_model_equity
def test_model_equity(self):
"Test equity model"
contact_type = ContactType(name='test')
contact_type.save()
contact = Contact(name='test', contact_type=contact_type)
contact.save()
obj = Equity(issue_price=10, sell_price=10, issuer=contact, owner=contact)
obj.save()
self.assertNotEquals(obj.id, None)
obj.delete()
示例4: test_model_asset
def test_model_asset(self):
"Test asset model"
contact_type = ContactType(name='test')
contact_type.save()
contact = Contact(name='test', contact_type=contact_type)
contact.save()
obj = Asset(name='test', owner=contact)
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
示例5: setUp
def setUp(self):
"Initial Setup"
if not self.prepared:
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(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.stream = MessageStream(name='test')
self.stream.set_default_user()
self.stream.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
示例6: setUp
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.stream = MessageStream(name='test')
self.stream.set_default_user()
self.stream.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
示例7: setUp
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
# Create objects
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='Person')
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.field = ContactField(name='Test', label='test', field_type='text')
self.field.set_default_user()
self.field.save()
self.client = Client()
self.prepared = True
示例8: messaging_compose
def messaging_compose(request, response_format='html'):
"New message page"
user = request.user.get_profile()
if request.POST:
if not 'cancel' in request.POST:
message = Message()
message.author = user.get_contact()
if not message.author:
return user_denied(request,
message="You can't send message without a Contact Card assigned to you.",
response_format=response_format)
form = MessageForm(
request.user.get_profile(), None, None, request.POST, instance=message)
if form.is_valid():
message = form.save()
message.recipients.add(user.get_contact())
message.set_user_from_request(request)
message.read_by.add(user)
try:
# if email entered create contact and add to recipients
if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']:
try:
conf = ModuleSetting.get_for_module(
'treeio.messaging', 'default_contact_type')[0]
default_contact_type = ContactType.objects.get(
pk=long(conf.value))
except Exception:
default_contact_type = None
emails = request.POST[
'multicomplete_recipients'].split(',')
for email in emails:
emailstr = unicode(email).strip()
if re.match('[a-zA-Z0-9+_\-\.][email protected][0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr):
contact, created = Contact.get_or_create_by_email(
emailstr, contact_type=default_contact_type)
message.recipients.add(contact)
if created:
contact.set_user_from_request(request)
except:
pass
# send email to all recipients
message.send_email()
return HttpResponseRedirect(reverse('messaging'))
else:
return HttpResponseRedirect(reverse('messaging'))
else:
form = MessageForm(request.user.get_profile(), None)
context = _get_default_context(request)
context.update({'form': form})
return render_to_response('messaging/message_compose', context,
context_instance=RequestContext(request), response_format=response_format)
示例9: save
def save(self, *args, **kwargs):
"Form processor"
profile = None
if self.invitation:
# Create DjangoUser
django_user = django_auth.User(
username=self.cleaned_data['username'], password='')
django_user.set_password(self.cleaned_data['password'])
django_user.save()
# Crate profile
try:
profile = django_user.get_profile()
except:
profile = User()
profile.user = django_user
profile.name = django_user.username
profile.default_group = self.invitation.default_group
profile.save()
# Create contact
try:
contact_type = ContactType.objects.get(
Q(name='Person') | Q(slug='person'))
except:
contact_type = ContactType.objects.all()[0]
try:
# Check if contact has already been created (e.g. by a signals
contact = profile.get_contact()
if not contact:
contact = Contact()
except:
contact = Contact()
contact.name = self.cleaned_data['name']
contact.contact_type = contact_type
contact.related_user = profile
contact.save()
# Set email
try:
emailfield = contact_type.fields.filter(field_type='email')[0]
email = ContactValue(
value=self.invitation.email, field=emailfield, contact=contact)
email.save()
except:
pass
# Add quick start widget
widget = Widget(user=profile,
perspective=profile.get_perspective(),
module_name='treeio.core',
widget_name='widget_welcome')
widget.save()
return profile
示例10: test_model_account
def test_model_account(self):
"Test account model"
contact_type = ContactType(name='test')
contact_type.save()
contact = Contact(name='test', contact_type=contact_type)
contact.save()
currency = Currency(code="GBP",
name="Pounds",
symbol="L",
is_default=True)
currency.save()
obj = Account(name='test', owner=contact,
balance_currency=currency)
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
示例11: process_msg
def process_msg(self, msg, attrs, attachments):
"Save message, Cap!"
from treeio.messaging.models import Message
try:
conf = ModuleSetting.get_for_module('treeio.messaging', 'default_contact_type')[0]
default_contact_type = ContactType.objects.get(pk=long(conf.value))
except:
default_contact_type = None
email_author, created = Contact.get_or_create_by_email(attrs.author_email.encode('utf-8', errors='replace'), attrs.author_name.encode('utf-8', errors='replace'), default_contact_type)
if created:
email_author.copy_permissions(self.stream)
# check if the message is already retrieved
# XXX should store a unique 'msg-id'
existing = Message.objects.filter(stream=self.stream, title=attrs.subject, author=email_author, body=attrs.body.encode('utf-8', errors='replace')).exists()
if not existing:
message = None
if attrs.subject[:3] == 'Re:':
# process replies
if attrs.subject[:4] == 'Re: ':
original_subject = attrs.subject[4:]
else:
original_subject = attrs.subject[3:]
try:
query = Q(reply_to__isnull=True) & Q(recipients=email_author) & (Q(title=original_subject) | Q(title=attrs.subject))
original = Message.objects.filter(query).order_by('-date_created')[:1][0]
message = Message(title=attrs.subject.encode('utf-8', errors='replace'), body=attrs.body.encode('utf-8', errors='replace').decode('unicode_escape'), author=email_author,
stream=self.stream, reply_to=original)
if attrs.email_date:
message.date_created = attrs.email_date
message.rfc822 = msg.as_string().decode('utf-8', errors='replace')
message.save()
message.copy_permissions(original)
original.read_by.clear()
except IndexError:
pass
if not message:
message = Message(title=attrs.subject.encode('utf-8', errors='replace'), body=attrs.body.encode('utf-8', errors='replace').decode('unicode_escape'), author=email_author, stream=self.stream)
if attrs.email_date:
message.date_created = attrs.email_date
message.rfc822 = msg.as_string().decode('utf-8', errors='replace') #utf-8', errors='replace')
message.save()
message.copy_permissions(self.stream)
message.recipients.add(email_author)
示例12: create
def create(self, request, *args, **kwargs):
"Send email to some recipients"
user = request.user.get_profile()
if request.data is None:
return rc.BAD_REQUEST
if request.data.has_key('stream'):
stream = getOrNone(MessageStream, request.data['stream'])
if stream and not user.has_permission(stream, mode='x'):
return rc.FORBIDDEN
message = Message()
message.author = user.get_contact()
if not message.author:
return rc.FORBIDDEN
form = MessageForm(user, None, None, request.data, instance=message)
if form.is_valid():
message = form.save()
message.recipients.add(user.get_contact())
message.set_user_from_request(request)
message.read_by.add(user)
try:
# if email entered create contact and add to recipients
if 'multicomplete_recipients' in request.POST and request.POST['multicomplete_recipients']:
try:
conf = ModuleSetting.get_for_module(
'treeio.messaging', 'default_contact_type')[0]
default_contact_type = ContactType.objects.get(
pk=long(conf.value))
except Exception:
default_contact_type = None
emails = request.POST[
'multicomplete_recipients'].split(',')
for email in emails:
emailstr = unicode(email).strip()
if re.match('[a-zA-Z0-9+_\-\.][email protected][0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+', emailstr):
contact, created = Contact.get_or_create_by_email(
emailstr, contact_type=default_contact_type)
message.recipients.add(contact)
if created:
contact.set_user_from_request(request)
except:
pass
# send email to all recipients
message.send_email()
return message
else:
self.status = 400
return form.errors
示例13: test_model_message
def test_model_message(self):
"Test message"
contact_type = ContactType(name='test')
contact_type.save()
contact = Contact(name='test', contact_type=contact_type)
contact.save()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
user = User(name='test', user=self.user)
user.save()
stream = MessageStream(name='test')
stream.save()
obj = Message(title='test', body='test', author=contact, stream=stream)
obj.save()
self.assertEquals('test', obj.title)
self.assertNotEquals(obj.id, None)
obj.delete()
示例14: parse_contacts
def parse_contacts(self, contacts):
"Break down CSV file into fields"
for row in contacts:
# Tidy up keys (iterkeys strip())
try:
type = row['type']
except Exception:
pass # Set type to default type
try:
name = row['name']
except Exception:
try:
firstname = row['firstname']
surname = row['surname']
name = firstname + " " + surname
except Exception:
continue
contact_type = ContactType.objects.filter(name=type)
if contact_type:
contact_type = contact_type[0]
# Create a new contact if it doesn't exist
contact_exists = Contact.objects.filter(
name=name, contact_type__name=type, trash=False)
# TODO: If one does exist then append the data on that contact
if not contact_exists:
contact = Contact()
contact.name = name
contact.contact_type = contact_type
contact.auto_notify = False
contact.save()
fields = contact_type.fields.filter(trash=False)
for field in fields:
if field.name in row:
x = row[field.name]
if field.field_type == 'email':
x = self.verify_email(x)
if field.field_type == 'url':
x = self.verify_url(x)
if x:
contact_value = ContactValue()
contact_value.field = field
contact_value.contact = contact
contact_value.value = x
contact_value.save()
示例15: FinanceViewsTest
class FinanceViewsTest(TestCase):
"Finance functional tests for views"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(
username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(
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.category = Category(name='test')
self.category.set_default_user()
self.category.save()
self.equity = Equity(
issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact)
self.equity.set_default_user()
self.equity.save()
self.asset = Asset(name='test', owner=self.contact)
self.asset.set_default_user()
self.asset.save()
self.tax = Tax(name='test', rate=10)
self.tax.set_default_user()
self.tax.save()
self.currency = Currency(code="GBP",
name="Pounds",
symbol="L",
is_default=True)
self.currency.set_default_user()
self.currency.save()
self.account = Account(
name='test', owner=self.contact, balance_currency=self.currency)
self.account.set_default_user()
self.account.save()
self.liability = Liability(name='test',
source=self.contact,
target=self.contact,
account=self.account,
value=10,
value_currency=self.currency)
self.liability.set_default_user()
self.liability.save()
self.transaction = Transaction(name='test', account=self.account, source=self.contact,
target=self.contact, value=10, value_currency=self.currency)
self.transaction.set_default_user()
self.transaction.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_finance_login(self):
"Test index page with login at /finance/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('finance'))
self.assertEquals(response.status_code, 200)
def test_finance_index_login(self):
"Test index page with login at /finance/index/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
#.........这里部分代码省略.........