Re: Change object class?

7 messages Options
Embed this post
Permalink
Bill Campbell-2 () Re: Change object class?
Reply Threaded More More options
Print post
Permalink
Is it possible to change the class of an existing object?

I am creating a product with argouml and archgenxml with a class
that is a subclass of a normal folder with a couple of additional
fields, and a customized view.  I would like to be able to change
some existing folders to this new class without having to create
a new object, then copy/paste or otherwise move the existing
objects in the folder?

Bill
--
INTERNET:   [hidden email]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:          (206) 236-1676  Mercer Island, WA 98040-0820
Fax:            (206) 232-9186  Skype: jwccsllc (206) 855-5792

We contend that for a nation to try to tax itself into prosperity is like a
man standing in a bucket and trying to lift himself up by the handle.
    -- Winston Churchill

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Vincent Fretin () Re: Change object class?
Reply Threaded More More options
Print post
Permalink
Sure you can:

>>> class A(object):
...   pass
...
>>> class B(object):
...   pass
...
>>> obj = A()
>>> obj.__class__
<class '__main__.A'>
>>> obj.__class__ = B
>>> obj.__class__
<class '__main__.B'>

Vincent Fretin
Ecreall
Site : http://vincentfretin.ecreall.com



On Thu, Nov 5, 2009 at 3:33 AM, Bill Campbell <[hidden email]> wrote:

> Is it possible to change the class of an existing object?
>
> I am creating a product with argouml and archgenxml with a class
> that is a subclass of a normal folder with a couple of additional
> fields, and a customized view.  I would like to be able to change
> some existing folders to this new class without having to create
> a new object, then copy/paste or otherwise move the existing
> objects in the folder?
>
> Bill
> --
> INTERNET:   [hidden email]  Bill Campbell; Celestial Software LLC
> URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
> Voice:          (206) 236-1676  Mercer Island, WA 98040-0820
> Fax:            (206) 232-9186  Skype: jwccsllc (206) 855-5792
>
> We contend that for a nation to try to tax itself into prosperity is like a
> man standing in a bucket and trying to lift himself up by the handle.
>    -- Winston Churchill
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Archetypes-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/archetypes-users
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Martin Aspeli () Re: Change object class?
Reply Threaded More More options
Print post
Permalink
Vincent Fretin wrote:

> Sure you can:
>
>>>> class A(object):
> ...   pass
> ...
>>>> class B(object):
> ...   pass
> ...
>>>> obj = A()
>>>> obj.__class__
> <class '__main__.A'>
>>>> obj.__class__ = B
>>>> obj.__class__
> <class '__main__.B'>

... but it is almost certainly a bad idea unless you know a *lot* about
Python's inner workings.

:)

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Martin Aspeli () Re: Change object class?
Reply Threaded More More options
Print post
Permalink
In reply to this post by Bill Campbell-2
Bill Campbell wrote:
> Is it possible to change the class of an existing object?
>
> I am creating a product with argouml and archgenxml with a class
> that is a subclass of a normal folder with a couple of additional
> fields, and a customized view.  I would like to be able to change
> some existing folders to this new class without having to create
> a new object, then copy/paste or otherwise move the existing
> objects in the folder?

What you want is migration. Look at
http://pypi.python.org/pypi/Products.contentmigration, which provides a
framework for this kind of thing. plone.app.blob contains examples of
its use.

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Bill Campbell-2 () Re: Change object class?
Reply Threaded More More options
Print post
Permalink
On Sun, Nov 08, 2009, Martin Aspeli wrote:

>Bill Campbell wrote:
>> Is it possible to change the class of an existing object?
>>
>> I am creating a product with argouml and archgenxml with a class
>> that is a subclass of a normal folder with a couple of additional
>> fields, and a customized view.  I would like to be able to change
>> some existing folders to this new class without having to create
>> a new object, then copy/paste or otherwise move the existing
>> objects in the folder?
>
>What you want is migration. Look at
>http://pypi.python.org/pypi/Products.contentmigration, which provides a
>framework for this kind of thing. plone.app.blob contains examples of
>its use.

Thanks.  I'll take a look at that.

I have read the migration docs in RichDocument several times, but
never have gotten my head around it.

Bill
--
INTERNET:   [hidden email]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:          (206) 236-1676  Mercer Island, WA 98040-0820
Fax:            (206) 232-9186  Skype: jwccsllc (206) 855-5792

One of the common failings among honorable people is a failure to
appreciate how thoroughly dishonorable some other people can be, and how
dangerous it is to trust them.
    - Thomas Sowell

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Martin Aspeli () Re: Change object class?
Reply Threaded More More options
Print post
Permalink
Bill Campbell wrote:

> On Sun, Nov 08, 2009, Martin Aspeli wrote:
>> Bill Campbell wrote:
>>> Is it possible to change the class of an existing object?
>>>
>>> I am creating a product with argouml and archgenxml with a class
>>> that is a subclass of a normal folder with a couple of additional
>>> fields, and a customized view.  I would like to be able to change
>>> some existing folders to this new class without having to create
>>> a new object, then copy/paste or otherwise move the existing
>>> objects in the folder?
>> What you want is migration. Look at
>> http://pypi.python.org/pypi/Products.contentmigration, which provides a
>> framework for this kind of thing. plone.app.blob contains examples of
>> its use.
>
> Thanks.  I'll take a look at that.
>
> I have read the migration docs in RichDocument several times, but
> never have gotten my head around it.

It's not rocket science - it's just a way to run a search over all
objects matching certain criteria (i.e. "find everything of the old
type") and then changing those objects. You can set up some mappings or
write some methods to help translate from "old" to "new" object. But the
changing of the portal_type and class is largely taken care of for you
by the framework.

Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Raphael Ritz () Re: Change object class?
Reply Threaded More More options
Print post
Permalink
In reply to this post by Martin Aspeli
Martin Aspeli wrote:

> Vincent Fretin wrote:
>> Sure you can:
>>
>>>>> class A(object):
>> ...   pass
>> ...
>>>>> class B(object):
>> ...   pass
>> ...
>>>>> obj = A()
>>>>> obj.__class__
>> <class '__main__.A'>
>>>>> obj.__class__ = B
>>>>> obj.__class__
>> <class '__main__.B'>
>
> ... but it is almost certainly a bad idea unless you know a *lot* about
> Python's inner workings.
>
> :)
>
> Martin
>

Still it works ;-)

http://plone.org/products/atcustomtypes/
https://dev.plone.org/collective/browser/ATCustomTypes/trunk/migrations.py

Raphael



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users