Skip to content

Commit

Permalink
Fix copy_project
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Feb 4, 2025
1 parent 1017b1e commit 32abdd3
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions rdmo/projects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,29 @@ def check_options(project, value):
return True


def copy_project(project, site, owners):
from .models import Membership, Value # to prevent circular inclusion
def copy_project(instance, site, owners):
from .models import Membership, Project, Value # to prevent circular inclusion

timestamp = now()

tasks = project.tasks.all()
views = project.views.all()
tasks = instance.tasks.all()
views = instance.views.all()

values = project.values.filter(snapshot=None)
values = instance.values.filter(snapshot=None)
snapshots = {
snapshot: project.values.filter(snapshot=snapshot)
for snapshot in project.snapshots.all()
snapshot: instance.values.filter(snapshot=snapshot)
for snapshot in instance.snapshots.all()
}

# unset the id, set current site and update timestamps
project.id = None
project.site = site
project.created = timestamp

# save the new project
project.save()
# a completely new project instance needs to be created in order for mptt to work
project = Project.objects.create(
parent=instance.parent,
site=instance.site,
title=instance.title,
description=instance.description,
catalog=instance.catalog,
created=timestamp
)

# save project tasks
for task in tasks:
Expand Down

0 comments on commit 32abdd3

Please sign in to comment.