Example #1
0
    def getCipsContactAddress(self, id, withPersonTitle=TITLE_OMITTED):
        """
        Constructs and returns a new Address object for the document.

        Parameters:
            id              - Integer ID for CDR Person document.
            docType         - 'Person' (default) or 'Organization'
            withPersonTitle - For Address constructor.
        Return value:
            Returns an Address object for the CIPS contact.
        """
        # Make string version of id
        docId = cdr.normalize(id)

        # Find fragment ID for CIPS contact location in Person doc
        rows = cdr.getQueryTermValueForId(
            '/Person/PersonLocations/CIPSContact', id, self.__conn)
        if not rows:
            raise Exception("no CIPSContact for %s" % docId)
        fragId = rows[0]

        # Filter to create AddressElement XML
        filters = ["name:Person Address Fragment With Name"]
        result = cdr.filterDoc(self.__session,
                               filters,
                               docId,
                               parm=(('fragId', fragId), ))

        # Expecting tuple of xml fragment, messages.  Single string is error.
        if type(result) == type(""):
            raise Exception("failure extracting contact address "
                            "for %s: %s" % (docId, result))
        return Address(result[0], withPersonTitle)
Example #2
0
    def __parsePersonDoc(self, id, ver, cursor):

        # If we don't have a fragment ID, use the CIPS contact location
        if not self.contactId:
            cursor.execute(
                """\
                SELECT DISTINCT value
                           FROM query_term
                          WHERE path = '/Person/PersonLocations/CIPSContact'
                            AND doc_id = ?""", id)
            rows = cursor.fetchall()
            if not rows:
                raise Exception("No CIPS contact found for board member %d" %
                                id)
            self.contactId = rows[0][0]

        # Get the address information.
        filters = ["name:Person Contact Fragment With Name"]
        #print("id=%s docVer=%s contactId=%s" % (id, str(ver), self.contactId))
        result = cdr.filterDoc('guest',
                               filters,
                               id,
                               docVer=str(ver),
                               parm=(('fragId', self.contactId), ))
        if isinstance(result, (str, bytes)):
            raise Exception("failure extracting contact address for %s: %s" %
                            (id, result))
        self.address = cdrmailer.Address(result[0], cdrmailer.TITLE_AFTER_NAME)
        self.name = self.address.getPersonalName()
Example #3
0
 def __init__(self, cdrId, fragId, filt='Person Address Fragment'):
     filters = ['name:%s' % filt]
     parms = (('fragId', fragId), )
     result = cdr.filterDoc('guest', filters, cdrId, parm=parms)
     if type(result) in (str, bytes):
         raise Exception("Person.Contact(%s, %s): %s" %
                         (cdrId, fragId, result))
     ContactInfo.__init__(self, result[0])
Example #4
0
    def getOrganizationAddress(self, id):
        """
        Parameters:
            id - Integer ID of the organization document.
        Return value:
            Address object for organization.
        """
        # Default 'name' of the recipient
        nameStr = 'Administrator'

        # See if we have a CIPS contact person whose real name we can use
        rows = cdr.getQueryTermValueForId(
            '/Organization/OrganizationDetails/CIPSContactPerson/@cdr:ref', id,
            self.__conn)
        if rows:
            # Construct and Address object for person, to get real name
            # Fatal error if we can't find one
            personAddr = self.getCipsContactAddress(rows[0])
            nameStr = personAddr.getAddressee()

        # Find the fragment id in the Organization doc for
        #   the address we need to send to
        # Filter the organization to construct an address
        rows = cdr.getQueryTermValueForId(
            '/Organization/OrganizationLocations/CIPSContact', id, self.__conn)
        if not rows:
            raise Exception("No CIPSContact element found for "
                            "Organization %d" % id)

        filters = ["name:Organization Address Fragment"]
        parms = (("fragId", rows[0]), )
        result = cdr.filterDoc(self.__session, filters, id, parm=parms)

        # Expecting tuple of xml fragment, messages.  Single string is error.
        if type(result) == type(""):
            raise Exception("failure extracting contact address "
                            "for %d: %s" % (id, result))

        # Construct an address from returned XML
        orgAddr = Address(result[0])

        # Add or replace the name string with the one we constructed above
        orgAddr.setAddressee(nameStr)

        return orgAddr
Example #5
0
 def __init__(self, control, doc_id):
     Summary.SUMMARIES_EXAMINED += 1
     self.control = control
     self.doc_id = doc_id
     self.changes = None
     query = control.Query("document", "title")
     query.where(query.Condition("id", doc_id))
     rows = [tuple(row) for row in query.execute(control.cursor).fetchall()]
     self.title = rows[0][0].split(";")[0]
     query = control.Query("publishable_version", "num")
     query.order("num DESC")
     query.where(query.Condition("id", doc_id))
     #start = datetime.datetime.strptime(control.start, "%Y-%m-%d")
     cutoff = control.start - datetime.timedelta(365)
     end = f"{control.end} 23:59:59"
     query.where(query.Condition("dt", str(cutoff), ">="))
     query.where(query.Condition("dt", end, "<"))
     versions = [row[0] for row in query.execute(control.cursor).fetchall()]
     html = ""
     for version in versions:
         Summary.VERSIONS_EXAMINED += 1
         control.logger.debug("examining CDR%dV%d", doc_id, version)
         query = control.Query("doc_version", "xml", "dt")
         query.where(query.Condition("id", doc_id))
         query.where(query.Condition("num", version))
         xml, date = query.execute(control.cursor).fetchone()
         match = self.PATTERN.search(xml)
         if match:
             last_modified = match.group(1)
             control.logger.debug("DateLastModified: %r", last_modified)
             if str(control.start) <= last_modified <= str(control.end):
                 date = str(date)
                 date = "%s/%s/%s" % (date[5:7], date[8:10], date[:4])
                 filt = ["name:Summary Changes Report"]
                 resp = cdr.filterDoc(control.session, filt, doc=xml)
                 if isinstance(resp, (str, bytes)):
                     error = "Failure parsing CDR%d V%d" % (doc_id, version)
                     raise Exception(error)
                 html = resp[0].replace("@@PubVerDate@@", date).strip()
                 break
     if html:
         div = "<div class='changes'>%s</div>" % html
         self.changes = lxml.html.fromstring(div)
Example #6
0
    def getBoardMemberAddress(self, personId, memberId):

        # Find fragment ID for CIPS contact location in BoardMemberInfo doc
        path = '/PDQBoardMemberInfo/BoardMemberContact/PersonContactID'
        rows = cdr.getQueryTermValueForId(path, memberId, self.__conn)

        # Filter to create AddressElement XML
        if rows:
            docId = cdr.normalize(personId)
            parms = (('fragId', rows[0]), )
            filters = ["name:Person Address Fragment With Name"]
        else:
            docId = cdr.normalize(memberId)
            parms = ()
            filters = ["name:Board Member Address Fragment With Name"]
        result = cdr.filterDoc(self.__session, filters, docId, parm=parms)
        if isinstance(result, (str, bytes)):
            raise Exception("failure extracting contact address "
                            "for %s: %s" % (docId, result))
        return Address(result[0])
Example #7
0
                """
                SELECT xml
                  FROM document
                 WHERE id = ?
            """, (filter, ))
            row = cursor.fetchone()
            if not row:
                sys.stderr.write("Unable to find filter '%s'" % filter)
                sys.exit(1)

        # Replace name with actual filter for use inline
        filter = row[0]
        inline = True

    # Transform the caller requested filter to incorporate tracing
    resp = cdr.filterDoc(session, filter=TRACE_FILTER, doc=filter, inline=True)
    if type(resp) in (type(""), type(u"")):
        sys.stderr.write("Error adding tracing to filter:\n  %s" % resp)
        sys.exit(1)

    # Substitute transformed filter for original
    filter = resp[0]

# Gather optional parms
parms = []
argx = 2
while argx < len(args):
    parms.append(args[argx].split('='))
    argx += 1

# Filter identifier strings should be in list format for cdr.filterDoc()