本文整理汇总了Python中people.models.Person.save方法的典型用法代码示例。如果您正苦于以下问题:Python Person.save方法的具体用法?Python Person.save怎么用?Python Person.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类people.models.Person
的用法示例。
在下文中一共展示了Person.save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def handle(self, *options, **kwoptions):
if len(options) != 1:
raise CommandError('Must provide a file')
with open(options[0]) as f:
for line in f:
line = line.strip()
# ingore blank lines
if line == '':
continue
(last_name, first_name, email, username) = line.split(' ')
password_chars = string.ascii_lowercase + string.digits
password = ''.join(random.choice(password_chars)
for x in range(6))
person = Person(first_name = first_name,
last_name = last_name,
username = username,
email = email)
person.set_password(password)
person.is_staff = True
person.is_superuser = True
mail_text = EMAIL_TEXT % (first_name, username, password)
send_mail('Welcome to ROSEdu People',
mail_text,
'[email protected]',
[email])
person.save()
print 'Invited %s %s' % (first_name, last_name)
示例2: make_a_person
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def make_a_person(max=1):
g, m, f = '','',''
i = 1
while i <= max:
i += 1
rg = random.randint(1,20)
if rg >= 3:
g = random.choice(GIVEN_NAMES)
elif rg == 2:
g = random.choice(INITIALS)
rm = random.randint(1,50)
if rm == 49:
m = random.choice(GIVEN_NAMES)
elif rm == 50:
m = random.choice(INITIALS)
rf = random.randint(0,10)
if rf >= 1:
f = random.choice(FAMILY_NAMES)
name = ' '.join(('%s %s %s' % (g, m, f)).split())
if name == '':
print('The name is empty!')
return
else:
p = Person(name=name)
p.save()
print('Created person named %s' % p.name)
示例3: getPerson
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def getPerson(row, fields, importrec):
Person, created = Person.objects.get_or_create(
firstname=Person.normalize("firstname",
getfield(fields, "nom", row)),
lastname=Person.normalize("lastname",
getfield(fields, "prenom", row)),
birthday=Person.normalize("lastname",
getfield(fields, "datenaissance", row))
)
if created:
Person.sourcetype = "I"
Person.sourceid = importrec.pk
if "prenoms" in fields:
Person.prenoms = Person.normalize("prenoms",
getfield(fields, "prenoms", row))
if "uniquid" in fields:
Person.uniquid = Person.normalize("uniquid",
getfield(fields, "uniquid", row))
if "email" in fields:
Person.email = Person.normalize("email",
getfield(fields, "email", row))
if "mobile" in fields:
Person.mobile = Person.normalize("mobile",
getfield(fields, "mobile", row))
password = User.objects.make_random_password(length=8)
Person.initpass = password
Person.save()
print "Created Person ", Person
else:
print "Existing Person", Person
示例4: add_person
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def add_person(r):
if(r.method == "GET"):
return render(r, 'edit_person.jinja')
elif(r.method == "POST"):
p = Person(
first_name=r.POST['fname'],
last_name=r.POST['lname'],
nickname=r.POST['nickname'],
active=True,
info=""
)
p.save()
return redirect(people)
示例5: create
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def create(request):
"""Render a form to create an entrepreneur."""
if request.method == "POST":
user_form = UserForm(request.POST)
startup_form = StartupForm(request.POST, request.FILES)
if user_form.is_valid() and startup_form.is_valid():
user = user_form.save()
startup = startup_form.save()
person = Person()
entrepreneur = Entrepreneur()
person.user = user
person.save()
entrepreneur.person = person
entrepreneur.startup = startup
entrepreneur.save()
msg = _("Your user and startup has been created successfully.")
return render_to_response("entrepreneurs/create.html",
{
"msg": msg,
"user": user,
},
context_instance=RequestContext(request)
)
else:
return render_to_response("entrepreneurs/create.html",
{
"user_form": user_form,
"startup_form": startup_form,
},
context_instance=RequestContext(request)
)
else:
return render_to_response("entrepreneurs/create.html",
{
"user_form": UserForm(),
"startup_form": StartupForm(),
},
context_instance=RequestContext(request)
)
示例6: add
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def add(request):
name=request.GET.get('name')
age = request.GET.get('age')
person= Person()
person.name=name
person.age=age
result= person.save()
return HttpResponse(str(result))
示例7: user
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def user(request):
if request.POST:
if '_save' in request.POST:
p = Person.objects.filter(netid=request.POST['netid'])
if (p):
p1 = p[0];
p1.netid = request.POST['netid']
p1.first_name = request.POST['firstname']
p1.last_name = request.POST['lastname']
p1.lat = request.POST['lat-s']
p1.lon = request.POST['lon-s']
p1.save();
else:
p1 = Person(netid=request.POST['netid'], first_name=request.POST['firstname'],
last_name=request.POST['lastname'], lat=request.POST['lat-s'], lon=request.POST['lon-s'])
p1.save();
return HttpResponseRedirect('/')
elif '_cancel' in request.POST:
return HttpResponseRedirect('/')
示例8: activate
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def activate(self, request, activation_key):
"""
Given an an activation key, look up and activate the user
account corresponding to that key (if possible).
After successful activation, the signal
``registration.signals.user_activated`` will be sent, with the
newly activated ``User`` as the keyword argument ``user`` and
the class of this backend as the sender.
"""
activated = RegistrationProfile.objects.activate_user(activation_key)
if activated:
signals.user_activated.send(sender=self.__class__,
user=activated,
request=request)
person = Person(user=activated)
activated.save()
person.save()
return activated
示例9: execute_upoad
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def execute_upoad(file, user_id, block_id):
global ERROR
user_id = CocoUser.objects.get(user__id=user_id)
block_id = Block.objects.get(id=block_id)
file_name = str(os.path.splitext(file)[0])
file_name_list = str(os.path.splitext(file)[0].split('/')[-1])
village_errors_file = open(file_name + '_errors_village.csv', 'wb')
wrtr = csv.writer(village_errors_file, delimiter=',', quotechar='"')
wrtr.writerow(["Entry No.", "Village Name", "Error"])
village_success_file = open(file_name + '_success_village.csv', 'wb')
wrtr_success = csv.writer(village_success_file, delimiter=',', quotechar='"')
wrtr_success.writerow(["Entry No.", "Village Name"])
csvfile = open(file, 'rb')
rows_villages = csv.DictReader(csvfile)
village_querry_set = Village.objects.values_list('village_name','id').filter(block_id=block_id.id)
village_map = dict(village_querry_set)
i = 0
for row in rows_villages:
if unicode(row['Village_Name']) not in village_map:
i = i + 1
try:
village = Village(user_created_id=user_id.id,
village_name=unicode(row['Village_Name']),
block_id=block_id.id)
village.save()
village_map[unicode(row['Village_Name'])] = village.id
wrtr_success.writerow([i, unicode(row['Village_Name'])])
village_success_file.flush()
except Exception as e:
ERROR += 1
wrtr.writerow([i, unicode(row['Village_Name']), e])
village_errors_file.flush()
village_success_file.close()
village_errors_file.close()
ERROR_FILENAMES.append(file_name_list + '_errors_village.csv')
SUCCESS_FILENAMES.append(file_name_list + '_success_village.csv')
group_errors_file = open(file_name + '_errors_group.csv', 'wb')
wrtr = csv.writer(group_errors_file, delimiter=',', quotechar='"')
wrtr.writerow(["Entry No.", "Shg Name", "Error"])
group_success_file = open(file_name + '_success_group.csv', 'wb')
wrtr_success = csv.writer(group_success_file, delimiter=',', quotechar='"')
wrtr_success.writerow(["Entry No.", "Shg Name"])
csvfile = open(file, 'rb')
rows_groups = csv.DictReader(csvfile)
group_querry_set = PersonGroup.objects.values_list('group_name', 'id')
group_map = dict(group_querry_set)
i = 0
for row in rows_groups:
if unicode(row['Shg_Name']) + unicode(row['Village_Name']) not in group_map:
i = i + 1
try:
group = PersonGroup(user_created_id=user_id.id,
partner_id=user_id.partner.id,
group_name=row['Shg_Name'],
village_id=village_map[unicode(row['Village_Name'])])
group.save()
group_map[row['Shg_Name'] + unicode(row['Village_Name'])] = group.id
wrtr_success.writerow([i, row['Shg_Name']])
group_success_file.flush()
except Exception as e:
ERROR += 1
wrtr.writerow([i, row['Shg_Name'], e] )
group_errors_file.flush()
group_errors_file.close()
group_success_file.close()
ERROR_FILENAMES.append(file_name_list + '_errors_group.csv')
SUCCESS_FILENAMES.append(file_name_list + '_success_group.csv')
person_errors_file = open(file_name + '_errors_person.csv', 'wb')
wrtr = csv.writer(person_errors_file, delimiter=',', quotechar='"')
wrtr.writerow(["Entry No.", "Person Name", "Error"])
person_success_file = open(file_name + '_success_person.csv', 'wb')
wrtr_success = csv.writer(person_success_file, delimiter=',', quotechar='"')
wrtr_success.writerow(["Entry No.", "Person Name"])
csvfile = open(file, 'rb')
rows_persons = csv.DictReader(csvfile)
i = 0
for row in rows_persons:
i = i + 1
try:
person_name = ' '.join([unicode(row['Member_Name']), unicode(row['Member_Surname'])])
#.........这里部分代码省略.........
示例10: handle
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def handle(self, *args, **options):
name = u" ".join(map(lambda s: s.decode("utf8"),args))
print options
person = Person(name=name, staff=options['staff'])
person.save()
print person.pk
示例11: meet
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
def meet(request):
# check that user is authenticated
if (not request.user.is_authenticated()):
return render(request, 'product_page.html')
first = "False"
p = Person.objects.filter(netid=request.user.username)
if (not p):
p1 = Person(netid=request.user.username)
p1.save()
# get information about the user
currentNetid = request.user.username
me = Person.objects.get(netid=currentNetid)
# first time visiting the site?
if request.method == 'GET':
if (not isinstance(me.lat, Decimal)):
first = "True"
# updating profile
if request.method == 'POST':
# get information from the form
pf = ProfileForm(request.POST)
# if the form is valid, update the user's information
if pf.is_valid():
cd = pf.cleaned_data
p = Person.objects.filter(netid=currentNetid)
# is the user already in the database? If so, just updated their info
if (p):
p1 = p[0];
p1.netid = currentNetid
p1.first_name = cd['first_name']
p1.last_name = cd['last_name']
p1.lat = cd['lat_s']
p1.lon = cd['lon_s']
p1.start = cd['start']
p1.end = cd['end']
p1.company = cd['company']
p1.year = (int)(cd['year'])
p1.desired = cd['desired']
p1.gender = cd['gender']
p1.save()
# otherwise, create a new Person for the user
else:
p1 = Person(netid=currentNetid, first_name=['first_name'],
last_name=cd['last_name'], lat=cd['lat_s'],
lon=cd['lon_s'], company=cd['company'], year=cd['year'])
p1.save()
# render the templates
t = get_template('tablefill.html')
friends = me.friends.all()
tfhtml = t.render(RequestContext(request, {'friend_list': friends}))
t = get_template('myhousetablefill.html')
myhouses = me.myhouses.all()
myhtfhtml = t.render(RequestContext(request, {'my_houses': myhouses, 'me':me}))
t = get_template('profile.html')
html = t.render(RequestContext(request, {'form': pf}))
data = {'success':'true', 'html':html, 'tfhtml':tfhtml, 'myhtfhtml':myhtfhtml}
return HttpResponse(json.dumps(data), content_type = "application/json")
# form is not valid
else:
pf.errors['lat_s'] = pf.error_class()
t = get_template('profile.html')
html = t.render(RequestContext(request, {'form': pf}))
data = {'success':'false', 'html':html}
return HttpResponse(json.dumps(data), content_type = "application/json")
else:
pf = ProfileForm(initial=model_to_dict(me))
friends = me.friends.all()
houses = me.houses.all()
myhouses = me.myhouses.all()
return render(request, 'meet.html', {'form': pf, 'friend_list':friends, 'house_list':houses,'my_houses':myhouses, 'firstTime':first, 'me': me})
示例12: log
# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import save [as 别名]
dates = production['dates']
for d in dates:
start_date, end_date = d[0]
place = d[1]
location = theatres[place]
log(' %s %s %s' % (start_date, end_date, location))
if not dry_run():
ProductionPlace.objects.get_or_create(production=production_obj, place=location, start_date=start_date, end_date=end_date)
cast = production['cast']
for name in cast:
m = re.match('(.*) (.*?)$', name)
if m:
first_name, last_name = m.group(1), m.group(2)
else:
first_name, last_name = u'', name
log(' Actor: ' + first_name + ' ' + last_name)
if not dry_run():
try:
person, created = Person.objects.get_or_create(first_name=first_name, last_name=last_name)
except:
person = Person(first_name=first_name, last_name=last_name)
person.save()
Part.objects.get_or_create(production=production_obj, person=person, cast=True)
if name in castLinks:
person.web = castLinks[name]
person.save()