本文整理汇总了Python中models.Profile.get_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.get_or_create方法的具体用法?Python Profile.get_or_create怎么用?Python Profile.get_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Profile
的用法示例。
在下文中一共展示了Profile.get_or_create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: settings
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import get_or_create [as 别名]
def settings():
if request.method == 'GET':
profile = Profile.get_or_create(users.get_current_user())
return jinja.get_template('settings.html').render(locals())
elif request.method == 'POST':
profile = Profile.get_or_create(users.get_current_user())
profile.timezone_offset = int(request.form.get('timezone_offset'))
profile.digest_hour = int(request.form.get('digest_hour'))
profile.prompt_hour = int(request.form.get('prompt_hour'))
profile.put()
return redirect(request.path)
示例2: home
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import get_or_create [as 别名]
def home():
if request.method == 'GET':
profile = Profile.get_or_create(users.get_current_user())
edit = request.query_string == 'edit'
return jinja.get_template('home.html').render(locals())
elif request.method == 'POST':
profile = Profile.get_or_create(users.get_current_user())
if request.query_string == 'edit':
e = profile.entry_today
e.body = request.form.get('body')
else:
e = Entry(body=request.form.get('body'))
e.put()
return redirect(request.path)
示例3: get
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import get_or_create [as 别名]
def get(self):
profile = Profile.get_or_create()
assert profile is not None
agencies = Agency.query(Agency.enabled == True)
if agencies.count(limit=1) < 1:
agencies = None
context = dict(
object_list=agencies,
report_count=StopReport.query(StopReport.user == profile.key).count(limit=100),
)
self.render_to_response('agency_list.html', context)
示例4: post
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import get_or_create [as 别名]
def post(self):
profile = Profile.get_or_create()
assert profile is not None
agency_id = self.request.get('agency_id')
vehicle = self.request.get('vehicle')
card_id = self.request.get('card_id')
known_stop = self.request.get('known_stop')
stop_name = self.request.get('stop_name')
comment = self.request.get('comment')
# Start validation!
# Check agency
try:
agency = Agency.get_by_id(int(agency_id))
if agency is None or not agency.enabled:
# Invalid agency
return self.send_404()
except:
return self.send_404()
# Check vehicle type
if vehicle not in VEHICLE_TYPES or vehicle not in agency.vehicle_types:
return self.send_404()
# Check card id
try:
card_id = int(card_id)
except:
# invalid card id, not a number.
return self._retry_form(agency, vehicle, card_id, known_stop, stop_name, comment, 'Card ID is not a number')
# Check known_stop
if known_stop != '':
try:
known_stop = Stop.get_by_id(int(known_stop))
if known_stop.agency.id() != agency.key.id():
# stop is not for agency
known_stop = None
except:
known_stop = None
if known_stop is None:
# Invalid stop
return self._retry_form(agency, vehicle, card_id, known_stop, stop_name, comment, 'Stop ID is not valid')
if known_stop == '':
known_stop = None
# Check stop_name is present if known_stop is not
if known_stop is None and stop_name == '':
# Custom name not specified and no known stop selected.
return self._retry_form(agency, vehicle, card_id, known_stop, stop_name, comment, 'No stop name was entered')
# If the user is banned, then say we processed the report, but don't
# actually store it anywhere.
if not profile.banned:
# Now get the extra metadata and make the report
country = self.request.headers.get('x-appengine-country', 'XX')
region = self.request.headers.get('x-appengine-region', '')
city = self.request.headers.get('x-appengine-city', '')
ip = self.request.remote_addr
report = StopReport(
agency=agency.key,
stop=known_stop.key if known_stop else None,
name=stop_name,
stop_type=vehicle,
card_id=str(card_id),
comment=comment,
gae_country=country,
gae_region=region,
gae_city=city,
gae_ip=ip,
user=profile.key
)
report.put()
context = dict(
agency_name=agency.name,
agency_id=agency.key.id(),
)
self.render_to_response('report_sent.html', context)