本文整理汇总了Python中core.models.Person.save方法的典型用法代码示例。如果您正苦于以下问题:Python Person.save方法的具体用法?Python Person.save怎么用?Python Person.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.Person
的用法示例。
在下文中一共展示了Person.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_user
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def add_user(req):
user = req.user
stub = user.username.split('@')[0]
user.email = req.POST['email']
user.first_name = req.POST['first_name']
user.last_name = req.POST['last_name']
user.save()
org_group = OrgGroup(pk=req.POST['team'])
office_location = OfficeLocation(pk=req.POST['office_location'])
attributes = {
'user': user,
'stub': stub,
'title': req.POST['title'],
'office_location': office_location,
'org_group': org_group,
'office_phone': req.POST['office_phone'],
'mobile_phone': req.POST['mobile_phone']
}
if req.FILES:
attributes['photo_file'] = req.FILES['photo_file']
person = Person(**attributes)
person.save()
return user
示例2: get_facebook_user
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def get_facebook_user(cls, client, facebook_id):
"""
method to retrieve facebook user, if it doesn't exist it'll be created
"""
try:
fbu = cls.objects.get(facebook_id__exact=facebook_id, deleted=False)
except cls.DoesNotExist:
try:
user_data = client.obj_id(
facebook_id,
fields='id,name,first_name,middle_name,last_name,link,username,gender,locale,picture',
)
except FacebookGenericError:
user_data = client.obj_id(
facebook_id,
fields='id,name,link,picture',
)
person = Person(
name=user_data[u'name'] if u'name' in user_data else None,
)
person.save()
fbu = cls(
person=person,
facebook_id=user_data[u'id'],
name=user_data[u'name'] if u'name' in user_data else None,
link=user_data[u'link'] if u'link' in user_data else None,
page=True,
)
if u'picture' in user_data:
fbu.picture = user_data[u'picture'][u'data'][u'url']
else:
person = Person(
name=user_data[u'name'] if u'name' in user_data else None,
gender=user_data[u'gender'] if u'gender' in user_data else None,
)
person.save()
fbu = cls(
person=person,
facebook_id=user_data[u'id'],
name=user_data[u'name'] if u'name' in user_data else None,
first_name=user_data[u'first_name'] if u'first_name' in user_data else None,
middle_name=user_data[u'middle_name'] if u'middle_name' in user_data else None,
last_name=user_data[u'last_name'] if u'last_name' in user_data else None,
link=user_data[u'link'] if u'link' in user_data else None,
username=user_data[u'username'] if u'username' in user_data else None,
gender=user_data[u'gender'] if u'gender' in user_data else None,
locale=user_data[u'locale'] if u'locale' in user_data else None,
picture=user_data[u'picture'][u'data'][u'url'] if u'picture' in user_data else None,
page=False,
)
fbu.save()
return fbu
示例3: create_superuser
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def create_superuser():
user = get_user_model().objects.create_superuser('[email protected]', '[email protected]', '1')
# If using collab, person objects needs to be created too
if 'core' in settings.INSTALLED_APPS:
from core.models import Person
person = Person()
person.user = user
person.save()
示例4: get_user
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def get_user(self, user, name, profile_picture):
person = None
try:
person = Person.objects.get(login=user)
except Person.DoesNotExist:
person = Person(login=user, name=name, profile_picture=profile_picture)
person.save()
return person
示例5: test_generating_slug
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def test_generating_slug(self):
person = Person(name='Charles Babbage')
person.save()
self.assertEqual(
person.slug,
'charles-babbage',
)
示例6: test_helper_no_profile
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def test_helper_no_profile(self):
u = get_user_model()()
u.first_name = "John"
u.last_name = "Smith"
u.save()
self.assertEquals(False, helpers.user_has_profile(u))
p = Person()
p.user = u
p.save()
self.assertEquals(True, helpers.user_has_profile(u))
示例7: handle
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def handle(self, *args, **options):
last_names = [
'Sherman', 'Maddox', 'Montgomery', 'Small', 'Larsen', 'Marsh', 'Gardner', 'White', 'Gill', 'Pennington', 'Stein', 'Kirby', 'Jennings', 'French', 'Glass', 'Velasquez', 'Doyle', 'York', 'Fisher', 'Strong', 'Henson', 'Harmon', 'Higgins', 'James', 'Hancock', 'Drake', 'Eaton', 'Gordon', 'Harrington', 'Blevins', 'Avila', 'Solis', 'Richmond', 'Stark', 'Haynes', 'Durham', 'Montoya', 'Barrett', 'Chase', 'Mckay', 'Little', 'Perry', 'Howard', 'Caldwell', 'West', 'Fox', 'Long', 'Wright', 'Foster', 'Sloan', 'Frazier', 'Lowe', 'Cabrera', 'Barron', 'Ayala', 'Frank', 'Hammond', 'Orr', 'Holloway', 'King', 'Rush', 'Wiley', 'Neal', 'Davis', 'Fulton', 'Webb', 'Sanchez', 'Strickland', 'Clark', 'Middleton', 'Moody', 'Owens', 'Graham', 'Cotton', 'Shaffer', 'Hawkins',
'Cooper', 'Justice', 'Clarke', 'Mcconnell', 'Mccarthy', 'Macdonald', 'Castillo', 'Gilbert', 'Horton', 'Finley', 'Beard', 'Sanders', 'Levy', 'Richard', 'Bowen', 'Grant', 'Wilkins', 'Ramsey', 'Lynch', 'Koch', 'Mercado', 'Roach', 'Bond', 'Lane', 'Tanner', 'Byers', 'Humphrey', 'Austin', 'Carney', 'Golden', 'Pope', 'Kramer', 'Ellison', 'Jefferson', 'Duffy', 'Gross', 'Mcmahon', 'Hudson', 'Mckee', 'Atkinson', 'Bush', 'Thompson', 'Faulkner', 'Christian', 'Ingram', 'Cannon', 'Gay', 'Nieves', 'Hodges', 'Langley', 'Watson', 'Woods', 'Gallagher', 'Delacruz', 'Stafford', 'Knight', 'Kerr', 'Chapman', 'Roman', 'Christensen', 'Robles', 'Mathews', 'Waller', 'Buckley', 'Myers', 'Powers', 'Lindsay', 'Gates', 'Miller', 'Johns', 'Morin', 'Fleming', 'Bishop', 'Clements']
first_names = [
'Sarah', 'Ian', 'Upton', 'Uriah', 'Hayden', 'Zia', 'Lila', 'Benjamin', 'Addison', 'Vivian', 'Kirby', 'Oscar', 'Demetrius', 'Hashim', 'Michelle', 'Odessa', 'Phillip', 'Michael', 'Dante', 'Omar', 'Dominic', 'Wing', 'Joshua', 'Charlotte', 'Thomas', 'Aquila', 'Rana', 'Jolene', 'Felix', 'Cailin', 'Tatiana', 'Oprah', 'Belle', 'Sydnee', 'Kuame', 'Fleur', 'Matthew', 'Sylvia', 'Mary', 'Deborah', 'Ross', 'Hyacinth', 'Jacqueline', 'Jessica', 'Callie', 'Ariana', 'Leo', 'Desiree', 'Lunea', 'Chava', 'Jorden', 'Rudyard', 'Cally', 'Knox', 'Arthur', 'Dana', 'Rebekah', 'Yen', 'Hadassah', 'Duncan', 'Ginger', 'Valentine', 'Ivana', 'Iona', 'Jemima', 'Dorothy', 'Joan', 'Timothy', 'Amity', 'Uriel', 'Skyler', 'Phelan', 'Alma', 'Hadley',
'Quemby', 'Sonya', 'Axel', 'Slade', 'Riley', 'Rajah', 'Giselle', 'Selma', 'Nadine', 'Pascale', 'Carol', 'Steel', 'Lane', 'Emi', 'Trevor', 'Wyatt', 'Claire', 'Harlan', 'Liberty', 'Alexandra', 'Avram', 'Barbara', 'Rashad', 'Holmes', 'Kenneth', 'Preston', 'Patience', 'Adele', 'Alfonso', 'Harrison', 'Julian', 'Jena', 'Peter', 'Kessie', 'Katell', 'Denton', 'Piper', 'Jerry', 'Teegan', 'Chandler', 'Walter', 'Cheryl', 'Desirae', 'Tasha', 'Hunter', 'Logan', 'Tatyana', 'Gail', 'Galvin', 'Dara', 'Athena', 'Kay', 'Dustin', 'Faith', 'Mariam', 'Leroy', 'Edan', 'Alexis', 'Nissim', 'Octavia', 'Kareem', 'Heidi', 'Aspen', 'Gregory', 'Garrison', 'Jolie', 'Gloria', 'Alec', 'Asher', 'Julie', 'Ayanna', 'Gavin', 'Germane', 'Bertha', 'Quinn', 'Tarik']
office_location = OfficeLocation.objects.get(pk='DC123')
for x in xrange(int(args[0])):
while True:
first_name = first_names[int(random.random() *
len(first_names))]
last_name = last_names[int(random.random() * len(last_names))]
username = last_name + first_name[0]
email = username + '@exmaple.com'
if not get_user_model().objects.filter(username=email).exists():
break
user_attr = {
'first_name': first_name,
'last_name': last_name,
'is_active': True,
'is_superuser': False,
'date_joined': '2012-03-01T16:03:14Z',
'password': 'pbkdf2_sha256$10000$ggAKkiHobFL8$xQzwPeHNX1vWr9uNmZ/gKbd17uLGZVM8QNcgmaIEAUs=',
'is_staff': True,
'email': email,
'username': email
}
userModel = get_user_model()
user = userModel(**user_attr)
user.save()
person_attr = {
'office_location': office_location,
'allow_tagging': True,
'photo_file': 'avatars/default.jpg',
'stub': username.replace('.', ''),
'office_phone': '5555555555',
'user': user,
'email_notifications': False,
'org_group': OrgGroup.objects.order_by('?')[0]
}
person = Person(**person_attr)
person.save()
self.stdout.write(
'Successfully created %d users and persons' % int(args[0]))
示例8: test_create_tags_for_person
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def test_create_tags_for_person(self):
user = UserF(username="[email protected]")
person = Person(user=user)
person.save()
tag_category = TagCategory(name='Test Category',
slug='staff-directory-test-category')
tag_category.save()
tagged_item = add_tags(person, 'TagA',
'staff-directory-test-category', user, 'person')
self.assertEqual(1, person.tags.count())
示例9: add_person
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def add_person(request):
"""
>>> from django.test import Client
>>> from django.core.urlresolver import reverse
>>> client = Client()
>>> response = client.get('add_person')
>>> response.status_code
200
>>> client.post('/add_person/', {'name': 'fred')
200
"""
items = Person.objects.all()
if request.method == 'POST': # If the form has been submitted...
form = PersonForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
newPerson = Person(
name=form.cleaned_data['name'],
bio=form.cleaned_data['bio'],
contacts=form.cleaned_data['contacts'],
surname=form.cleaned_data['surname'],
birth_date=form.cleaned_data['birth_date']
)
newPerson.save()
if request.is_ajax():
rdict = {'bad': 'false'}
if not form.is_valid():
rdict.update({'bad': 'true'})
d = {}
for e in form.errors.iteritems():
d.update({e[0]: unicode(e[1])})
rdict.update({'errs': d})
json = simplejson.dumps(rdict, ensure_ascii=False)
return HttpResponse(json, mimetype='application/javascript')
else:
return HttpResponseRedirect('/') # Redirect after POST
else:
form = PersonForm() # An unbound form
return render_to_response('add_person.html', {
'form': form,
'items': items,
},
context_instance=RequestContext(request),
)
示例10: test_single_tag_single_user
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def test_single_tag_single_user(self):
user = UserF(username="[email protected]")
person = Person(user=user)
person.save()
tag_category = TagCategory(name='Test Category',
slug='staff-directory-test-category')
tag_category.save()
tags = []
tagged_item = add_tags(person, 'TagA',
'staff-directory-test-category', user, 'person')
tags.append(tagged_item.tag.slug)
emails = _get_emails_for_tag(tags)
self.assertTrue(len(emails) == 1)
self.assertIn(user.email, emails)
示例11: test_single_tag_user_profile
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def test_single_tag_user_profile(self):
user = UserF(username="[email protected]")
user.set_password("x")
user.save()
person = Person(user=user)
person.stub = "jack"
person.save()
resp1 = self.client.login(username="[email protected]", password="x")
self.assertTrue(resp1)
tag_category = TagCategory(name='Test Category',
slug='staff-directory-test-category')
tag_category.save()
resp2 = self.client.post('/staff/add-person-to-tag/%s/hello!/' %
(person.stub), {'person_stub': person.stub,
'tag_category': 'staff-directory-test-category'})
self.assertContains(resp2, "redirect", status_code=200)
示例12: test_multiple_tags_multiple_users
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def test_multiple_tags_multiple_users(self):
user1 = UserF(username="[email protected]")
person1 = Person(user=user1)
person1.save()
user2 = UserF(username="[email protected]")
person2 = Person(user=user2)
person2.save()
user3 = UserF(username="[email protected]")
person3 = Person(user=user3)
person3.save()
tag_category = TagCategory(name='Test Category',
slug='staff-directory-test-category')
tag_category.save()
tags = []
tagged_item = add_tags(person1, 'TagA',
'staff-directory-test-category', user1, 'person')
tagged_item = add_tags(person2, 'TagA',
'staff-directory-test-category', user1, 'person')
tags.append(tagged_item.tag.slug)
tagged_item = add_tags(person2, 'TagB',
'staff-directory-test-category', user1, 'person')
tagged_item = add_tags(person3, 'TagB',
'staff-directory-test-category', user2, 'person')
tags.append(tagged_item.tag.slug)
emails = _get_emails_for_tag(tags)
self.assertTrue(len(emails) == 1)
self.assertIn(user2.email, emails)
示例13: test_no_emails
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def test_no_emails(self):
user1 = UserF(username="[email protected]")
person1 = Person(user=user1)
person1.save()
user2 = UserF(username="[email protected]")
person2 = Person(user=user2)
person2.save()
tag_category = TagCategory(name='Test Category',
slug='staff-directory-test-category')
tag_category.save()
tags = []
tagged_item = add_tags(person1, 'TagA',
'staff-directory-test-category', user1, 'person')
tags.append(tagged_item.tag.slug)
tagged_item = add_tags(person2, 'TagB',
'staff-directory-test-category', user1, 'person')
tags.append(tagged_item.tag.slug)
emails = _get_emails_for_tag(tags)
self.assertEqual(len(emails), 0)
示例14: respond_with_new_user
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def respond_with_new_user(self, request, next_url, desuprofile):
User = get_user_model()
password = create_temporary_password()
# Kompassi has stricter rules for username validation than Desusite
username = desuprofile.username.lower()
try:
valid_username(username)
except DjangoValidationError:
username = None
with transaction.atomic():
try:
User.objects.get(username=username)
except User.DoesNotExist:
# Username is free
pass
else:
# Username clash with an existing account, use safe username
username = None
if username is None:
username = "desuprofile_{id}".format(id=desuprofile.id)
user = User(
username=username,
is_active=True,
is_staff=False,
is_superuser=False,
)
user.set_password(password)
user.save()
person = Person(
first_name=desuprofile.first_name,
surname=desuprofile.last_name,
nick=desuprofile.nickname,
email=desuprofile.email,
phone=desuprofile.phone,
birth_date=datetime.strptime(desuprofile.birth_date, '%Y-%m-%d').date() if desuprofile.birth_date else None,
notes=u'Luotu Desuprofiilista',
user=user,
)
person.save()
connection = Connection(
id=int(desuprofile.id),
desuprofile_username=desuprofile.username,
user=user,
)
connection.save()
person.setup_email_verification(request)
if 'ipa_integration' in settings.INSTALLED_APPS:
from ipa_integration.utils import create_user
create_user(user, password)
messages.success(request, u'Sinulle on luotu Desuprofiiliisi liitetty Kompassi-tunnus. Tervetuloa Kompassiin!')
return respond_with_connection(request, next_url, connection)
示例15: respond_with_new_user
# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import save [as 别名]
def respond_with_new_user(self, request, next_url, desuprofile):
"""
This implements the following case:
2. No Kompassi account is linked to this Desuprofile, and no Kompassi account matches the
Desuprofile by email address. A new Kompassi account is created and logged in.
"""
User = get_user_model()
password = create_temporary_password()
# Kompassi has stricter rules for username validation than Desusite
username = desuprofile.username.lower()
try:
valid_username(username)
except DjangoValidationError:
username = None
else:
try:
User.objects.get(username=username)
except User.DoesNotExist:
# Username is free
pass
else:
# Username clash with an existing account, use safe username
username = None
if username is None:
username = "desuprofile_{id}".format(id=desuprofile.id)
with transaction.atomic():
user = User(
username=username,
is_active=True,
is_staff=False,
is_superuser=False,
)
user.set_password(password)
user.save()
person = Person(
first_name=desuprofile.first_name.strip(),
surname=desuprofile.last_name.strip(),
nick=desuprofile.nickname.strip(),
email=desuprofile.email.strip(),
phone=desuprofile.phone.strip(),
birth_date=(
datetime.strptime(desuprofile.birth_date.strip(), '%Y-%m-%d').date()
if desuprofile.birth_date
else None
),
notes='Luotu Desuprofiilista',
user=user,
)
person.save()
connection = Connection(
id=int(desuprofile.id),
desuprofile_username=desuprofile.username,
user=user,
)
connection.save()
person.apply_state_new_user(request, password)
messages.success(request, 'Sinulle on luotu Desuprofiiliisi liitetty Kompassi-tunnus. Tervetuloa Kompassiin!')
return respond_with_connection(request, next_url, connection)