Logo Search packages:      
Sourcecode: qm version File versions

def qm::test::web::web::QMTestServer::HandleShowItem (   self,
  request 
)

Handle a request to show a test or resource.

'request' -- A 'WebRequest' object.

This function generates pages to handle these requests:

  'create-test' -- Generate a form for initial editing of a test
  about to be created, given its test ID and test class.

  'create-resource' -- Likewise for an resource.

  'show-test' -- Display a test.

  'show-resource' -- Likewise for an resource.

  'edit-test' -- Generate a form for editing an existing test.

  'edit-resource' -- Likewise for an resource.

This function distinguishes among these cases by checking the script
name of the request object.

The request must have the following fields:

  'id' -- A test or resource ID.  For show or edit pages, the ID of an
  existing item.  For create pages, the ID of the item being
  created.

  'class' -- For create pages, the name of the test or resource
  class.

Definition at line 1943 of file web.py.

01943                                      :
        """Handle a request to show a test or resource.

        'request' -- A 'WebRequest' object.

        This function generates pages to handle these requests:

          'create-test' -- Generate a form for initial editing of a test
          about to be created, given its test ID and test class.

          'create-resource' -- Likewise for an resource.

          'show-test' -- Display a test.

          'show-resource' -- Likewise for an resource.

          'edit-test' -- Generate a form for editing an existing test.

          'edit-resource' -- Likewise for an resource.

        This function distinguishes among these cases by checking the script
        name of the request object.

        The request must have the following fields:

          'id' -- A test or resource ID.  For show or edit pages, the ID of an
          existing item.  For create pages, the ID of the item being
          created.

          'class' -- For create pages, the name of the test or resource
          class.

        """

        # Paramaterize this function based on the request's script name.
        url = request.GetScriptName()
        edit, create, type = {
            "show-test":       (0, 0, "test"),
            "edit-test":       (1, 0, "test"),
            "create-test":     (1, 1, "test"),
            "show-resource":   (0, 0, "resource"),
            "edit-resource":   (1, 0, "resource"),
            "create-resource": (1, 1, "resource"),
            }[url]

        database = self.__database

        try:
            # Determine the ID of the item.
            item_id = request["id"]
        except KeyError:
            # The user probably submitted the form without entering an ID.
            message = qm.error("no id for show")
            return qm.web.generate_error_page(request, message)

        if create:
            # We're in the middle of creating a new item.  
            class_name = request["class"]

            # First perform some validation.
            field_errors = {}
            # Check that the ID is valid.
            if not database.IsValidLabel(item_id, is_component = 0):
                field_errors["_id"] = qm.error("invalid id", id=item_id)
            else:
                # Check that the ID doesn't already exist.
                if type is "resource":
                    if database.HasResource(item_id):
                        field_errors["_id"] \
                           = qm.error("resource already exists",
                                      resource_id=item_id)
                elif type is "test":
                    if database.HasTest(item_id):
                        field_errors["_id"] = qm.error("test already exists",
                                                       test_id=item_id)
            # Check that the class exists.
            try:
                qm.test.base.get_extension_class(class_name, type,
                                                 database)
            except ValueError:
                # The class name was incorrectly specified.
                field_errors["_class"] = qm.error("invalid class name",
                                                  class_name=class_name)
            except:
                # Can't find the class.
                field_errors["_class"] = qm.error("class not found",
                                                  class_name=class_name)
            # Were there any errors?
            if len(field_errors) > 0:
                # Yes.  Instead of showing the edit page, re-show the new
                # item page.
                page = NewItemPage(server=self,
                                   type=type,
                                   item_id=item_id,
                                   class_name=class_name,
                                   field_errors=field_errors)
                return page(request)

            # Construct a test with default argument values, as the
            # starting point for editing.
            if type is "resource":
                item = self.MakeNewResource(class_name, item_id)
            elif type is "test":
                item = self.MakeNewTest(class_name, item_id)
        else:
            # We're showing or editing an existing item.
            # Look it up in the database.
            if type is "resource":
                try:
                    item = database.GetResource(item_id)
                except qm.test.database.NoSuchTestError, e:
                    # An test with the specified test ID was not fount.
                    # Show a page indicating the error.
                    return qm.web.generate_error_page(request, str(e))
            elif type is "test":
                try:
                    item = database.GetTest(item_id)
                except qm.test.database.NoSuchResourceError, e:
                    # An test with the specified resource ID was not fount.
                    # Show a page indicating the error.
                    return qm.web.generate_error_page(request, str(e))

        # Generate HTML.
        return ShowItemPage(self, item, edit, create, type)(request)


    def HandleShowResult(self, request):


Generated by  Doxygen 1.6.0   Back to index