def report_index(self, report=None, reportid=None, fromdate=None, todate=None): logging.debug('index: %s, %s' % (fromdate, todate)) if fromdate is not None: var_fromdate = parse_date(fromdate) else: var_fromdate = datetime.date.today() if todate is not None: var_todate = parse_date(todate) else: var_todate = datetime.date.today() #if reportid specified with not date, then get the latest for the report type / group if reportid and not (fromdate or todate): reportargs = self.getargsGroupDir(reportid) elif (fromdate or todate): reportargs = self.getargsSearch(reportparam=reportid, fromdate=var_fromdate, todate=var_todate) elif report: reportargs = self.getargsDir(report) else: reportargs = self.getargs() reportargs['reporttypes'] = [] for item in reportconfig.reportmenu: reportargs['reporttypes'].append({ 'index' : item[0], 'id' : item[1], 'name' : item[2], }) return reportargs
def report_index(self, report=None, reportid=None, fromdate=None, todate=None): logging.debug('index: %s, %s' % (fromdate, todate)) if fromdate is not None: var_fromdate = parse_date(fromdate) else: var_fromdate = datetime.date.today() if todate is not None: var_todate = parse_date(todate) else: var_todate = datetime.date.today() #if reportid specified with not date, then get the latest for the report type / group if reportid and not (fromdate or todate): reportargs = self.getargsGroupDir(reportid) elif (fromdate or todate): reportargs = self.getargsSearch(reportparam=reportid, fromdate=var_fromdate, todate=var_todate) elif report: reportargs = self.getargsDir(report) else: reportargs = self.getargs() reportargs['reporttypes'] = [] groupmenu = [] for item in reportconfig.reportmenu: #apply sorting inbetween index = 0 rows if item[0] == 0 : groupmenu.sort(key=lambda a: (a["index"], sortKey(a["name"]), a["name"])) reportargs['reporttypes'] += groupmenu groupmenu = [] groupmenu.append({ 'index' : item[0], 'id' : item[1], 'name' : item[2], }) #finally append last section of data reportargs['reporttypes'] += groupmenu return reportargs
def getargsSearch(self, reportparam=None, fromdate=None, todate=None): logging.debug('getargsSearch') if isinstance(fromdate, datetime.date): pass elif fromdate is not None: fromdate = parse_date(fromdate) else: fromdate = datetime.date.today() if isinstance(todate, datetime.date): pass elif todate is not None: todate = parse_date(todate) else: todate = datetime.date.today() reportdata = { 'd' : [], 'w' : [], 'm' : [], } defaultItem = { "name" : None, "maxasof" : datetime.date(datetime.MINYEAR, 1, 1), "minasof" : datetime.date(datetime.MAXYEAR, 12, 31), "asof" : datetime.date(datetime.MINYEAR, 1, 1), "files" : {}, } groupindex = {} for info in self._filescan_cache: groupby = info["groupby"] reportid = info["reportid"] fileasof = info["fileasof"] reportname = info["reportname"] period = info["period"] if not reportparam: pass elif reportparam == period: pass elif info["reportid"] != reportparam and info["groupname"] != reportparam: continue if not inRange(fileasof, period, fromdate, todate): continue reportItem = groupindex.get(reportname, copy.deepcopy(defaultItem)) reportItem["name"] = info["reportname"] reportItem["reportid"] = reportid if reportItem["minasof"] is None or reportItem["minasof"] > fileasof: reportItem["minasof"] = fileasof if reportItem["maxasof"] is None or reportItem["maxasof"] < fileasof: reportItem["maxasof"] = fileasof files_asof = reportItem["files"].get(fileasof, []) files_asof.append(info) reportItem["files"][fileasof] = files_asof groupindex[reportname] = reportItem for reportname, reportItem in groupindex.iteritems(): for fileasof, reportfiles in reportItem["files"].iteritems(): reportid = reportItem["reportid"] row = { "type" : "report", "name" : reportItem["name"], "maxasof" : reportItem["maxasof"], "minasof" : reportItem["minasof"], "asof" : fileasof, "published" : "", "files" : [], } basepath = reportconfig.reportindex[reportid]["basepath"] virtualpath = reportconfig.folderindex[basepath] files = [] period = None for info in reportfiles: path = os.path.join(virtualpath, info["childpath"], info["name"]) files.append((path, info["name"], "ext_" + info["filetype"])) row["published"] = info["modified"] period = info["period"] row["files"] = files row["url"] = path reportdata[period].append(row) reportdata['d'].sort(lambda a, b : cmp((a["name"],a["asof"]), (b["name"],b["asof"]))) reportdata['w'].sort(lambda a, b : cmp((a["name"],a["asof"]), (b["name"],b["asof"]))) reportdata['m'].sort(lambda a, b : cmp((a["name"],a["asof"]), (b["name"],b["asof"]))) return reportdata