Beispiel #1
0
 def test_datafield(self):
     f = DataField(app_name='tests', model_name='month', field_name='id')
     self.assertEqual(f.values(), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))
     self.assertEqual(f.labels(), (u'January', u'February', u'March',
         u'April', u'May', u'June', u'July', u'August', u'September',
         u'October', u'November', u'December'))
     self.assertEqual(f.codes(), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
Beispiel #2
0
    def handle(self, field_label, model_label, **options):
        model = get_model(*model_label.split('.'))

        if model is None:
            raise CommandError(
                u'Not model named {0} was found'.format(model_label))

        toks = field_label.split('.')
        if len(toks) != 3:
            raise CommandError(
                u'{0} is not a valid field identifier. Use a '
                '"." delimited notation, e.g. "app.model.field"'.format(
                    field_label))

        # Not required to be persisted to the database..
        f = DataField(app_name=toks[0], model_name=toks[1], field_name=toks[2])

        if not f.field:
            raise CommandError(
                u'The field {0} could not be found.'.format(field_label))

        count = 0
        values = list(f.values())
        values.sort(key=coerce_float)

        for value in values:
            if value is None or value == '':
                continue
            label = non_alnum.sub(value, ' ').title()
            obj = model(label=label, value=value, order=count, code=count)
            obj.save()
            count += 1

        print(u'{0} distinct values loaded'.format(count))
Beispiel #3
0
    def handle(self, field_label, model_label, **options):
        model = get_model(*model_label.split('.'))

        if model is None:
            raise CommandError(u'Not model named {0} was found'.format(
                model_label))

        toks = field_label.split('.')
        if len(toks) != 3:
            raise CommandError(u'{0} is not a valid field identifier. Use a '
                               '"." delimited notation, e.g. "app.model.field"'
                               .format(field_label))

        # Not required to be persisted to the database..
        f = DataField(app_name=toks[0], model_name=toks[1], field_name=toks[2])

        if not f.field:
            raise CommandError(u'The field {0} could not be found.'.format(
                field_label))

        count = 0
        values = list(f.values())
        values.sort(key=coerce_float)

        for value in values:
            if value is None or value == '':
                continue
            label = non_alnum.sub(value, ' ').title()
            obj = model(label=label, value=value, order=count, code=count)
            obj.save()
            count += 1

        print(u'{0} distinct values loaded'.format(count))
Beispiel #4
0
 def test_datafield_properties(self):
     [RecordSet(name=u'Set {0}'.format(i)).save() for i in xrange(10)]
     f = DataField(app_name='tests', model_name='recordset',
                   field_name='id')
     self.assertEqual(list(f.values()), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
     self.assertEqual(list(f.labels()), ['Set 0', 'Set 1', 'Set 2', 'Set 3',
                                         'Set 4', 'Set 5', 'Set 6', 'Set 7',
                                         'Set 8', 'Set 9'])
Beispiel #5
0
 def test_datafield(self):
     f = DataField(app_name='tests', model_name='month', field_name='id')
     self.assertEqual(f.values(), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))
     self.assertEqual(f.labels(),
                      (u'January', u'February', u'March', u'April', u'May',
                       u'June', u'July', u'August', u'September',
                       u'October', u'November', u'December'))
     self.assertEqual(f.codes(), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
Beispiel #6
0
 def test_datafield_properties(self):
     [RecordSet(name=u'Set {0}'.format(i)).save() for i in xrange(10)]
     f = DataField(app_name='tests',
                   model_name='recordset',
                   field_name='id')
     self.assertEqual(list(f.values()), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
     self.assertEqual(list(f.labels()), [
         'Set 0', 'Set 1', 'Set 2', 'Set 3', 'Set 4', 'Set 5', 'Set 6',
         'Set 7', 'Set 8', 'Set 9'
     ])