Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/local/bin/python
2# encoding: utf-8
3"""
4*The data model module for the `services_refresh_sidebar_list_counts` resource*
6:Author:
7 David Young
8"""
9from builtins import object
10import sys
11import os
12import khufu
14class services_refresh_sidebar_list_counts(object):
15 """
16 The worker class for the services_refresh_sidebar_list_counts module
18 **Key Arguments**
20 - ``log`` -- logger
21 - ``request`` -- the pyramid request
22 - ``elementId`` -- the specific element id requests (or False)
24 """
26 def __init__(
27 self,
28 log,
29 request,
30 elementId=False
31 ):
32 self.log = log
33 self.request = request
34 self.elementId = elementId
35 # xt-self-arg-tmpx
37 log.debug(
38 "instansiating a new 'services_refresh_sidebar_list_counts' object")
39 return None
41 def close(self):
42 del self
43 return None
45 def put(self):
46 """execute the put method on the services_refresh_sidebar_list_counts object
48 **Return**
50 - ``responseContent`` -- the reponse to send to the browser
52 """
53 self.log.debug('starting the ``put`` method')
55 # all marshall workflow list titles
56 marshallWorkflowLists = ["inbox", "archive", "following", "pending observation",
57 "followup complete", "review for followup", "pending classification"]
59 # count objects in each list and update the `meta_workflow_lists_counts`
60 # table
61 for thisList in marshallWorkflowLists:
62 sqlListName = thisList.replace(" ", "_")
63 sqlQuery = """update meta_workflow_lists_counts set count = (select count(*) from pesstoObjects where marshallWorkflowLocation="%(thisList)s") where listname = "%(thisList)s" """ % locals(
64 )
65 self.request.db.execute(sqlQuery)
66 self.request.db.commit()
68 # content for response
69 responseContent = "updated `marshallWorkflowLocations` in `meta_workflow_lists_counts` table"
71 # all alert workflow list titles
72 alertWorkflowLists = [
73 "external alert released", "pessto classification released", "archived without alert", "queued for atel"]
75 # count objects in each list and update the `meta_workflow_lists_counts`
76 # table
77 for thisList in alertWorkflowLists:
78 sqlListName = thisList.replace(" ", "_")
79 sqlQuery = """update meta_workflow_lists_counts set count = (select count(*) from pesstoObjects where alertWorkflowLocation="%(thisList)s") where listname = "%(thisList)s" """ % locals(
80 )
81 self.request.db.execute(sqlQuery)
82 self.request.db.commit()
84 # count all objects
85 sqlQuery = """update meta_workflow_lists_counts set count = (select count(*) from pesstoObjects) where listname = "all" """ % locals(
86 )
87 self.request.db.execute(sqlQuery)
88 self.request.db.commit()
90 # content for response
91 responseContent += "<BR>updated `alertWorkflowLocation` in `meta_workflow_lists_counts` table"
93 # count classified objects
94 sqlQuery = """update meta_workflow_lists_counts set count = (select count(*) from pesstoObjects where classifiedFlag = 1) where listname = "classified" """ % locals(
95 )
96 self.request.db.execute(sqlQuery)
97 self.request.db.commit()
99 # content for response
100 responseContent += "<BR>updated `classified` list in `meta_workflow_lists_counts` table"
102 # count snoozed objects
103 sqlQuery = """update meta_workflow_lists_counts set count = (select count(*) from pesstoObjects where snoozed = 1) where listname = "snoozed" """ % locals(
104 )
105 self.request.db.execute(sqlQuery)
106 self.request.db.commit()
108 # content for response
109 responseContent += "<BR>updated `snoozed` list in `meta_workflow_lists_counts` table"
111 self.log.debug('completed the ``put`` method')
112 return responseContent
114 # xt-class-method