本文整理汇总了Python中custom.ilsgateway.models.ILSGatewayConfig.for_domain方法的典型用法代码示例。如果您正苦于以下问题:Python ILSGatewayConfig.for_domain方法的具体用法?Python ILSGatewayConfig.for_domain怎么用?Python ILSGatewayConfig.for_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类custom.ilsgateway.models.ILSGatewayConfig
的用法示例。
在下文中一共展示了ILSGatewayConfig.for_domain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_historical_data
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def update_historical_data(domain, locations=None):
"""
If we don't have a record of this supply point being updated, run
through all historical data and just fill in with zeros.
"""
org_summaries = OrganizationSummary.objects.order_by('date')
if org_summaries.count() == 0:
return
start_date = org_summaries[0].date
if locations is None:
if not ILSGatewayConfig.for_domain(domain).all_stock_data:
locations = _get_test_locations(domain)
else:
locations = Location.by_domain(domain)
for sp in locations:
try:
SupplyPointWarehouseRecord.objects.get(supply_point=sp._id)
except SupplyPointWarehouseRecord.DoesNotExist:
# we didn't have a record so go through and historically update
# anything we maybe haven't touched
for year, month in months_between(start_date, sp.sql_location.created_at):
window_date = datetime(year, month, 1)
for cls in [OrganizationSummary, ProductAvailabilityData, GroupSummary]:
_init_warehouse_model(cls, sp, window_date)
SupplyPointWarehouseRecord.objects.create(supply_point=sp._id,
create_date=datetime.utcnow())
示例2: ils_sync_stock_data
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def ils_sync_stock_data(request, domain):
config = ILSGatewayConfig.for_domain(domain)
domain = config.domain
endpoint = ILSGatewayEndpoint.from_config(config)
apis = get_ilsgateway_data_migrations()
stock_data_task.delay(domain, endpoint, apis, config, ILS_FACILITIES)
return HttpResponse('OK')
示例3: handle
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def handle(verified_contact, text, msg=None):
user = verified_contact.owner if verified_contact else None
domain = user.domain
if domain and not ILSGatewayConfig.for_domain(domain):
return False
args = text.split()
if not args:
return False
keyword = args[0]
args = args[1:]
params = {
'user': user,
'domain': domain,
'args': args,
'msg': msg,
'verified_contact': verified_contact
}
def not_function(word):
if args and re.match("del", word):
return NotDeliveredHandler
elif args and re.match("sub", word):
return NotSubmittedHandler
return None
handlers = {
('soh', 'hmk'): SOHHandler,
('submitted', 'nimetuma'): RandrHandler,
('delivered', 'dlvd', 'nimepokea'): DeliveredHandler,
('sijapokea',): NotDeliveredHandler,
('sijatuma',): NotSubmittedHandler,
('supervision', 'usimamizi'): SupervisionHandler,
('arrived', 'aliwasili'): ArrivedHandler,
('help', 'msaada'): HelpHandler,
('language', 'lang', 'lugha'): LanguageHandler,
('stop', 'acha', 'hapo'): StopHandler,
('yes', 'ndio', 'ndyo'): YesHandler,
('register', 'reg', 'join', 'sajili'): RegisterHandler,
('test',): MessageInitiatior,
('not',): not_function(args[0]) if args else None
}
def choose_handler(keyword):
for k, v in handlers.iteritems():
if keyword in k:
return v
return None
handler_class = choose_handler(keyword)
handler = handler_class(**params) if handler_class else None
if handler:
if args:
handler.handle()
else:
handler.help()
return False
示例4: fix_stock_data
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def fix_stock_data(domain):
start_date = '2015-07-01'
end_date = StockDataCheckpoint.objects.get(domain=domain).date.strftime('%Y-%m-%d')
with connection.cursor() as c:
c.execute(
'DELETE FROM ilsgateway_supplypointstatus WHERE location_id IN '
'(SELECT location_id FROM locations_sqllocation WHERE domain=%s) AND status_date BETWEEN %s AND %s',
[domain, start_date, end_date]
)
c.execute(
'DELETE FROM ilsgateway_deliverygroupreport WHERE location_id IN '
'(SELECT location_id FROM locations_sqllocation WHERE domain=%s) AND report_date BETWEEN %s AND %s',
[domain, start_date, end_date]
)
c.execute(
"DELETE FROM ilsgateway_groupsummary WHERE org_summary_id IN "
"(SELECT id FROM ilsgateway_organizationsummary WHERE location_id IN "
"(SELECT location_id FROM locations_sqllocation WHERE domain=%s) AND date BETWEEN %s AND %s)",
[domain, start_date, end_date]
)
c.execute(
"DELETE FROM ilsgateway_organizationsummary WHERE location_id IN "
"(SELECT location_id FROM locations_sqllocation WHERE domain=%s AND date BETWEEN %s AND %s)",
[domain, start_date, end_date]
)
config = ILSGatewayConfig.for_domain(domain)
endpoint = ILSGatewayEndpoint.from_config(config)
filters = {'status_date__gte': start_date, 'status_date__lte': end_date}
offset = 0
_, statuses = endpoint.get_supplypointstatuses(domain, filters=filters, limit=1000, offset=offset)
while statuses:
for status in statuses:
try:
SupplyPointStatus.objects.get(external_id=status.external_id, location_id=status.location_id)
except SupplyPointStatus.DoesNotExist:
status.save()
offset += 1000
_, statuses = endpoint.get_supplypointstatuses(domain, filters=filters, limit=1000, offset=offset)
filters = {'report_date__gte': start_date, 'report_date__lte': end_date}
offset = 0
_, reports = endpoint.get_deliverygroupreports(domain, filters=filters, limit=1000, offset=offset)
while reports:
for report in reports:
try:
DeliveryGroupReport.objects.get(external_id=report.external_id, location_id=report.location_id)
except DeliveryGroupReport.DoesNotExist:
report.save()
offset += 1000
_, reports = endpoint.get_deliverygroupreports(domain, filters=filters, limit=1000, offset=offset)
示例5: tearDownClass
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def tearDownClass(cls):
MobileBackend.load_by_name(TEST_DOMAIN, TEST_BACKEND).delete()
CommCareUser.get_by_username('stella').delete()
CommCareUser.get_by_username('bella').delete()
CommCareUser.get_by_username('trella').delete()
CommCareUser.get_by_username('msd_person').delete()
for product in Product.by_domain(TEST_DOMAIN):
product.delete()
SQLProduct.objects.all().delete()
ILSGatewayConfig.for_domain(TEST_DOMAIN).delete()
DocDomainMapping.objects.all().delete()
Location.by_site_code(TEST_DOMAIN, 'loc1').delete()
Location.by_site_code(TEST_DOMAIN, 'loc2').delete()
Location.by_site_code(TEST_DOMAIN, 'dis1').delete()
Location.by_site_code(TEST_DOMAIN, 'reg1').delete()
Location.by_site_code(TEST_DOMAIN, 'moh1').delete()
SQLLocation.objects.all().delete()
generator.delete_all_subscriptions()
Domain.get_by_name(TEST_DOMAIN).delete()
示例6: settings_context
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def settings_context(self):
config = ILSGatewayConfig.for_domain(self.domain_object.name)
if config:
return {
"source_config": config._doc,
}
else:
return {
"source_config": ILSGatewayConfig()._doc
}
示例7: stock_data_task
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def stock_data_task(domain):
ilsgateway_config = ILSGatewayConfig.for_domain(domain)
domain = ilsgateway_config.domain
endpoint = ILSGatewayEndpoint.from_config(ilsgateway_config)
commtrack_settings_sync(domain)
for product in endpoint.get_products():
sync_ilsgateway_product(domain, product)
get_locations(domain, endpoint)
get_product_stock(domain, endpoint)
get_stock_transaction(domain, endpoint)
get_supply_point_statuses(domain, endpoint)
get_delivery_group_reports(domain, endpoint)
示例8: ils_sync_stock_data
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def ils_sync_stock_data(request, domain):
config = ILSGatewayConfig.for_domain(domain)
domain = config.domain
endpoint = ILSGatewayEndpoint.from_config(config)
apis = (
('product_stock', get_product_stock),
('stock_transaction', get_stock_transaction),
('supply_point_status', get_supply_point_statuses),
('delivery_group', get_delivery_group_reports)
)
stock_data_task.delay(domain, endpoint, apis, ILS_FACILITIES)
return HttpResponse('OK')
示例9: ils_clear_stock_data_task
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def ils_clear_stock_data_task(domain):
assert ILSGatewayConfig.for_domain(domain)
locations = SQLLocation.objects.filter(domain=domain)
SupplyPointStatus.objects.filter(location_id__in=locations.values_list('location_id', flat=True)).delete()
DeliveryGroupReport.objects.filter(location_id__in=locations.values_list('location_id', flat=True)).delete()
products = Product.ids_by_domain(domain)
StockState.objects.filter(product_id__in=products).delete()
StockTransaction.objects.filter(
case_id__in=locations.exclude(supply_point_id__isnull=True).values_list('supply_point_id', flat=True)
).delete()
StockReport.objects.filter(domain=domain).delete()
StockDataCheckpoint.objects.filter(domain=domain).delete()
示例10: populate_report_data
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def populate_report_data(start_date, end_date, domain, runner, locations=None, strict=True):
# first populate all the warehouse tables for all facilities
# hard coded to know this is the first date with data
start_date = max(start_date, default_start_date())
# For QA purposes generate reporting data for only some small part of data.
if not ILSGatewayConfig.for_domain(domain).all_stock_data:
if locations is None:
locations = _get_test_locations(domain)
facilities = filter(lambda location: location.location_type == 'FACILITY', locations)
non_facilities_types = ['DISTRICT', 'REGION', 'MSDZONE', 'MOHSW']
non_facilities = []
for location_type in non_facilities_types:
non_facilities.extend(filter(lambda location: location.location_type == location_type, locations))
else:
facilities = Location.filter_by_type(domain, 'FACILITY')
non_facilities = list(Location.filter_by_type(domain, 'DISTRICT'))
non_facilities += list(Location.filter_by_type(domain, 'REGION'))
non_facilities += list(Location.filter_by_type(domain, 'MSDZONE'))
non_facilities += list(Location.filter_by_type(domain, 'MOHSW'))
if runner.location:
if runner.location.location_type.name.upper() != 'FACILITY':
facilities = []
non_facilities = itertools.dropwhile(
lambda location: location._id != runner.location.location_id,
non_facilities
)
else:
facilities = itertools.dropwhile(
lambda location: location._id != runner.location.location_id,
facilities
)
facilities_chunked_list = chunked(facilities, 5)
for chunk in facilities_chunked_list:
res = chain(process_facility_warehouse_data.si(fac, start_date, end_date, runner) for fac in chunk)()
res.get()
non_facilities_chunked_list = chunked(non_facilities, 50)
# then populate everything above a facility off a warehouse table
for chunk in non_facilities_chunked_list:
res = chain(
process_non_facility_warehouse_data.si(org, start_date, end_date, runner, strict)
for org in chunk
)()
res.get()
runner.location = None
runner.save()
# finally go back through the history and initialize empty data for any
# newly created facilities
update_historical_data(domain)
示例11: handle
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def handle(self, domain, *args, **options):
if len(args) == 1:
ilsgateway_id = args[0]
else:
ilsgateway_id = 1166 # defaults to bondenzi: http://ilsgateway.com/tz/facility/1166/
# monkey patch the default start date to cover less data
updater.default_start_date = lambda: datetime(2015, 1, 1)
config = ILSGatewayConfig.for_domain(domain)
assert config.enabled, 'ilsgateway sync must be configured for this domain'
locations = _get_locations_from_ilsgateway_id(domain, ilsgateway_id)
_clear_data(domain)
report_run(domain, locations, strict=False)
示例12: handle
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def handle(self, domain, *args, **options):
if len(args) == 1:
ilsgateway_id = args[0]
else:
ilsgateway_id = 1166 # defaults to bondenzi: http://ilsgateway.com/tz/facility/1166/
# cleanup
_cleanup_existing_data(domain, ilsgateway_id)
# migrate
config = ILSGatewayConfig.for_domain(domain)
assert config.enabled, 'ilsgateway sync must be configured for this domain'
endpoint = ILSGatewayEndpoint.from_config(config)
stock_data_task(domain, endpoint, get_ilsgateway_data_migrations(), config,
test_facilities=[ilsgateway_id])
示例13: populate_report_data
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def populate_report_data(start_date, end_date, domain, runner, locations=None, strict=True):
# first populate all the warehouse tables for all facilities
# hard coded to know this is the first date with data
start_date = max(start_date, default_start_date())
# For QA purposes generate reporting data for only some small part of data.
if not ILSGatewayConfig.for_domain(domain).all_stock_data:
if locations is None:
locations = _get_test_locations(domain)
facilities = filter(lambda location: location.location_type == "FACILITY", locations)
non_facilities_types = ["DISTRICT", "REGION", "MSDZONE", "MOHSW"]
non_facilities = []
for location_type in non_facilities_types:
non_facilities.extend(filter(lambda location: location.location_type == location_type, locations))
else:
facilities = Location.filter_by_type(domain, "FACILITY")
non_facilities = list(Location.filter_by_type(domain, "DISTRICT"))
non_facilities += list(Location.filter_by_type(domain, "REGION"))
non_facilities += list(Location.filter_by_type(domain, "MSDZONE"))
non_facilities += list(Location.filter_by_type(domain, "MOHSW"))
if runner.location:
if runner.location.location_type.name.upper() != "FACILITY":
facilities = []
non_facilities = itertools.dropwhile(
lambda location: location.location_id != runner.location.location_id, non_facilities
)
else:
facilities = itertools.dropwhile(
lambda location: location.location_id != runner.location.location_id, facilities
)
facilities_chunked_list = chunked(facilities, 5)
for chunk in facilities_chunked_list:
res = chain(process_facility_warehouse_data.si(fac, start_date, end_date, runner) for fac in chunk)()
res.get()
non_facilities_chunked_list = chunked(non_facilities, 50)
# then populate everything above a facility off a warehouse table
for chunk in non_facilities_chunked_list:
res = chain(
process_non_facility_warehouse_data.si(org, start_date, end_date, runner, strict) for org in chunk
)()
res.get()
runner.location = None
runner.save()
示例14: tearDownClass
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def tearDownClass(cls):
delete_domain_phone_numbers(TEST_DOMAIN)
if cls.sms_backend_mapping.id is not None:
cls.sms_backend_mapping.delete()
if cls.sms_backend.id is not None:
cls.sms_backend.delete()
users = get_user_docs_by_username([
'stella',
'bella',
'trella',
'msd_person',
])
if users:
CommCareUser.bulk_delete([
CommCareUser.wrap_correctly(user)
for user in users
])
for product in Product.by_domain(TEST_DOMAIN):
product.delete()
SQLProduct.objects.all().delete()
ils_gateway_config = ILSGatewayConfig.for_domain(TEST_DOMAIN)
if ils_gateway_config:
ils_gateway_config.delete()
DocDomainMapping.objects.all().delete()
for site_code in [
'loc1',
'loc2',
'dis1',
'reg1',
'moh1',
]:
location = cls.get_location_by_site_code(site_code)
if location:
location.delete()
SQLLocation.objects.all().delete()
test_domain = Domain.get_by_name(TEST_DOMAIN, strict=True)
if test_domain:
test_domain.delete()
super(ILSTestScript, cls).tearDownClass()
示例15: ils_sms_users_fix
# 需要导入模块: from custom.ilsgateway.models import ILSGatewayConfig [as 别名]
# 或者: from custom.ilsgateway.models.ILSGatewayConfig import for_domain [as 别名]
def ils_sms_users_fix(request, domain):
config = ILSGatewayConfig.for_domain(domain)
endpoint = ILSGatewayEndpoint.from_config(config)
sms_users_fix.delay(ILSGatewayAPI(domain=domain, endpoint=endpoint))
return HttpResponse('OK')