本文整理汇总了Python中corehq.apps.programs.models.Program类的典型用法代码示例。如果您正苦于以下问题:Python Program类的具体用法?Python Program怎么用?Python Program使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Program类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __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)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.label_class = 'col-sm-3 col-md-4 col-lg-2'
self.helper.field_class = 'col-sm-4 col-md-5 col-lg-3'
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
self.helper.layout = Layout(
'name',
'code',
'description',
'unit',
'program_id',
'cost'
)
示例2: test_product_type_filter
def test_product_type_filter(self):
"""
Notifications will not be sent if the stockout is a product type does
not interest the user.
"""
self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id
self.user.save()
program = Program(domain=self.TEST_DOMAIN, name='Test Program 2')
program.save()
bootstrap_web_user(
username='test2', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district,
password='dummy', email='[email protected]', user_data={}, program_id=program.get_id
)
assign_products_to_location(self.facility, [self.product])
assign_products_to_location(self.other_facility, [self.product])
assign_products_to_location(self.last_facility, [self.product])
create_stock_report(self.facility, {'tp': 0})
create_stock_report(self.other_facility, {'tp': 0})
create_stock_report(self.last_facility, {'tp': 0})
generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications())
self.assertEqual(len(generated), 1)
self.assertEqual(generated[0].user.get_id, self.user.get_id)
示例3: 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")
示例4: test_programs
def test_programs(self):
self.domain = bootstrap_domain(TEST_DOMAIN)
self.addCleanup(self.domain.delete)
bootstrap_products(self.domain.name)
self.products = sorted(Product.by_domain(self.domain.name), key=lambda p: p._id)
self.default_program = Program.by_domain(self.domain.name, wrap=True).one()
self.new_program = make_program(
self.domain.name,
'new program',
'newprogram'
)
self.assertTrue(self.default_program.default)
self.assertFalse(self.new_program.default)
with self.assertRaises(Exception) as context:
self.default_program.delete()
self.assertEqual(six.text_type(context.exception), 'You cannot delete the default program')
# 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, self.default_program.get_products_count())
self.assertEqual(1, self.new_program.get_products_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, self.default_program.get_products_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
)
示例5: 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
)
示例6: createProgram
def createProgram(self):
self.program = Program()
self.program.domain = TEST_DOMAIN
self.program.code = "QYZ"
self.program.name = "hiv_program"
self.program.save()
示例7: program_fixture_generator
def program_fixture_generator(user, version, last_sync=None):
fields = [
'name',
'code'
]
data_fn = lambda: Program.by_domain(user.domain)
return _simple_fixture_generator(user, "program", fields, data_fn, last_sync)
示例8: 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)
示例9: 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
示例10: get_url
def get_url(cls, domain=None, render_as=None, **kwargs):
def _is_admin(user, domain):
return isinstance(user, WebUser) and user.get_domain_membership(domain).is_admin
def _is_read_only(user, domain):
user_role = user.get_role()
return isinstance(user, WebUser) and user_role == UserRole.get_read_only_role_by_domain(domain)
def _can_see_reports(user):
user_role = user.get_role()
return isinstance(user, CommCareUser) and user_role.permissions.view_reports
url = super(MultiReport, cls).get_url(domain=domain, render_as=None, kwargs=kwargs)
request = kwargs.get('request')
user = getattr(request, 'couch_user', None)
if user:
if _is_admin(user, domain):
loc = SQLLocation.objects.filter(domain=domain, location_type='country')[0]
url = '%s?location_id=%s' % (url, loc.location_id)
elif _is_read_only(user, domain) or _can_see_reports(user):
dm = user.get_domain_membership(domain)
if dm.program_id:
program_id = dm.program_id
else:
program_id = Program.default_for_domain(domain)
url = '%s?location_id=%s&program_id=%s' % (
url,
dm.location_id if dm.location_id else '',
program_id if program_id else ''
)
return url
示例11: 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 != "" and user.get_domain_membership(self.domain):
self.selected = user.get_domain_membership(self.domain).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
示例12: product_sync
def product_sync(self, ilsgateway_product):
from custom.ilsgateway import PRODUCTS_CODES_PROGRAMS_MAPPING
product = super(ILSGatewayAPI, self).product_sync(ilsgateway_product)
programs = list(Program.by_domain(self.domain))
for program, products in PRODUCTS_CODES_PROGRAMS_MAPPING.iteritems():
if product.code in products:
existing_program = filter(lambda p: p.name == program, programs)
if not existing_program:
new_program = Program(domain=self.domain)
new_program.name = program
new_program.save()
product.program_id = new_program.get_id
product.save()
else:
product.program_id = existing_program[0].get_id
product.save()
return product
示例13: drilldown_map
def drilldown_map(self):
options = []
for program in Program.by_domain(self.domain):
products = []
for product in Product.by_program_id(self.domain, program._id):
products.append({"val": product.get_id, "text": product.name})
options.append({"val": program.get_id, "text": program.name, "next": products})
return options
示例14: __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
示例15: __call__
def __call__(self, restore_state):
restore_user = restore_state.restore_user
data_fn = lambda: Program.by_domain(restore_user.domain)
return simple_fixture_generator(
restore_user, self.id, "program",
PROGRAM_FIELDS, data_fn, restore_state.last_sync_log
)