REVERT opportunity with CBV in django-reversion app?
See original GitHub issueI use next CBV to revert to a specific version of a record. Unfortunately it raise error. I am little bit confused. Can you say whats the reason? Problem in my CBV or in django-reversion?
views.py:
from reversion.views import RevisionMixin
from django.views import View
from django.shortcuts import get_object_or_404, redirect
from reversion.models import Version
import reversion
class ArticleRevert(RevisionMixin, View):
def get(self, request, *args, **kwargs):
article=get_object_or_404(Article, pk=self.kwargs.get('pk'))
revision=get_object_or_404(Version.objects.get_for_object(article), pk=self.kwargs.get('article_reversion_id')).revision
reversion.set_comment("Revert to version #{}".format(revision.id))
revision.revert()
return redirect('article_list')
ERROR:
Traceback (most recent call last):
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/views.py", line 43, in do_revision_view
return func(request, *args, **kwargs)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/Applications/Projects/web/project/article/views.py", line 165, in get
reversion.set_comment("Revert to version #{}".format(reversion.id))
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/revisions.py", line 122, in set_comment
_update_frame(comment=comment)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/revisions.py", line 87, in _update_frame
_local.stack = _local.stack[:-1] + (_current_frame()._replace(**kwargs),)
File "/Users/nurzhan_nogerbek/Virtualenvs/py2714/lib/python2.7/site-packages/reversion/revisions.py", line 53, in _current_frame
raise RevisionManagementError("There is no active revision for this thread")
RevisionManagementError: There is no active revision for this thread
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How create REVERT opportunity in django-reversion app?
I have task to rewrite correct Function Based View to Class Based View . Below you can see my code. My question is...
Read more >django-reversion API - Read the Docs
Use the django-reversion API to build version-controlled apps. ... Revert the first revision. versions[1].revision.revert() # Check the model instance has ...
Read more >How create REVERT opportunity in django-reversion app
I have task to rewrite correct Function anycodings_django-reversion Based View to Class Based View. Below you anycodings_django-reversion can see my code.
Read more >Xadmin: Drop-in Replacement Of Django Admin - Morioh
Drop-in replacement of Django admin comes with lots of goodies, ... and even how to change the look of your app and page...
Read more >Two Scoops of Django: Best Practices for Django 1.8
What to Name Your Django Apps . . ... Allows for More App and Template Reverse Tricks . ... Constraining Django CBV/GCBV Access...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s not dirty, it’s exactly the was django’s transaction.atomic() is supposed to be used.
HOWEVER, I didn’t notice that you were using RevisionMixin! So that requires some more explanation.
RevisionMixin only does not create a revision for GET, HEAD or OPTIONS request methods, since those are supposed to be “safe”, and not modify data. You can get around this by using the reversion.create_revision() decorator manually, or by using a more appropriate HTTP method.
On 7 December 2017 at 03:26, NogerbekNurzhan notifications@github.com wrote:
It works now but it seems to me that its dirty solution.
Before I thought that
@reversion.create_revision()
we can use only in Function Based View and in Class Based View we need to use onlyRevisionMixin
. Isn’t that right?