本文整理汇总了Python中custom.ilsgateway.models.ILSGatewayConfig类的典型用法代码示例。如果您正苦于以下问题:Python ILSGatewayConfig类的具体用法?Python ILSGatewayConfig怎么用?Python ILSGatewayConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ILSGatewayConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.endpoint = MockEndpoint("http://test-api.com/", "dummy", "dummy")
self.stock_api_object = MockILSStockDataSynchronization(TEST_DOMAIN, self.endpoint)
self.datapath = os.path.join(os.path.dirname(__file__), "data")
initial_bootstrap(TEST_DOMAIN)
self.api_object = ILSGatewayAPI(TEST_DOMAIN, self.endpoint)
self.api_object.prepare_commtrack_config()
config = ILSGatewayConfig()
config.domain = TEST_DOMAIN
config.enabled = True
config.all_stock_data = True
config.password = "dummy"
config.username = "dummy"
config.url = "http://test-api.com/"
config.save()
l1 = Location(name="Test location 1", external_id="3445", location_type="FACILITY", domain=TEST_DOMAIN)
l2 = Location(name="Test location 2", external_id="4407", location_type="FACILITY", domain=TEST_DOMAIN)
l1.save()
l2.save()
SupplyPointCase.create_from_location(TEST_DOMAIN, l1)
SupplyPointCase.create_from_location(TEST_DOMAIN, l2)
with open(os.path.join(self.datapath, "sample_products.json")) as f:
for product_json in json.loads(f.read()):
self.api_object.product_sync(Product(product_json))
StockTransaction.objects.all().delete()
示例2: prepare_domain
def prepare_domain(domain_name):
from corehq.apps.commtrack.tests.util import bootstrap_domain
domain = bootstrap_domain(domain_name)
previous = None
for name, administrative in [
("MOHSW", True),
("MSDZONE", True),
("REGION", True),
("DISTRICT", True),
("FACILITY", False)
]:
previous, _ = LocationType.objects.get_or_create(
domain=domain_name,
name=name,
parent_type=previous,
administrative=administrative,
)
generator.instantiate_accounting_for_tests()
account = BillingAccount.get_or_create_account_by_domain(
domain.name,
created_by="automated-test",
)[0]
plan = DefaultProductPlan.get_default_plan_by_domain(
domain, edition=SoftwarePlanEdition.ADVANCED
)
commtrack = domain.commtrack_settings
commtrack.actions.append(
CommtrackActionConfig(action='receipts',
keyword='delivered',
caption='Delivered')
)
commtrack.save()
subscription = Subscription.new_domain_subscription(
account,
domain.name,
plan
)
subscription.is_active = True
subscription.save()
ils_config = ILSGatewayConfig(enabled=True, domain=domain.name, all_stock_data=True)
ils_config.save()
fields_definition = CustomDataFieldsDefinition.get_or_create(domain.name, 'LocationFields')
fields_definition.fields.append(CustomDataField(
slug='group',
label='Group',
is_required=False,
choices=['A', 'B', 'C'],
is_multiple_choice=False
))
fields_definition.save()
return domain
示例3: ils_sync_stock_data
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')
示例4: migration_task
def migration_task():
from custom.ilsgateway.stock_data import ILSStockDataSynchronization
for config in ILSGatewayConfig.get_all_steady_sync_configs():
if config.enabled:
endpoint = ILSGatewayEndpoint.from_config(config)
ils_bootstrap_domain(ILSGatewayAPI(config.domain, endpoint))
stock_data_task.delay(ILSStockDataSynchronization(config.domain, endpoint))
示例5: update_historical_data
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())
示例6: migration_task
def migration_task():
for config in ILSGatewayConfig.get_all_steady_sync_configs():
if config.enabled:
endpoint = ILSGatewayEndpoint.from_config(config)
ils_bootstrap_domain(ILSGatewayAPI(config.domain, endpoint))
apis = get_ilsgateway_data_migrations()
stock_data_task.delay(config.domain, endpoint, apis, config, ILS_FACILITIES)
示例7: handle
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
示例8: handle
def handle(self):
words = self.args
if len(words) < 2 or len(words) > 3:
self.respond(REGISTER_HELP)
return
name = words[0]
code = words[1]
params = {
"msd_code": code
}
if not self.user:
domains = [config.domain for config in ILSGatewayConfig.get_all_configs()]
for domain in domains:
loc = self._get_facility_location(domain, code)
if not loc:
continue
splited_name = name.split(' ', 1)
first_name = splited_name[0]
last_name = splited_name[1] if len(splited_name) > 1 else ""
clean_name = name.replace(' ', '.')
username = "%[email protected]%s.commcarehq.org" % (clean_name, domain)
password = User.objects.make_random_password()
user = CommCareUser.create(domain=domain, username=username, password=password,
commit=False)
user.first_name = first_name
user.last_name = last_name
if len(words) == 3:
user.user_data = {
'role': words[2]
}
try:
user.set_default_phone_number(self.msg.phone_number.replace('', ''))
user.save_verified_number(domain, self.msg.phone_number.replace('', ''), True, self.msg.backend_api)
except PhoneNumberInUseException as e:
v = VerifiedNumber.by_phone(self.msg.phone_number, include_pending=True)
v.delete()
user.save_verified_number(domain, self.msg.phone_number.replace('', ''), True, self.msg.backend_api)
except CommCareUser.Inconsistent:
continue
user.language = Languages.DEFAULT
params.update({
'sdp_name': loc.name,
'contact_name': name
})
dm = user.get_domain_membership(domain)
dm.location_id = loc._id
user.save()
add_location(user, loc._id)
self.respond(REGISTRATION_CONFIRM, **params)
示例9: setUp
def setUp(self):
self.endpoint = MockEndpoint('http://test-api.com/', 'dummy', 'dummy')
self.api_object = ILSGatewayAPI(TEST_DOMAIN, self.endpoint)
self.datapath = os.path.join(os.path.dirname(__file__), 'data')
initial_bootstrap(TEST_DOMAIN)
config = ILSGatewayConfig(
domain=TEST_DOMAIN, enabled=True, all_stock_data=True, password='dummy', username='dummy',
url='http//test-api.com/'
)
config.save()
with open(os.path.join(self.datapath, 'sample_locations.json')) as f:
location = Loc(**json.loads(f.read())[1])
self.api_object.prepare_commtrack_config()
self.api_object.location_sync(location)
for user in WebUser.by_domain(TEST_DOMAIN):
user.delete()
示例10: fix_stock_data
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)
示例11: post
def post(self, request, *args, **kwargs):
payload = json.loads(request.POST.get('json'))
ils = ILSGatewayConfig.wrap(self.settings_context['source_config'])
ils.enabled = payload['source_config'].get('enabled', None)
ils.domain = self.domain_object.name
ils.url = payload['source_config'].get('url', None)
ils.username = payload['source_config'].get('username', None)
ils.password = payload['source_config'].get('password', None)
ils.save()
return self.get(request, *args, **kwargs)
示例12: tearDownClass
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()
示例13: setUp
def setUp(self):
self.datapath = os.path.join(os.path.dirname(__file__), 'data')
initial_bootstrap(TEST_DOMAIN)
config = ILSGatewayConfig()
config.domain = TEST_DOMAIN
config.enabled = True
config.password = 'dummy'
config.username = 'dummy'
config.url = 'http://test-api.com/'
config.save()
for product in Product.by_domain(TEST_DOMAIN):
product.delete()
示例14: prepare_domain
def prepare_domain(domain_name):
from corehq.apps.commtrack.tests import bootstrap_domain
domain = bootstrap_domain(domain_name)
previous = None
for name, administrative in [
("MOHSW", True),
("REGION", True),
("DISTRICT", True),
("FACILITY", False)
]:
previous, _ = LocationType.objects.get_or_create(
domain=domain_name,
name=name,
parent_type=previous,
administrative=administrative,
)
generator.instantiate_accounting_for_tests()
account = BillingAccount.get_or_create_account_by_domain(
domain.name,
created_by="automated-test",
)[0]
plan = DefaultProductPlan.get_default_plan_by_domain(
domain, edition=SoftwarePlanEdition.ADVANCED
)
commtrack = domain.commtrack_settings
commtrack.actions.append(
CommtrackActionConfig(action='receipts',
keyword='delivered',
caption='Delivered')
)
commtrack.save()
subscription = Subscription.new_domain_subscription(
account,
domain.name,
plan
)
subscription.is_active = True
subscription.save()
ils_config = ILSGatewayConfig(enabled=True, domain=domain.name)
ils_config.save()
return domain
示例15: settings_context
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
}