本文整理汇总了Python中models.account.Account.get_or_insert方法的典型用法代码示例。如果您正苦于以下问题:Python Account.get_or_insert方法的具体用法?Python Account.get_or_insert怎么用?Python Account.get_or_insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.account.Account
的用法示例。
在下文中一共展示了Account.get_or_insert方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
self.account = Account.get_or_insert(
"123",
email="[email protected]",
registered=True)
self.account.put()
self.account_banned = Account.get_or_insert(
"456",
email="[email protected]",
registered=True,
shadow_banned=True,
)
self.account_banned.put()
event = Event(id="2016test", name="Test Event", event_short="Test Event", year=2016, event_type_enum=EventType.OFFSEASON)
event.put()
self.match = Match(id="2016test_f1m1", event=ndb.Key(Event, "2016test"), year=2016, comp_level="f", set_number=1, match_number=1, alliances_json='')
self.match.put()
示例2: loginUser
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def loginUser(self):
self.testbed.setup_env(
user_email="[email protected]",
user_id="123",
user_is_admin='0',
overwrite=True)
Account.get_or_insert(
"123",
email="[email protected]",
registered=True)
示例3: account
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def account(self):
if self._account is None:
self._account = Account.get_or_insert(
self.user.user_id(),
email = self.user.email(),
nickname = self.user.nickname())
return self._account
示例4: givePermission
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def givePermission(self):
account = Account.get_or_insert(
"123",
email="[email protected]",
registered=True)
account.permissions.append(AccountPermissions.MUTATE_DATA)
account.put()
示例5: account
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def account(self):
if self._account is None and self.user:
self._account = Account.get_or_insert(
self.user.user_id(),
email = self.user.email(),
nickname = self.user.nickname(),
registered = False,
display_name = self.user.nickname())
return self._account
示例6: setUp
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.account = Account.get_or_insert(
"123",
email="[email protected]",
registered=True)
self.account.put()
示例7: post
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def post(self):
account = Account.get_or_insert(
self.user_bundle.user.user_id(),
email = self.user_bundle.user.email(),
nickname = self.user_bundle.user.nickname())
printer = Printer(
owner = account.key,
cloudprint_id = self.request.get("printer_cloudprint_id"),
display_name = self.request.get("printer_display_name"),
).put()
return self.redirect("/dashboard")
示例8: get
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def get(self):
if not self.user_bundle.user:
return self.redirect(self.user_bundle.login_url)
account = Account.get_or_insert(self.user_bundle.user.user_id())
printers = Printer.query(Printer.owner == account.key).fetch(10000)
print_jobs = PrintJob.query().fetch(3)
self.template_values.update({
"printers": printers,
"print_jobs": print_jobs,
})
path = os.path.join(os.path.dirname(__file__), '../templates/dashboard.html')
self.response.write(template.render(path, self.template_values))
示例9: setUp
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
account = Account.get_or_insert(
"123",
email="[email protected]",
registered=True).put()
suggestion = Suggestion(
author=account,
review_state=Suggestion.REVIEW_PENDING,
target_key="2012cmp",
target_model="event").put()
示例10: createDummyOffseasonSuggestions
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get_or_insert [as 别名]
def createDummyOffseasonSuggestions(cls, events_to_suggest):
"""
Create an offseason suggestion from a made up bot.
Used to link offseasons with official data sync
"""
keys_to_check = map(
lambda event: ndb.Key(Suggestion, 'offseason_with_data_{}'.format(event.key_name)),
events_to_suggest,
)
keys_found = ndb.get_multi(keys_to_check)
logging.info("Fetched {} suggestion keys from ndb".format(len(keys_found)))
# Make sure we have a dummy account to link these suggestions with
account = Account.get_or_insert(
'tba-bot-account',
email='[email protected]',
nickname='TBA-Bot',
registered=True,
permissions=[],
)
for event, suggestion, key in zip(events_to_suggest, keys_found, keys_to_check):
if suggestion:
# We've already created a suggestion for this event
logging.info("Skipping creating a suggestion for {}".format(event.key_name))
continue
logging.info("Creating suggestion for {}".format(event.key_name))
status, failures = cls.createOffseasonEventSuggestion(
author_account_key=account.key,
name=event.name,
start_date=event.start_date.strftime("%Y-%m-%d"),
end_date=event.end_date.strftime("%Y-%m-%d"),
website=event.website,
venue_name=event.venue,
address=event.venue_address,
city=event.city,
state=event.state_prov,
country=event.country,
first_code=event.event_short.upper(),
suggestion_id=key.id(),
)
if status != 'success':
logging.warning("Failed to create suggestion: {}".format(failures))