本文整理汇总了Python中reversion.create_revision方法的典型用法代码示例。如果您正苦于以下问题:Python reversion.create_revision方法的具体用法?Python reversion.create_revision怎么用?Python reversion.create_revision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reversion
的用法示例。
在下文中一共展示了reversion.create_revision方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_institution
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def update_institution(self, no_progress, update):
self.updated, self.inserted, self.errored, self.skipped = 0, 0, 0, 0
with transaction.atomic() and reversion.create_revision():
for regon in self.get_iter(self.get_queryset(update), no_progress):
item = self.insert_throguth_terc(regon)
if not item:
item = self.insert_throught_simc(regon)
if not item:
self.errored += 1
self.stdout.write(
"There is {} connection changed, which {} updated, {} skipped and {} inserted. but {} errored.".
format(self.updated + self.inserted,
self.updated,
self.skipped,
self.inserted,
self.errored))
示例2: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [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 create_revision [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 create_revision [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 create_revision [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: test_reversion
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def test_reversion():
with reversion.create_revision():
key = mommy.make(Topic, name="key1")
key_from_db = Topic.objects.get(pk=key.pk)
assert key.name == key_from_db.name
with reversion.create_revision():
key_from_db.name = "new name"
key_from_db.save()
key.refresh_from_db()
assert key.name == "new name"
assert key_from_db.name == "new name"
versions = Version.objects.get_for_model(Topic)
assert len(versions) == 2
assert versions[1].field_dict["name"] == "key1"
assert versions[0].field_dict["name"] == "new name"
versions[1].revision.revert()
key.refresh_from_db()
assert key.name == "key1"
示例7: from_row
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def from_row(self, row):
"""Retrieve/create/update a Policy object"""
policy_number = int(row['policyNumber'])
uri_key = find_key("uri_policy_ids", row)
omb_key = find_key("omb_policy_ids", row)
if policy_number not in self.policies:
policy = Policy.objects.filter(policy_number=policy_number).first()
policy = policy or Policy(policy_number=policy_number)
policy.title = row['policyTitle']
policy.uri = row[uri_key]
policy.omb_policy_id = convert_omb_policy_id(row[omb_key])
policy.policy_status = row.get("policyStatus", "")
policy.policy_type = convert_policy_type(row['policyType'])
policy.issuance = convert_date(row['policyIssuanceYear'])
policy.sunset = convert_date(row['policySunset'])
policy.issuing_body = row['issuingBody']
with reversion.create_revision():
policy.save()
self.policies[policy_number] = policy
return self.policies[policy_number]
示例8: sync_row
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def sync_row(self, row):
"""Create/update a single agency from itdashboard.gov"""
agency = Agency.objects.filter(
omb_agency_code=row['agencyCode']).first()
agency = agency or Agency(omb_agency_code=row['agencyCode'])
agency.name = row['agencyName']
agency.abbr = row['agencyAbbreviation'] or agency.abbr
with reversion.create_revision():
agency.save()
agency.groups.add(self.system_groups['all-agencies'])
if row['agencyType'] != '5-Other Branches':
self.system_groups['executive'].agencies.add(agency)
if row['CFO_Act']:
self.system_groups['cfo-act'].agencies.add(agency)
if row['CIO_Council']:
self.system_groups['cio-council'].agencies.add(agency)
示例9: testRevisionSignals
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def testRevisionSignals(self):
pre_revision_receiver_called = []
def pre_revision_receiver(**kwargs):
self.assertEqual(kwargs["instances"], [self.test11])
self.assertTrue(isinstance(kwargs["revision"], Revision))
self.assertEqual(len(kwargs["versions"]), 1)
pre_revision_receiver_called.append(True)
post_revision_receiver_called = []
def post_revision_receiver(**kwargs):
self.assertEqual(kwargs["instances"], [self.test11])
self.assertTrue(isinstance(kwargs["revision"], Revision))
self.assertEqual(len(kwargs["versions"]), 1)
post_revision_receiver_called.append(True)
reversion.pre_revision_commit.connect(pre_revision_receiver)
reversion.post_revision_commit.connect(post_revision_receiver)
# Create a revision.
with reversion.create_revision():
self.test11.save()
# Check the signals were called.
self.assertTrue(pre_revision_receiver_called)
self.assertTrue(post_revision_receiver_called)
示例10: testRevertWithDelete
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def testRevertWithDelete(self):
with reversion.create_revision():
test23 = ReversionTestModel2.objects.create(
name = "model2 instance3 version1",
)
self.follow1.test_model_2s.add(test23)
self.follow1.save()
self.assertEqual(reversion.get_for_object(test23).count(), 1)
self.assertEqual(self.follow1.test_model_2s.all().count(), 3)
# Test that a revert with delete works.
test23_pk = test23.pk
self.assertEqual(ReversionTestModel2.objects.count(), 3)
with reversion.create_revision():
reversion.get_for_object(self.follow1)[1].revision.revert(delete=True)
self.assertEqual(ReversionTestModel1.objects.get(id=self.test11.pk).name, "model1 instance1 version1")
self.assertEqual(ReversionTestModel2.objects.get(id=self.test22.pk).name, "model2 instance2 version1")
self.assertEqual(ReversionTestModel2.objects.get(id=self.test22.pk).name, "model2 instance2 version1")
self.assertEqual(ReversionTestModel2.objects.count(), 2)
self.assertRaises(ReversionTestModel2.DoesNotExist, lambda: ReversionTestModel2.objects.get(id=test23_pk))
# Roll back to the revision where all models were present.
reversion.get_for_object(self.follow1)[1].revision.revert()
self.assertEqual(self.follow1.test_model_2s.all().count(), 3)
# Roll back to a revision where a delete flag is present.
reversion.get_for_object(self.follow1)[0].revision.revert(delete=True)
self.assertEqual(self.follow1.test_model_2s.all().count(), 2)
示例11: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [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))
示例12: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [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))
示例13: update_regon
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def update_regon(self, no_progress, update):
self.updated, self.inserted, self.errored, self.skipped = 0, 0, 0, 0
with transaction.atomic() and reversion.create_revision():
for regon in self.get_iter(self.get_queryset_regon(update), no_progress):
jst_id = get_jst_id(regon.data)
jst = self.get_jst(jst_id)
if not jst:
self.stderr.write("Unable to find JST {} for {}".format(jst_id, regon))
self.errored +=1
continue
if hasattr(regon, 'regonjst'):
if regon.regonjst.jst == jst:
self.skipped += 1
else:
self.updated += 1
regon.regonjst.jst = jst
regon.regonjst.save()
else:
self.inserted += 1
REGONJST.objects.create(regon=regon, jst=jst)
self.stdout.write(
"There is {} connection changed, which {} updated, {} skipped and {} inserted. but {} errored.".
format(self.updated + self.inserted,
self.updated,
self.skipped,
self.inserted,
self.errored))
示例14: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [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))
示例15: handle
# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import create_revision [as 别名]
def handle(self, no_progress, verbose, comment, *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
qs = self.get_queryset()
for regon in self.get_iter(qs, no_progress):
with transaction.atomic() and reversion.create_revision():
data = gus.search(regon=regon.data['regon14'], report_type='PublDaneRaportLokalnePrawnej', list=True)
for item in data:
# item_data = gus.search(regon=item['regon14'])
item_data = item
try:
obj = REGON.objects.get(regon=item['regon14'])
if obj.data != item_data:
obj.data = item_data
obj.save()
self.updated += 1
else:
self.skipped += 1
except REGON.DoesNotExist:
REGON.objects.create(regon=item['regon14'], data=item_data)
self.inserted += 1
self.stdout.write("There is {} courts, which {} skipped, {} updated and {} inserted.".format(
self.updated + self.inserted + self.skipped,
self.skipped,
self.updated,
self.inserted))