Skip to content

Commit

Permalink
fix rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jun 12, 2017
1 parent d006fc5 commit 23a46e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions apps/projects/models.py
Expand Up @@ -143,18 +143,19 @@ def __str__(self):
def get_absolute_url(self):
return reverse('project', kwargs={'pk': self.project.pk})

# def rollback(self):
# # first remove all current values
# Value.objects.filter(snapshot=None).delete()

# # remove the snapshot from this snapshots values
# for value in self.values.all():
# value.snapshot = None
# value.save()

# # remove all snapshot created later and the current_snapshot
# for snapshot in Snapshot.objects.filter(created__gte=self.created):
# snapshot.delete()
def rollback(self):
# remove all current values for this project
self.project.values.filter(snapshot=None).delete()

# remove the snapshot_id from this snapshots values so they are current values
for value in self.values.all():
value.snapshot = None
value.save()

# remove all snapshot created later and the current_snapshot
# this also removes the values of these snapshots
for snapshot in self.project.snapshots.filter(created__gte=self.created):
snapshot.delete()


def create_values_for_snapshot(sender, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion apps/projects/urls.py
Expand Up @@ -48,7 +48,7 @@

url(r'^(?P<project_id>[0-9]+)/snapshots/create/$', SnapshotCreateView.as_view(), name='snapshot_create'),
url(r'^(?P<project_id>[0-9]+)/snapshots/(?P<pk>[0-9]+)/update/$', SnapshotUpdateView.as_view(), name='snapshot_update'),
# url(r'^(?P<project_id>[0-9]+)/snapshots/(?P<pk>[0-9]+)/rollback/$', SnapshotRollbackView.as_view(), name='snapshot_rollback'),
url(r'^(?P<project_id>[0-9]+)/snapshots/(?P<pk>[0-9]+)/rollback/$', SnapshotRollbackView.as_view(), name='snapshot_rollback'),

url(r'^(?P<pk>[0-9]+)/answers/$', ProjectAnswersView.as_view(), name='project_answers'),
url(r'^(?P<pk>[0-9]+)/answers/export/(?P<format>[a-z]+)/$', ProjectAnswersExportView.as_view(), name='project_answers_export'),
Expand Down
2 changes: 1 addition & 1 deletion apps/projects/viewsets.py
Expand Up @@ -15,7 +15,7 @@
from apps.conditions.models import Condition
from apps.questions.models import Catalog, QuestionEntity

from .models import Project, Membership, Snapshot, Value
from .models import Project, Snapshot, Value

from .serializers import ProjectSerializer, ValueSerializer
from .serializers.question_entity import QuestionEntitySerializer
Expand Down

0 comments on commit 23a46e7

Please sign in to comment.