[Zope] forms and variable mix-ups

ed colmar element@immersivearts.com
Tue, 4 Jan 2000 19:32:02 -0700


    This being my first post to the list, I want to thank everyone for all
the insight and information that is so freely given here.  I'm pleased to be
a part of this community.

    I have been using zope for 6 months now, and I have started to build a
python product, based on some pre-existing code (mostly Squishdot).  I have
been getting some strange variable mixups, that i can't track down.  So I am
coming to the group to try and figure it out.

    I should say that I have searched the archives, and read the relavent
how-tos, and have not found the answers I am looking for.  I realize that
this is a syntax problem somewhere, and any help is greatly appreciated.
This is a huge post, with a bunch of problems (i'm sure) and I apologize if
it irritates anyone.

    Problem 1:  I have a form that submits a bunch of fields to a python
method "addSRPerson"  This is based on "addPosting" in Squishdot.  The first
10 fields work as expected, then the strangeness starts.   The field
"otherwebsite" seems to store the value of "description" except that it is
stored in brackets and single quotes, like this: ['description']   The
description and summary variables come up blank, and the only checkbox,
switches to checked.

    I notice that some variables in Squishdot are defined simply with the
variable name, while others are defined as variablename=''.  I have a
feeling this is where my problem is, because I do not understand the
difference.

    Problem 2:  I have a select box, that I want people to be able to select
multiple items from.  The selecting and submission seems to work, but I
can't get them to display in the editPersonFrom page.  I got this list into
the addSRPerson method by using "styles=[]" is this the right way to do it?
Also, how to make it not freak out with a single selection.  Do I force it
into a list on the input form?

    Thanks in advance for the help!

    -ed-


    here are snippits of the code
-------------------------------------------------------------------
The python source, primary class
-------------------------------------------------------------------


    def addSRPerson(self,firstname,lastname,username,city,state,country,
                   birthdate,mixingsince,personalwebsite, description,
                   voicecontact,djname,otherwebsite='',file='',
                   styles=[],
                   summary='', email='',private='',
                   REQUEST=None,RESPONSE=None,internal=0):
        """   add a person to the database
              this is based on Squishsite.addPosting
        """
        firstname =strip(firstname)
        lastname=strip(lastname)
        username=strip(username)
        city=strip(city)
        state=strip(state)
        country=strip(country)
        birthdate =strip(birthdate)
        personalwebsite=strip(personalwebsite)
        voicecontact=strip(voicecontact)
        email=strip(email)
        private=private
        djname=strip(djname)
        styles=styles
        mixingsince=strip(mixingsince)
        otherwebsite=strip(otherwebsite)
        summary = strip(summary)
        if summary:
            summary  =split(CRLF.sub('\n',summary),'\n')
        else:
            summary = None
        description = strip(description)
        if description:
            description  =split(CRLF.sub('\n',description),'\n')
        else:
            description = None

-------------------------------------------------------------------
The python source, post class
-------------------------------------------------------------------


class StarRavePersonPost(StarRavePerson):
    """ A class for peoples' data
        Based on Class Article in Squishdot  """
    meta_type  ='SRPersonPost'
    icon   ='misc_/Squishdot/person_img'
    def __init__(self, id, srprojects, firstname, lastname, username,
                 city, state, country,
                 birthdate, personalwebsite, voicecontact,
                 email, otherwebsite, description, validated, file,
                 djname, styles, mixingsince, private, summary ):

StarRavePerson.__init__(self,id,srprojects,firstname,lastname,username,
                 city,state,country,
                 birthdate,personalwebsite,voicecontact,
                 email, otherwebsite, description, validated, djname,
                 styles,mixingsince,private, file, summary)

    def
manage_edit(self,firstname,lastname,username,city,state,country,birthdate,
                    personalwebsite,voicecontact,otherwebsite,description,

djname,styles,mixingsince,email='',private='',validated='',
                    summary='',REQUEST=None,RESPONSE=None):
        """ edit a person """

        firstname =strip(firstname)
        lastname=strip(lastname)
        username=strip(username)
        city=strip(city)
        state=strip(state)
        country=strip(country)
        birthdate =strip(birthdate)
        personalwebsite=strip(personalwebsite)
        voicecontact=strip(voicecontact)
        email=strip(email)
        description=strip(description)
        private=private
        id = self.id
        description  =split(CRLF.sub('\n',description),'\n')
        summary  =split(CRLF.sub('\n',summary),'\n')

        self.firstname      =firstname
        self.lastname       =lastname
        self.username       =username
        self.city           =city
        self.state          =state
        self.country        =country
        self.birthdate      =birthdate
        self.personalwebsite=personalwebsite
        self.voicecontact   =voicecontact
        self.email          =email
        self.summary        =summary
        self.djname         =djname
        self.styles         =styles
        self.mixingsince    =mixingsince
        self.otherwebsite   =otherwebsite
        self.description    =description
        self.private        =private
        self.validated      =validated

-------------------------------------------------------------------
a bit from The submission form (I left out most of the fields that work)
-------------------------------------------------------------------


<TR>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <STRONG>Other Website</STRONG>  Any other websites that you are involved
with  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <INPUT TYPE="TEXT" NAME="otherwebsite" VALUE="" SIZE="40">
  </TD>
</TR>

<dtml-if "meta_type == 'StarRave Site'">
<TR>
  <TD ALIGN="LEFT" VALIGN="TOP"><font color="RED">*</font><STRONG>Brief
description</STRONG>  One or two sentances describing yourself.
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
<TEXTAREA NAME="summary" WRAP ROWS="5" COLS="50"></TEXTAREA></TD>
</TR>
</dtml-if>

<TR>
  <TD ALIGN="LEFT" VALIGN="TOP"><font
color="RED">*</font><STRONG>Description</STRONG>  Your life's story goes
here
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
<TEXTAREA NAME="description" WRAP ROWS="14" COLS="50"><dtml-if body><dtml-in
body>> <dtml-var sequence-item html_quote>
</dtml-in></dtml-if></TEXTAREA>
  </TD>
</TR>

<TR><TD>&nbsp</TD><TD>If you are a Dj fill out these fields</TD></TR>
<TR>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <STRONG>Dj Pseudonym</STRONG>
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <INPUT TYPE="TEXT" NAME="djname" VALUE="" SIZE="40">
  </TD>
</TR>

<TR>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <STRONG>Styles</STRONG> Select multiples with shift-click
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
<dtml-if has_styles>
  <SELECT NAME="styles" size="4" multiple>
  <OPTION VALUE="" SELECTED>&nbsp;
  <dtml-in styles_list>
  <OPTION VALUE="<dtml-var sequence-item html_quote>"><dtml-var
sequence-item>
  </dtml-in styles_list>
  </SELECT>
<dtml-else>
  <INPUT TYPE="TEXT" NAME="subject" VALUE="" SIZE="40">
</dtml-if has_subjects>
<TR>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <STRONG>Mixing since</STRONG>  Date that you started spinning.  Unknown
format
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <INPUT TYPE="TEXT" NAME="mixingsince" VALUE="" SIZE="40">
  </TD>
</TR>

-------------------------------------------------------------------
a bit from The edit form (I left out most of the fields that work)
-------------------------------------------------------------------
<TR>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <STRONG>Other Website</STRONG>
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
    <INPUT TYPE="TEXT" NAME="otherwebsite" VALUE="<dtml-var otherwebsite
html_quote>" SIZE="40">
  </TD>
</TR>

<dtml-if "meta_type == 'SrPersonPost'">
<TR>
  <TD ALIGN="LEFT" VALIGN="TOP"><STRONG>Summary</STRONG>
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
<dtml-if "REQUEST.has_key('summary')">
<TEXTAREA NAME="summary" WRAP ROWS="5" COLS="50"><dtml-if
"REQUEST['summary']"><dtml-var "REQUEST['summary']" html_quote
newline_to_br></dtml-if></TEXTAREA>

<dtml-else>
<TEXTAREA NAME="summary" WRAP ROWS="5" COLS="50"><dtml-if summary><dtml-in
summary><dtml-var sequence-item html_quote></dtml-in summary></dtml-if
summary></TEXTAREA>
</dtml-if>
  </TD>
</TR>
</dtml-if>

<TR>
  <TD ALIGN="LEFT" VALIGN="TOP"><STRONG>Description</STRONG>
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
<dtml-if "REQUEST.has_key('description')">
<TEXTAREA NAME="description" WRAP ROWS="5" COLS="50"><dtml-if
"REQUEST['description']"><dtml-var "REQUEST['description']" html_quote
newline_to_br></dtml-if></TEXTAREA>
<dtml-else>
<TEXTAREA NAME="description" WRAP ROWS="14" COLS="50"><dtml-if
description><dtml-in description><dtml-var sequence-item
html_quote></dtml-in description></dtml-if description></TEXTAREA>
</dtml-if>
  </TD>
</TR>


<TR><TD>&nbsp</TD><TD>Dj fields</TD></TR>

<TR>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <STRONG>Dj Pseudonym</STRONG>
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <dtml-if "REQUEST.has_key('email')">
  <INPUT TYPE="TEXT" NAME="djname" VALUE="<dtml-var "REQUEST['djname']"
html_quote>" SIZE="40">
  <dtml-else>
  <INPUT TYPE="TEXT" NAME="djname" VALUE="<dtml-var djname html_quote>"
SIZE="40">
  </dtml-if>
 </TD>
</TR>


<TR>
  <TD ALIGN="LEFT" VALIGN="TOP">
  <STRONG>Styles</STRONG>
  </TD>
  <TD ALIGN="LEFT" VALIGN="TOP">
<dtml-if has_styles>
  <SELECT NAME="styles" size="4" multiple>
  <dtml-if "REQUEST.has_key('styles')" >
     <dtml-if "REQUEST['styles']" >
     <OPTION VALUE="">&nbsp;
     <dtml-else>
     <OPTION VALUE="" SELECTED>&nbsp;
     </dtml-if>
  <dtml-else>
  <OPTION VALUE="">&nbsp;
  </dtml-if>
<dtml-in styles_list>
  <dtml-if "REQUEST.has_key('styles')" >
     <dtml-if "_['sequence-item'] == REQUEST['styles']">
     <OPTION VALUE="<dtml-var sequence-item html_quote>" SELECTED><dtml-var
sequence-item>
     <dtml-else>
     <OPTION VALUE="<dtml-var sequence-item html_quote>"><dtml-var
sequence-item>
     </dtml-if>
  <dtml-else>
     <dtml-if "_['sequence-item'] == styles">
     <OPTION VALUE="<dtml-var sequence-item html_quote>" SELECTED><dtml-var
sequence-item>
     <dtml-else>
     <OPTION VALUE="<dtml-var sequence-item html_quote>"><dtml-var
sequence-item>
     </dtml-if>
  </dtml-if>
  </dtml-in styles_list>
  </SELECT>
<dtml-else>
  <dtml-if "REQUEST.has_key('username')" >
  <INPUT TYPE="TEXT" NAME="styles" VALUE="<dtml-var "REQUEST['styles']"
html_quote>" SIZE="40">
  <dtml-else>
  <INPUT TYPE="TEXT" NAME="styles" VALUE="<dtml-var styles html_quote>"
SIZE="40">
  </dtml-if>
</dtml-if has_styles>

-------------------------------------------------------------------