Changeset 9633 for main/waeup.kofa/trunk/src
- Timestamp:
- 14 Nov 2012, 18:40:59 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 6 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/reports.py
r9510 r9633 44 44 """not when any output was created.""") 45 45 46 title = schema.TextLine( 47 title = u"A human readable short description for a report.", 48 default = u'Untitled', 49 ) 50 51 description = schema.Text( 52 title = u"A human readable text describing a report.", 53 default = u'No description' 54 ) 55 46 56 def create_pdf(): 47 57 """Generate a PDF copy. … … 121 131 """ 122 132 133 def get_report_jobs_description(user_id=None): 134 """Get running/completed report jobs fur ?user_id` as list of tuples. 135 136 Each tuple holds ``<job_id>, <description>, 137 <status_translated>`` in that order, where ``<description>`` 138 is a human readable description of the report run and 139 ``<status_translated>`` is the report jobs' status 140 (translated). 141 """ 142 123 143 def delete_report_entry(entry): 124 144 """Delete the report job denoted by `entry`. … … 162 182 class Report(object): 163 183 creation_dt = None 184 185 @property 186 def title(self): 187 return _(u'A report') 188 189 @property 190 def description(self): 191 return _(u'A dummy report') 164 192 165 193 def __init__(self, args=[], kwargs={}): … … 170 198 def create_pdf(self): 171 199 raise NotImplementedError() 200 201 def __repr__(self): 202 return 'Report(args=%r, kwargs=%r)' % (self.args, self.kwargs) 203 172 204 173 205 @implementer(IReportGenerator) … … 266 298 str_repr = '(' + str_repr + ')' 267 299 try: 268 generator = queryUtility(300 generator = getUtility( 269 301 IReportGenerator, name=self._generator_name) 270 name = generator. name302 name = generator.title 271 303 except: 272 name = _(' Invalid Report Generator')304 name = _('Unregistered Report Generator') 273 305 return name + ' ' + str_repr 274 306 … … 351 383 return result 352 384 385 def get_report_jobs_description(self, user_id=None): 386 """Get running/completed report jobs fur ?user_id` as list of tuples. 387 388 Each tuple holds ``<job_id>, <description>, 389 <status_translated>`` in that order, where ``<description>`` 390 is a human readable description of the report run and 391 ``<status_translated>`` is the report jobs' status 392 (translated). 393 """ 394 entries = self.get_running_report_jobs(user_id) 395 result = [] 396 for (job_id, gen_name, user_name) in entries: 397 manager = getUtility(IJobManager) 398 job = manager.get(job_id) 399 status = JOB_STATUS_MAP.get(job.status, job.status)[1] 400 if not hasattr(job, 'description'): 401 continue 402 result.append((job_id, job.description, status),) 403 return result 404 353 405 def delete_report_entry(self, entry): 354 406 """Delete the report job denoted by `entry`. -
main/waeup.kofa/trunk/src/waeup/kofa/tests/test_reports.py
r9511 r9633 25 25 26 26 def __init__(self, name=None, perm_create=None, perm_view=None): 27 self. name = 'Report 1'27 self.title = 'Report 1' 28 28 self.perm_create = perm_create 29 29 self.perm_view = perm_view … … 31 31 32 32 def __eq__(self, obj): 33 if getattr(obj, ' name', None) is None:33 if getattr(obj, 'title', None) is None: 34 34 return False 35 return self. name == obj.name35 return self.title == obj.title 36 36 37 37 def generate(self, site, args=[], kw={}): … … 142 142 self.assertEqual( 143 143 result, 144 [( 'report1', FakeReportGenerator('report1')),145 ( 'report2', FakeReportGenerator('report2'))])144 [(u'report1', FakeReportGenerator('report1')), 145 (u'report2', FakeReportGenerator('report2'))]) 146 146 return 147 147 … … 238 238 job = AsyncReportJob(self.root_folder, 'NOT EXISTENT') 239 239 self.assertEqual( 240 job.description, u' Invalid Report Generator ()')240 job.description, u'Unregistered Report Generator ()') 241 241 # with args set (no kws) 242 242 job = AsyncReportJob( 243 243 self.root_folder, 'NOT EXISTENT', args=['a', 'b']) 244 244 self.assertEqual( 245 job.description, u" Invalid Report Generator ('a', 'b')")245 job.description, u"Unregistered Report Generator ('a', 'b')") 246 246 # with kw set (no args) 247 247 job = AsyncReportJob( 248 248 self.root_folder, 'NOT_EXISTENT', kw=dict(a=1, b=2)) 249 249 self.assertEqual( 250 job.description, u' Invalid Report Generator (a=1, b=2)')250 job.description, u'Unregistered Report Generator (a=1, b=2)') 251 251 # with args and kws set 252 252 job = AsyncReportJob( 253 253 self.root_folder, 'NOT_EXISTENT', args=['a'], kw=dict(b=2)) 254 254 self.assertEqual( 255 job.description, u"Invalid Report Generator ('a', b=2)") 256 return 257 255 job.description, u"Unregistered Report Generator ('a', b=2)") 256 return 258 257 259 258 class FakeJobWithResult(FakeJob): 260 259 261 260 def __init__(self, args=[], kw={}): 262 #self.dir_path = tempfile.mkdtemp()263 #self.result = os.path.join(self.dir_path, 'fake.csv')264 #open(self.result, 'wb').write('a fake result')265 261 self.result = Report() 266 262 self.result.args = args … … 358 354 self.assertEqual( 359 355 result, 360 [('new', u'new', u'Unnamed Report'), 361 ('completed', u'completed', u'Unnamed Report')] 356 [('new', u'new', u'Report 1'), 357 ('completed', u'completed', u'Report 1')] 358 ) 359 return 360 361 def test_get_report_job_description(self): 362 # we can get the descriptions of jobs... 363 container = ReportJobContainer() 364 container.start_report_job('report1', 'alice') 365 container.start_report_job('report1', 'bob') 366 result = container.get_report_jobs_description(user_id='bob') 367 # we'll get the job id, a description and the status 368 self.assertEqual( 369 result, 370 [('2', 'Report 1 ()', u'new'),] 362 371 ) 363 372 return
Note: See TracChangeset for help on using the changeset viewer.