This repository was archived by the owner on May 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInvalidDocs.py
More file actions
executable file
·91 lines (73 loc) · 3.03 KB
/
InvalidDocs.py
File metadata and controls
executable file
·91 lines (73 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
"""Report on invalid or blocked CDR documents.
"""
from functools import cached_property
from cdrcgi import Controller
class Control(Controller):
SUBTITLE = "Invalid Documents"
def build_tables(self):
"""Assemble the two tables used for this report."""
if not self.doctype:
message = "No document type has been selected."
self.alerts.append(dict(message=message, type="warning"))
return self.show_form()
subquery = self.Query("doc_version", "MAX(num)").where("id = v.id")
fields = "v.id", "v.title", "d.active_status"
query = self.Query("doc_version v", *fields).order("v.id")
query.join("document d", "d.id = v.id")
query.join("doc_type t", "t.id = d.doc_type")
query.where(query.Condition("t.id", self.doctype))
query.where(query.Condition("v.num", subquery))
query.where("v.val_status = 'I'")
invalid = []
blocked = []
for doc in query.execute(self.cursor).fetchall():
row = (self.Reporter.Cell(doc.id, classes="right"), doc.title)
if doc.active_status == "I":
blocked.append(row)
else:
invalid.append(row)
doctype = dict(self.doctypes)[int(self.doctype)]
caption = f"Invalid {doctype} Documents"
opts = dict(columns=self.columns, caption=caption)
invalid = self.Reporter.Table(invalid, **opts)
opts["caption"] = f"Blocked {doctype} Documents"
blocked = self.Reporter.Table(blocked, **opts)
return invalid, blocked
def populate_form(self, page):
"""Let the user pick a document type.
Pass:
page - HTMLPage document on which to drop the fields
"""
fieldset = page.fieldset("Select Document Type")
for id, name in self.doctypes:
opts = dict(value=id, label=name)
fieldset.append(page.radio_button("doctype", **opts))
page.form.append(fieldset)
@cached_property
def columns(self):
"""Column headers for the report."""
return (
self.Reporter.Column("ID", width="50px"),
self.Reporter.Column("Title", width="950px"),
)
@cached_property
def doctype(self):
"""CDR document type selected for the report."""
return self.fields.getvalue("doctype")
@cached_property
def doctypes(self):
"""Active document types for the form's picklist."""
query = self.Query("doc_type", "id", "name").order("name")
query.where("active = 'Y'")
query.where("xml_schema IS NOT NULL")
query.where("name NOT IN ('Filter', 'xxtest', 'schema')")
rows = query.execute(self.cursor).fetchall()
return [tuple(row) for row in rows]
@cached_property
def same_window(self):
"""Don't open more than one new browser tab."""
return [self.SUBMIT] if self.request else []
if __name__ == "__main__":
"""Don't execute the script if loaded as a module."""
Control().run()