本文整理汇总了Python中avocado.models.DataConcept.save方法的典型用法代码示例。如果您正苦于以下问题:Python DataConcept.save方法的具体用法?Python DataConcept.save怎么用?Python DataConcept.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类avocado.models.DataConcept
的用法示例。
在下文中一共展示了DataConcept.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def setUp(self):
management.call_command('avocado', 'sync', 'export', quiet=True)
first_name_field = DataField.objects.get_by_natural_key('export', 'employee', 'first_name')
first_name_field.description = 'First Name'
last_name_field = DataField.objects.get_by_natural_key('export', 'employee', 'last_name')
last_name_field.description = 'Last Name'
title_field = DataField.objects.get_by_natural_key('export', 'title', 'name')
title_field.description = 'Employee Title'
salary_field = DataField.objects.get_by_natural_key('export', 'title', 'salary')
salary_field.description = 'Salary'
is_manager_field = DataField.objects.get_by_natural_key('export', 'employee', 'is_manager')
is_manager_field.description = 'Is a Manager?'
[x.save() for x in [first_name_field, last_name_field, title_field,
salary_field, is_manager_field]]
employee_concept = DataConcept()
employee_concept.name = 'Employee'
employee_concept.description = 'A Single Employee'
employee_concept.save()
DataConceptField(concept=employee_concept, field=first_name_field, order=1).save()
DataConceptField(concept=employee_concept, field=last_name_field, order=2).save()
DataConceptField(concept=employee_concept, field=is_manager_field, order=3).save()
DataConceptField(concept=employee_concept, field=title_field, order=4).save()
DataConceptField(concept=employee_concept, field=salary_field, order=5).save()
self.concepts = [employee_concept]
self.query = models.Employee.objects.values_list('first_name', 'last_name',
'is_manager', 'title__name', 'title__salary')
示例2: test_field_for_concept
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def test_field_for_concept(self):
f = DataField.objects.get(model_name='title', field_name='name')
c1 = DataConcept()
c2 = DataConcept()
c1.save()
c2.save()
cf = DataConceptField(concept=c1, field=f)
cf.save()
attrs = {
'concept': c1.pk,
'field': f.pk,
'operator': 'exact',
'value': 'CEO',
'cleaned_value': {'value': 'CEO', 'label': 'CEO'},
'language': 'Name is CEO'
}
self.assertEqual(
parsers.datacontext.validate(deepcopy(attrs), tree=Employee),
attrs)
# Invalid concept
attrs = parsers.datacontext.validate({
'concept': c2.pk,
'field': f.pk,
'operator': 'exact',
'value': 'CEO',
}, tree=Employee)
self.assertFalse(attrs['enabled'])
示例3: test_get_all_unrelated
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def test_get_all_unrelated(self):
# Publish unrelated field and concept
f = DataField.objects.get(model_name='unrelated')
f.published = True
f.save()
c = DataConcept(name='Unrelated', published=True)
c.save()
DataConceptField(concept=c, field=f, order=1).save()
# Concept from two unrelated fields.. this will never show.
# TODO don't allow this
c = DataConcept(name='Unrelated', published=True)
c.save()
DataConceptField(concept=c, field=f, order=1).save()
DataConceptField(concept=c, field=self.boss_field, order=2).save()
# Still 2 concepts visible by default tree
response = self.client.get('/api/concepts/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 2)
# 1 concept visible for unrelated tree
response = self.client.get('/api/concepts/?tree=unrelated',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 1)
示例4: test_published
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [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()
# Published, not specific to any user
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()], [1])
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)], [1])
user2 = User.objects.create_user('user2', 'user2')
# `user2` is not assigned
self.assertEqual([x.pk for x in DataConcept.objects.published(user2)], [])
示例5: setUp
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def setUp(self):
management.call_command("avocado", "init", "tests", quiet=True)
first_name_field = DataField.objects.get_by_natural_key("tests", "employee", "first_name")
first_name_field.description = "First Name"
last_name_field = DataField.objects.get_by_natural_key("tests", "employee", "last_name")
last_name_field.description = "Last Name"
title_field = DataField.objects.get_by_natural_key("tests", "title", "name")
title_field.description = "Employee Title"
salary_field = DataField.objects.get_by_natural_key("tests", "title", "salary")
salary_field.description = "Salary"
is_manager_field = DataField.objects.get_by_natural_key("tests", "employee", "is_manager")
is_manager_field.description = "Is a Manager?"
[x.save() for x in [first_name_field, last_name_field, title_field, salary_field, is_manager_field]]
employee_concept = DataConcept()
employee_concept.name = "Employee"
employee_concept.description = "A Single Employee"
employee_concept.save()
DataConceptField(concept=employee_concept, field=first_name_field, order=1).save()
DataConceptField(concept=employee_concept, field=last_name_field, order=2).save()
DataConceptField(concept=employee_concept, field=is_manager_field, order=3).save()
DataConceptField(concept=employee_concept, field=title_field, order=4).save()
DataConceptField(concept=employee_concept, field=salary_field, order=5).save()
self.concepts = [employee_concept]
self.query = models.Employee.objects.values_list(
"first_name", "last_name", "is_manager", "title__name", "title__salary"
)
示例6: test_implicit_apply_distinct
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def test_implicit_apply_distinct(self):
f1 = DataField.objects.get_by_natural_key('tests',
'office',
'location')
f2 = DataField.objects.get_by_natural_key('tests',
'title',
'name')
c = DataConcept()
c.save()
DataConceptField(concept=c, field=f1).save()
DataConceptField(concept=c, field=f2).save()
# Due to the use of distinct, the concept fields appear in the SELECT
# statement at this point. This is not a bug, but a requirement of SQL.
# These columns are stripped downstream by the exporter.
node = parsers.dataview.parse([{
'concept': c.pk,
'sort': 'desc',
'visible': False,
}], tree=Employee)
self.assertEqual(
unicode(node.apply(Employee.objects.distinct()).query)
.replace(' ', ''),
'SELECT DISTINCT "tests_employee"."id", '
'"tests_office"."location", "tests_title"."name" FROM '
'"tests_employee" INNER JOIN "tests_office" ON '
'("tests_employee"."office_id" = "tests_office"."id") LEFT OUTER '
'JOIN "tests_title" ON ("tests_employee"."title_id" = '
'"tests_title"."id") ORDER BY "tests_office"."location" DESC, '
'"tests_title"."name" DESC'
.replace(' ', ''))
示例7: create_dataconcept_single
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def create_dataconcept_single(self, request, queryset):
fields = list(queryset)
max_length = DataConcept._meta.get_field_by_name('name')[0].max_length
name = ', '.join([f.name for f in fields])[:max_length - 5] + '...'
concept = DataConcept(name='"{0}"'.format(name))
concept.save()
for i, datafield in enumerate(queryset):
DataConceptField(concept=concept, field=datafield, order=i).save()
示例8: setUp
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def setUp(self):
management.call_command('avocado', 'init', 'query', quiet=True)
f1 = DataField.objects.get(pk=1)
f2 = DataField.objects.get(pk=2)
c1 = DataConcept()
c1.save()
DataConceptField(concept=c1, field=f1).save()
DataConceptField(concept=c1, field=f2).save()
示例9: test_published
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [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()], [])
示例10: test_dataview_order_by
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def test_dataview_order_by(self):
f = DataField(app_name='lexicon', model_name='month', field_name='id')
f.save()
c = DataConcept()
c.save()
cf = DataConceptField(field=f, concept=c)
cf.save()
v = DataView({'ordering': [c.pk]})
qs = Month.objects.filter(label__startswith='J').values('id')
self.assertEqual(str(v.apply(qs).query), 'SELECT "lexicon_month"."id" FROM "lexicon_month" WHERE "lexicon_month"."label" LIKE J% ESCAPE \'\\\' ORDER BY "lexicon_month"."order" ASC')
示例11: create_dataconcept_single
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def create_dataconcept_single(self, request, queryset):
fields = list(queryset)
# If only a single field is selected with this action, directly map
if len(fields) == 1:
DataConcept.objects.create_from_field(fields[0])
return
max_length = DataConcept._meta.get_field_by_name("name")[0].max_length
name = ", ".join([f.name for f in fields])[: max_length - 5] + "..."
concept = DataConcept(name=u'"{0}"'.format(name))
concept.save()
for i, datafield in enumerate(queryset):
DataConceptField(concept=concept, field=datafield, order=i).save()
示例12: setUp
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def setUp(self):
management.call_command('avocado', 'init', 'tests', quiet=True)
f1 = DataField.objects.get(pk=1)
f2 = DataField.objects.get(pk=2)
c1 = DataConcept()
c1.save()
DataConceptField(concept=c1, field=f1).save()
DataConceptField(concept=c1, field=f2).save()
self.request = HttpRequest()
self.request.session = SessionStore()
self.request.session.save()
示例13: setUp
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def setUp(self):
super(ConceptFieldResourceTestCase, self).setUp()
self.name_field = DataField.objects.get_by_natural_key(
'tests', 'title', 'name')
self.salary_field = DataField.objects.get_by_natural_key(
'tests', 'title', 'salary')
self.boss_field = DataField.objects.get_by_natural_key(
'tests', 'title', 'boss')
c1 = DataConcept(name='Title', published=True)
c1.save()
DataConceptField(concept=c1, field=self.name_field, order=1).save()
DataConceptField(concept=c1, field=self.salary_field, order=2).save()
DataConceptField(concept=c1, field=self.boss_field, order=3).save()
示例14: test_unique_keys
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def test_unique_keys(self):
title_name = DataField.objects.get_by_natural_key('tests', 'title', 'name')
project_name = DataField.objects.get_by_natural_key('tests', 'project', 'name')
concept = DataConcept()
concept.save()
DataConceptField(concept=concept, field=title_name, order=1).save()
DataConceptField(concept=concept, field=project_name, order=2).save()
f = Formatter(concept)
self.assertEqual(OrderedDict([
('title__name', 'one'),
('project__name', 'two'),
]), f(['one', 'two']))
示例15: test_unique_keys
# 需要导入模块: from avocado.models import DataConcept [as 别名]
# 或者: from avocado.models.DataConcept import save [as 别名]
def test_unique_keys(self):
title_name = DataField.objects.get_by_natural_key(
'tests', 'title', 'name')
project_name = DataField.objects.get_by_natural_key(
'tests', 'project', 'name')
concept = DataConcept()
concept.save()
DataConceptField(concept=concept, field=title_name, order=1).save()
DataConceptField(concept=concept, field=project_name, order=2).save()
f = Formatter(concept=concept)
meta = f.get_meta()
names = [x['name'] for x in meta['header']]
self.assertEqual(names, ['title__name', 'project__name'])