本文整理汇总了Python中models.Contact类的典型用法代码示例。如果您正苦于以下问题:Python Contact类的具体用法?Python Contact怎么用?Python Contact使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Contact类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_contacts
def upload_contacts(request):
if not request.user.is_authenticated():
return HttpResponse('You are not logged in')
if request.FILES.__contains__('csv'):
rows = csv.reader(request.FILES['csv'])
count = 0
for row in rows:
if count > 0 and len(row) == 11:
contactExists = Contact.objects.filter(email=row[4]).count()
if not contactExists:
contact = Contact(
first_name = row[0],
last_name = row[1],
phone = row[2],
mobile = row[3],
email = row[4],
address = row[5],
colony = row[6],
city = row[7],
zip_code = row[8],
birth_date = row[10] if row[10] != '' else '1988-11-16',
amount = '',
period = '',
payment = '',
tax_info = ''
)
contact.save()
if len(row[9]) > 0:
for group in Group.objects.filter(id__in=row[9].split(' ')):
contact.group.add(group)
contact.save()
count+=1
return HttpResponseRedirect('/admin/impulso/contact/')
return render('admin/upload.html', {}, context_instance = RequestContext(request))
示例2: test_encoding_is_proper
def test_encoding_is_proper(self):
# test_str = unicode("✄", "utf-8")
test_str = u"✄"
name = Contact(first_name=test_str)
name.save()
name2 = Contact.objects.get(first_name=test_str)
self.assertEqual(name.first_name, name2.first_name)
示例3: test_contact_attributes
def test_contact_attributes(self):
source = Source.objects.get(slug="test")
attributes = {
'procedure' : 'test',
'procedures_long' : 'long',
'contact_by' : 'June 12',
'best_call_time' : '12am',
'hear_about_us' : 'magazine',
'date_contacted' : 'july 1',
'call_message' : 'hey there',
'location' : 'none'
}
contact_params = {
'name' : 'test',
'address' : '123 fake st.',
'city' : 'test city',
'state' : 'state',
'zip_code' : 'zip_code',
'phone' : 'phone',
'email' : 'email',
'message' : 'test',
'source' : source,
'attributes' : simplejson.dumps(attributes)
}
contact = Contact(**contact_params)
contact.save()
assert contact.json_attributes == attributes, True
assert contact.get_attribute("procedure") == "test", True
assert contact.get_attribute("procedures_long") == "long", True
示例4: setUp
def setUp(self):
# Set up Google App Engine testbed
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.testbed.init_app_identity_stub()
self.contactNumber = "+16135551234"
# Set up some handy constants
self._APP_ID = app_identity.get_application_id()
self.MAIL_SUFFIX = "@" + self._APP_ID + ".appspotmail.com"
self.XMPP_SUFFIX = "@" + self._APP_ID + ".appspotchat.com"
self.ownerPhoneNumber = "+16135554444"
self.ownerJid = "[email protected]"
self.ownerEmailAddress = "[email protected]"
self.owner = Owner(self.ownerPhoneNumber, self.ownerJid, self.ownerEmailAddress)
self.xmppvoicemail = XmppVoiceMail(self.owner)
self.communications = self.xmppvoicemail._communications = CommunicationsFixture()
# Subscribe the default sender.
defaultSender = Contact.getDefaultSender()
defaultSender.subscribed = True
Contact.update(defaultSender)
示例5: send_invitation
def send_invitation(invitation):
"""
"""
try:
user = User.objects.get(email=invitation.email)
message = "{0} added you to his contacts".format(
invitation.sender.username)
contact = Contact(owner=invitation.sender, user=user)
contact.save()
invitation.delete()
return HttpResponseRedirect(contact.get_absolute_url())
except User.DoesNotExist:
message = """
{0} Invites you to join his contacts.
You can register on http://{1}/user/create_account/ \
if you want to accept his invitation""".format(
invitation.sender.username,
Site.objects.get_current().domain
)
send_mail('An invitation sent to you',
message,
invitation.sender,
[invitation.email],
fail_silently=False
)
return HttpResponseRedirect(invitation.get_absolute_url())
示例6: new
def new(self, name, phone=None, fax=None):
contact = Contact(
name=name,
phone=phone,
fax=fax
)
contact.save()
return serialize(contact, excludes=[re.compile(r'^datetime_'),])
示例7: setUp
def setUp(self):
u = User(username='phil',email_address='[email protected]')
u.save()
ct = Contact(first_name='tom',last_name='salfield',organisation='the-hub',email_address='[email protected]',location='islington',apply_msg='about me', find_out='through the grapevine',invited_by=u)
ct.save()
self.u = u
self.ct = ct
return
示例8: contactlist
def contactlist(id):
contact = Contact.find_first('where id=?',id)
if contact is None:
raise notfound()
contactlist = Contact.find_by('where groupid=?',contact.groupid)
if contactlist:
return dict(contactlist=contactlist,group=contact.groupid)
else:
raise APIResourceNotFoundError(contact.groupid,'failed')
示例9: create_task
def create_task():
contact = Contact(
firstName = request.json['firstName'],
lastName = request.json['lastName'],
bday = request.json['bday'],
zodiac = request.json['zodiac']
)
contact.put()
return redirect(url_for('index'))
示例10: createContact
def createContact(self, subscribed):
# Create a known contact
c = Contact(
name="mrtest",
phoneNumber=self.contactNumber,
normalizedPhoneNumber=phonenumberutils.toNormalizedNumber(self.contactNumber),
subscribed=subscribed,
)
Contact.update(c)
示例11: 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()
示例12: contacts
def contacts(request):
if request.method == "GET":
contacts = Contact.objects.all()
return HttpResponse(format_contacts(contacts), mimetype="application/json")
elif request.method == "POST":
contact = Contact()
data = json.loads(request.raw_post_data)
contact.fromRaw(data)
contact.save()
return HttpResponse(format_contacts([contact]), mimetype="application/json")
示例13: done
def done(self, form_list, **kwargs):
new = Contact()
#new.user = self.request.user
for form in form_list:
for k, v in form.cleaned_data.iteritems():
setattr(new, k, v)
new.save()
return redirect('/users/')
示例14: create
def create():
form = ContactForm()
if form.validate_on_submit():
new_contact = Contact()
new_name = Name()
new_contact.email = form.email.data
new_name.first_name = form.first_name.data
new_name.last_name = form.last_name.data
new_contact.name = new_name
new_contact.group = form.group.data
new_contact.known_from = form.known_from.data
new_contact.general_comment = form.general_note.data
new_contact.current_status = form.status.data
for language in form.languages.data:
if language:
new_contact.tags.append(language)
other_tags = form.other_tags.data.replace(', ', ',').split(',')
for tag in other_tags:
new_contact.tags.append(tag)
try:
new_contact.save()
flash_string = '<a href=\"/{}\">{} {}</a> was added to the database.'
flash_string = flash_string.format(new_contact.email, new_contact.name.first_name,
new_contact.name.last_name)
flash(Markup(flash_string))
update_p_dict()
return redirect(url_for('index'))
except NotUniqueError:
msg = "That email address is already in use. <a href=\"/" + form.email.data + "\">View Entry.</a>"
form.email.errors.append(Markup(msg))
except Exception as e:
flash("There were database-raised errors in the form. Specifically, " + e.message)
return render_template('create_contact.html', form=form)
示例15: add_contact
def add_contact(data, instance_id=""):
if instance_id:
contact = Contact.get_by_id(int(instance_id))
else:
contact = Contact()
if data["name"]:
contact.name = data["name"]
if data["contacts"]:
if contact.contacts:
contact.contacts.append(data["contacts"])
else:
contact.contacts = data["contacts"]
if data["email"]:
contact.email = data["email"]
if data["facebook"]:
contact.facebook = data["facebook"]
if data["twitter"]:
contact.twitter = data["twitter"]
contact.put()
return contact