本文整理汇总了Python中corehq.apps.commtrack.models.Program类的典型用法代码示例。如果您正苦于以下问题:Python Program类的具体用法?Python Program怎么用?Python Program使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Program类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, *args, **options):
self.stdout.write("Fixing default programs...\n")
for domain in Domain.get_all():
if not domain.commtrack_enabled:
continue
if Program.default_for_domain(domain.name):
continue
programs = Program.by_domain(domain.name)
# filter anything named 'default' or 'Default'
current_default = [
p for p in programs
if p.name == 'Default' or p.name == 'default'
]
# if they never changed their default programs
# name, we don't want to add a confusing new one
# so just flip this to the default
if len(current_default) == 1:
p.default = True
p.save()
else:
get_or_create_default_program(domain.name)
示例2: SignalsTest
class SignalsTest(OpenLMISTestBase):
requisitions_enabled = True
program = None
def createProgram(self):
self.program = Program()
self.program.domain = TEST_DOMAIN
self.program.code = 'QYZ'
self.program.name = "hiv_program"
self.program.save()
def createProducts(self):
with open(os.path.join(self.datapath, 'sample_product_1.json')) as f:
lmis_product_1 = json.loads(f.read())
with open(os.path.join(self.datapath, 'sample_product_2.json')) as f:
lmis_product_2 = json.loads(f.read())
lmis_product_1['program_id'] = self.program._id
lmis_product_2['program_id'] = self.program._id
product_1 = Product(lmis_product_1)
product_2 = Product(lmis_product_2)
product_1.save()
product_2.save()
self.products = []
self.products.append(product_1)
self.products.append(product_2)
def setUp(self):
super(SignalsTest, self).setUp()
self.datapath = os.path.join(os.path.dirname(__file__), 'data')
self.spps.clear()
self.createProgram()
self.createProducts()
def fixmetestSyncStockRequisition(self):
from corehq.apps.commtrack.stockreport import Requisition
requisition_cases = []
config = self.domain.commtrack_settings
for spp in self.spps.values():
transaction = Requisition(
config=config,
product_id=spp.product,
case_id=spp._id,
action_name=config.get_action_by_type(RequisitionActions.REQUEST).action_name,
value=20,
)
req = create_requisition(self.user._id, spp, transaction)
requisition_cases.append(req)
endpoint = MockOpenLMISSubmitEndpoint("uri://mock/lmis/endpoint", username='ned', password='honor')
stock_data_submission(sender=None, cases=requisition_cases, endpoint=endpoint)
for req in requisition_cases:
self.assertEqual(req.external_id, 'REQ_123')
示例3: test_delete
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
)
示例4: sync_openlmis_program
def sync_openlmis_program(domain, lmis_program):
program = get_program(domain, lmis_program)
if program is None:
program = Program(domain=domain)
else:
# currently impossible
raise NotImplementedError('updating existing programs is not yet supported')
program.name = lmis_program.name
program.code = lmis_program.code
program.save()
if lmis_program.products:
for lmis_product in lmis_program.products:
sync_openlmis_product(domain, program, lmis_product)
return program
示例5: stock_data_submission
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)
示例6: __init__
def __init__(self, product, *args, **kwargs):
self.product = product
kwargs["initial"] = self.product._doc
kwargs["initial"]["code"] = self.product.code
super(ProductForm, self).__init__(*args, **kwargs)
programs = Program.by_domain(self.product.domain, wrap=False)
self.fields["program_id"].choices = tuple((prog["_id"], prog["name"]) for prog in programs)
示例7: product_data
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
示例8: createProgram
def createProgram(self):
self.program = Program()
self.program.domain = TEST_DOMAIN
self.program.code = 'QYZ'
self.program.name = "hiv_program"
self.program.save()
示例9: test_program_fixture
def test_program_fixture(self):
user = bootstrap_user(self, phone_number="1234567890")
Program(
domain=user.domain,
name="test1",
code="t1"
).save()
program_list = Program.by_domain(user.domain)
program_xml = ''
for program in program_list:
program_xml += '''
<program id="{id}">
<name>{name}</name>
<code>{code}</code>
</program>
'''.format(
id=program.get_id,
name=program.name,
code=program.code
)
fixture = program_fixture_generator(user, V1, None)
self.assertXmlEqual('''<fixture id="commtrack:programs" user_id="{user_id}">
<programs>
{programs}
</programs>
</fixture>'''.format(user_id=user.user_id, programs=program_xml),
ElementTree.tostring(fixture[0]))
示例10: setUp
def setUp(self):
super(ProgramsTest, self).setUp()
self.default_program = Program.by_domain(self.domain.name, wrap=True).one()
self.new_program = make_program(
self.domain.name,
'new program',
'newprogram'
)
示例11: __init__
def __init__(self, product, *args, **kwargs):
self.product = product
kwargs['initial'] = self.product._doc
kwargs['initial']['code'] = self.product.code
super(ProductForm, self).__init__(*args, **kwargs)
programs = Program.by_domain(self.product.domain, wrap=False)
self.fields['program_id'].choices = tuple((prog['_id'], prog['name']) for prog in programs)
# make sure to select default program if
# this is a new product
if not product._id:
self.initial['program_id'] = Program.default_for_domain(
self.product.domain
)._id
示例12: update_params
def update_params(self):
self.selected = self.request.GET.get('program')
user = WebUser.get_by_username(str(self.request.user))
if not self.selected and self.selected != '':
self.selected = user.program_id
self.programs = Program.by_domain(self.domain)
opts = [dict(val=program.get_id, text=program.name) for program in self.programs]
self.options = opts
示例13: program_data
def program_data(self):
data = []
programs = Program.by_domain(self.domain)
for p in programs:
info = p._doc
info['edit_url'] = reverse('commtrack_program_edit', kwargs={'domain': self.domain, 'prog_id': p._id})
data.append(info)
return data
示例14: clean_name
def clean_name(self):
name = self.cleaned_data['name']
other_programs = [p for p in Program.by_domain(self.program.domain) if p._id != self.program._id]
if name in [p.name for p in other_programs]:
raise forms.ValidationError(_('Name already in use'))
return name
示例15: delete_program
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,
)
})