本文整理汇总了Python中models.History类的典型用法代码示例。如果您正苦于以下问题:Python History类的具体用法?Python History怎么用?Python History使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了History类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_game
def new_game(self, request):
"""Creates a Game.
Args:
request: The NEW_GAME_REQUEST objects, which includes two players'
names
Returns:
GameForm with created game
Raises:
endpoints.NotFoundException: If the user does not exist.
endpoints.BadRequestException: If the game is created with one
user.
"""
user_x = User.query(User.name == request.user_name_x).get()
user_o = User.query(User.name == request.user_name_o).get()
if (not user_o) or (not user_x):
raise endpoints.NotFoundException(
'A User with that name does not exist!')
try:
game = Game.new_game(user_x.key, user_o.key)
history = History(game=game.key)
history.put()
except ValueError:
raise endpoints.BadRequestException('Players should be '
'different!')
return game.to_form('Good luck playing TicTacToe!')
示例2: post
def post(self):
isajax = self.request.get('isajax')
phone = self.request.get('phone')
msg = self.request.get('msg')
contact_name = self.request.get('contact_name')
user = users.get_current_user()
email = user.email().lower()
q = Token.query(Token.email == email)
token = q.get()
status = 100
hist=''
logging.debug(email + ' ' + phone + ' ' + msg + ' ' + contact_name)
if token:
status = 101
if len(phone) and len(msg):
status = 200
hist = History(email=email, msg=msg, phone=phone, contact_name = contact_name)
hist.put()
airship.push({
"android": {
"extra": {"msgid": str(hist.key.id()), "phone": phone, "msg":msg}
}
}, apids=[token.apid])
id = hist.key.id()
hist = hist.to_dict()
hist['created']=hist['created'].isoformat();
hist['id'] = id
hist['type'] = 'sms'
self.response.out.write(json.dumps({'status':status, 'msg':hist}))
示例3: upload
def upload(request):
if request.method == 'POST':
form = SelfieForm(request.POST, request.FILES)
if form.is_valid():
instance = Selfie(photo=request.FILES['photo'])
instance.user = request.user
instance.info = form.cleaned_data["info"]
instance.save()
hist = History(selfie=instance, date=instance.pub_date, matches=0, score=1500)
hist.save()
img = Image.open(instance.photo.file)
x1 = float(request.POST["x1"])
x2 = float(request.POST["x2"])
y1 = float(request.POST["y1"])
y2 = float(request.POST["y2"])
img.crop((x1, y1, x2, y2)).resize((640, 640)).save(instance.photo.file.file.name)
print "new salfie: ", instance, "; anlisys result: ", instance.analyze()
return HttpResponseRedirect(reverse('selfzone.panel:index'))
return render(request, 'selfzone/uploadForm.html', {'form': form})
else:
form = SelfieForm()
return render(request, 'selfzone/uploadForm.html', {'form': form})
示例4: addToHistory
def addToHistory(self, song_instance, user_list):
history_instance = History(
Song=song_instance
)
history_instance.save()
if user_list is not None and user_list.count() > 0:
for user_instance in user_list.all():
history_instance.User.add(user_instance)
示例5: confirm_order
def confirm_order(request):
cart=get_cart(request)
history = History(id_user=request.user)
history.save()
for product in cart.id_products.all():
product.quantity = product.quantity - 1
history.id_product.add(product)
product.save()
history.save()
cart.delete()
return redirect('home')
示例6: get
def get(self):
contact_name = self.request.get('contact_name')
phone = self.request.get('phone')
msg = self.request.get('msg')
email = self.request.get("email",'').lower()
hist = History(email=email, msg=msg, phone=phone, contact_name = contact_name, byme=False)
hist.put()
id = hist.key.id()
hist = hist.to_dict()
hist['created']=hist['created'].isoformat();
hist['id'] = id
hist['type'] = 'sms'
channel.send_message(email, json.dumps(hist))
self.response.out.write(json.dumps({}))
示例7: smoke_on
def smoke_on(all_sensors, all_rules):
smoke = True
GPIO.output(4, 1)
for sensor in all_sensors:
if sensor.name == 'Smoke':
sensor.open = True
sensor.save()
for rule in all_rules:
if rule.rule_id == 6 and rule.is_enabled:
msg = 'Smoke alarm was triggered!'
Push.message(msg, channels=["Notifications"])
history_item = History(Text=msg)
history_item.save()
message = sendgrid.Mail(to='[email protected]', subject='Allstate Hub Notification', html='', text=msg, from_email='[email protected]')
status, mersg = sg.send(message)
示例8: get_game_history
def get_game_history(self, request):
"""Returns all of the game history"""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if not game:
raise endpoints.NotFoundException(
'A Game with that game key does not exist!')
qry = History.query(History.game == game.key)
return HistoryForms(items=[history.to_form() for history in qry])
示例9: get_game_history
def get_game_history(self, request):
"""Returns a history of all moves made in game."""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if game:
history = History.query(ancestor=game.key).order(History.order)
return HistoryForms(items=[move.to_form() for move in history])
else:
raise endpoints.NotFoundException("Game not found!")
示例10: history
def history():
gr = {}
for r in History.all():
d = r['date'].date()
if not d in gr:
gr[d] = []
gr[d].append(r)
return render_template('history.html', data=gr)
示例11: crawl_user
def crawl_user(account):
client = weibo.APIClient(app_key=settings.WEIBO_APPKEY, app_secret=settings.WEIBO_APPSECRET)
client.set_access_token(account.access_token, 0)
if settings.DEBUG:
COUNT = 21
else:
COUNT = settings.WEIBO_API_MAX_COUNT
id_func = lambda s:s.id
##TODO: handle exception
if not account.latest_status:
all_statuses = client.statuses.home_timeline.get(count = COUNT).statuses
else:
statuses = client.statuses.home_timeline.get(since_id = account.latest_status.id, count = COUNT).statuses
all_statuses = statuses
while len(statuses) == COUNT:
last_minid = min(map(id_func, statuses))
## The API will return the largest COUNT statuses whose id is larger than since_id
## so here is how we iterate to retrieve the entire set
statuses = client.statuses.home_timeline.get(max_id = last_minid - 1, since_id = account.latest_status.id, count = COUNT).statuses
all_statuses.extend(statuses)
all_statuses.sort(key=id_func)
ids = map(id_func, all_statuses)
assert len(ids) == len(set(ids)) ## Sanity check: no duplicates in the list
saved_statuses = map(store_status, all_statuses)
for status in saved_statuses:
## If we encounter duplicated status, do not create history m2m again
if not status.weiboaccount_set.exists():
h = History()
h.user = account
h.status = status
h.save()
## Move on if the status is 15 minutes old
## This is to deal with API sometimes having missing statuses in between (not even eventually consistent?!)
if saved_statuses:
for i in reversed(range(len(saved_statuses))):
if older_than(all_statuses[i].created_at, 15):
account.latest_status = saved_statuses[i]
break
account.save()
return map(lambda s:s.id, saved_statuses)
示例12: cancel_game
def cancel_game(self, request):
""" Cancels a game from it's urlsafe key """
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if not game:
raise endpoints.NotFoundException("Game not found")
if not game.game_over and not game.canceled:
game.canceled = True
msg = "Game canceled"
hist = History()
hist.guess = "-1"
hist.message = msg
print hist
game.history.append(hist)
game.put()
return game.to_form(msg)
else:
return game.to_form("You cannot cancel a game that is already over")
示例13: get_game_history
def get_game_history(self, request):
"""Return game history."""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if not game:
raise endpoints.NotFoundException('Game not found!')
histories = History.query(ancestor=game.key)
histories = histories.order(History.turn)
histories = histories.order(History.player_turn)
return HistoryForms(items=[history.to_form() for history in histories])
示例14: testUpdatePoints
def testUpdatePoints(self):
Coin.add('points')
Coin.add('gold')
Formula.add('level-gold', definition='gold=10*{level}', owner=None)
player = self._get_player()
player.points = 82
player.level_no = 1
player.save()
update_points(player, None)
coins = History.user_coins(player.user)
self.assertIn('gold', coins)
self.assertEqual(coins['gold'], 20)
player.points = 10
player.save()
update_points(player, None)
coins = History.user_coins(player.user)
self.assertIn('gold', coins)
self.assertEqual(coins['gold'], 0)
示例15: get_game_history
def get_game_history(self, request):
"""Return the game history."""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if game:
histories = History.query(History.game==game.key).order(History.datetime)
# histories = History.query(History.game==game.key)
return HistoryForms(items = [history.to_form() for history in histories])
else:
raise endpoints.NotFoundException('Game not found!')