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), ), ]
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'), )
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'), )
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'})
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'), )
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'), )
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)
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
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()