Logo Search packages:      
Sourcecode: qm version File versions

def qm::fields::AttachmentField::FormatValueAsHtml (   self,
  name = None 

Return an HTML rendering of a 'value' for this field.

'server' -- The 'WebServer' in which the HTML will be

'value' -- The value for this field.  May be 'None', which
renders a default value (useful for blank forms).

'style' -- The rendering style.  Can be "full" or "brief" (both
read-only), or "new" or "edit" or "hidden".

'name' -- The name to use for the primary HTML form element
containing the value of this field, if 'style' specifies the
generation of form elements.  If 'name' is 'None', the value
returned by 'GetHtmlFormFieldName()' should be used.

returns -- A string containing the HTML representation of

Reimplemented from qm::fields::Field.

Definition at line 1250 of file fields.py.

01250                                                                 :
        field_name = self.GetName()

        if value is None:
            # The attachment field value may be 'None', indicating no
            # attachment. 
        elif isinstance(value, attachment.Attachment):
            location = value.GetLocation() 
            mime_type = value.GetMimeType()
            description = value.GetDescription()
            file_name = value.GetFileName()
            raise ValueError, "'value' must be 'None' or an 'Attachment'"

        # Use the default field form field name if requested.
        if name is None:
            name = self.GetHtmlFormFieldName()

        if style == "full" or style == "brief":
            if value is None:
                return "None"
            # Link the attachment description to the data itself.
            download_url = web.WebRequest(self.download_url,
            # Here's a nice hack.  If the user saves the attachment to a
            # file, browsers (some at least) guess the default file name
            # from the URL by taking everything following the final
            # slash character.  So, we add this bogus-looking argument
            # to fool the browser into using our file name.
            download_url = download_url + \
                           "&=/" + urllib.quote_plus(file_name)
            result = '<a href="%s">%s</a>' \
                     % (download_url, description)
            # For the full style, display the MIME type.
            if style == "full":
                result = result + ' (%s)' % (mime_type)
            return result

        elif style == "new" or style == "edit":

            # Some trickiness here.
            # For attachment fields, the user specifies the file to
            # upload via a popup form, which is shown in a new browser
            # window.  When that form is submitted, the attachment data
            # is immediately uploaded to the server.
            # The information that's stored for an attachment is made of
            # four parts: a description, a MIME type, the file name, and
            # the location of the data itself.  The user enters these
            # values in the popup form, which sets a hidden field on
            # this form to an encoding of that information.
            # Also, when the popup form is submitted, the attachment
            # data is uploaded.  By the time this form is submitted, the
            # attachment data should be uploaded already.  The uploaded
            # attachment data is stored in the temporary attachment
            # area; it's copied into the IDB when the issue revision is
            # submitted. 

            summary_field_name = "_attachment" + name

            # Fill in the description if there's already an attachment.
            summary_value = 'value="%s"' % self._FormatSummary(value)
            if value is None:
                field_value = ""
                # We'll encode all the relevant information.
                parts = (description, mime_type, location, file_name,
                # Each part is URL-encoded.
                parts = map(urllib.quote, parts)
                # The parts are joined into a semicolon-delimited list.
                field_value = string.join(parts, ";")
            field_value = 'value="%s"' % field_value

            # Generate the popup upload page.
            upload_page = \
            # Generate controls for this form.
            # A text control for the user-visible summary of the
            # attachment.  The "readonly" property isn't supported in
            # Netscape, so prevent the user from typing into the form by
            # forcing focus away from the control.
            text_control = '''
            <input type="text"
                   %s>''' % (summary_field_name, summary_value)
            # A button to pop up the upload form.  It causes the upload
            # page to appear in a popup window.
            upload_button \
                = server.MakeButtonForCachedPopup("Upload",
            # A button to clear the attachment.
            clear_button = '''
            <input type="button"
                   value=" Clear "
                   onclick="document.form.%s.value = 'None';
                            document.form.%s.value = '';" />
            ''' % (field_name, summary_field_name, name)
            # A hidden control for the encoded attachment value.  The
            # popup upload form fills in this control.
            hidden_control = '''
            <input type="hidden"
                   %s>''' % (name, field_value)
            # Now assemble the controls with some layout bits.
            result = '''
            ''' % (text_control, hidden_control, upload_button, clear_button)

            return result

            raise ValueError, style

    def MakeDomNodeForValue(self, value, document):

Generated by  Doxygen 1.6.0   Back to index