本文整理汇总了Python中profiles.models.Profile.title方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.title方法的具体用法?Python Profile.title怎么用?Python Profile.title使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profiles.models.Profile
的用法示例。
在下文中一共展示了Profile.title方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_player
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import title [as 别名]
def load_player(self, member_url, team, char_name=None):
""" Loads player and team membership data, and adds as member to team. Return profile, membership """
try:
member_d = self.visit_url(member_url)
except IOError:
profile_name = " ".join((word.capitalize() for word in member_url.strip("/").split("/")[-1].split("-")))
print("Page not found, constructing from {0} name and {1} charname".format(profile_name, char_name))
# create profile and membership
profile, created = Profile(name=profile_name, user=self.master_user), True
profile.save()
membership = TeamMembership(team=team, profile=profile, char_name=char_name, active=False)
membership.save()
return profile, membership
if "Player not found in database" in tostring(member_d):
print("Player not found...skipping", file=self.stdout)
return
info_ps = member_d.cssselect('.content-section-1 p')
info_h3s = member_d.cssselect('.content-section-1 h3')
profile_name = info_ps[1].text
if char_name is None:
char_name = info_ps[4].text
if "." in char_name:
char_name = char_name.split(".", 1)[0]
if Profile.objects.filter(name=profile_name).count():
profile, created = Profile.objects.get(name=profile_name), False
membership, membership_created = TeamMembership.objects.get_or_create(team=team, profile=profile, defaults={'char_name': char_name})
membership.char_name = char_name
else:
try:
membership = TeamMembership.objects.get(team=team, char_name=char_name)
profile, created = membership.profile, False
except TeamMembership.DoesNotExist:
# create profile and membership
profile, created = Profile(name=profile_name, user=self.master_user), True
profile.save()
membership = TeamMembership(team=team, profile=profile, char_name=char_name)
print(created, file=self.stdout)
profile.name = profile_name
member_photo_url = info_ps[0].cssselect('img')[0].get('src')
if member_photo_url != self.unknown_photo:
filename = slugify(profile.name) + posixpath.splitext(member_photo_url)[1]
profile.photo.save(filename, ContentFile(urllib2.urlopen(member_photo_url).read()))
if info_ps[3].text:
profile.title = info_ps[3].text
if info_ps[-1].text: # deal with blank race
if info_h3s[-1].text.strip().lower() == "champion":
membership.champion = info_ps[-1].text.strip()
else:
try:
membership.race = info_ps[-1].text[0].upper()
membership.clean_fields()
except ValidationError:
membership.race = None
try:
membership.questions_answers = tostring(member_d.cssselect('div.content-section-2 ol')[0])
except:
pass
try:
profile.full_clean()
except ValidationError as e:
print("Profile did not validate! {profile_name} {e}".format(profile_name=profile_name.encode('ascii', 'ignore'), e=e), file=self.stderr)
else:
profile.save()
membership.save()
return profile, membership