[Zope] manage_clone issue

Marco Mariani m.mariani@imola.nettuno.it
Sun, 23 Apr 2000 02:02:14 +0200


--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii

On Sat, Apr 22, 2000 at 03:14:49PM -0500, Stephan Richter wrote:


> Can you send me your upload.py file? It seems like you wrote it.

Here it comes. It smells "newbie" all over, and it's work in progress.

> PS: Zope should not be installed under /usr/lib/zope and /var/lib/zope.

We should tell that to the debian mantainer (flight@debian.org), I use
a stock potato.



--8t9RHnE3ZwKMSgU+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="upload.py"







def _table(border=0,cellpadding=1,cellspacing=1,bgcolor=None):
    r = '<TABLE BORDER=%s CELLPADDING=%s CELLSPACING=%s' % (border,cellpadding,cellspacing)
    if bgcolor:
        r = r + ' BGCOLOR=%s' % bgcolor

    return r



def thumb_size(h,w,max=100):

    if h>w:
        w = 100.0/h*w
        h = 100
    else:
        h = 100.0/w*h
        w = 100

    return h,w



def NuovoArticolo(self,REQUEST,RESPONSE):
    r=''
    r=r+ str(REQUEST)


    gruppo = REQUEST.form.get('gruppo')

    if gruppo:
        next_art = self['prossimo_articolo']             # proprieta' del folder 'foto'
        upload=self.upload.this()
        id = 'art_%s'%next_art
        newob=upload.Control_Panel.Products.MArticolo.ArtClass(id)
        newob.id=id

        upload._setObject(id,newob)

    r=r+ 'Articolo %s aggiunto.' % next_art

    next_art = next_art + 1

    next_foto = self['prossima_foto']

    for i in gruppo:
        newob.manage_clone(upload[i],'foto_%s'%next_foto)
        newob[next_foto].manage_changeProperties({'filename': i})
        next_foto = next_foto + 1
    
    self.manage_changeProperties({'prossimo_articolo': next_art})
    self.manage_changeProperties({'prossima_foto': next_foto})

    return r





def DisplayFotoConLink(img):
        r=''

        height = int(img.height)
        width = int(img.width)

        (h,w) = thumb_size(height,width)

        r=r+ '<A HREF="%s">' % img.absolute_url()
        r=r+ ('<IMG BORDER=0 SRC="%s" WIDTH="%s" HEIGHT="%s" ALT="%s">' %
              (img.absolute_url(),w,h,img.__name__))
        r=r+ '</A>'

        return r



def ViewPhotoSet(self,gruppo,tablewidth=5):
    r= _table()

    n = 0
    for img in immagini:
        if n%tablewidth==0:
            r=r+ '<TR>'

        r=r+ '<TD VALIGN=BOTTOM>%s</TD>' % DisplayFotoConLink(img)

        if (n%tablewidth) == (tablewidth-1) :
            r=r+ '</TR>'

        n = n+1

    r=r+ '</TABLE>'

    return r



def CancellaFoto(self,REQUEST,RESPONSE):
    r=''

    gruppo = REQUEST.get('gruppo')

    if gruppo:
        
        r=r+ ViewPhotoSet(gruppo)




def uploadMenu(self, REQUEST=None, RESPONSE=None, tablewidth=6):

    sub = REQUEST.get('SUBMIT')

    if sub=='Cancella foto':
        return CancellaFoto(self,REQUEST,RESPONSE)

    if sub=="Nuovo Articolo":
        return NuovoArticolo(self,REQUEST,RESPONSE)


    r=''

    immagini = self.upload.objectValues('Image')

    l = len(immagini)

    r=r+ '<FORM METHOD=POST>'

    r=r+ '<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Nuovo Articolo">'
    r=r+ '<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Aggiungi foto a un articolo">'
    r=r+ '<INPUT NAME=SUBMIT TYPE="SUBMIT" VALUE="Cancella foto">'

    r=r+ _table()

    n = 0
    for img in immagini:
        if n%tablewidth==0:
            r=r+ '<TR>'

        r=r+ '<TD VALIGN=BOTTOM>'

        r=r+ '<SMALL>'
        r=r+ _table() + '<TR><TD><TABLE BORDER=1><TD>'

        r=r+ DisplayFotoConLink(img)

        r=r+ '</TD></TR></TABLE></TD></TR><TR><TD>'
        r=r+ '<INPUT TYPE="CHECKBOX" NAME="gruppo:list" VALUE="%s"> %s' % (img.__name__,img.__name__)
        r=r+ '</TD></TR></TABLE>'

        r=r+ '</TD>'

        if (n%tablewidth) == (tablewidth-1) :
            r=r+ '</TR>'

        n = n+1

    r=r+ '</TABLE>'
    r=r+ '</SMALL>'
    r=r+ '</FORM>'

    r=r+ str(REQUEST)

    return r




--8t9RHnE3ZwKMSgU+--