Ignore:
Timestamp:
14 Nov 2012, 18:40:59 (12 years ago)
Author:
uli
Message:

Basic statistics for kofa. Still the functionality is hidden - but available :-)

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  
    4444        """not when any output was created.""")
    4545
     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
    4656    def create_pdf():
    4757        """Generate a PDF copy.
     
    121131        """
    122132
     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
    123143    def delete_report_entry(entry):
    124144        """Delete the report job denoted by `entry`.
     
    162182class Report(object):
    163183    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')
    164192
    165193    def __init__(self, args=[], kwargs={}):
     
    170198    def create_pdf(self):
    171199        raise NotImplementedError()
     200
     201    def __repr__(self):
     202        return 'Report(args=%r, kwargs=%r)' % (self.args, self.kwargs)
     203
    172204
    173205@implementer(IReportGenerator)
     
    266298        str_repr = '(' + str_repr + ')'
    267299        try:
    268             generator = queryUtility(
     300            generator = getUtility(
    269301                IReportGenerator, name=self._generator_name)
    270             name = generator.name
     302            name = generator.title
    271303        except:
    272             name = _('Invalid Report Generator')
     304            name = _('Unregistered Report Generator')
    273305        return name + ' ' + str_repr
    274306
     
    351383        return result
    352384
     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
    353405    def delete_report_entry(self, entry):
    354406        """Delete the report job denoted by `entry`.
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_reports.py

    r9511 r9633  
    2525
    2626    def __init__(self, name=None, perm_create=None, perm_view=None):
    27         self.name = 'Report 1'
     27        self.title = 'Report 1'
    2828        self.perm_create = perm_create
    2929        self.perm_view = perm_view
     
    3131
    3232    def __eq__(self, obj):
    33         if getattr(obj, 'name', None) is None:
     33        if getattr(obj, 'title', None) is None:
    3434            return False
    35         return self.name == obj.name
     35        return self.title == obj.title
    3636
    3737    def generate(self, site, args=[], kw={}):
     
    142142        self.assertEqual(
    143143            result,
    144             [('report1', FakeReportGenerator('report1')),
    145              ('report2', FakeReportGenerator('report2'))])
     144            [(u'report1', FakeReportGenerator('report1')),
     145             (u'report2', FakeReportGenerator('report2'))])
    146146        return
    147147
     
    238238        job = AsyncReportJob(self.root_folder, 'NOT EXISTENT')
    239239        self.assertEqual(
    240             job.description, u'Invalid Report Generator ()')
     240            job.description, u'Unregistered Report Generator ()')
    241241        # with args set (no kws)
    242242        job = AsyncReportJob(
    243243            self.root_folder, 'NOT EXISTENT', args=['a', 'b'])
    244244        self.assertEqual(
    245             job.description, u"Invalid Report Generator ('a', 'b')")
     245            job.description, u"Unregistered Report Generator ('a', 'b')")
    246246        # with kw set (no args)
    247247        job = AsyncReportJob(
    248248            self.root_folder, 'NOT_EXISTENT', kw=dict(a=1, b=2))
    249249        self.assertEqual(
    250             job.description, u'Invalid Report Generator (a=1, b=2)')
     250            job.description, u'Unregistered Report Generator (a=1, b=2)')
    251251        # with args and kws set
    252252        job = AsyncReportJob(
    253253            self.root_folder, 'NOT_EXISTENT', args=['a'], kw=dict(b=2))
    254254        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
    258257
    259258class FakeJobWithResult(FakeJob):
    260259
    261260    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')
    265261        self.result = Report()
    266262        self.result.args = args
     
    358354        self.assertEqual(
    359355            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'),]
    362371            )
    363372        return
Note: See TracChangeset for help on using the changeset viewer.