<s> from django . core . urlresolvers import reverse <EOL> from corehq import privileges <EOL> from corehq . apps . domain . dbaccessors import get_doc_ids_in_domain_by_class <EOL> from corehq . apps . domain . models import Domain <EOL> from corehq . apps . hqadmin . reports import ( <EOL> AdminDomainStatsReport , <EOL> AdminDomainMapReport , <EOL> AdminAppReport , <EOL> AdminUserReport , <EOL> RealProjectSpacesReport , <EOL> CommConnectProjectSpacesReport , <EOL> CommTrackProjectSpacesReport , <EOL> DeviceLogSoftAssertReport , <EOL> ) <EOL> from corehq . apps . hqpillow_retry . views import PillowErrorsReport <EOL> from corehq . apps . reports . standard import ( monitoring , inspect , export , <EOL> deployments , sms , ivr ) <EOL> from corehq . apps . reports . standard . forms import reports as receiverwrapper <EOL> from corehq . apps . reports . standard . project_health import ProjectHealthDashboard <EOL> from corehq . apps . userreports . exceptions import BadSpecError <EOL> from corehq . apps . userreports . models import ( <EOL> StaticReportConfiguration , <EOL> ReportConfiguration , <EOL> ) <EOL> from corehq . apps . userreports . reports . view import ( <EOL> ConfigurableReport , <EOL> CustomConfigurableReportDispatcher , <EOL> ) <EOL> import phonelog . reports as phonelog <EOL> from corehq . apps . reports import commtrack <EOL> from corehq . apps . fixtures . interface import FixtureViewInterface , FixtureEditInterface <EOL> import hashlib <EOL> from dimagi . utils . modules import to_function <EOL> import logging <EOL> import toggles <EOL> from django . utils . translation import ugettext_noop as _ , ugettext_lazy <EOL> from corehq . apps . indicators . admin import document_indicators , couch_indicators , dynamic_indicators <EOL> from corehq . apps . data_interfaces . interfaces import CaseReassignmentInterface , BulkFormManagementInterface <EOL> from corehq . apps . importer . base import ImportCases <EOL> from corehq . apps . accounting . interface import ( <EOL> AccountingInterface , <EOL> SubscriptionInterface , <EOL> SoftwarePlanInterface , <EOL> InvoiceInterface , <EOL> WireInvoiceInterface , <EOL> PaymentRecordInterface , <EOL> SubscriptionAdjustmentInterface , <EOL> CreditAdjustmentInterface , <EOL> ) <EOL> from corehq . apps . smsbillables . interface import ( <EOL> SMSBillablesInterface , <EOL> SMSGatewayFeeCriteriaInterface , <EOL> ) <EOL> from corehq . apps . domain . views import DomainForwardingRepeatRecords <EOL> def REPORTS ( project ) : <EOL> from corehq . apps . reports . standard . cases . basic import CaseListReport <EOL> from corehq . apps . reports . standard . cases . careplan import make_careplan_reports <EOL> from corehq . apps . reports . standard . maps import DemoMapReport , DemoMapReport2 , DemoMapCaseList <EOL> reports = [ ] <EOL> reports . extend ( _get_configurable_reports ( project ) ) <EOL> reports . extend ( [ <EOL> ( ugettext_lazy ( "<STR_LIT>" ) , ( <EOL> monitoring . WorkerActivityReport , <EOL> monitoring . DailyFormStatsReport , <EOL> monitoring . SubmissionsByFormReport , <EOL> monitoring . FormCompletionTimeReport , <EOL> monitoring . CaseActivityReport , <EOL> monitoring . FormCompletionVsSubmissionTrendsReport , <EOL> monitoring . WorkerActivityTimes , <EOL> ProjectHealthDashboard , <EOL> ) ) , <EOL> ( ugettext_lazy ( "<STR_LIT>" ) , ( <EOL> inspect . SubmitHistory , CaseListReport , <EOL> ) ) , <EOL> ( ugettext_lazy ( "<STR_LIT>" ) , ( <EOL> deployments . ApplicationStatusReport , <EOL> receiverwrapper . SubmissionErrorReport , <EOL> phonelog . DeviceLogDetailsReport , <EOL> deployments . SyncHistoryReport , <EOL> ) ) , <EOL> ( ugettext_lazy ( "<STR_LIT>" ) , ( <EOL> DemoMapReport , DemoMapReport2 , DemoMapCaseList , <EOL> ) ) , <EOL> ] ) <EOL> if project . commtrack_enabled : <EOL> reports . insert ( <NUM_LIT:0> , ( ugettext_lazy ( "<STR_LIT>" ) , ( <EOL> commtrack . SimplifiedInventoryReport , <EOL> commtrack . InventoryReport , <EOL> commtrack . CurrentStockStatusReport , <EOL> commtrack . StockStatusMapReport , <EOL> commtrack . ReportingRatesReport , <EOL> commtrack . ReportingStatusMapReport , <EOL> commtrack . LedgersByLocationReport , <EOL> ) ) ) <EOL> if project . has_careplan : <EOL> from corehq . apps . app_manager . models import CareplanConfig <EOL> config = CareplanConfig . for_domain ( project . name ) <EOL> if config : <EOL> cp_reports = tuple ( make_careplan_reports ( config ) ) <EOL> reports . insert ( <NUM_LIT:0> , ( ugettext_lazy ( "<STR_LIT>" ) , cp_reports ) ) <EOL> from corehq . apps . accounting . utils import domain_has_privilege <EOL> messaging_reports = [ ] <EOL> project_can_use_sms = domain_has_privilege ( project . name , privileges . OUTBOUND_SMS ) <EOL> if project_can_use_sms : <EOL> messaging_reports . extend ( [ <EOL> sms . MessagesReport , <EOL> ] ) <EOL> messaging_reports . extend ( [ <EOL> sms . MessagingEventsReport , <EOL> sms . MessageEventDetailReport , <EOL> sms . SurveyDetailReport , <EOL> sms . MessageLogReport , <EOL> ivr . CallReport , <EOL> ivr . ExpectedCallbackReport , <EOL> ] ) <EOL> messaging_reports += getattr ( Domain . get_module_by_name ( project . name ) , '<STR_LIT>' , ( ) ) <EOL> messaging = ( ugettext_lazy ( "<STR_LIT>" ) , messaging_reports ) <EOL> reports . append ( messaging ) <EOL> reports . extend ( _get_dynamic_reports ( project ) ) <EOL> return reports <EOL> def _get_dynamic_reports ( project ) : <EOL> """<STR_LIT>""" <EOL> for reportset in project . dynamic_reports : <EOL> yield ( reportset . section_title , <EOL> filter ( None , <EOL> ( _make_dynamic_report ( report , [ reportset . section_title ] ) for report in reportset . reports ) ) ) <EOL> def _make_dynamic_report ( report_config , keyprefix ) : <EOL> """<STR_LIT>""" <EOL> report_key = keyprefix + [ report_config . report , report_config . name ] <EOL> slug = hashlib . sha1 ( '<STR_LIT::>' . join ( report_key ) ) . hexdigest ( ) [ : <NUM_LIT:12> ] <EOL> kwargs = dict ( report_config . kwargs ) <EOL> kwargs . update ( { <EOL> '<STR_LIT:name>' : report_config . name , <EOL> '<STR_LIT>' : slug , <EOL> } ) <EOL> if report_config . previewers_only : <EOL> @ classmethod <EOL> def show_in_navigation ( cls , domain = None , project = None , user = None ) : <EOL> return user and user . is_previewer ( ) <EOL> kwargs [ '<STR_LIT>' ] = show_in_navigation <EOL> try : <EOL> metaclass = to_function ( report_config . report , failhard = True ) <EOL> except StandardError : <EOL> logging . error ( '<STR_LIT>' % report_config . report ) <EOL> return None <EOL> return type ( '<STR_LIT>' % slug , ( metaclass , ) , kwargs ) <EOL> def _safely_get_report_configs ( project_name ) : <EOL> try : <EOL> configs = ReportConfiguration . by_domain ( project_name ) <EOL> except BadSpecError as e : <EOL> logging . exception ( e ) <EOL> configs = [ ] <EOL> for config_id in get_doc_ids_in_domain_by_class ( project_name , ReportConfiguration ) : <EOL> try : <EOL> configs . append ( ReportConfiguration . get ( config_id ) ) <EOL> except BadSpecError as e : <EOL> logging . error ( "<STR_LIT>" % ( e . message , config_id ) ) <EOL> try : <EOL> configs . extend ( StaticReportConfiguration . by_domain ( project_name ) ) <EOL> except BadSpecError as e : <EOL> logging . exception ( e ) <EOL> return configs <EOL> def _get_configurable_reports ( project ) : <EOL> """<STR_LIT>""" <EOL> configs = _safely_get_report_configs ( project . name ) <EOL> if configs : <EOL> def _make_report_class ( config ) : <EOL> from corehq . apps . reports . generic import GenericReportView <EOL> @ classmethod <EOL> def get_url ( cls , domain , ** kwargs ) : <EOL> from corehq . apps . userreports . models import CUSTOM_REPORT_PREFIX <EOL> slug = ( <EOL> ConfigurableReport . slug <EOL> if not config . _id . startswith ( CUSTOM_REPORT_PREFIX ) <EOL> else CustomConfigurableReportDispatcher . slug <EOL> ) <EOL> return reverse ( slug , args = [ domain , config . _id ] ) <EOL> @ classmethod <EOL> def show_in_navigation ( cls , domain = None , project = None , user = None ) : <EOL> return config . visible or ( user and toggles . USER_CONFIGURABLE_REPORTS . enabled ( user . username ) ) <EOL> return type ( '<STR_LIT>' . format ( config . _id ) , ( GenericReportView , ) , { <EOL> '<STR_LIT:name>' : config . title , <EOL> '<STR_LIT:description>' : config . description or None , <EOL> '<STR_LIT>' : get_url , <EOL> '<STR_LIT>' : show_in_navigation , <EOL> } ) <EOL> yield ( _ ( '<STR_LIT>' ) , [ _make_report_class ( config ) for config in configs ] ) <EOL> DATA_INTERFACES = ( <EOL> ( ugettext_lazy ( "<STR_LIT>" ) , ( <EOL> export . DeidExportReport , <EOL> ) ) , <EOL> ) <EOL> EDIT_DATA_INTERFACES = ( <EOL> ( ugettext_lazy ( '<STR_LIT>' ) , ( <EOL> CaseReassignmentInterface , <EOL> ImportCases , <EOL> BulkFormManagementInterface , <EOL> ) ) , <EOL> ) <EOL> FIXTURE_INTERFACES = ( <EOL> ( _ ( '<STR_LIT>' ) , ( <EOL> FixtureEditInterface , <EOL> FixtureViewInterface , <EOL> ) ) , <EOL> ) <EOL> INDICATOR_ADMIN_INTERFACES = ( <EOL> ( _ ( "<STR_LIT>" ) , ( <EOL> document_indicators . FormLabelIndicatorDefinitionAdminInterface , <EOL> document_indicators . FormAliasIndicatorDefinitionAdminInterface , <EOL> document_indicators . CaseDataInFormAdminInterface , <EOL> ) ) , <EOL> ( _ ( "<STR_LIT>" ) , ( <EOL> document_indicators . FormDataInCaseAdminInterface , <EOL> ) ) , <EOL> ( _ ( "<STR_LIT>" ) , ( <EOL> dynamic_indicators . CombinedIndicatorAdminInterface , <EOL> ) ) , <EOL> ( _ ( "<STR_LIT>" ) , ( <EOL> couch_indicators . CouchIndicatorAdminInterface , <EOL> couch_indicators . CountUniqueCouchIndicatorAdminInterface , <EOL> couch_indicators . MedianCouchIndicatorAdminInterface , <EOL> couch_indicators . SumLastEmittedCouchIndicatorAdminInterface , <EOL> ) ) , <EOL> ) <EOL> ACCOUNTING_ADMIN_INTERFACES = ( <EOL> ( _ ( "<STR_LIT>" ) , ( <EOL> AccountingInterface , <EOL> SubscriptionInterface , <EOL> SoftwarePlanInterface , <EOL> InvoiceInterface , <EOL> WireInvoiceInterface , <EOL> PaymentRecordInterface , <EOL> SubscriptionAdjustmentInterface , <EOL> CreditAdjustmentInterface , <EOL> ) ) , <EOL> ) <EOL> SMS_ADMIN_INTERFACES = ( <EOL> ( _ ( "<STR_LIT>" ) , ( <EOL> SMSBillablesInterface , <EOL> SMSGatewayFeeCriteriaInterface , <EOL> ) ) , <EOL> ) <EOL> BASIC_REPORTS = ( <EOL> ( _ ( '<STR_LIT>' ) , ( ) ) , <EOL> ) <EOL> ADMIN_REPORTS = ( <EOL> ( _ ( '<STR_LIT>' ) , ( <EOL> AdminDomainStatsReport , <EOL> AdminDomainMapReport , <EOL> AdminUserReport , <EOL> AdminAppReport , <EOL> PillowErrorsReport , <EOL> RealProjectSpacesReport , <EOL> CommConnectProjectSpacesReport , <EOL> CommTrackProjectSpacesReport , <EOL> DeviceLogSoftAssertReport , <EOL> ) ) , <EOL> ) <EOL> DOMAIN_REPORTS = ( <EOL> ( _ ( '<STR_LIT>' ) , ( <EOL> DomainForwardingRepeatRecords , <EOL> ) ) , <EOL> ) </s>
