本文整理汇总了Python中models.Log.action方法的典型用法代码示例。如果您正苦于以下问题:Python Log.action方法的具体用法?Python Log.action怎么用?Python Log.action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Log
的用法示例。
在下文中一共展示了Log.action方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: click_mine_interact
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import action [as 别名]
def click_mine_interact(request):
# data_dict = {}
user = request.user;
userProfile = UserProfile.objects.get(user= user)
mine_index = request.POST.get('mine_index')
mine_index = int(mine_index)
panel_id = request.POST.get('panel_id')
panel_id = int(panel_id)
panel = Panel.objects.get(pk = panel_id)
progress = panel.progress
progress = progress[0:mine_index] + '1' + progress[mine_index+1:]
panel.progress = progress
panel.save()
rows = panel.game.columns
log = Log()
log.game = panel.game
log.group = panel.group
log.panel = panel
log.action = '\"Click (%d, %d)\"' % (mine_index/rows, mine_index % rows)
log.action_time = datetime.now()
log.user_profile = userProfile
log.save()
response_data={}
game = panel.game
response_data['rowses'] = game.rows
response_data['columns'] = game.columns
response_data['progress'] = panel.progress
response_data['wait_time'] = game.wait_time
return HttpResponse(json.dumps(response_data), mimetype="application/json")
示例2: execute_actions
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import action [as 别名]
def execute_actions(self, item, match):
"""Performs the action(s) for the condition.
Also sends any comment/messages (if set) and creates a log entry.
"""
if self.action or self.comment or self.modmail or self.message:
log_actions = [self.action]
else:
log_actions = []
# perform the action
if self.action == 'remove':
item.remove(False)
elif self.action == 'spam':
item.remove(True)
elif self.action == 'approve':
item.approve()
elif self.action == 'report':
item.report()
# set flairs
if (isinstance(item, praw.objects.Submission) and
(self.link_flair_text or self.link_flair_class)):
text = replace_placeholders(self.link_flair_text, item, match)
css_class = replace_placeholders(self.link_flair_class, item, match)
item.set_flair(text, css_class.lower())
item.link_flair_text = text
item.link_flair_css_class = css_class.lower()
log_actions.append('link_flair')
if (self.user_flair_text or self.user_flair_class):
text = replace_placeholders(self.user_flair_text, item, match)
css_class = replace_placeholders(self.user_flair_class, item, match)
item.subreddit.set_flair(item.author, text, css_class.lower())
item.author_flair_text = text
item.author_flair_css_class = css_class.lower()
log_actions.append('user_flair')
if self.comment:
comment = self.build_message(self.comment, item, match,
disclaimer=True)
if isinstance(item, praw.objects.Submission):
response = item.add_comment(comment)
elif isinstance(item, praw.objects.Comment):
response = item.reply(comment)
response.distinguish()
if self.modmail:
message = self.build_message(self.modmail, item, match,
permalink=True)
subject = replace_placeholders(self.modmail_subject, item, match)
r.send_message('/r/'+item.subreddit.display_name, subject, message)
if self.message and item.author:
message = self.build_message(self.message, item, match,
disclaimer=True, permalink=True)
subject = replace_placeholders(self.message_subject, item, match)
r.send_message(item.author.name, subject, message)
log_entry = Log()
log_entry.item_fullname = item.name
log_entry.condition_yaml = self.yaml
log_entry.datetime = datetime.utcnow()
for entry in log_actions:
log_entry.action = entry
session.add(log_entry)
session.commit()
item_time = datetime.utcfromtimestamp(item.created_utc)
logging.info('Matched {0}, actions: {1} (age: {2})'
.format(get_permalink(item).encode('ascii', 'ignore'),
log_actions,
datetime.utcnow() - item_time))
示例3: switch_view
# 需要导入模块: from models import Log [as 别名]
# 或者: from models.Log import action [as 别名]
def switch_view(request, panel_id):
data_dict = {}
user = request.user;
userProfile = UserProfile.objects.get(user= user)
panel_id = int(panel_id)
panel = Panel.objects.get(pk = panel_id)
session_id = panel.session
group_id = panel.group.id
group_name = panel.group.name
panel_name = panel.name
game = panel.game
count = 0
for tmp in panel.progress:
if tmp == '1':
count += 1
cost = utils.cost(game.switch_cost)
if count < cost:
#cannot switch
log = Log()
log.game = game
log.group = panel.group
log.panel = panel
log.user_profile = userProfile
log.action = '\"Switch failed, Not enough credit\"'
log.action_time = datetime.now()
log.save()
data_dict['panel_id'] = panel_id
nextUrl = reverse('mine.views.mine_field_view', args=(panel_id,))
return HttpResponseRedirect(nextUrl)
else:
log = Log()
log.game = game
log.group = panel.group
log.panel = panel
log.user_profile = userProfile
log.action = '\"Go to Switch page, cost %s\"' % cost
log.action_time = datetime.now()
log.save()
#cost
index = 0
for s in panel.progress:
if cost == 0:
break
if s == '1':
cost -= 1
index += 1
panel.progress = '0'*(index+1) + panel.progress[index+1:]
panel.save()
panels = Panel.objects.filter(group__id = group_id, session = session_id)
panel_id_status_dict={}
for panel in panels:
progress = panel.progress
count = 0
for s in progress:
if s == '1':
count +=1
panel_id_status_dict[panel.id] = {'current': count, 'total': len(progress), 'panel_name': panel.name}
panel_id_status_json = json.dumps(panel_id_status_dict)
data_dict['panel_id_status_json'] = panel_id_status_json
data_dict['panel_id'] = panel_id
data_dict['group_name'] = group_name
data_dict['panel_name'] = panel_name
return render(request, 'switch.html', data_dict)