Python reversion.revisions.create_revision() Examples

The following are 19 code examples of reversion.revisions.create_revision(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module reversion.revisions , or try the search function .
Example #1
Source File: social_auth.py    From online-judge with GNU Affero General Public License v3.0 6 votes vote down vote up
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,
        }) 
Example #2
Source File: xversion.py    From myblog with GNU Affero General Public License v3.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #3
Source File: xversion.py    From ImitationTmall_Django with GNU General Public License v3.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #4
Source File: xversion.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #5
Source File: xversion.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #6
Source File: xversion.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #7
Source File: xversion.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #8
Source File: mixins.py    From django-project with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def save_revision(self, user, comment, *args, **kwargs):
        with transaction.atomic(), reversion.create_revision():
            self.save()
            reversion.set_user(user)
            reversion.set_comment(comment) 
Example #9
Source File: xversion.py    From django_OA with GNU General Public License v3.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #10
Source File: xversion.py    From CTF_AWD_Platform with MIT License 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #11
Source File: xversion.py    From StormOnline with Apache License 2.0 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #12
Source File: comment.py    From online-judge with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #13
Source File: user.py    From online-judge with GNU Affero General Public License v3.0 5 votes vote down vote up
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()}}) 
Example #14
Source File: user.py    From online-judge with GNU Affero General Public License v3.0 5 votes vote down vote up
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({}) 
Example #15
Source File: user.py    From online-judge with GNU Affero General Public License v3.0 5 votes vote down vote up
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()}}) 
Example #16
Source File: comments.py    From online-judge with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #17
Source File: xversion.py    From weibo-analysis-system with MIT License 5 votes vote down vote up
def do_create_revision(request):
    with create_revision():
        set_user(request.user)
        yield 
Example #18
Source File: test_model_anonymization.py    From django-GDPR with MIT License 4 votes vote down vote up
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) 
Example #19
Source File: user.py    From online-judge with GNU Affero General Public License v3.0 4 votes vote down vote up
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',
    })