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


Python models.DataConcept类代码示例

本文整理汇总了Python中avocado.models.DataConcept的典型用法代码示例。如果您正苦于以下问题:Python DataConcept类的具体用法?Python DataConcept怎么用?Python DataConcept使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setUp

    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')
开发者ID:leipzig,项目名称:avocado,代码行数:31,代码来源:tests.py

示例2: test_published

    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)], [])
开发者ID:leipzig,项目名称:avocado,代码行数:34,代码来源:tests.py

示例3: setUp

    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"
        )
开发者ID:hassanNS,项目名称:avocado,代码行数:31,代码来源:tests.py

示例4: test_implicit_apply_distinct

    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(' ', ''))
开发者ID:chop-dbhi,项目名称:avocado,代码行数:33,代码来源:parsers.py

示例5: create_dataconcept_single

 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()
开发者ID:leipzig,项目名称:avocado,代码行数:8,代码来源:admin.py

示例6: setUp

    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()
开发者ID:aaron0browne,项目名称:avocado,代码行数:10,代码来源:parsers.py

示例7: setUp

    def setUp(self):
        super(ConceptResourceTestCase, 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')

        cat = DataCategory(name='Test', published=True, order=1.0)
        cat.save()

        c1 = DataConcept(name='Title', published=True, category=cat)
        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()

        # Not published
        c2 = DataConcept(name='Salary', category=cat)
        c2.save()
        DataConceptField(concept=c2, field=self.salary_field, order=1).save()
        DataConceptField(concept=c2, field=self.boss_field, order=2).save()

        c3 = DataConcept(name='Name', published=True, category=cat)
        c3.save()
        DataConceptField(concept=c3, field=self.name_field, order=1).save()

        self.c1 = c1
        self.c2 = c2
        self.c3 = c3
开发者ID:chop-dbhi,项目名称:serrano,代码行数:32,代码来源:concept.py

示例8: create_dataconcept_single

    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()
开发者ID:hassanNS,项目名称:avocado,代码行数:14,代码来源:admin.py

示例9: test_dataview_order_by

    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')
开发者ID:leipzig,项目名称:avocado,代码行数:14,代码来源:tests.py

示例10: setUp

    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()
开发者ID:awenocur,项目名称:serrano,代码行数:15,代码来源:concept.py

示例11: setUp

    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()
开发者ID:rv816,项目名称:serrano,代码行数:15,代码来源:tests.py

示例12: test_unique_keys

    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']))
开发者ID:hassanNS,项目名称:avocado,代码行数:16,代码来源:tests.py

示例13: setUp

    def setUp(self):
        management.call_command('avocado', 'init', 'tests', quiet=True)

        name_field = DataField.objects.get_by_natural_key(
            'tests', 'title', 'name')
        salary_field = DataField.objects.get_by_natural_key(
            'tests', 'title', 'salary')
        boss_field = DataField.objects.get_by_natural_key(
            'tests', 'title', 'boss')

        concept = DataConcept(name='Title')
        concept.save()

        DataConceptField(concept=concept, field=name_field, order=1).save()
        DataConceptField(concept=concept, field=salary_field, order=2).save()
        DataConceptField(concept=concept, field=boss_field, order=3).save()

        self.concept = concept
        self.values = ['CEO', 100000, True]
开发者ID:chop-dbhi,项目名称:avocado,代码行数:19,代码来源:tests.py

示例14: test_unique_keys

    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'])
开发者ID:chop-dbhi,项目名称:avocado,代码行数:19,代码来源:tests.py

示例15: test_view

    def test_view(self):
        salary_field = DataField.objects.get_by_natural_key('exporting', 'title', 'salary')
        salary_concept = DataConcept()
        salary_concept.save()
        DataConceptField(concept=salary_concept, field=salary_field, order=1).save()

        view = DataView(json={'ordering': [[salary_concept.pk, 'desc']]})
        query = view.apply(tree=models.Employee).raw()

        # Ick..
        exporter = export.CSVExporter(view)
        exporter.params.insert(0, (RawFormatter(keys=['pk']), 1))
        exporter.row_length += 1

        buff = exporter.write(query)
        buff.seek(0)

        lines = buff.read().splitlines()
        # Skip the header
        self.assertEqual([int(x) for x in lines[1:]], [2, 4, 6, 1, 3, 5])
开发者ID:aaron0browne,项目名称:avocado,代码行数:20,代码来源:tests.py


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