Esempio n. 1
0
    def _setup_collection_udfs(self):
        self.plotstew = make_collection_udf(self.instance, model='Plot',
                                            datatype=COLLECTION_UDF_DATATYPE)
        self.treestew = make_collection_udf(self.instance, model='Tree',
                                            datatype=COLLECTION_UDF_DATATYPE)

        set_write_permissions(self.instance, self.commander, 'Plot',
                              [self.plotstew.canonical_name])
        set_write_permissions(self.instance, self.commander, 'Tree',
                              [self.treestew.canonical_name])

        p1, _ = self.create_tree_and_plot(
            plotudfs={self.plotstew.name:
                      [{'action': 'water', 'date': "2013-08-06 00:00:00"},
                       {'action': 'prune', 'date': "2013-09-15 00:00:00"}]},
            treeudfs={self.treestew.name:
                      [{'action': 'water', 'date': "2013-05-15 00:00:00"},
                       {'action': 'water', 'date': None}]})

        p2, _ = self.create_tree_and_plot(
            plotudfs={self.plotstew.name: [
                {'action': 'water', 'date': "2014-11-26 00:00:00"}]},
            treeudfs={self.treestew.name: [
                {'action': 'prune', 'date': "2014-06-23 00:00:00"}]})

        p3, _ = self.create_tree_and_plot(
            plotudfs={self.plotstew.name: [
                {'action': 'water', 'date': "2015-08-05 00:00:00"},
                {'action': 'prune', 'date': "2015-04-13 00:00:00"}]},
            treeudfs={self.treestew.name:
                      [{'action': 'prune', 'date': "2013-06-19 00:00:00"},
                       {'action': 'water', 'date': None}]})

        return (p.pk for p in [p1, p2, p3])
Esempio n. 2
0
    def _setup_collection_udfs(self):
        self.plotstew = make_collection_udf(self.instance, model='Plot',
                                            datatype=COLLECTION_UDF_DATATYPE)
        self.treestew = make_collection_udf(self.instance, model='Tree',
                                            datatype=COLLECTION_UDF_DATATYPE)

        set_write_permissions(self.instance, self.commander, 'Plot',
                              [self.plotstew.canonical_name])
        set_write_permissions(self.instance, self.commander, 'Tree',
                              [self.treestew.canonical_name])

        p1, _ = self.create_tree_and_plot(
            plotudfs={self.plotstew.name:
                      [{'action': 'water', 'date': "2013-08-06 00:00:00"},
                       {'action': 'prune', 'date': "2013-09-15 00:00:00"}]},
            treeudfs={self.treestew.name:
                      [{'action': 'water', 'date': "2013-05-15 00:00:00"},
                       {'action': 'water', 'date': None}]})

        p2, _ = self.create_tree_and_plot(
            plotudfs={self.plotstew.name: [
                {'action': 'water', 'date': "2014-11-26 00:00:00"}]},
            treeudfs={self.treestew.name: [
                {'action': 'prune', 'date': "2014-06-23 00:00:00"}]})

        p3, _ = self.create_tree_and_plot(
            plotudfs={self.plotstew.name: [
                {'action': 'water', 'date': "2015-08-05 00:00:00"},
                {'action': 'prune', 'date': "2015-04-13 00:00:00"}]},
            treeudfs={self.treestew.name:
                      [{'action': 'prune', 'date': "2013-06-19 00:00:00"},
                       {'action': 'water', 'date': None}]})

        return (p.pk for p in [p1, p2, p3])
Esempio n. 3
0
    def setUp(self):
        self.instance = make_instance()
        datatype = [
            {'type': 'choice', 'choices': ['love', 'hug'], 'name': 'action'},
            {'type': 'int', 'name': 'times'},
            {'type': 'date', 'name': 'day'},
        ]
        create_stewardship_udfs(self.instance)
        make_collection_udf(self.instance, model='Plot', name='Caring',
                            datatype=datatype)
        make_collection_udf(self.instance, model='Tree', name='Caring',
                            datatype=datatype)

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({'type': 'string'}),
            iscollection=False,
            name='Name')

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Tree',
            datatype=json.dumps({'type': 'int'}),
            iscollection=False,
            name='Man Units')
Esempio n. 4
0
def _setup_collection_udfs(instance, user):
    plotstew = make_collection_udf(instance, model='Plot',
                                   datatype=COLLECTION_UDF_DATATYPE)
    treestew = make_collection_udf(instance, model='Tree',
                                   datatype=COLLECTION_UDF_DATATYPE)

    set_write_permissions(instance, user, 'Plot', [plotstew.canonical_name])
    set_write_permissions(instance, user, 'Tree', [treestew.canonical_name])

    return plotstew, treestew
Esempio n. 5
0
def _setup_collection_udfs(instance, user):
    plotstew = make_collection_udf(instance,
                                   model='Plot',
                                   datatype=COLLECTION_UDF_DATATYPE)
    treestew = make_collection_udf(instance,
                                   model='Tree',
                                   datatype=COLLECTION_UDF_DATATYPE)

    set_write_permissions(instance, user, 'Plot', [plotstew.canonical_name])
    set_write_permissions(instance, user, 'Tree', [treestew.canonical_name])

    return plotstew, treestew
Esempio n. 6
0
    def setUp(self):
        self.instance = make_instance()
        datatype = [
            {
                'type': 'choice',
                'choices': ['love', 'hug'],
                'name': 'action'
            },
            {
                'type': 'int',
                'name': 'times'
            },
            {
                'type': 'date',
                'name': 'day'
            },
        ]
        create_stewardship_udfs(self.instance)
        make_collection_udf(self.instance,
                            model='Plot',
                            name='Caring',
                            datatype=datatype)
        make_collection_udf(self.instance,
                            model='Tree',
                            name='Caring',
                            datatype=datatype)

        UserDefinedFieldDefinition.objects.create(instance=self.instance,
                                                  model_type='Plot',
                                                  datatype=json.dumps(
                                                      {'type': 'string'}),
                                                  iscollection=False,
                                                  name='Name')

        UserDefinedFieldDefinition.objects.create(instance=self.instance,
                                                  model_type='Tree',
                                                  datatype=json.dumps(
                                                      {'type': 'int'}),
                                                  iscollection=False,
                                                  name='Man Units')
Esempio n. 7
0
    def _setup_tree_and_collection_udf(self):
        instance = make_instance()

        self.plotstew = make_collection_udf(instance, model='Plot',
                                            datatype=COLLECTION_UDF_DATATYPE)
        self.treestew = make_collection_udf(instance, model='Tree',
                                            datatype=COLLECTION_UDF_DATATYPE)

        commander = make_commander_user(instance)
        set_write_permissions(instance, commander, 'Plot', ['udf:Stewardship'])
        set_write_permissions(instance, commander, 'Tree', ['udf:Stewardship'])

        d1 = {'action': 'prune', 'date': "2014-05-3 00:00:00"}
        d2 = {'action': 'water', 'date': "2014-04-29 00:00:00"}

        self.plot = Plot(instance=instance, geom=instance.center)
        self.plot.udfs[self.plotstew.name] = [d1]
        self.plot.save_with_user(commander)

        self.tree = Tree(instance=instance, plot=self.plot)
        self.tree.udfs[self.treestew.name] = [d2]
        self.tree.save_with_user(commander)
Esempio n. 8
0
    def _setup_tree_and_collection_udf(self):
        instance = make_instance()

        self.plotstew = make_collection_udf(instance, model='Plot',
                                            datatype=COLLECTION_UDF_DATATYPE)
        self.treestew = make_collection_udf(instance, model='Tree',
                                            datatype=COLLECTION_UDF_DATATYPE)

        commander = make_commander_user(instance)
        set_write_permissions(instance, commander, 'Plot', ['udf:Stewardship'])
        set_write_permissions(instance, commander, 'Tree', ['udf:Stewardship'])

        d1 = {'action': 'prune', 'date': "2014-05-3 00:00:00"}
        d2 = {'action': 'water', 'date': "2014-04-29 00:00:00"}

        self.plot = Plot(instance=instance, geom=instance.center)
        self.plot.udfs[self.plotstew.name] = [d1]
        self.plot.save_with_user(commander)

        self.tree = Tree(instance=instance, plot=self.plot)
        self.tree.udfs[self.treestew.name] = [d2]
        self.tree.save_with_user(commander)
Esempio n. 9
0
    def test_parse_collection_udf_nested_pass_numeric_comparison(self):
        self._setup_tree_and_collection_udf()
        agility = make_collection_udf(self.instance, model='Tree',
                                      name='Agility',
                                      datatype=[{'type': 'float',
                                                 'name': 'current'}])
        set_write_permissions(self.instance, self.commander,
                              'Tree', ['udf:Agility'])
        new_tree = Tree(instance=self.instance, plot=self.plot)
        new_tree.udfs[agility.name] = [{'current': '1.5'}]
        new_tree.save_with_user(self.commander)

        pred = search._parse_query_dict(
            {'udf:tree:%s.current' % agility.pk: {'MIN': 1}},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__id__in', (new_tree.pk,))})

        self.assertEqual(destructure_query_set(pred), target)
Esempio n. 10
0
    def test_parse_collection_udf_nested_pass_numeric_comparison(self):
        self._setup_tree_and_collection_udf()
        agility = make_collection_udf(self.instance,
                                      model='Tree',
                                      name='Agility',
                                      datatype=[{
                                          'type': 'float',
                                          'name': 'current'
                                      }])
        set_write_permissions(self.instance, self.commander, 'Tree',
                              ['udf:Agility'])
        new_tree = Tree(instance=self.instance, plot=self.plot)
        new_tree.udfs[agility.name] = [{'current': '1.5'}]
        new_tree.save_with_user(self.commander)

        pred = search._parse_predicate(
            {'udf:tree:%s.current' % agility.pk: {
                'MIN': 1
            }},
            mapping=search.DEFAULT_MAPPING)

        target = ('AND', {('tree__id__in', (new_tree.pk, ))})

        self.assertEqual(self.destructure_query_set(pred), target)