コード例 #1
0
    def test_short_json(self):
        """Short JSON strings shouldn't get compressed, but should be
        invertible"""
        field = CompressedJSONField()
        to_store = field.get_prep_value({'a': 'dictionary'})
        self.assertEqual(to_store[:2], 'j$')
        self.assertIn('dictionary', to_store)

        from_store = field.to_python(to_store)
        self.assertEqual(from_store, {'a': 'dictionary'})
コード例 #2
0
    def test_long_json(self):
        """Long JSON objects _do_ get compressed, in addition to being
        invertible"""
        field = CompressedJSONField()
        value = {'key': 'value'*1000}
        to_store = field.get_prep_value(value)
        self.assertEqual(to_store[:4], 'jb6$')
        self.assertNotIn('value', to_store)     # because it's been compressed
        self.assertTrue(len(to_store) < 1000)

        from_store = field.to_python(to_store)
        self.assertEqual(from_store, value)
コード例 #3
0
class Migration(migrations.Migration):

    dependencies = [
        ('regcore', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='regulation',
            name='level',
            field=models.PositiveIntegerField(default=1,
                                              editable=False,
                                              db_index=True),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='regulation',
            name='lft',
            field=models.PositiveIntegerField(default=1,
                                              editable=False,
                                              db_index=True),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='regulation',
            name='parent',
            field=mptt.fields.TreeForeignKey(blank=True,
                                             to='regcore.Regulation',
                                             null=True,
                                             on_delete=models.SET_NULL),
        ),
        migrations.AddField(
            model_name='regulation',
            name='rght',
            field=models.PositiveIntegerField(default=1,
                                              editable=False,
                                              db_index=True),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='regulation',
            name='tree_id',
            field=models.PositiveIntegerField(default=1,
                                              editable=False,
                                              db_index=True),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name='regulation',
            name='id',
            field=models.TextField(serialize=False, primary_key=True),
        ),
        migrations.AlterField(
            model_name='regulation',
            name='children',
            field=CompressedJSONField(null=True, blank=True),
        ),
    ]
コード例 #4
0
class Diff(models.Model):
    label = models.SlugField(max_length=200)
    old_version = models.SlugField(max_length=20)
    new_version = models.SlugField(max_length=20)
    diff = CompressedJSONField()

    class Meta:
        index_together = (('label', 'old_version', 'new_version'), )
        unique_together = (('label', 'old_version', 'new_version'), )
コード例 #5
0
ファイル: models.py プロジェクト: adderall/regulations-core
class Layer(models.Model):
    version = models.SlugField(max_length=20)
    name = models.SlugField(max_length=20)
    label = models.SlugField(max_length=200)
    layer = CompressedJSONField()

    class Meta:
        index_together = (('version', 'name', 'label'), )
        unique_together = (('version', 'name', 'label'), )
コード例 #6
0
class Notice(models.Model):
    document_number = models.SlugField(max_length=20)
    cfr_part = models.SlugField(max_length=200)
    effective_on = models.DateField(null=True)
    fr_url = models.CharField(max_length=200)
    publication_date = models.DateField()
    notice = CompressedJSONField()

    class Meta:
        index_together = (('document_number', 'cfr_part'), )
        unique_together = (('document_number', 'cfr_part'), )
コード例 #7
0
ファイル: models.py プロジェクト: adderall/regulations-core
class Regulation(models.Model):
    version = models.SlugField(max_length=20)
    label_string = models.SlugField(max_length=200)
    text = models.TextField()
    title = models.TextField(blank=True)
    node_type = models.SlugField(max_length=10)
    children = CompressedJSONField()
    root = models.BooleanField(default=False, db_index=True)

    class Meta:
        index_together = (('version', 'label_string'), )
        unique_together = (('version', 'label_string'), )
コード例 #8
0
class Layer(models.Model):
    name = models.SlugField(max_length=20)
    layer = CompressedJSONField()
    doc_type = models.SlugField(max_length=20)
    # We allow doc_ids to contain slashes, which are particularly important
    # for CFR docs, which use the [version_id]/[reg_label_id] format. It might
    # make sense to split off a version identifier into a separate field in
    # the future, if we can't treat that doc_id as an opaque string
    doc_id = models.SlugField(max_length=250)

    class Meta:
        index_together = (('name', 'doc_type', 'doc_id'), )
        unique_together = index_together
コード例 #9
0
class Notice(models.Model):
    document_number = models.SlugField(max_length=20, primary_key=True)
    effective_on = models.DateField(null=True)
    fr_url = models.CharField(max_length=200, null=True)
    publication_date = models.DateField()
    notice = CompressedJSONField()