本文整理汇总了Python中reversion.set_comment方法的典型用法代码示例。如果您正苦于以下问题:Python reversion.set_comment方法的具体用法?Python reversion.set_comment怎么用?Python reversion.set_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reversion
的用法示例。
在下文中一共展示了reversion.set_comment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def handle(self, comment, no_progress, infile, *args, **options):
self.updated, self.inserted, self.skipped, self.deactivated = 0, 0, 0, 0
self.cached_courts = {}
with transaction.atomic() and reversion.create_revision():
reversion.set_comment(comment)
for item in self.get_iter(self.generate_data(infile), no_progress):
self.process_item(item)
for obj in Court.objects.exclude(pk__in=self.cached_courts.values()).all():
obj.active = False
obj.save()
self.stdout.write("There is {} courts, which {} skipped, {} updated, {} inserted and {} deactivated.".format(
self.updated + self.inserted + self.skipped,
self.skipped,
self.updated,
self.inserted,
self.deactivated))
示例2: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def handle(self, comment, no_progress, verbose, update, *args, **options):
self.updated, self.inserted, self.skipped, self.deleted, self.missing = 0, 0, 0, 0, 0
print(update)
with transaction.atomic() and reversion.create_revision():
reversion.set_comment(comment)
for court in self.get_iter(self.get_queryset(update), no_progress):
self.process_item(court, verbose)
self.stdout.write(
"There is {} connection, which {} skipped, {} updated, {} deleted, {} inserted, {} missing.".format(
self.updated + self.inserted + self.skipped,
self.skipped,
self.updated,
self.deleted,
self.inserted,
self.missing))
示例3: player_unresponsive
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def player_unresponsive(round_, pairing, player, groups):
has_warning = PlayerWarning.objects.filter(player=player, round__season=round_.season, type='unresponsive').exists()
if not has_warning:
with reversion.create_revision():
reversion.set_comment('Automatic warning for unresponsiveness')
PlayerWarning.objects.create(player=player, round=round_, type='unresponsive')
punishment = 'You may receive a yellow card.'
allow_continue = True
groups['warning'].append(player)
else:
card_color = give_card(round_, player, 'card_unresponsive')
if not card_color:
return
punishment = 'You have been given a %s card.' % card_color
allow_continue = card_color != 'red'
groups[card_color].append(player)
signals.notify_unresponsive.send(sender=automod_unresponsive, round_=round_, player=player, punishment=punishment, allow_continue=allow_continue)
示例4: claim_win_noshow_approved
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def claim_win_noshow_approved(instance, **kwargs):
p = instance.pairing
opponent = p.white if p.white != instance.requester else p.black
with reversion.create_revision():
reversion.set_comment('Auto forfeit for no-show')
if p.white == instance.requester:
p.result = '1X-0F'
if p.black == instance.requester:
p.result = '0F-1X'
p.save()
add_system_comment(p, '%s no-show' % opponent.lichess_username)
sp = SeasonPlayer.objects.filter(player=opponent, season=instance.season).first()
add_system_comment(sp, 'Round %d no-show' % instance.round.number)
card_color = give_card(instance.round, opponent, 'card_noshow')
if not card_color:
return
punishment = 'You have been given a %s card.' % card_color
allow_continue = card_color != 'red'
signals.notify_noshow_claim.send(sender=claim_win_noshow_approved, round_=instance.round, player=opponent, punishment=punishment, allow_continue=allow_continue)
示例5: revoke_card
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def revoke_card(round_, player, type_):
with transaction.atomic():
sp = SeasonPlayer.objects.filter(season=round_.season, player=player).first()
if not sp:
logger.error('Season player did not exist for %s %s' % (round_.season, player))
return
card = PlayerWarning.objects.filter(player=player, round=round_, type=type_).first()
if not card:
return
card.delete()
has_other_card = PlayerWarning.objects.filter(player=player, round=round_, type__startswith='card').exists()
if not has_other_card and sp.games_missed > 0:
sp.games_missed -= 1
with reversion.create_revision():
reversion.set_comment('Card revocation')
sp.save()
示例6: process_requirements
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def process_requirements(self) -> None:
"""
Go through each requirement.
If its impacted_entity field is blank, return the requirement.
Otherwise, try to extract agencies and agency groups from the
impacted_entity value and create relationships accordingly.
"""
for requirement in Requirement.objects.iterator():
impacted = requirement.impacted_entity.lower()
if not impacted:
continue
with reversion.create_revision():
agencies = extract_agencies(impacted)
requirement.agencies.add(*agencies)
reversion.set_comment(
"Add agency via extraction from impacted_entity.")
with reversion.create_revision():
groups = extract_groups(impacted)
requirement.agency_groups.add(*groups)
reversion.set_comment(
"Add agency group via extraction from impacted_entity.")
示例7: _save_as_revision
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def _save_as_revision(self, object_list, user, comment):
for object in object_list:
object.save()
reversion.set_user(user=user)
reversion.set_comment(comment=comment)
示例8: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def handle(self, infile, comment, no_progress, *args, **options):
self.esp_cache = {}
self.updated, self.inserted, self.skipped = 0, 0, 0
self.regon_fixed = 0
self.esp_updated, self.esp_inserted, self.esp_skipped = 0, 0, 0
self.no_progress = no_progress
with transaction.atomic() and reversion.create_revision():
reversion.set_comment(comment)
# Transaction usage means that the disk has been written to the disk only after commit,
# which greatly influences the speed.
for epuap_id, esps in self.get_iter(self.generate_data(infile)):
items = list(esps)
regon = items[0]['regon'] if items[0]['regon'] != 'NULL' else None
institution = Institution.objects.get_or_create(epuap_id=epuap_id,
defaults={'regon': regon,
'name': items[0]['name']})[0]
self._process_resp(institution, items[0])
self._process_esps(institution, items)
self.stdout.write("There is {} RESPs {} skipped and changed, which {} updated and {} inserted.".format(
self.updated + self.inserted + self.skipped,
self.skipped,
self.updated,
self.inserted))
self.stdout.write("There is {} REGON's fixed in institution".format(self.regon_fixed))
self.stdout.write(("There is {} ESPs changed, which {} skipped, {} "
"updated and {} inserted.").format(self.esp_updated + self.esp_inserted + self.esp_skipped,
self.esp_skipped,
self.esp_updated,
self.esp_inserted))
示例9: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def handle(self, comment, institutions_id, update, no_progress, *args, **options):
gus = GUS(api_key=settings.GUSREGON_API_KEY, sandbox=settings.GUSREGON_SANDBOX)
if settings.GUSREGON_SANDBOX is True:
self.stderr.write("You are using sandbox mode for the REGON database. Data may be incorrect. "
"Set the environemnt variable GUSREGON_SANDBOX and GUSREGON_API_KEY correctly.")
inserted, updated, errored, skipped = 0, 0, 0, 0
qs = self.get_queryset(update, institutions_id)
for institution in self.get_iter(qs, no_progress):
with transaction.atomic() and reversion.create_revision():
try:
data = gus.search(regon=normalize_regon(institution.regon))
except TypeError as e:
regon_obj = REGON.objects.create(institution=institution, regon=institution.regon)
REGONError.objects.create(regon=regon_obj, exception=repr(e))
errored += 1
self.stderr.write("Errored for {} in {} as {}".format(institution.regon, institution.pk, repr(e)))
continue
if hasattr(institution, 'regon_data'):
if institution.regon_data.data != data:
institution.regon_data.regon = institution.regon
institution.regon_data.data = data
institution.regon_data.save()
updated += 1
else:
skipped += 1
else:
REGON.objects.create(institution=institution,
regon=institution.regon,
data=data)
inserted += 1
reversion.set_comment(comment)
time.sleep(2)
total = updated + inserted + errored + skipped
self.stdout.write(("There is {} REGON changed, which "
"{} updated, "
"{} skipped, "
"{} inserted and "
"{} errored.").format(total, updated, skipped, inserted, errored))
示例10: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def handle(self, krs, regon, nip, comment, google, no_progress, no_regon, no_nip, *args, **options):
gus = GUS(api_key=settings.GUSREGON_API_KEY, sandbox=settings.GUSREGON_SANDBOX)
if settings.GUSREGON_SANDBOX is True:
self.stderr.write("You are using sandbox mode for the REGON database. Data may be incorrect. "
"Set the environemnt variable GUSREGON_SANDBOX and GUSREGON_API_KEY correctly.")
self.inserted, self.updated, self.errored, self.skipped = 0, 0, 0, 0
if not any([krs, regon, nip, google]):
raise CommandError("Provide at least one '--krs' or '--regon' or '--nip' or '--google' is required. ")
queries = self.get_queryset(krs, nip, regon, google, no_regon, no_nip)
with transaction.atomic() and reversion.create_revision():
reversion.set_comment(comment)
for query in self.get_iter(queries, no_progress):
data = gus.search(**query)
if data:
regon_id = query.get('regon', data.get('regon14', data.get('regon9')))
try:
regon = REGON.objects.regon(regon_id)
if regon.data != data:
regon.data = data
regon.save()
self.updated += 1
else:
self.skipped += 1
except REGON.DoesNotExist:
regon = REGON(regon=regon_id, data=data)
self.stdout.write("Added {}".format(regon.data.get('nazwa', '')))
regon.save()
self.inserted += 1
else:
self.stderr.write("Unable to find {}".format(query))
self.errored += 1
total = self.inserted + self.updated + self.errored
self.stdout.write(("There is {} REGON changed, which "
"{} updated, "
"{} skipped, "
"{} inserted and "
"{} errored.").format(total, self.updated, self.skipped, self.inserted, self.errored))
示例11: withdraw_approved
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def withdraw_approved(instance, **kwargs):
# Add the withdrawal if it doesn't already exist
with reversion.create_revision():
reversion.set_comment('Withdraw request approved by %s' % instance.status_changed_by)
PlayerWithdrawal.objects.get_or_create(player=instance.requester, round=instance.round)
示例12: appeal_late_response_approved
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def appeal_late_response_approved(instance, **kwargs):
with reversion.create_revision():
reversion.set_comment('Late response appeal approved by %s' % instance.status_changed_by)
warning = PlayerWarning.objects.filter(player=instance.requester, round=instance.round, type='unresponsive').first()
if warning:
warning.delete()
else:
revoke_card(instance.round, instance.requester, 'card_unresponsive')
示例13: appeal_noshow_approved
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def appeal_noshow_approved(instance, **kwargs):
with reversion.create_revision():
reversion.set_comment('No-show appeal approved by %s' % instance.status_changed_by)
revoke_card(instance.round, instance.requester, 'card_noshow')
with reversion.create_revision():
reversion.set_comment('No-show appeal approved by %s' % instance.status_changed_by)
instance.pairing.result = ''
instance.pairing.save()
示例14: reset_alternate_search
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def reset_alternate_search(season, round_, setting):
# Reset the alternate states
for alt in Alternate.objects.filter(season_player__season=season):
# TODO: Maybe send a notification to contacted alternates here
if alt.status == 'contacted' and alt.last_contact_date is not None and timezone.now() - alt.last_contact_date > setting.unresponsive_interval:
with reversion.create_revision():
reversion.set_comment('Alternate search over')
alt.status = 'unresponsive'
alt.save()
if alt.status != 'waiting':
with reversion.create_revision():
reversion.set_comment('Reset alternate status')
alt.status = 'waiting'
alt.save()
# Fail any ongoing searches from last round
last_round = season.round_set.filter(number=round_.number - 1).first()
if last_round is not None:
for search in AlternateSearch.objects.filter(round=last_round, status__in=('started', 'all_contacted')):
if search.still_needs_alternate():
with reversion.create_revision():
reversion.set_comment('Alternate search failed')
search.status = 'failed'
search.save()
signals.alternate_search_failed.send(sender=do_alternate_search, season=season, team=search.team, \
board_number=search.board_number, round_=last_round)
else:
with reversion.create_revision():
reversion.set_comment('Alternate search cancelled')
search.status = 'cancelled'
search.save()
# Update the alternate board order, but only if it hasn't been updated within the past hour
some_bucket = season.alternatebucket_set.first()
if some_bucket is None or some_bucket.date_modified < timezone.now() - _min_bucket_update_interval:
UpdateBoardOrderWorkflow(season).run(alternates_only=True)
示例15: alternate_accepted
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import set_comment [as 别名]
def alternate_accepted(alternate):
# This is called by the alternate_accept endpoint
# The alternate gets there via a private link sent to their slack
season = alternate.season_player.season
round_ = current_round(season)
# Validate that the alternate is in the correct state
if alternate.status != 'contacted':
return False
# Validate that the alternate doesn't already have a game in the round
# Players can sometimes play multiple games (e.g. playing up a board), but that isn't done through the alternates manager
if (TeamPlayerPairing.objects.filter(team_pairing__round=round_, white=alternate.season_player.player) | \
TeamPlayerPairing.objects.filter(team_pairing__round=round_, black=alternate.season_player.player)).nocache().exists():
return False
# Find an open spot to fill, prioritized by the time the search started
active_searches = AlternateSearch.objects.filter(round=round_, board_number=alternate.board_number, is_active=True) \
.order_by('date_created').select_related('team').nocache()
for search in active_searches:
if search.still_needs_alternate():
with reversion.create_revision():
reversion.set_comment('Alternate assigned')
assignment, _ = AlternateAssignment.objects.update_or_create(round=round_, team=search.team, board_number=search.board_number, \
defaults={'player': alternate.season_player.player, 'replaced_player': None})
with reversion.create_revision():
reversion.set_comment('Alternate assigned')
alternate.status = 'accepted'
alternate.save()
with reversion.create_revision():
reversion.set_comment('Alternate search completed')
search.status = 'completed'
search.save()
signals.alternate_assigned.send(sender=alternate_accepted, season=season, alt_assignment=assignment)
return True
return False