Skip to content

Commit

Permalink
Merge pull request #5221 from specify/issue-5175
Browse files Browse the repository at this point in the history
Respect naming convention for new geo tables
  • Loading branch information
CarolineDenis authored Aug 14, 2024
2 parents 3850165 + 530fbe9 commit 1419cd7
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion specifyweb/businessrules/rules/cogtype_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from specifyweb.businessrules.orm_signal_handler import orm_signal_handler
from specifyweb.specify.models import Picklist, Picklistitem

@orm_signal_handler('pre_save', 'CollectionObjectGroupType')
@orm_signal_handler('pre_save', 'Collectionobjectgrouptype')
def cogtype_pre_save(cog_type):

# Ensure the cog_type type is validated by being the picklist.
Expand Down
8 changes: 4 additions & 4 deletions specifyweb/businessrules/rules/cojo_rules.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from specifyweb.businessrules.exceptions import BusinessRuleException
from specifyweb.businessrules.orm_signal_handler import orm_signal_handler
from specifyweb.specify.models import CollectionObjectGroupJoin
from specifyweb.specify.models import Collectionobjectgroupjoin

@orm_signal_handler('pre_save', 'CollectionObjectGroupJoin')
@orm_signal_handler('pre_save', 'Collectionobjectgroupjoin')
def cojo_pre_save(cojo):
# Ensure the both the childcog and childco fields are not null.
if cojo.childcog == None and cojo.childco == None:
Expand All @@ -16,12 +16,12 @@ def cojo_pre_save(cojo):
# So when a record is saved with isPrimary set to True, we need to set all other records with the same parentcog
# to isPrimary = False.
if cojo.isprimary == True:
(CollectionObjectGroupJoin.objects
(Collectionobjectgroupjoin.objects
.filter(parentcog=cojo.parentcog)
.update(isprimary=False))

if cojo.issubstrate == True:
(CollectionObjectGroupJoin.objects
(Collectionobjectgroupjoin.objects
.filter(parentcog=cojo.parentcog)
.update(issubstrate=False))

6 changes: 3 additions & 3 deletions specifyweb/businessrules/tests/test_cog_type.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from specifyweb.businessrules.exceptions import BusinessRuleException
from specifyweb.specify.models import CollectionObjectGroupType, Picklist, Picklistitem
from specifyweb.specify.models import Collectionobjectgrouptype, Picklist, Picklistitem
from specifyweb.specify.tests.test_api import DefaultsSetup
from django.db import transaction

# NOTE: Edit this test when a new COG type rule is decided upon.
class COGTypeTest(DefaultsSetup):
def test_cog_type_select_values(self):
CollectionObjectGroupType.objects.create(name='microscope slide', type='Discrete', collection=self.collection)
Collectionobjectgrouptype.objects.create(name='microscope slide', type='Discrete', collection=self.collection)

with self.assertRaises(BusinessRuleException), transaction.atomic():
CollectionObjectGroupType.objects.create(name='whole rock', type='Burrito', collection=self.collection)
Collectionobjectgrouptype.objects.create(name='whole rock', type='Burrito', collection=self.collection)

28 changes: 14 additions & 14 deletions specifyweb/businessrules/tests/test_cojo.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
from specifyweb.specify.models import CollectionObjectGroup, CollectionObjectGroupJoin, CollectionObjectGroupType, Picklist, Picklistitem
from specifyweb.specify.models import Collectionobjectgroup, Collectionobjectgroupjoin, Collectionobjectgrouptype, Picklist, Picklistitem
from specifyweb.specify.tests.test_api import DefaultsSetup

class CoJoTest(DefaultsSetup):
def test_cojo_rules_enforcement(self):
cog_type = CollectionObjectGroupType.objects.create(name='microscope slide', type='Discrete', collection=self.collection)
cog_1 = CollectionObjectGroup.objects.create(
cog_type = Collectionobjectgrouptype.objects.create(name='microscope slide', type='Discrete', collection=self.collection)
cog_1 = Collectionobjectgroup.objects.create(
collection=self.collection,
cogtype=cog_type
)
cog_2 = CollectionObjectGroup.objects.create(
cog_2 = Collectionobjectgroup.objects.create(
collection=self.collection,
cogtype=cog_type
)
cog_3 = CollectionObjectGroup.objects.create(
cog_3 = Collectionobjectgroup.objects.create(
collection=self.collection,
cogtype=cog_type
)
cojo_1 = CollectionObjectGroupJoin.objects.create(
cojo_1 = Collectionobjectgroupjoin.objects.create(
parentcog=cog_1,
childcog=cog_2,
isprimary=True,
issubstrate=True
)
cojo_2 = CollectionObjectGroupJoin.objects.create(
cojo_2 = Collectionobjectgroupjoin.objects.create(
parentcog=cog_1,
childcog=cog_3,
isprimary=True,
issubstrate=True
)

cojo_1 = CollectionObjectGroupJoin.objects.get(id=cojo_1.id)
cojo_2 = CollectionObjectGroupJoin.objects.get(id=cojo_2.id)
cojo_1 = Collectionobjectgroupjoin.objects.get(id=cojo_1.id)
cojo_2 = Collectionobjectgroupjoin.objects.get(id=cojo_2.id)

self.assertFalse(cojo_1.isprimary)
self.assertFalse(cojo_1.issubstrate)
self.assertTrue(cojo_2.isprimary)
self.assertTrue(cojo_2.issubstrate)

cog_4 = CollectionObjectGroup.objects.create(
cog_4 = Collectionobjectgroup.objects.create(
collection=self.collection,
cogtype=cog_type
)
cojo_3 = CollectionObjectGroupJoin.objects.create(
cojo_3 = Collectionobjectgroupjoin.objects.create(
parentcog=cog_1,
childcog=cog_4,
isprimary=False,
issubstrate=False
)

cojo_1 = CollectionObjectGroupJoin.objects.get(id=cojo_1.id)
cojo_2 = CollectionObjectGroupJoin.objects.get(id=cojo_2.id)
cojo_3 = CollectionObjectGroupJoin.objects.get(id=cojo_3.id)
cojo_1 = Collectionobjectgroupjoin.objects.get(id=cojo_1.id)
cojo_2 = Collectionobjectgroupjoin.objects.get(id=cojo_2.id)
cojo_3 = Collectionobjectgroupjoin.objects.get(id=cojo_3.id)

self.assertFalse(cojo_1.isprimary)
self.assertFalse(cojo_1.issubstrate)
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/businessrules/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def test_collection_objects_block_delete(self):
with self.assertRaises(ProtectedError):
self.collection.delete()

models.CollectionObjectType.objects.filter(collection=self.collection).delete()
models.Collectionobjecttype.objects.filter(collection=self.collection).delete()
models.Collectionobject.objects.filter(collection=self.collection).delete()
self.collection.delete()
4 changes: 2 additions & 2 deletions specifyweb/businessrules/tests/test_collectionobject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from specifyweb.specify.models import Collection, Collectionobject, CollectionObjectType
from specifyweb.specify.models import Collection, Collectionobject, Collectionobjecttype
from specifyweb.specify.tests.test_api import ApiTests
from ..exceptions import BusinessRuleException

Expand All @@ -15,7 +15,7 @@ def test_catalog_number_unique_in_collection(self):
catalognumber=self.collectionobjects[0].catalognumber + 'foo')

def test_default_collectionobjecttype(self):
default_type = CollectionObjectType.objects.create(
default_type = Collectionobjecttype.objects.create(
name="default type",
collection=self.collection,
taxontreedef=self.discipline.taxontreedef
Expand Down
4 changes: 2 additions & 2 deletions specifyweb/specify/calculated_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Loan,
Deaccession,
Accession,
CollectionObjectGroupJoin,
Collectionobjectgroupjoin,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -104,7 +104,7 @@ def calculate_extra_fields(obj, data: Dict[str, Any]) -> Dict[str, Any]:
(det["resource_uri"] for det in dets if det["iscurrent"]), None
)

extra["isMemberOfCOG"] = CollectionObjectGroupJoin.objects.filter(childco=obj).exists()
extra["isMemberOfCOG"] = Collectionobjectgroupjoin.objects.filter(childco=obj).exists()

elif isinstance(obj, Loan):
preps = data["loanpreparations"]
Expand Down
32 changes: 16 additions & 16 deletions specifyweb/specify/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8234,8 +8234,8 @@
fields=[
Field(name='name', column='Name', indexed=False, unique=False, required=True, type='java.lang.String', length=255),
Field(name='version', column='Version', indexed=False, unique=False, required=False, type='java.lang.Integer'),
Field(name='timestampcreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampmodified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
Field(name='timestampCreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampModified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
Field(name='text1', column='Text1', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='text2', column='Text2', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='text3', column='Text3', indexed=False, unique=False, required=False, type='java.lang.String', length=255)
Expand Down Expand Up @@ -8268,8 +8268,8 @@
Field(name='igsn', column='IGSN', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='guid', column='GUID', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='version', column='Version', indexed=False, unique=False, required=False, type='java.lang.Integer'),
Field(name='timestampcreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampmodified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
Field(name='timestampCreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampModified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
Field(name='text1', column='Text1', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='text2', column='Text2', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='text3', column='Text3', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Expand All @@ -8288,9 +8288,9 @@
],
relationships=[
Relationship(name='collection', type='many-to-one', required=False, relatedModelName='Collection', column='CollectionID'),
Relationship(name='cogtype', type='many-to-one', required=True, relatedModelName='CollectionObjectGroupType', column='COGTypeID'),
Relationship(name='parentcojos', type='one-to-many', required=False, relatedModelName='CollectionObjectGroupJoin', otherSideName='parentcog', dependent=True),
Relationship(name='cojo', type='one-to-many', required=False, relatedModelName='CollectionObjectGroupJoin', otherSideName='childcog', dependent=True),
Relationship(name='cogType', type='many-to-one', required=True, relatedModelName='CollectionObjectGroupType', column='COGTypeID'),
Relationship(name='parentCojos', type='one-to-many', required=False, relatedModelName='CollectionObjectGroupJoin', otherSideName='parentCog', dependent=True),
Relationship(name='cojo', type='one-to-many', required=False, relatedModelName='CollectionObjectGroupJoin', otherSideName='childCog', dependent=True),
Relationship(name='createdByAgent', type='many-to-one', required=False, relatedModelName='Agent', column='CreatedByAgentID'),
Relationship(name='modifiedByAgent', type='many-to-one', required=False, relatedModelName='Agent', column='ModifiedByAgentID'),
],
Expand All @@ -8308,12 +8308,12 @@
idFieldName='collectionObjectGroupJoinId',
idField=IdField(name='collectionObjectGroupJoinId', column='CollectionObjectGroupJoinID', type='java.lang.Integer'),
fields=[
Field(name='isprimary', column='IsPrimary', indexed=False, unique=False, required=True, type='java.lang.Boolean'),
Field(name='issubstrate', column='IsSubstrate', indexed=False, unique=False, required=True, type='java.lang.Boolean'),
Field(name='isPrimary', column='IsPrimary', indexed=False, unique=False, required=True, type='java.lang.Boolean'),
Field(name='isSubstrate', column='IsSubstrate', indexed=False, unique=False, required=True, type='java.lang.Boolean'),
Field(name='precedence', column='Precedence', indexed=False, unique=False, required=True, type='java.lang.Integer'),
Field(name='version', column='Version', indexed=False, unique=False, required=False, type='java.lang.Integer'),
Field(name='timestampcreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampmodified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
Field(name='timestampCreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampModified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
Field(name='text1', column='Text1', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='text2', column='Text2', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Field(name='text3', column='Text3', indexed=False, unique=False, required=False, type='java.lang.String', length=255),
Expand All @@ -8328,9 +8328,9 @@

],
relationships=[
Relationship(name='parentcog', type='many-to-one', required=True, relatedModelName='CollectionObjectGroup', column='ParentCOGID', otherSideName='parentcojos'),
Relationship(name='childcog', type='one-to-one', required=False, relatedModelName='CollectionObjectGroup', column='ChildCOGID', otherSideName='cojo'),
Relationship(name='childco', type='one-to-one', required=False, relatedModelName='CollectionObject', column='ChildCOID', otherSideName='cojo'),
Relationship(name='parentCog', type='many-to-one', required=True, relatedModelName='CollectionObjectGroup', column='ParentCOGID', otherSideName='parentcojos'),
Relationship(name='childCog', type='one-to-one', required=False, relatedModelName='CollectionObjectGroup', column='ChildCOGID', otherSideName='cojo'),
Relationship(name='childCo', type='one-to-one', required=False, relatedModelName='CollectionObject', column='ChildCOID', otherSideName='cojo'),
],
fieldAliases=[

Expand All @@ -8349,8 +8349,8 @@
Field(name='name', column='Name', indexed=False, unique=False, required=True, type='java.lang.String', length=255),
Field(name='type', column='Type', indexed=False, unique=False, required=True, type='java.lang.String', length=255),
Field(name='version', column='Version', indexed=False, unique=False, required=False, type='java.lang.Integer'),
Field(name='timestampcreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampmodified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
Field(name='timestampCreated', column='TimestampCreated', indexed=False, unique=False, required=True, type='java.sql.Timestamp'),
Field(name='timestampModified', column='TimestampModified', indexed=False, unique=False, required=False, type='java.sql.Timestamp'),
],
indexes=[

Expand Down
18 changes: 9 additions & 9 deletions specifyweb/specify/migrations/0002_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from specifyweb.specify.models import (
protect_with_blockers,
Collectionobject,
CollectionObjectType,
Collectionobjecttype,
Collection,
Discipline,
Institution,
Expand Down Expand Up @@ -60,7 +60,7 @@ def create_default_collection_types():
for collection in Collection.objects.all():
discipline = collection.discipline
discipline_name = discipline.name
cot, created = CollectionObjectType.objects.get_or_create(
cot, created = Collectionobjecttype.objects.get_or_create(
name=discipline_name,
collection=collection,
taxontreedef_id=discipline.taxontreedef_id
Expand Down Expand Up @@ -123,7 +123,7 @@ def create_default_collection_object_types():
for collection in Collection.objects.all():
cog_type_picklist = Picklist.objects.create(
name='Default Collection Object Group Types',
tablename='CollectionObjectGroupType',
tablename='Collectionobjectgrouptype',
issystem=False,
type=1,
readonly=False,
Expand All @@ -140,7 +140,7 @@ def revert_default_collection_object_types():
for collection in Collection.objects.all():
cog_type_picklist_qs = Picklist.objects.filter(
name='Default Collection Object Group Types',
tablename='CollectionObjectGroupType',
tablename='Collectionobjectgrouptype',
collection=collection
)
if cog_type_picklist_qs.exists():
Expand All @@ -152,7 +152,7 @@ def set_discipline_for_taxon_treedefs():
for treedef in Taxontreedef.objects.all():
if treedef.discipline:
continue
cot = CollectionObjectType.objects.filter(taxontreedef=treedef).first()
cot = Collectionobjecttype.objects.filter(taxontreedef=treedef).first()
if cot:
treedef.discipline = cot.collection.discipline
treedef.save()
Expand Down Expand Up @@ -186,7 +186,7 @@ def revert_cosolidated_python_django_migration_operations(apps, schema_editor):

operations = [
migrations.CreateModel(
name='CollectionObjectType',
name='Collectionobjecttype',
fields=[
('id', models.AutoField(db_column='CollectionObjectTypeID', primary_key=True, serialize=False)),
('name', models.CharField(db_column='Name', max_length=255)),
Expand All @@ -207,7 +207,7 @@ def revert_cosolidated_python_django_migration_operations(apps, schema_editor):
},
),
migrations.CreateModel(
name='CollectionObjectGroupType',
name='Collectionobjectgrouptype',
fields=[
('id', models.AutoField(db_column='COGTypeID', primary_key=True, serialize=False)),
('name', models.CharField(db_column='Name', max_length=255, null=False)),
Expand Down Expand Up @@ -235,7 +235,7 @@ def revert_cosolidated_python_django_migration_operations(apps, schema_editor):
field=models.ForeignKey(db_column='CollectionObjectTypeID', null=True, on_delete=models.SET_NULL, related_name='collections', to='specify.collectionobjecttype'),
),
migrations.CreateModel(
name='CollectionObjectGroup',
name='Collectionobjectgroup',
fields=[
('id', models.AutoField(db_column='collectionobjectgroupid', primary_key=True, serialize=False)),
('name', models.CharField(blank=True, db_column='Name', max_length=255, null=True)),
Expand Down Expand Up @@ -268,7 +268,7 @@ def revert_cosolidated_python_django_migration_operations(apps, schema_editor):
},
),
migrations.CreateModel(
name='CollectionObjectGroupJoin',
name='Collectionobjectgroupjoin',
fields=[
('id', models.AutoField(db_column='collectionobjectgroupjoinid', primary_key=True, serialize=False)),
('isprimary', models.BooleanField(blank=True, db_column='IsPrimary', null=True)),
Expand Down
Loading

0 comments on commit 1419cd7

Please sign in to comment.