SV: [Zope] More verbose undo/transaction desciptions

Carsten Gehling carsten@gehling.dk
Thu, 31 Jul 2003 11:24:27 +0200


Yes that did the trick, and that - of course - gave birth to a few more
questions:

1) Can i do any linebreaks in this note() function? It's to make it look
nicer on the Undo list. I've tried with \n and <br> but neither gives the
expected result (<br> is converted to &lt;br&gt; and \n is of course just
ignored by the browser).

2) As said before, I want to use this to let the manager know which
attributes in the object, that has been altered. Currently I do it like
this:
--------------------------------------------------
class TVTeknik(SimpleItem):
    "Et TVTeknik objekt"

    meta_type = "TV Teknik"

    def __init__(self, id, serienummer = ""):
        self.id = id
        self.editTVTeknik(serienummer)

    def editTVTeknik(self,
             serienummer = "",
             model = "",
             fabrikat = "",
             REQUEST = None):
        "Metode til at opdatere data"

        l = []
        try:
            if self.serienummer != serienummer:
                l.append("serienummer: '%s' => '%s'" % (self.serienummer,
serienummer))
                self.serienummer = serienummer
        except: self.serienummer = serienummer
        try:
            if self.model != model:
                l.append("model: '%s' => '%s'" % (self.model, model))
                self.model = model
        except: self.model = model
        try:
            if self.fabrikat != fabrikat:
                l.append("fabrikat: '%s' => '%s'" % (self.fabrikat,
fabrikat))
                self.fabrikat = fabrikat
        except: self.fabrikat = fabrikat

        if len(l) > 0:
            s = " | Opdaterede felter: %s" % string.join(l, ", ")
            get_transaction().note(s)
            self.__changed__(1)
--------------------------------------------------

BUT add only a few more attributes, and the code gets unnessarily long.
Maybe it's because I haven't got enough Python experience.

Isn't there a way of looping through the function arguments so all this
could be made as a loop? Something like (mind you, this is NOT intended to
be valid Python code - just a sort of pseudo):

def editTVTeknik(self,
		 serienummer = "",
		 model = "",
		 fabrikat = "",
		 REQUEST = None):
	"Metode til at opdatere data"

	l = []
	for a in function_arguments:
		try:
			if eval('self.' + a.name) != a.value:
				l.append("%s: '%s' => '%s'" % (a.name, eval('self.'+a.name, a.value)))
				eval('self.' + a.name) = a.value
        except: eval('self.' + a.name) = a.value

    if len(l) > 0:
        s = " | Opdaterede felter: %s" % string.join(l, ", ")
        get_transaction().note(s)
        self.__changed__(1)

- Carsten


> -----Oprindelig meddelelse-----
> Fra: zope-admin@zope.org [mailto:zope-admin@zope.org]Pa vegne af Jens
> Vagelpohl
> Sendt: 30. juli 2003 23:46
> Til: Carsten Gehling
> Cc: Zope@Zope.Org
> Emne: Re: [Zope] More verbose undo/transaction desciptions
>
>
> If this is for your own python filesystem product you could make a call
> in the filesystem python code like...
>
> 	get_transaction().note('I just foobared my widget')
>
> ...and then that's what shows up for it on the undo list.
>
> jens
>
>
> On Wednesday, Jul 30, 2003, at 17:26 US/Eastern, Carsten Gehling wrote:
>
> > Is it possible to make the Undo tab's list of transactions more
> > verbose?
> >
> > Say that I change the value of one property of an object, and then at a
> > later time change another property of the same object. In the object's
> > Undo
> > tab, there's only displayed, that I called the
> > "editTheObject-something"
> > method twice, not which properties that were changed.
> >
> > Is it something that I tweak in my product's code?
> >
> > - Carsten
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
>