当前位置: 首页>>代码示例>>Python>>正文


Python models.Program类代码示例

本文整理汇总了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'
        )
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:28,代码来源:forms.py

示例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)
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:28,代码来源:test_notifications.py

示例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")
开发者ID:jmaina,项目名称:commcare-hq,代码行数:58,代码来源:test_signals.py

示例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
        )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:56,代码来源:test_programs.py

示例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
        )
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:50,代码来源:test_programs.py

示例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()
开发者ID:jmaina,项目名称:commcare-hq,代码行数:7,代码来源:test_signals.py

示例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)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:7,代码来源:fixtures.py

示例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)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:35,代码来源:signals.py

示例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
开发者ID:atinus,项目名称:commcare-hq,代码行数:34,代码来源:views.py

示例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
开发者ID:jmaina,项目名称:commcare-hq,代码行数:33,代码来源:__init__.py

示例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
开发者ID:jmaina,项目名称:commcare-hq,代码行数:8,代码来源:fields.py

示例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
开发者ID:puttarajubr,项目名称:commcare-hq,代码行数:17,代码来源:api.py

示例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
开发者ID:bradmerlin,项目名称:commcare-hq,代码行数:8,代码来源:filters.py

示例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
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:17,代码来源:forms.py

示例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
        )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:8,代码来源:fixtures.py


注:本文中的corehq.apps.programs.models.Program类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。