本文整理汇总了Python中person.models.Person类的典型用法代码示例。如果您正苦于以下问题:Python Person类的具体用法?Python Person怎么用?Python Person使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Person类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_name_prefix
def test_find_name_prefix(self):
name = 'Ard van der Steur'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'van der')
name = 'Ard van derSteur'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'van')
name = 'Ard van de Steur'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'van de')
name = 'Ard van Steur'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'van')
name = 'Gerard \'t Hooft'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, '\'t')
name = 'Jan Peter Balkenende'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, '')
name = 'Boris van der Ham'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'van der')
name = 'van der Ham'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'van der')
name = 'van derHam'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'van')
name = 'von Martels'
prefix, pos = Person.find_prefix(name)
self.assertEqual(prefix, 'von')
示例2: save
def save(self):
data = self.cleaned_data
person = Person(
first_name=data['first_name'],
last_name=data['last_name'],
username=data['username'],
email=data['email']
)
person.set_password(data['password'])
person.save()
# Send confirmation email
TemplateEmail(
subject='Registration',
from_email='[email protected]',
to_emails=person.email,
template='email/confirmation_email.html',
context={
'user': person,
'activation_link': absreverse('person:confirmation', kwargs={'key': person.confirmation})
}
).send()
return person
示例3: test_find_by_surname_initials
def test_find_by_surname_initials(self):
p_found = Person.find_surname_initials('Balkenende', 'J.P.')
self.assertEqual(p_found, self.p1)
p_found = Person.find_surname_initials('Balkenende', 'J.')
self.assertEqual(p_found, self.p2)
p_found = Person.find_surname_initials('Balkenende', '')
self.assertEqual(p_found, None)
p_found = Person.find_surname_initials('van der Steur', 'J.P.')
self.assertEqual(p_found, None)
p_found = Person.find_surname_initials('Koşer Kaya', 'F.')
self.assertEqual(p_found, self.p5)
示例4: CitationsTest
class CitationsTest(TestCase):
def setUp(self):
self.person1 = Person(full_name='João Carlos da Silva')
self.person1.save()
self.person2 = Person(full_name='Antonio da Silva')
self.person2.save()
self.person1_id = self.person1.pk
self.person2_id = self.person2.pk
citation2 = CitationName(person_id=self.person2_id, name='da Silva, A', default_name=True)
citation2.save()
def test_name_with_first_letters(self):
result = name_with_first_letters(self.person1.full_name.split(), False)
self.assertEqual(result, 'Silva, JC')
result = name_with_first_letters(self.person1.full_name.split(), True)
self.assertEqual(result, 'da Silva, JC')
def test_names_without_last_name(self):
result = names_without_last_name(self.person1.full_name.split(), False)
self.assertEqual(result, 'Silva, João Carlos')
result = names_without_last_name(self.person1.full_name.split(), True)
self.assertEqual(result, 'da Silva, João Carlos')
def test_first_name_and_first_letter(self):
result = first_name_and_first_letter(self.person1.full_name.split(), False)
self.assertEqual(result, 'Silva, João C')
result = first_name_and_first_letter(self.person1.full_name.split(), True)
self.assertEqual(result, 'da Silva, João C')
def test_generate_citation_names(self):
for person in Person.objects.all():
generate_citation_names(person)
citation = CitationName.objects.filter(person_id=self.person1_id, default_name=True)
self.assertEqual('Silva, JC', citation[0].name)
citation = CitationName.objects.filter(person_id=self.person2_id, default_name=True)
self.assertEqual('da Silva, A', citation[0].name)
def test_citation_names(self):
response = self.client.get(reverse('citation_names'))
self.assertEqual(response.status_code, 302)
示例5: setUp
def setUp(self):
self.person1 = Person(full_name='João Carlos da Silva')
self.person1.save()
self.person2 = Person(full_name='Antonio da Silva')
self.person2.save()
self.person1_id = self.person1.pk
self.person2_id = self.person2.pk
citation2 = CitationName(person_id=self.person2_id, name='da Silva, A', default_name=True)
citation2.save()
示例6: create_parliament_and_government
def create_parliament_and_government():
PoliticalParty.objects.all().delete()
PartyMember.objects.all().delete()
ParliamentMember.objects.all().delete()
create_parties(update_votes=False)
create_governments()
create_parliament_members(update_votes=False)
for party in PoliticalParty.objects.all():
party.set_current_parliament_seats()
set_party_votes_derived_info()
set_individual_votes_derived_info()
Person.update_persons_all(language='nl')
stats.models.update_all()
示例7: test_chantal_nijkerken_de_haan
def test_chantal_nijkerken_de_haan(self):
wikidata_id = 'Q19830701'
wikidata_item = wikidata.WikidataItem(wikidata_id)
fullname = wikidata_item.get_label()
forename, surname, surname_prefix = Person.get_name_parts(fullname, wikidata_item)
self.assertEqual(forename, 'Chantal')
self.assertEqual(surname, 'Nijkerken-de Haan')
示例8: set_district
def set_district(request):
try:
state = request.POST["state"]
if state != "XX" and state not in us.statenames: raise Exception()
district = int(request.POST["district"])
except:
return HttpResponseBadRequest()
# Who represents?
from person.models import Person
mocs = None
if state != "XX":
mocs = [p.id for p in Person.from_state_and_district(state, district)]
# Form response.
response = HttpResponse(
json.dumps({ "status": "ok", "mocs": mocs }),
content_type="application/json")
if request.user.is_authenticated():
# Save to database.
prof = request.user.userprofile()
prof.congressionaldistrict = "%s%02d" % (state, district)
prof.save()
else:
# Save in cookie.
response.set_cookie("cong_dist", json.dumps({ "state": state, "district": district }),
max_age=60*60*24*21)
return response
示例9: homepage_summary
def homepage_summary(request):
# parse & validate parameters
try:
state = request.GET["district"][0:2]
district = int(request.GET["district"][2:])
if state not in statenames: raise Exception()
except:
return None
from django.contrib.humanize.templatetags.humanize import ordinal
# view
people = Person.from_state_and_district(state, district)
feeds = [p.get_feed() for p in people]
events = Feed.get_events_for(feeds, 6)
from events.templatetags.events_utils import render_event
for i in range(len(events)):
events[i] = render_event(events[i], feeds)
if not isinstance(events[i]["date"], str):
events[i]["date"] = events[i]["date"].strftime('%B %d, %Y') # can't JSON-serialize a datetime anyway, TODO handle date_has_no_time
for k in list(events[i]): # remove anything else in case it is not JSON-serializable
if k not in ('type', 'date', 'title', 'body_html', 'url'):
del events[i][k]
# form output
return {
"state": state,
"district": district,
"state_name": statenames[state],
"district_ordinal": ordinal(district),
"reps": [ { "link": p.get_absolute_url(), "name": p.name_and_title(), "title": p.role.get_description(), "photo": p.get_photo_url() } for p in people],
"events": events,
}
示例10: parse_name_surname_initials
def parse_name_surname_initials(name):
name = remove_forename(name)
name = name.replace(',', '')
initials = find_initials(name)
surname_prefix, pos = Person.find_prefix(name)
surname = name.replace(surname_prefix, '').replace(initials, '').replace(',', '').strip()
return initials, surname, surname_prefix
示例11: test_sybrand_van_haersma_buma
def test_sybrand_van_haersma_buma(self):
wikidata_id = 'Q377266'
wikidata_item = wikidata.WikidataItem(wikidata_id)
fullname = wikidata_item.get_label()
forename, surname, surname_prefix = Person.get_name_parts(fullname, wikidata_item)
self.assertEqual(forename, 'Sybrand')
self.assertEqual(surname, 'Haersma Buma')
self.assertEqual(surname_prefix, 'van')
示例12: test_sjoerd_sjoerdsma
def test_sjoerd_sjoerdsma(self):
wikidata_id = 'Q516335'
wikidata_item = wikidata.WikidataItem(wikidata_id)
fullname = wikidata_item.get_label()
forename, surname, surname_prefix = Person.get_name_parts(fullname, wikidata_item)
self.assertEqual(forename, 'Sjoerd')
self.assertEqual(surname, 'Sjoerdsma')
self.assertEqual(surname_prefix, '')
示例13: test_jan_kees_de_jager
def test_jan_kees_de_jager(self):
wikidata_id = 'Q1666631'
wikidata_item = wikidata.WikidataItem(wikidata_id)
fullname = wikidata_item.get_label()
forename, surname, surname_prefix = Person.get_name_parts(fullname, wikidata_item)
self.assertEqual(forename, 'Jan Kees')
self.assertEqual(surname, 'Jager')
self.assertEqual(surname_prefix, 'de')
示例14: test_jan_peter_balkenende
def test_jan_peter_balkenende(self):
wikidata_id = 'Q133386'
wikidata_item = wikidata.WikidataItem(wikidata_id)
fullname = wikidata_item.get_label()
forename, surname, surname_prefix = Person.get_name_parts(fullname, wikidata_item)
self.assertEqual(forename, 'Jan Peter')
self.assertEqual(surname, 'Balkenende')
self.assertEqual(surname_prefix, '')
示例15: test_fatma_koser_kaya
def test_fatma_koser_kaya(self):
wikidata_id = 'Q467610' # Fatma Koşer Kaya
wikidata_item = wikidata.WikidataItem(wikidata_id)
fullname = wikidata_item.get_label()
forename, surname, surname_prefix = Person.get_name_parts(fullname, wikidata_item)
self.assertEqual(forename, 'Fatma')
self.assertEqual(surname, 'Koşer Kaya')
self.assertEqual(surname_prefix, '')