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


Python Program.by_domain方法代码示例

本文整理汇总了Python中corehq.apps.commtrack.models.Program.by_domain方法的典型用法代码示例。如果您正苦于以下问题:Python Program.by_domain方法的具体用法?Python Program.by_domain怎么用?Python Program.by_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.apps.commtrack.models.Program的用法示例。


在下文中一共展示了Program.by_domain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_delete

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [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
        )
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:52,代码来源:test_programs.py

示例2: __init__

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
 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)
开发者ID:kkaczmarczyk,项目名称:commcare-hq,代码行数:9,代码来源:forms.py

示例3: test_program_fixture

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
    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]))
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:32,代码来源:test_fixture.py

示例4: handle

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
    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)
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:28,代码来源:fix_default_program.py

示例5: program_data

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
 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
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:10,代码来源:views.py

示例6: update_params

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
 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
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:10,代码来源:fields.py

示例7: clean_name

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
    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
开发者ID:amonkeykong81,项目名称:commcare-hq,代码行数:10,代码来源:forms.py

示例8: setUp

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
 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'
     )
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:10,代码来源:test_programs.py

示例9: __init__

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
 def __init__(self, *args, **kwargs):
     domain = None
     if 'domain' in kwargs:
         domain = kwargs['domain']
         del kwargs['domain']
     super(CommtrackUserForm, self).__init__(*args, **kwargs)
     self.fields['supply_point'].widget = SupplyPointSelectWidget(domain=domain)
     programs = Program.by_domain(domain, wrap=False)
     choices = list((prog['_id'], prog['name']) for prog in programs)
     choices.insert(0, ('', ''))
     self.fields['program_id'].choices = choices
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:13,代码来源:forms.py

示例10: clean_name

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
    def clean_name(self):
        name = self.cleaned_data['name']

        other_program_names = [
            p['name'] for p in Program.by_domain(self.program.domain, wrap=False)
            if p['_id'] != self.program._id
        ]
        if name in other_program_names:
            raise forms.ValidationError(_('Name already in use'))

        return name
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:13,代码来源:forms.py

示例11: __init__

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
 def __init__(self, data=None, excluded_emails=None, *args, **kwargs):
     domain = None
     if 'domain' in kwargs:
         domain = Domain.get_by_name(kwargs['domain'])
         del kwargs['domain']
     super(AdminInvitesUserForm, self).__init__(data=data, *args, **kwargs)
     if domain and domain.commtrack_enabled:
         self.fields['supply_point'] = forms.CharField(label='Supply Point:', required=False, widget=SupplyPointSelectWidget(domain=domain.name))
         self.fields['program'] = forms.ChoiceField(label="Program", choices=(), required=False)
         programs = Program.by_domain(domain.name, wrap=False)
         choices = list((prog['_id'], prog['name']) for prog in programs)
         choices.insert(0, ('', ''))
         self.fields['program'].choices = choices
     self.excluded_emails = excluded_emails or []
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:16,代码来源:forms.py

示例12: __init__

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
 def __init__(self, *args, **kwargs):
     domain = None
     if "domain" in kwargs:
         domain = kwargs["domain"]
         del kwargs["domain"]
     if "is_admin" in kwargs:
         attrs = {"is_admin": kwargs["is_admin"]}
         del kwargs["is_admin"]
     else:
         attrs = {"is_admin": False}
     super(CommtrackUserForm, self).__init__(*args, **kwargs)
     self.fields["supply_point"].widget = SupplyPointSelectWidget(domain=domain, attrs=attrs)
     programs = Program.by_domain(domain, wrap=False)
     choices = list((prog["_id"], prog["name"]) for prog in programs)
     choices.insert(0, ("", ""))
     self.fields["program_id"].choices = choices
开发者ID:pawelreise,项目名称:commcare-hq,代码行数:18,代码来源:forms.py

示例13: test_program_fixture

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
    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 = self.generate_program_xml(program_list, user)

        fixture = program_fixture_generator(user, V1, None, None)

        self.assertXmlEqual(
            program_xml,
            ElementTree.tostring(fixture[0])
        )
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:19,代码来源:test_fixture.py

示例14: __init__

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
    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:kamilk161,项目名称:commcare-hq,代码行数:19,代码来源:forms.py

示例15: test_selective_program_sync

# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import by_domain [as 别名]
    def test_selective_program_sync(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 = self.generate_program_xml(program_list, user)

        fixture_original = program_fixture_generator(user, V1, None, None)

        generate_restore_payload(user.to_casexml_user())
        self.assertXmlEqual(
            program_xml,
            ElementTree.tostring(fixture_original[0])
        )

        first_sync = sorted(SyncLog.view(
            "phone/sync_logs_by_user",
            include_docs=True,
            reduce=False
        ).all(), key=lambda x: x.date)[-1]

        # make sure the time stamp on this first sync is
        # not on the same second that the programs were created
        first_sync.date += datetime.timedelta(seconds=1)

        # second sync is before any changes are made, so there should
        # be no programs synced
        fixture_pre_change = program_fixture_generator(user, V1, None, first_sync)
        generate_restore_payload(user.to_casexml_user())
        self.assertEqual(
            [],
            fixture_pre_change,
            "Fixture was not empty on second sync"
        )

        second_sync = sorted(SyncLog.view(
            "phone/sync_logs_by_user",
            include_docs=True,
            reduce=False
        ).all(), key=lambda x: x.date)[-1]

        self.assertTrue(first_sync._id != second_sync._id)

        # save should make the program more recently updated than the
        # last sync
        for program in program_list:
            program.save()

        # now that we've updated a program, we should get
        # program data in sync again
        fixture_post_change = program_fixture_generator(user, V1, None, second_sync)

        # regenerate the fixture xml to make sure it is still legit
        self.assertXmlEqual(
            program_xml,
            ElementTree.tostring(fixture_post_change[0])
        )
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:63,代码来源:test_fixture.py


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