Ejemplo n.º 1
0
    def clone(self):
        """
        **Note:** In order for clone to work, you need to have an
        auto-incrementing primary key.

        Also see https://docs.djangoproject.com/en/dev/topics/db/queries/#copying-model-instances
        """
        # TODO: Maybe provide support for many-to-many relationships too, or
        # document that you should provide your own clone()
        # See https://code.djangoproject.com/ticket/4027
        new = copy.copy(self)
        unset_pks(new)
        try:
            # Contents keep a cached copy of their Node. After the clone the
            # cache is invalid.
            del new._node
        except AttributeError:
            pass
        new.save()

        for f in self._meta.many_to_many:
            # This will only handle simple many-to-manies, those that don't
            # have a custom through table.
            f.save_form_data(new, f.value_from_object(self))

        assert new != self
        return new
Ejemplo n.º 2
0
    def clone(self):
        """
        **Note:** In order for clone to work, you need to have an
        auto-incrementing primary key.

        Also see https://docs.djangoproject.com/en/dev/topics/db/queries/#copying-model-instances
        """
        # TODO: Maybe provide support for many-to-many relationships too, or
        # document that you should provide your own clone()
        # See https://code.djangoproject.com/ticket/4027
        new = copy.copy(self)
        unset_pks(new)
        new.save()
        return new
Ejemplo n.º 3
0
    def clone(self):
        """
        **Note:** In order for clone to work, you need to have an
        auto-incrementing primary key.

        Also see https://docs.djangoproject.com/en/dev/topics/db/queries/#copying-model-instances
        """
        # TODO: Maybe provide support for many-to-many relationships too, or
        # document that you should provide your own clone()
        # See https://code.djangoproject.com/ticket/4027
        new = copy.copy(self)
        unset_pks(new)
        new.save()
        return new
Ejemplo n.º 4
0
 def clone(self):
     vt = copy.copy(self)
     vt.working_copy = vt.working_copy.clone_tree(freeze=False)
     commits = list(self._commits_to_clone())
     unset_pks(vt)
     vt.head = None
     vt.save()
     for commit in commits:
         commit.tracker = vt
         commit.parent = vt.head
         unset_pks(commit)
         commit.save()
         vt.head = commit
     vt.save()
     return vt
Ejemplo n.º 5
0
    def form_valid(self, form):
        page = form.instance
        unset_pks(page)
        page.root_node = page.root_node.clone(new_page=True)
        page.status = CONTENT_STATUS_DRAFT
        form.save()

        messages.success(
            self.request,
            _("'{old_title}' successfully cloned as '{new_title}'.").format(
                old_title=self.original_title, new_title=page.title
            ),
        )
        # We can't do a normal HTTP redirect because the form is in a modal
        # window.
        return render(self.request, "widgy/widgy_mezzanine/clone_success.html", {"success_url": self.get_success_url()})
Ejemplo n.º 6
0
    def form_valid(self, form):
        page = form.instance
        unset_pks(page)
        page.root_node = page.root_node.clone()
        form.save()

        messages.success(
            self.request,
            _("'{old_title}' successfully cloned as '{new_title}'.").format(
                old_title=self.original_title,
                new_title=page.title,
            )
        )
        # We can't do a normal HTTP redirect because the form is in a modal
        # window.
        return render(self.request, 'widgy/widgy_mezzanine/clone_success.html', {
            'success_url': self.get_success_url(),
        })
Ejemplo n.º 7
0
    def form_valid(self, form):
        page = form.instance
        unset_pks(page)
        page.root_node = page.root_node.clone()
        page.status = CONTENT_STATUS_DRAFT
        form.save()

        messages.success(
            self.request,
            _("'{old_title}' successfully cloned as '{new_title}'.").format(
                old_title=self.original_title,
                new_title=page.title,
            )
        )
        # We can't do a normal HTTP redirect because the form is in a modal
        # window.
        return render(self.request, 'widgy/widgy_mezzanine/clone_success.html', {
            'success_url': self.get_success_url(),
        })
Ejemplo n.º 8
0
    def clone(self):
        """
        **Note:** In order for clone to work, you need to have an
        auto-incrementing primary key.

        Also see https://docs.djangoproject.com/en/dev/topics/db/queries/#copying-model-instances
        """
        # TODO: Maybe provide support for many-to-many relationships too, or
        # document that you should provide your own clone()
        # See https://code.djangoproject.com/ticket/4027
        new = copy.copy(self)
        unset_pks(new)
        new.save()

        for f in self._meta.many_to_many:
            # This will only handle simple many-to-manies, those that don't
            # have a custom through table.
            f.save_form_data(new, f.value_from_object(self))

        return new
Ejemplo n.º 9
0
 def clone_new_page(self):
     new = copy.copy(self)
     unset_pks(new)
     new.ident = uuid.uuid4()
     new.save()
     return new
Ejemplo n.º 10
0
 def test_unset_pks(self):
     obj = Child.objects.create()
     unset_pks(obj)
     self.assertIsNone(obj.foo)
     self.assertIsNone(obj.base_ptr_id)
Ejemplo n.º 11
0
 def test_unset_pks(self):
     obj = Child.objects.create()
     unset_pks(obj)
     self.assertIsNone(obj.foo)
     self.assertIsNone(obj.base_ptr_id)
Ejemplo n.º 12
0
 def clone_new_page(self):
     new = copy.copy(self)
     unset_pks(new)
     new.ident = uuid.uuid4()
     new.save()
     return new