本文整理汇总了Python中corehq.apps.commtrack.models.Program.default_for_domain方法的典型用法代码示例。如果您正苦于以下问题:Python Program.default_for_domain方法的具体用法?Python Program.default_for_domain怎么用?Python Program.default_for_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.commtrack.models.Program
的用法示例。
在下文中一共展示了Program.default_for_domain方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import default_for_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)
示例2: get_or_create_default_program
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import default_for_domain [as 别名]
def get_or_create_default_program(domain):
program = Program.default_for_domain(domain)
if program:
return program
else:
return make_program(
domain,
_('Uncategorized'),
_('uncategorized'),
default=True
)
示例3: __init__
# 需要导入模块: from corehq.apps.commtrack.models import Program [as 别名]
# 或者: from corehq.apps.commtrack.models.Program import default_for_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