def _inactive_checked_out_documents(self): """ Report on locked documents which haven't seen any action recently Parameters: InactivityLength - required string for how long a document can be active before showing up on the report in the form YYYY-MM-DD Return: XML document node with the following structure: ReportBody ReportName ReportRow* DocId DocType CheckedOutTo WhenCheckedOut LastActivity ActionType ActionWhen """ deltas = self.__opts.get("InactivityLength") if not deltas: raise Exception("Missing required 'InactivityLength' parameter") try: years, months, days = [int(digits) for digits in deltas.split("-")] except: message = "InactivityLength parameter must be in YYYY-MM-DD format" raise Exception(message) delta = relativedelta(years=years, months=months, days=days) cutoff = (datetime.now() - delta).replace(microsecond=0) subquery = Query("audit_trail", "MAX(dt)") subquery.where("document = a.document") fields = "d.id", "t.name", "c.dt_out", "u.name", "w.name", "a.dt" query = Query("document d", *fields) query.join("doc_type t", "t.id = d.doc_type") query.join("checkout c", "c.id = d.id") query.join("open_usr u", "u.id = c.usr") query.join("audit_trail a", "a.document = d.id") query.join("action w", "w.id = a.action") query.where("c.dt_in IS NULL") query.where(query.Condition("c.dt_out", cutoff, "<")) query.where(query.Condition("a.dt", cutoff, "<")) query.where(query.Condition("a.dt", subquery)) rows = query.order("c.id").execute(self.cursor).fetchall() body = self.__start_body() for id, doctype, locked, locker, what, when in rows: wrapper = etree.SubElement(body, "ReportRow") etree.SubElement(wrapper, "DocId").text = Doc.normalize_id(id) etree.SubElement(wrapper, "DocType").text = doctype etree.SubElement(wrapper, "CheckedOutTo").text = locker etree.SubElement(wrapper, "WhenCheckedOut").text = str(locked) last_activity = etree.SubElement(wrapper, "LastActivity") etree.SubElement(last_activity, "ActionType").text = what etree.SubElement(last_activity, "ActionWhen").text = str(when) return body
def get_definitions(cls, session): """ Fetch the list of CDR query term definitions Required positional argument: session - reference to object for current login Called by: cdr.listQueryTermDefs() client XML wrapper command CdrListQueryTermDefs Return: sequence of `QueryTermDef` objects """ session.log("QueryTermDef.get_definitions()") query = Query("query_term_def d", "d.path", "r.name") query.outer("query_term_rule r", "r.id = d.term_rule") query.order("d.path", "r.name") definitions = [] for row in query.execute(session.cursor).fetchall(): definitions.append(QueryTermDef(session, row.path, row.name)) return definitions
def _locked_documents(self): """ Report on documents locked by specified user Parameters: UserId - required string identifying a user account; this is the value often referred to as the 'name' rather than the integer primary key for the row in the usr table Return: XML document node with the following structure: ReportBody ReportName ReportRow* DocId DocType WhenCheckedOut """ user_name = self.__opts.get("UserId") if not user_name: raise Exception("Missing required 'UserId' parameter") query = Query("document d", "d.id", "t.name", "c.dt_out") query.join("doc_type t", "t.id = d.doc_type") query.join("checkout c", "c.id = d.id") query.join("open_usr u", "u.id = c.usr") query.where("c.dt_in IS NULL") query.where(query.Condition("u.name", user_name)) rows = query.order("c.id").execute(self.cursor).fetchall() body = self.__start_body() for id, doctype, locked in rows: wrapper = etree.SubElement(body, "ReportRow") etree.SubElement(wrapper, "DocId").text = Doc.normalize_id(id) etree.SubElement(wrapper, "DocType").text = doctype etree.SubElement(wrapper, "WhenCheckedOut").text = str(locked) return body