@staticmethod
    @task
    def createcalculatorreport(planid, stamp, request, language=None):
        logger.debug('Starting task to create a report.')
        try:
            plan = Plan.objects.get(pk=planid)
        except:
            logger.debug("Couldn't retrieve plan information for plan %d", planid)
            return 

        function_ids = map(lambda s: int(s), request['functionIds'].split(','))

        prev_lang = None
        if not language is None:
            prev_lang = get_language()
            activate(language)

        try:
            # Render the report
            display = ScoreDisplay.objects.get(name='%s_reports' % plan.legislative_body.name)
            html = display.render(plan, request, function_ids=function_ids)
        except Exception as ex:
            logger.warn('Error creating calculator report')
            logger.debug('Reason: %s', ex)
            html = _('Error creating calculator report.')

        # Add to report container template
        html = loader.get_template('report_panel_container.html').render(DjangoContext({'report_panels': html}))
            
        # Write it to file
        tempdir = settings.WEB_TEMP
        filename = '%s_p%d_v%d_%s' % (plan.owner.username, plan.id, plan.version, stamp)
        htmlfile = open('%s/%s.html' % (tempdir, filename,), mode='w', encoding='utf=8')
        htmlfile.write(html)
        htmlfile.close()

        # reset the language back to default
        if not prev_lang is None:
            activate(prev_lang)
            
        return
Create the report.
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/tasks.py/CalculatorReport.createcalculatorreport