本文整理汇总了Python中reversion.revisions.create_revision方法的典型用法代码示例。如果您正苦于以下问题:Python revisions.create_revision方法的具体用法?Python revisions.create_revision怎么用?Python revisions.create_revision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reversion.revisions
的用法示例。
在下文中一共展示了revisions.create_revision方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_profile
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def make_profile(backend, user, response, is_new=False, *args, **kwargs):
if is_new:
if not hasattr(user, 'profile'):
profile = Profile(user=user)
profile.language = Language.get_default_language()
logger.info('Info from %s: %s', backend.name, response)
profile.save()
form = ProfileForm(instance=profile, user=user)
else:
data = backend.strategy.request_data()
logger.info(data)
form = ProfileForm(data, instance=user.profile, user=user)
if form.is_valid():
with transaction.atomic(), revisions.create_revision():
form.save()
revisions.set_user(user)
revisions.set_comment('Updated on registration')
return
return render(backend.strategy.request, 'registration/profile_creation.html', {
'title': 'Create your profile', 'form': form,
})
示例2: do_create_revision
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def do_create_revision(request):
with create_revision():
set_user(request.user)
yield
示例3: post
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def post(self, request, *args, **kwargs):
self.object = self.get_object()
page = self.get_comment_page()
if self.is_comment_locked():
return HttpResponseForbidden()
parent = request.POST.get('parent')
if parent:
if len(parent) > 10:
return HttpResponseBadRequest()
try:
parent = int(parent)
except ValueError:
return HttpResponseNotFound()
else:
if not Comment.objects.filter(hidden=False, id=parent, page=page).exists():
return HttpResponseNotFound()
form = CommentForm(request, request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.author = request.profile
comment.page = page
with LockModel(write=(Comment, Revision, Version), read=(ContentType,)), revisions.create_revision():
revisions.set_user(request.user)
revisions.set_comment(_('Posted comment'))
comment.save()
return HttpResponseRedirect(request.path)
context = self.get_context_data(object=self.object, comment_form=form)
return self.render_to_response(context)
示例4: generate_api_token
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def generate_api_token(request):
profile = request.profile
with transaction.atomic(), revisions.create_revision():
revisions.set_user(request.user)
revisions.set_comment(_('Generated API token for user'))
return JsonResponse({'data': {'token': profile.generate_api_token()}})
示例5: remove_api_token
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def remove_api_token(request):
profile = request.profile
with transaction.atomic(), revisions.create_revision():
profile.api_token = None
profile.save()
revisions.set_user(request.user)
revisions.set_comment(_('Removed API token for user'))
return JsonResponse({})
示例6: generate_scratch_codes
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def generate_scratch_codes(request):
profile = request.profile
with transaction.atomic(), revisions.create_revision():
revisions.set_user(request.user)
revisions.set_comment(_('Generated scratch codes for user'))
return JsonResponse({'data': {'codes': profile.generate_scratch_codes()}})
示例7: form_valid
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def form_valid(self, form):
with transaction.atomic(), revisions.create_revision():
revisions.set_comment(_('Edited from site'))
revisions.set_user(self.request.user)
return super(CommentEditAjax, self).form_valid(form)
示例8: save_revision
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def save_revision(self, user, comment, *args, **kwargs):
with transaction.atomic(), reversion.create_revision():
self.save()
reversion.set_user(user)
reversion.set_comment(comment)
示例9: edit_profile
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def edit_profile(request):
if request.profile.mute:
raise Http404()
if request.method == 'POST':
form = ProfileForm(request.POST, instance=request.profile, user=request.user)
if form.is_valid():
with transaction.atomic(), revisions.create_revision():
form.save()
revisions.set_user(request.user)
revisions.set_comment(_('Updated on site'))
if newsletter_id is not None:
try:
subscription = Subscription.objects.get(user=request.user, newsletter_id=newsletter_id)
except Subscription.DoesNotExist:
if form.cleaned_data['newsletter']:
Subscription(user=request.user, newsletter_id=newsletter_id, subscribed=True).save()
else:
if subscription.subscribed != form.cleaned_data['newsletter']:
subscription.update(('unsubscribe', 'subscribe')[form.cleaned_data['newsletter']])
perm = Permission.objects.get(codename='test_site', content_type=ContentType.objects.get_for_model(Profile))
if form.cleaned_data['test_site']:
request.user.user_permissions.add(perm)
else:
request.user.user_permissions.remove(perm)
return HttpResponseRedirect(request.path)
else:
form = ProfileForm(instance=request.profile, user=request.user)
if newsletter_id is not None:
try:
subscription = Subscription.objects.get(user=request.user, newsletter_id=newsletter_id)
except Subscription.DoesNotExist:
form.fields['newsletter'].initial = False
else:
form.fields['newsletter'].initial = subscription.subscribed
form.fields['test_site'].initial = request.user.has_perm('judge.test_site')
tzmap = settings.TIMEZONE_MAP
return render(request, 'user/edit-profile.html', {
'require_staff_2fa': settings.DMOJ_REQUIRE_STAFF_2FA,
'form': form, 'title': _('Edit profile'), 'profile': request.profile,
'can_download_data': bool(settings.DMOJ_USER_DATA_DOWNLOAD),
'has_math_config': bool(settings.MATHOID_URL),
'TIMEZONE_MAP': tzmap or 'http://momentjs.com/static/img/world.png',
'TIMEZONE_BG': settings.TIMEZONE_BG if tzmap else '#4E7CAD',
})
示例10: test_reversion_anonymization
# 需要导入模块: from reversion import revisions [as 别名]
# 或者: from reversion.revisions import create_revision [as 别名]
def test_reversion_anonymization(self):
from reversion import revisions as reversion
from reversion.models import Version
from gdpr.utils import get_reversion_versions
anon = ContactFormAnonymizer()
anon.Meta.anonymize_reversion = True
anon.Meta.reversible_anonymization = True
user = User(username='test_username')
user.save()
with reversion.create_revision():
form = ContactForm()
form.email = CUSTOMER__EMAIL
form.full_name = CUSTOMER__LAST_NAME
form.save()
reversion.set_user(user)
with reversion.create_revision():
form.email = CUSTOMER__EMAIL2
form.save()
reversion.set_user(user)
with reversion.create_revision():
form.email = CUSTOMER__EMAIL3
form.save()
reversion.set_user(user)
versions: List[Version] = get_reversion_versions(form)
self.assertEqual(versions[0].field_dict['email'], CUSTOMER__EMAIL)
self.assertEqual(versions[1].field_dict['email'], CUSTOMER__EMAIL2)
self.assertEqual(versions[2].field_dict['email'], CUSTOMER__EMAIL3)
anon.anonymize_obj(form, base_encryption_key=self.base_encryption_key)
anon_versions: List[Version] = get_reversion_versions(form)
anon_form = ContactForm.objects.get(pk=form.pk)
self.assertNotEqual(anon_versions[0].field_dict['email'], CUSTOMER__EMAIL)
self.assertNotEqual(anon_versions[1].field_dict['email'], CUSTOMER__EMAIL2)
self.assertNotEqual(anon_versions[2].field_dict['email'], CUSTOMER__EMAIL3)
self.assertNotEqual(anon_form.email, CUSTOMER__EMAIL3)
anon.deanonymize_obj(anon_form, base_encryption_key=self.base_encryption_key)
deanon_versions: List[Version] = get_reversion_versions(form)
deanon_form = ContactForm.objects.get(pk=form.pk)
self.assertEqual(deanon_versions[0].field_dict['email'], CUSTOMER__EMAIL)
self.assertEqual(deanon_versions[1].field_dict['email'], CUSTOMER__EMAIL2)
self.assertEqual(deanon_versions[2].field_dict['email'], CUSTOMER__EMAIL3)
self.assertEqual(deanon_form.email, CUSTOMER__EMAIL3)
self.assertDictEqual(versions[0].field_dict, deanon_versions[0].field_dict)
self.assertDictEqual(versions[1].field_dict, deanon_versions[1].field_dict)
self.assertDictEqual(versions[2].field_dict, deanon_versions[2].field_dict)