本文整理汇总了Python中corehq.apps.commtrack.models.Program.get方法的典型用法代码示例。如果您正苦于以下问题:Python Program.get方法的具体用法?Python Program.get怎么用?Python Program.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.commtrack.models.Program
的用法示例。
在下文中一共展示了Program.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import get [as 别名]
def test_delete(self):
# assign some product to the new program
self.products[0].program_id = self.new_program._id
self.products[0].save()
# make sure start state is okay
self.assertEqual(
2,
len(Program.by_domain(self.domain.name))
)
self.assertEqual(
2,
Product.by_program_id(self.domain.name, self.default_program._id).count()
)
self.assertEqual(
1,
Product.by_program_id(self.domain.name, self.new_program._id).count()
)
self.assertEqual(
self.new_program._id,
self.products[0].program_id
)
self.assertEqual(
self.new_program._id,
SQLProduct.objects.get(product_id=self.products[0]._id).program_id
)
# stash the id before we delete
new_program_id = self.new_program._id
self.new_program.delete()
with self.assertRaises(ResourceNotFound):
Program.get(new_program_id)
self.assertEqual(
1,
len(Program.by_domain(self.domain.name))
)
self.assertEqual(
3,
Product.by_program_id(self.domain.name, self.default_program._id).count()
)
self.assertEqual(
self.default_program._id,
Product.get(self.products[0]._id).program_id
)
self.assertEqual(
self.default_program._id,
SQLProduct.objects.get(product_id=self.products[0]._id).program_id
)
示例2: stock_data_submission
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import get [as 别名]
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)
示例3: product_data
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import get [as 别名]
def product_data(self):
data = []
if self.show_inactive:
products = Product.archived_by_domain(
domain=self.domain,
limit=self.limit,
skip=self.skip(),
)
else:
products = Product.by_domain(
domain=self.domain,
limit=self.limit,
skip=self.skip(),
)
for p in products:
if p.program_id:
program = Program.get(p.program_id)
else:
program = get_or_create_default_program(self.domain)
p.program_id = program.get_id
p.save()
info = p._doc
info['program'] = program.name
info['edit_url'] = reverse('commtrack_product_edit', kwargs={'domain': self.domain, 'prod_id': p._id})
info['archive_action_desc'] = self.get_archive_text(self.show_inactive)
info['archive_action_text'] = _("Un-Archive") if self.show_inactive else _("Archive")
info['archive_url'] = reverse(
'unarchive_product' if self.show_inactive else 'archive_product',
kwargs={'domain': self.domain, 'prod_id': p._id}
)
data.append(info)
return data
示例4: delete_program
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import get [as 别名]
def delete_program(request, domain, prog_id):
program = Program.get(prog_id)
program.delete()
return json_response({
'success': True,
'message': _("Program '{program_name}' has successfully been deleted.").format(
program_name=program.name,
)
})
示例5: product_data
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import get [as 别名]
def product_data(self):
data = []
products = Product.by_domain(domain=self.domain, limit=self.limit, skip=self.skip())
for p in products:
if p.program_id:
program = Program.get(p.program_id)
else:
program = get_or_make_def_program(self.domain)
p.program_id = program.get_id
p.save()
info = p._doc
info['program'] = program.name
info['edit_url'] = reverse('commtrack_product_edit', kwargs={'domain': self.domain, 'prod_id': p._id})
data.append(info)
return data
示例6: stock_data_submission
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import get [as 别名]
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 rq in cases:
product = rq.get_product()
products.append({'productCode': product.code,
'beginningBalance': product.beginningBalance,
'quantityReceived': product.quantityReceived,
'quantityDispensed': product.quantityDispensed,
'lossesAndAdjustments': product.lossesAndAdjustments,
'newPatientCount': product.newPatientCount,
'stockOnHand': product.stockOnHand,
'stockOutDays': product.stockOutDays,
'quantityRequested': product.quantityRequested,
'reasonForRequestedQuantity': product.reasonForRequestedQuantity,
'remarks': product.remarks})
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 rq in cases:
rq.external_id = response['requisitionId']
rq.save()
示例7: program
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import get [as 别名]
def program(self):
try:
return Program.get(self.program_id)
except ResourceNotFound:
raise Http404()