本文整理汇总了Python中avocado.models.DataConcept.category方法的典型用法代码示例。如果您正苦于以下问题:Python DataConcept.category方法的具体用法?Python DataConcept.category怎么用?Python DataConcept.category使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类avocado.models.DataConcept
的用法示例。
在下文中一共展示了DataConcept.category方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_published
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import category [as 别名]
def test_published(self):
concept = DataConcept(published=True)
concept.save()
DataConceptField(concept=concept, field=self.is_manager).save()
DataConceptField(concept=concept, field=self.salary).save()
self.assertEqual([x.pk for x in DataConcept.objects.published()], [])
self.is_manager.published = True
self.is_manager.save()
self.salary.published = True
self.salary.save()
# Now published, it will appear
self.assertEqual([x.pk for x in DataConcept.objects.published()],
[concept.pk])
# Set the category to be an unpublished category and it should no
# longer appear.
concept.category = self.category
concept.save()
self.assertEqual([x.pk for x in DataConcept.objects.published()], [])
# Publish the category and the concept should appear again
self.category.published = True
self.category.save()
self.assertEqual([x.pk for x in DataConcept.objects.published()],
[concept.pk])
user1 = User.objects.create_user('user1', 'user1')
# Nothing since user1 cannot view either datafield
self.assertEqual(
[x.pk for x in DataConcept.objects.published(user1)], [])
assign('avocado.view_datafield', user1, self.is_manager)
# Still nothing since user1 has no permission for salary
self.assertEqual(
[x.pk for x in DataConcept.objects.published(user1)], [])
assign('avocado.view_datafield', user1, self.salary)
# Now user1 can see the concept
self.assertEqual([x.pk for x in DataConcept.objects.published(user1)],
[concept.pk])
user2 = User.objects.create_user('user2', 'user2')
# `user2` is not assigned
self.assertEqual(
[x.pk for x in DataConcept.objects.published(user2)], [])
# Remove the fields from the concept and it should no longer appear
# as published.
DataConceptField.objects.filter(concept=concept).delete()
self.assertEqual([x.pk for x in DataConcept.objects.published()], [])
示例2: _migrate_concept
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import category [as 别名]
def _migrate_concept(self, model, migrate_func, **options):
no_input = options.get('no_input')
total_migrated = 0
for lc in model.objects.iterator():
field_nks = list(lc.fields.values('app_name', 'model_name',
'field_name').distinct())
field_cond = Q()
for f in field_nks:
field_cond = field_cond | Q(**f)
fields = DataField.objects.filter(field_cond).distinct()
# Mismatch of fields from new to old
if len(fields) != len(field_nks):
print('One or more fields mismatched for "{0}". '
'Skipping...'.format(lc))
continue
matches = DataConcept.objects.filter(name=lc.name)
# Filter concepts by existence of fields
for f in fields:
matches = matches.filter(fields__app_name=f.app_name,
fields__model_name=f.model_name,
fields__field_name=f.field_name)
num = len(matches)
if num > 1:
print('{0} have the same name and fields. '
'Skipping...'.format(num))
continue
if num == 1:
c = matches[0]
existing = True
if not no_input:
override = True
while True:
response = raw_input(u'Match found for "{0}". '
'Override? [n/Y] '.format(c))
if not response:
break
if response.lower() == 'n':
override = False
break
if not override:
continue
else:
c = DataConcept(queryable=False, viewable=False)
existing = False
c.name = lc.name
c.order = lc.order
c.published = lc.is_public
# This looks odd, but this handles choosing the longer of the two
# descriptions for criterion and column if both exist.
if not c.description or lc.description and \
len(lc.description) > len(c.description):
c.description = lc.description
if lc.category:
try:
kwargs = {
'name__iexact': lc.category.name,
}
# Filter by parent if one exists since categories with the
# same name can exists as sub-categories.
if lc.category.parent_id:
kwargs['parent__name'] = lc.category.parent.name
c.category = DataCategory.objects.get(**kwargs)
except DataCategory.DoesNotExist:
pass
# Apply migration specific function to concept from legacy concept
migrate_func(c, lc)
# Save for foreign key references to concept fields
c.save()
cfs = []
if not existing:
lcfs = list(lc.conceptfields.select_related('field'))
# Dict of legacy concept fields to the new field it
# corresponds to
lcf_map = {}
for lcf in lcfs:
for f in fields:
# Match and break
if lcf.field.natural_key() == f.natural_key():
lcf_map[lcf.pk] = f
break
#.........这里部分代码省略.........