def product_fixture_generator(user, version, last_sync): if not user.domain: return [] domain = Domain.get_by_name(user.domain) if not domain or not Domain.get_by_name(user.domain).commtrack_enabled: return [] root = ElementTree.Element('fixture', attrib={'id': 'commtrack:products', 'user_id': user.user_id}) products = ElementTree.Element('products') root.append(products) for product_data in Product.by_domain(user.domain): product = (ElementTree.Element('product', {'id': product_data.get_id})) products.append(product) product_fields = ['name', 'unit', 'code', 'description', 'category', 'program_id', 'cost'] for product_field in product_fields: field = ElementTree.Element(product_field) field.text = unicode(getattr(product_data, product_field) or '') product.append(field) return [root]
def tearDownClass(cls): MobileBackend.load_by_name(TEST_DOMAIN, TEST_BACKEND).delete() CommCareUser.get_by_username('stella').delete() CommCareUser.get_by_username('super').delete() delete_all_locations() LocationType.objects.all().delete() for product in Product.by_domain(TEST_DOMAIN): product.delete() SQLProduct.objects.all().delete() EWSGhanaConfig.for_domain(TEST_DOMAIN).delete() DocDomainMapping.objects.all().delete() generator.delete_all_subscriptions() Domain.get_by_name(TEST_DOMAIN).delete()
def tearDownClass(cls): MobileBackend.load_by_name(TEST_DOMAIN, TEST_BACKEND).delete() CommCareUser.get_by_username('stella').delete() CommCareUser.get_by_username('super').delete() delete_all_locations() LocationType.objects.all().delete() for product in Product.by_domain(TEST_DOMAIN): product.delete() SQLProduct.objects.all().delete() EWSGhanaConfig.for_domain(TEST_DOMAIN).delete() DocDomainMapping.objects.all().delete() generator.delete_all_subscriptions() Domain.get_by_name(TEST_DOMAIN).delete()
def handle(self, *args, **options): if options.get("domain"): domains = [Domain.get_by_name(options.get("domain"))] else: domains = Domain.get_all() since = options.get("since") seen_since = False for d in domains: if since and not seen_since: if d.name == since: seen_since = True else: continue if d.name in DOMS_TO_IGNORE: continue try: for app in d.full_applications(): try: if app.is_remote_app(): continue for _, m in app.get_media_objects(): if app.domain not in m.valid_domains: m.valid_domains.append(app.domain) self.stdout.write("adding domain %s to media file %s" % (app.domain, m._id)) m.save() except Exception as e: self.stdout.write("Error in app %s-%s: %s" % (app.domain, app._id, e)) except Exception as e: self.stdout.write("Error in domain %s: %s" % (d.name, e))
def handle(self, *args, **options): if options.get('domain'): domains = [Domain.get_by_name(options.get('domain'))] else: domains = Domain.get_all() since = options.get('since') seen_since = False for d in domains: if since and not seen_since: if d.name == since: seen_since = True else: continue if d.name in DOMS_TO_IGNORE: continue try: for app in d.full_applications(): try: if app.is_remote_app(): continue for _, m in app.get_media_objects(): if app.domain not in m.valid_domains: m.valid_domains.append(app.domain) self.stdout.write( "adding domain %s to media file %s" % (app.domain, m._id)) m.save() except Exception as e: self.stdout.write("Error in app %s-%s: %s" % (app.domain, app._id, e)) except Exception as e: self.stdout.write("Error in domain %s: %s" % (d.name, e))
def get_settings_values(app): try: profile = app.profile except AttributeError: profile = {} hq_settings = dict([ (attr, app[attr]) for attr in app.properties() if not hasattr(app[attr], 'pop') ]) if getattr(app, 'use_custom_suite', False): hq_settings.update({'custom_suite': getattr(app, 'custom_suite', None)}) hq_settings['build_spec'] = app.build_spec.to_string() # the admin_password hash shouldn't be sent to the client hq_settings.pop('admin_password', None) domain = Domain.get_by_name(app.domain) return { 'properties': profile.get('properties', {}), 'features': profile.get('features', {}), 'hq': hq_settings, '$parent': { 'doc_type': app.get_doc_type(), '_id': app.get_id, 'domain': app.domain, 'commtrack_enabled': domain.commtrack_enabled, } }
def filter_context(self): api_root = reverse('api_dispatch_list', kwargs={'domain': self.domain, 'resource_name': 'location', 'api_name': 'v0.3'}) selected_loc_id = self.request.GET.get('location_id') user = CouchUser.get_by_username(unicode(self.request.user)) domain = Domain.get_by_name(self.domain) context = {} location_id = None domain_membership = user.get_domain_membership(self.domain) if domain_membership: location_id = domain_membership.location_id if not selected_loc_id and location_id and domain.commtrack_enabled: selected_loc_id = location_id if domain.location_restriction_for_users: context.update({'restriction': domain.location_restriction_for_users}) context.update({ 'api_root': api_root, 'control_name': self.label, # todo: cleanup, don't follow this structure 'control_slug': self.slug, # todo: cleanup, don't follow this structure 'loc_id': selected_loc_id, 'locations': json.dumps(load_locs_json(self.domain, selected_loc_id)), 'hierarchy': location_hierarchy_config(self.domain) }) return context
def location_restriction_for_users(request, domain): project = Domain.get_by_name(domain) if "restrict_users" in request.POST: project.location_restriction_for_users = json.loads( request.POST["restrict_users"]) project.save() return HttpResponse()
def stock_data_submission(sender, cases, endpoint=None, **kwargs): project = Domain.get_by_name(cases[0].domain) if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled: if endpoint is None: endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config) # get agentCode and programCode - I assume all cases are part of the same program agentCode = (cases[0].get_supply_point_case()).location.site_code programCode = Program.get(cases[0].get_product().program_id).code products = [] for case in cases: product = case.get_product() product_json = {'productCode': product.code} product_json['stockInHand'] = int(case.get_default_value()) products.append(product_json) stock_data = { 'agentCode': agentCode, 'programCode': programCode, 'products': products } response = sync_stock_data_to_openlmis(submission=stock_data, openlmis_endpoint=endpoint) if response['requisitionId'] is not None: for case in cases: case.external_id = response['requisitionId'] case.save() cases, send_notification = sync_requisition_from_openlmis(project.name, response['requisitionId'], endpoint) if send_notification: send_notifications(xform=None, cases=cases)
def update_careplan_config(config, parent_app_id, application): app_props = config.app_configs.get(parent_app_id, CareplanAppProperties()) app_props.latest_release = application.get_id for module in application.get_modules(): if isinstance(module, CareplanModule): app_props.name = module.default_name() app_props.case_type = module.case_type app_props.goal_conf = { "edit_module_id": module.id, "edit_form_id": module.get_form_by_type(CAREPLAN_GOAL, 'update').id, "create_module_id": module.id, "create_form_id": module.get_form_by_type(CAREPLAN_GOAL, 'create').id, } app_props.task_conf = { "edit_module_id": module.id, "edit_form_id": module.get_form_by_type(CAREPLAN_TASK, 'update').id, "create_module_id": module.id, "create_form_id": module.get_form_by_type(CAREPLAN_TASK, 'create').id, } break config.app_configs[parent_app_id] = app_props config.save() domain = Domain.get_by_name(application.domain) if not domain.has_careplan: domain.has_careplan = True domain.save()
def handle(self, *args, **options): if len(args) != 1: print "Invalid arguments: %s" % str(args) return domain = Domain.get_by_name(args[0]) if not domain: print "Invalid domain name: %s" % args[0] return account, _ = BillingAccount.get_or_create_account_by_domain( domain.name, account_type=BillingAccountType.CONTRACT, created_by="management command", ) enterprise_plan_version = SoftwarePlanVersion.objects.filter( plan__edition=SoftwarePlanEdition.ENTERPRISE )[0] try: subscription = Subscription.new_domain_subscription( account, domain.name, enterprise_plan_version ) except NewSubscriptionError as e: print e.message return subscription.is_active = True subscription.save() print 'Domain %s has been upgraded to enterprise level.' % domain.name
def invite(self, invitation, user): project = Domain.get_by_name(self.domain) user.add_domain_membership(domain=self.domain) user.set_role(self.domain, invitation.role) if project.commtrack_enabled and not project.location_restriction_for_users: user.location_id = invitation.supply_point user.save()
def __init__(self, domain, new_plan_version, changed_privs, verbose=False, date_start=None, web_user=None): self.web_user = web_user self.verbose = verbose self.date_start = date_start or datetime.date.today() if isinstance(changed_privs, set): changed_privs = list(changed_privs) if not isinstance(domain, Domain): domain = Domain.get_by_name(domain) self.domain = domain # plan dependent privilege changed_privs.append(privileges.MOBILE_WORKER_CREATION) # check to make sure that no subscriptions are scheduled to # start in the future changed_privs.append(LATER_SUBSCRIPTION_NOTIFICATION) self.privileges = filter(lambda x: x in self.supported_privileges, changed_privs) self.new_plan_version = new_plan_version
def enable_usercase(domain_name): with CriticalSection(['enable_usercase_' + domain_name]): domain = Domain.get_by_name(domain_name, strict=True) if not domain.usercase_enabled: domain.usercase_enabled = True domain.save() create_user_cases.delay(domain_name)
def get_settings_values(app): try: profile = app.profile except AttributeError: profile = {} hq_settings = dict([(attr, app[attr]) for attr in app.properties() if not hasattr(app[attr], 'pop')]) if getattr(app, 'use_custom_suite', False): hq_settings.update( {'custom_suite': getattr(app, 'custom_suite', None)}) hq_settings['build_spec'] = app.build_spec.to_string() # the admin_password hash shouldn't be sent to the client hq_settings.pop('admin_password', None) domain = Domain.get_by_name(app.domain) return { 'properties': profile.get('properties', {}), 'features': profile.get('features', {}), 'hq': hq_settings, '$parent': { 'doc_type': app.get_doc_type(), '_id': app.get_id, 'domain': app.domain, 'commtrack_enabled': domain.commtrack_enabled, } }
def stock_data_submission(sender, cases, endpoint=None, **kwargs): project = Domain.get_by_name(cases[0].domain) if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled: if endpoint is None: endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config) # get agentCode and programCode - I assume all cases are part of the same program agentCode = (cases[0].get_supply_point_case()).location.site_code programCode = Program.get(cases[0].get_product().program_id).code products = [] for case in cases: product = case.get_product() product_json = {'productCode': product.code} product_json['stockInHand'] = int(case.get_default_value()) products.append(product_json) stock_data = { 'agentCode': agentCode, 'programCode': programCode, 'products': products } response = sync_stock_data_to_openlmis(submission=stock_data, openlmis_endpoint=endpoint) if response['requisitionId'] is not None: for case in cases: case.external_id = response['requisitionId'] case.save() cases, send_notification = sync_requisition_from_openlmis(project.name, response['requisitionId'], endpoint) if send_notification: send_notifications(xform=None, cases=cases)
def update_careplan_config(config, parent_app_id, application): app_props = config.app_configs.get(parent_app_id, CareplanAppProperties()) app_props.latest_release = application.get_id for module in application.get_modules(): if isinstance(module, CareplanModule): app_props.name = module.default_name() app_props.case_type = module.case_type app_props.goal_conf = { "edit_module_id": module.id, "edit_form_id": module.get_form_by_type(CAREPLAN_GOAL, 'update').id, "create_module_id": module.id, "create_form_id": module.get_form_by_type(CAREPLAN_GOAL, 'create').id, } app_props.task_conf = { "edit_module_id": module.id, "edit_form_id": module.get_form_by_type(CAREPLAN_TASK, 'update').id, "create_module_id": module.id, "create_form_id": module.get_form_by_type(CAREPLAN_TASK, 'create').id, } break config.app_configs[parent_app_id] = app_props config.save() domain = Domain.get_by_name(application.domain) if not domain.has_careplan: domain.has_careplan = True domain.save()
def approve_requisitions(sender, requisitions, **kwargs): if requisitions and requisitions[ 0].requisition_status == RequisitionStatus.APPROVED: project = Domain.get_by_name(requisitions[0].domain) if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled: endpoint = OpenLMISEndpoint.from_config( project.commtrack_settings.openlmis_config) approve_requisition(requisitions, endpoint)
def confirm_delivery(sender, requisitions, **kwargs): if requisitions and requisitions[ 0].requisition_status == RequisitionStatus.RECEIVED: project = Domain.get_by_name(requisitions[0].domain) if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled: endpoint = OpenLMISEndpoint.from_config( project.commtrack_settings.openlmis_config) delivery_update(requisitions, endpoint)
def get_locations(self): location_types = [ loc_type.name for loc_type in filter(lambda loc_type: loc_type.administrative, Domain.get_by_name(self.config['domain']).location_types ) ] return SQLLocation.objects.filter(parent__location_id=self.config['location_id'], location_type__in=location_types)
def location_restriction_for_users(request, domain): if not toggles.RESTRICT_WEB_USERS_BY_LOCATION.enabled(request.domain): raise Http403() project = Domain.get_by_name(domain) if "restrict_users" in request.POST: project.location_restriction_for_users = json.loads(request.POST["restrict_users"]) project.save() return HttpResponse()
def get_locations(self): location_types = [ location_type.name for location_type in Domain.get_by_name(self.domain).location_types if location_type.administrative ] return SQLLocation.objects.filter(parent__location_id=self.config['location_id'], location_type__name__in=location_types, is_archived=False)
def can_edit_form_location(domain, user, form): if not toggles.RESTRICT_FORM_EDIT_BY_LOCATION.enabled(domain): return True location = get_xform_location(form) if not location: return True return user_can_edit_location(user, location, Domain.get_by_name(domain))
def invite(self, invitation, user): project = Domain.get_by_name(self.domain) user.add_domain_membership(domain=self.domain) user.set_role(self.domain, invitation.role) if project.commtrack_enabled and not project.location_restriction_for_users: user.get_domain_membership(self.domain).location_id = invitation.supply_point user.get_domain_membership(self.domain).program_id = invitation.program user.save()
def facilities(self, **kwargs): reporting_types = [ loc_type.name for loc_type in Domain.get_by_name(self.config['domain']).location_types if not loc_type.administrative ] return SQLLocation.objects.filter(domain=self.domain, location_type__in=reporting_types, **kwargs)
def supply_point_updated(sender, supply_point, created, **kwargs): project = Domain.get_by_name(supply_point.domain) if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled: # check if supply_point is of 'chw type' if supply_point.location and supply_point.location.location_type == "chw": #check if supply_point is linked to an OpenLMIS facility if supply_point.location.lineage and len(supply_point.location.lineage) > 0: endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config) sync_supply_point_to_openlmis(supply_point, endpoint, created)
def supply_point_updated(sender, supply_point, created, **kwargs): project = Domain.get_by_name(supply_point.domain) if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled: # check if supply_point is of 'chw type' if supply_point.location and supply_point.location.location_type == "chw": #check if supply_point is linked to an OpenLMIS facility if supply_point.location.lineage and len(supply_point.location.lineage) > 0: endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config) sync_supply_point_to_openlmis(supply_point, endpoint, created)
def careplan_removed(domain_name, config, app_id): if config and app_id in config.app_configs: del config.app_configs[app_id] config.save() if not config.app_configs: domain = Domain.get_by_name(domain_name) domain.has_careplan = False domain.save()
def _create_location_type_if_not_exists(self, supply_point, location): domain = Domain.get_by_name(self.domain) if not filter(lambda l: l.name == supply_point.type, domain.location_types): domain.location_types.append(LocationType( name=supply_point.type, allowed_parents=[location.location_type], administrative=False )) domain.save()
def location_restriction_for_users(request, domain): if not toggles.RESTRICT_WEB_USERS_BY_LOCATION.enabled(request.domain): raise Http403() project = Domain.get_by_name(domain) if "restrict_users" in request.POST: project.location_restriction_for_users = json.loads( request.POST["restrict_users"]) project.save() return HttpResponse()
def careplan_removed(domain_name, config, app_id): if config and app_id in config.app_configs: del config.app_configs[app_id] config.save() if not config.app_configs: domain = Domain.get_by_name(domain_name) domain.has_careplan = False domain.save()
def is_reporting_type(self): if not self.report_config.get('location_id'): return False sql_location = SQLLocation.objects.get(location_id=self.report_config['location_id'], is_archived=False) reporting_types = [ location_type.name for location_type in Domain.get_by_name(self.domain).location_types if not location_type.administrative ] return sql_location.location_type.name in reporting_types
def invite(self, invitation, user): project = Domain.get_by_name(self.domain) user.add_domain_membership(domain=self.domain) user.set_role(self.domain, invitation.role) if project.commtrack_enabled: user.get_domain_membership(self.domain).program_id = invitation.program if project.uses_locations: user.get_domain_membership(self.domain).location_id = invitation.supply_point user.save()
def handle(self, *args, **options): if len(args) != 2: raise CommandError('Usage: manage.py bootstrap_app <domain> <app-name>') domain_name, app_name = args try: Domain.get_by_name(domain_name) except ResourceNotFound: raise CommandError("Domain with name '{domain_name}' not found".format( domain_name=domain_name )) self.create_two_module_app(domain_name, app_name) if not getattr(settings, 'BASE_ADDRESS', None): print ("Warning: You must set BASE_ADDRESS setting " "in your localsettings.py file in order for commcare-hq " "to be able to generate absolute urls. " "This is necessary for a number of features.")
def supply_point_updated(sender, supply_point, created, **kwargs): project = Domain.get_by_name(supply_point.domain) if project.commtrack_enabled and project.commtrack_settings.openlmis_enabled: # check if supply_point is of 'chw type' if supply_point.location and supply_point.location.type is 'chw': #check if supply_point is linked to an OpenLMIS facility if supply_point.location.parent and supply_point.location.parent.external_id: endpoint = OpenLMISEndpoint.from_config(project.commtrack_settings.openlmis_config) sync_supply_point_to_openlmis(supply_point, endpoint)
def is_reporting_type(self): if not self.report_config.get('location_id'): return False sql_location = SQLLocation.objects.get( location_id=self.report_config['location_id'], is_archived=False) reporting_types = [ location_type.name for location_type in Domain.get_by_name(self.domain).location_types if not location_type.administrative ] return sql_location.location_type.name in reporting_types
def __init__(self, domain, new_plan_version, downgraded_privileges): if isinstance(downgraded_privileges, set): downgraded_privileges = list(downgraded_privileges) if not isinstance(domain, Domain): domain = Domain.get_by_name(domain) self.domain = domain # plan dependent privilege downgraded_privileges.append(privileges.MOBILE_WORKER_CREATION) self.privileges = filter(lambda x: x in self.supported_privileges, downgraded_privileges) self.new_plan_version = new_plan_version
def __init__(self, domain, new_plan_version, changed_privs, verbose=False): self.verbose = verbose if isinstance(changed_privs, set): changed_privs = list(changed_privs) if not isinstance(domain, Domain): domain = Domain.get_by_name(domain) self.domain = domain # plan dependent privilege changed_privs.append(privileges.MOBILE_WORKER_CREATION) self.privileges = filter(lambda x: x in self.supported_privileges, changed_privs) self.new_plan_version = new_plan_version
def handle(self, *args, **options): if len(args) != 2: raise CommandError( 'Usage: manage.py bootstrap_app <domain> <app-name>') domain_name, app_name = args try: Domain.get_by_name(domain_name) except ResourceNotFound: raise CommandError( "Domain with name '{domain_name}' not found".format( domain_name=domain_name)) self.create_two_module_app(domain_name, app_name) if not getattr(settings, 'BASE_ADDRESS', None): print( "Warning: You must set BASE_ADDRESS setting " "in your localsettings.py file in order for commcare-hq " "to be able to generate absolute urls. " "This is necessary for a number of features.")
def __call__(self, user, version, last_sync=None): if user.domain in M4CHANGE_DOMAINS: domain = Domain.get_by_name(user.domain) location_id = get_commtrack_location_id(user, domain) if location_id is not None: fixture = self.get_fixture(user, location_id) if fixture is None: return [] return [fixture] else: return [] else: return []
def generator(user, version, last_sync=None): if user.domain in M4CHANGE_DOMAINS: domain = Domain.get_by_name(user.domain) location_id = get_commtrack_location_id(user, domain) if location_id is not None: fixture = LocationFixtureProvider('user-locations', user, domain, location_id).to_fixture() if fixture is None: return [] return [fixture] else: return [] else: return []
def generator(user, version, synclog, last_sync): if user.domain in M4CHANGE_DOMAINS: domain = Domain.get_by_name(user.domain) location_id = get_commtrack_location_id(user, domain) if location_id is not None: fixture = ReportFixtureProvider('reports:m4change-mobile', user, domain, location_id).to_fixture() if fixture is None: return [] return [fixture] else: return [] else: return []
def can_edit_form_location(domain, user, form): # Domain admins can always edit locations. If the user isn't an admin and # the location restriction is enabled, they can only edit forms that are # explicitly at or below them in the location tree. domain_obj = Domain.get_by_name(domain) if (not toggles.RESTRICT_FORM_EDIT_BY_LOCATION.enabled(domain) or user_can_edit_any_location(user, domain_obj)): return True location = get_xform_location(form) if not location: return False return user_can_edit_location(user, location, domain_obj)
def __call__(self, user, version, last_sync=None): if user.domain in M4CHANGE_DOMAINS: domain = Domain.get_by_name(user.domain) location_id = get_commtrack_location_id(user, domain) if location_id is not None: fixture = self.get_fixture(user, location_id) if fixture is None: return [] return [fixture] else: return [] else: return []
def can_edit_form_location(domain, user, form): # Domain admins can always edit locations. If the user isn't an admin and # the location restriction is enabled, they can only edit forms that are # explicitly at or below them in the location tree. domain_obj = Domain.get_by_name(domain) if (not toggles.RESTRICT_FORM_EDIT_BY_LOCATION.enabled(domain) or user_can_edit_any_location(user, domain_obj)): return True location = get_xform_location(form) if not location: return False return user_can_edit_location(user, location, domain_obj)
def main_context(self): contacts = CommCareUser.by_domain(self.domain, reduce=True) web_users = WebUser.by_domain(self.domain) web_users_admins = web_users_read_only = 0 facilities = SQLLocation.objects.filter(domain=self.domain, location_type__iexact='FACILITY') for web_user in web_users: role = web_user.get_domain_membership(self.domain).role if role and role.name.lower().startswith('admin'): web_users_admins += 1 else: web_users_read_only += 1 main_context = super(GlobalStats, self).main_context location_types = Domain.get_by_name(self.domain).location_types administrative_types = [ location_type.name for location_type in location_types if not location_type.administrative ] entities_reported_stock = SQLLocation.objects.filter( domain=self.domain, location_type__in=administrative_types ).count() context = { 'root_name': self.root_name, 'country': SQLLocation.objects.filter(domain=self.domain, location_type__iexact=self.root_name).count(), 'region': SQLLocation.objects.filter(domain=self.domain, location_type__iexact='region').count(), 'district': SQLLocation.objects.filter(domain=self.domain, location_type__iexact='district').count(), 'entities_reported_stock': entities_reported_stock, 'facilities': len(facilities), 'contacts': contacts[0]['value'] if contacts else 0, 'web_users': len(web_users), 'web_users_admins': web_users_admins, 'web_users_read_only': web_users_read_only, 'products': SQLProduct.objects.filter(domain=self.domain).count(), 'product_stocks': StockState.objects.filter(sql_product__domain=self.domain).count(), 'stock_transactions': StockTransaction.objects.filter(report__domain=self.domain).count(), 'inbound_messages': SMSLog.count_incoming_by_domain(self.domain), 'outbound_messages': SMSLog.count_outgoing_by_domain(self.domain) } if self.show_supply_point_types: counts = SQLLocation.objects.values('location_type').filter(domain=self.domain).annotate( Count('location_type') ).order_by('location_type') context['location_types'] = counts main_context.update(context) return main_context
def generator(user, version, last_sync): if user.domain in M4CHANGE_DOMAINS: domain = Domain.get_by_name(user.domain) location_id = get_commtrack_location_id(user, domain) if location_id is not None: fixture = ReportFixtureProvider('reports:m4change-mobile', user, domain, location_id).to_fixture() if fixture is None: return [] return [fixture] else: return [] else: return []
def data_providers(self): config = self.report_config location_types = [loc_type.name for loc_type in filter( lambda loc_type: not loc_type.administrative, Domain.get_by_name(self.domain).location_types )] if not self.needs_filters and Location.get(config['location_id']).location_type in location_types: return [FacilityReportData(config), StockLevelsLegend(config), InputStock(config), FacilitySMSUsers(config), FacilityUsers(config), FacilityInChargeUsers(config), InventoryManagementData(config)]
def check_reportcase_es_index(doc_id=None, interval=10): do_check = False for domain in settings.ES_CASE_FULL_INDEX_DOMAINS: domain_doc = Domain.get_by_name(domain) if domain_doc is not None: do_check = True break if do_check: db = CommCareCase.get_db() es_index = REPORT_CASE_INDEX check_doc_id = doc_id if doc_id else _get_latest_doc_from_index(es_index, sort_field='opened_on') return check_index_by_doc(es_index, db, check_doc_id, interval=interval) else: return {}
def check_reportxform_es_index(doc_id=None, interval=10): do_check = False for domain in settings.ES_XFORM_FULL_INDEX_DOMAINS: domain_doc = Domain.get_by_name(domain) if domain_doc is not None: do_check = True break if do_check: db = XFormInstance.get_db() es_index = REPORT_XFORM_INDEX check_doc_id = doc_id if doc_id else _get_latest_doc_from_index(es_index, 'received_on') return check_index_by_doc(es_index, db, check_doc_id, interval=interval) else: return {}
def handle(self): verified_contact = self.verified_contact domain = Domain.get_by_name(verified_contact.domain) text = self.msg.text try: data = StockReportParser(domain, verified_contact).parse(text) if not data: return False except NotAUserClassError: return False except Exception, e: # todo: should we only trap SMSErrors? if settings.UNIT_TESTING or settings.DEBUG: raise send_sms_to_verified_number( verified_contact, 'problem with stock report: %s' % str(e)) return True
def data_providers(self): config = self.report_config location_types = [ loc_type.name for loc_type in filter( lambda loc_type: not loc_type.administrative, Domain.get_by_name(self.domain).location_types) ] if not self.needs_filters and Location.get( config['location_id']).location_type in location_types: if self.is_rendered_as_email: return [FacilityReportData(config)] else: return [ FacilityReportData(config), StockLevelsLegend(config), InputStock(config), UsersData(config), InventoryManagementData(config), ProductSelectionPane(config, hide_columns=False) ]
def handle(self, *args, **options): if len(args) != 1: print "Invalid arguments: %s" % str(args) return domain = Domain.get_by_name(args[0]) if not domain: print "Invalid domain name: %s" % args[0] return account, _ = BillingAccount.get_or_create_account_by_domain( domain.name, account_type=BillingAccountType.CONTRACT, created_by="management command", ) enterprise_plan_version = SoftwarePlanVersion.objects.filter( plan__edition=SoftwarePlanEdition.ENTERPRISE)[0] try: subscription = Subscription.new_domain_subscription( account, domain.name, enterprise_plan_version) except NewSubscriptionError as e: print e.message return subscription.is_active = True subscription.save() print 'Domain %s has been upgraded to enterprise level.' % domain.name
def handle(self, *args, **options): if len(args) != 1: print "Invalid arguments: %s" % str(args) return domain = Domain.get_by_name(args[0]) if not domain: print "Invalid domain name: %s" % args[0] return plan_version, subscription = Subscription.get_subscribed_plan_by_domain( domain.name) if plan_version.plan.edition == SoftwarePlanEdition.ENTERPRISE: print "Domain %s is already enterprise level" % domain.name return if subscription: subscription.change_plan(self.enterprise_plan_version) else: try: self.make_new_enterprise_subscription(domain) except NewSubscriptionError as e: print e.message return print 'Domain %s has been upgraded to enterprise level.' % domain.name
def is_usercase_in_use(domain_name): domain = Domain.get_by_name(domain_name) if domain_name else None return domain and domain.usercase_enabled
def ensure_domain_instance(domain): if not isinstance(domain, Domain): domain = Domain.get_by_name(domain) return domain
def core_product(self): domain = Domain.get_by_name(self.payment_method.billing_admin.domain) return SoftwareProductType.get_type_by_domain(domain)
def domain_obj(self): return Domain.get_by_name(self.domain)
def obj_get(self, bundle, **kwargs): domain = Domain.get_by_name(kwargs.get('domain')) if domain is None: raise NotFound return domain