Skip to content

Commit

Permalink
WIP add SpdatasetAttachment
Browse files Browse the repository at this point in the history
  • Loading branch information
alesan99 committed Feb 24, 2025
1 parent 473b18b commit e422e17
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 6 deletions.
23 changes: 22 additions & 1 deletion specifyweb/frontend/js_src/lib/components/DataModel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ export type Attachment = {
readonly preparationAttachments: RA<PreparationAttachment>;
readonly referenceWorkAttachments: RA<ReferenceWorkAttachment>;
readonly repositoryAgreementAttachments: RA<RepositoryAgreementAttachment>;
readonly spdatasetAttachments: RA<SpdatasetAttachment>;
readonly storageAttachments: RA<StorageAttachment>;
readonly tags: RA<AttachmentTag>;
readonly taxonAttachments: RA<TaxonAttachment>;
Expand Down Expand Up @@ -6463,7 +6464,9 @@ export type Spdataset = {
readonly modifiedbyagent: Agent | null;
readonly specifyuser: SpecifyUser;
};
readonly toManyDependent: RR<never, never>;
readonly toManyDependent: {
readonly spdatasetAttachments: RA<SpdatasetAttachment>;
};
readonly toManyIndependent: RR<never, never>;
};
export type CollectionObjectType = {
Expand Down Expand Up @@ -6814,3 +6817,21 @@ export type TectonicUnit = {
readonly paleoContexts: RA<PaleoContext>;
};
};
export type SpdatasetAttachment = {
readonly tableName: 'SpdatasetAttachment';
readonly fields: {
readonly ordinal: number;
readonly remarks: string | null;
readonly timestampCreated: string;
readonly timestampModified: string | null;
readonly version: number | null;
};
readonly toOneDependent: { readonly attachment: Attachment };
readonly toOneIndependent: {
readonly spdataset: Spdataset;
readonly createdByAgent: Agent | null;
readonly modifiedByAgent: Agent | null;
};
readonly toManyDependent: RR<never, never>;
readonly toManyIndependent: RR<never, never>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ test('Parent table relationships are calculated properly', () =>
"RolePolicy": "[relationship RolePolicy.role]",
"SpAppResourceData": "[relationship SpAppResourceData.spAppResource]",
"SpAuditLogField": "[relationship SpAuditLogField.spAuditLog]",
"SpdatasetAttachment": "[relationship SpdatasetAttachment.spdataset]",
"SpExportSchemaItem": "[relationship SpExportSchemaItem.spExportSchema]",
"SpExportSchemaItemMapping": "[relationship SpExportSchemaItemMapping.exportSchemaItem]",
"SpLocaleContainerItem": "[relationship SpLocaleContainerItem.container]",
Expand Down
36 changes: 35 additions & 1 deletion specifyweb/specify/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@
Relationship(name='tags', type='one-to-many',required=False, relatedModelName='AttachmentTag', otherSideName='attachment'),
Relationship(name='taxonAttachments', type='one-to-many',required=False, relatedModelName='TaxonAttachment', otherSideName='attachment'),
Relationship(name='treatmentEventAttachments', type='one-to-many',required=False, relatedModelName='TreatmentEventAttachment', otherSideName='attachment'),
Relationship(name='visibilitySetBy', type='many-to-one',required=False, relatedModelName='SpecifyUser', column='VisibilitySetByID')
Relationship(name='visibilitySetBy', type='many-to-one',required=False, relatedModelName='SpecifyUser', column='VisibilitySetByID'),
Relationship(name='spdatasetAttachments', type='one-to-many',required=False, relatedModelName='SpdatasetAttachment', otherSideName='attachment')
],
fieldAliases=[

Expand Down Expand Up @@ -8221,6 +8222,7 @@

],
relationships=[
Relationship(name='spdatasetAttachments', type='one-to-many',required=False, relatedModelName='SpdatasetAttachment', otherSideName='spdataset', dependent=True),
Relationship(name='collection', type='many-to-one', required=False, relatedModelName='Collection', column='Collection_ID'),
Relationship(name='specifyuser', type='many-to-one', required=True, relatedModelName='SpecifyUser', column='SpecifyUser_ID'),
Relationship(name='createdbyagent', type='many-to-one', required=False, relatedModelName='Agent', column='CreatedByAgent_ID'),
Expand Down Expand Up @@ -8707,6 +8709,38 @@
{'vname':'acceptedParent', 'aname':'acceptedTectonicUnit'}
],
),
Table( # SpDataSetAttachment
sp7_only=True,
classname='edu.ku.brc.specify.datamodel.SpdatasetAttachment',
table='spadatasetattachment',
tableId=1028,
system=True,
idColumn='SpdatasetAttachmentID',
idFieldName='SpdatasetAttachmentId',
idField=IdField(name='SpdatasetAttachmentId', column='SpdatasetAttachmentID', type='java.lang.Integer'),
fields=[
Field(name='collectionMemberId', column='CollectionMemberID', indexed=True, unique=False, required=True, type='java.lang.Integer'),
Field(name='ordinal', column='Ordinal', indexed=False, unique=False, required=True, type='java.lang.Integer'),
Field(name='remarks', column='Remarks', indexed=False, unique=False, required=False, type='text', length=4096),
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='version', column='Version', indexed=False, unique=False, required=False, type='java.lang.Integer')
],
indexes=[
Index(name='CEAColMemIDX', column_names=['CollectionMemberID'])
],
relationships=[
Relationship(name='attachment', type='many-to-one',required=True, relatedModelName='Attachment', column='AttachmentID', otherSideName='SpdatasetAttachments', dependent=True),
Relationship(name='spdataset', type='many-to-one',required=True, relatedModelName='Spdataset', column='SpDataSetID', otherSideName='SpdatasetAttachments'),
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')
],
fieldAliases=[

],
view='ObjectAttachment',
searchDialog=None
),
])

# add_collectingevents_to_locality(datamodel) # added statically to datamodel definitions
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/specify/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7907,4 +7907,4 @@ class Meta:
db_table = 'tectonicunit'
ordering = ()

save = partialmethod(custom_save)
save = partialmethod(custom_save)
4 changes: 3 additions & 1 deletion specifyweb/specify/models_by_table_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
1025:'Tectonicunittreedef',
1026:'Tectonicunittreedefitem',
1027:'Tectonicunit',
# 1027:'Spdatasetattachment',
}

model_names_by_app = {
Expand Down Expand Up @@ -244,7 +245,8 @@
'LibraryRolePolicy'
},
'workbench': {
'Spdataset'
'Spdataset',
# 'Spdatasetattachment'
},
'specify': {
'Accession',
Expand Down
30 changes: 28 additions & 2 deletions specifyweb/workbench/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.http import Http404
from django.utils import timezone

from specifyweb.specify.models import Collection, Specifyuser, Agent, datamodel, custom_save
from specifyweb.specify.models import Collection, Specifyuser, Agent, datamodel, custom_save, protect_with_blockers
from specifyweb.specify.api import uri_for_model

class Dataset(models.Model):
Expand Down Expand Up @@ -44,7 +44,7 @@ def get_meta_fields(cls, request, extra_meta_fields=None, extra_filters=None):
collection=request.specify_collection,
**(extra_filters if extra_filters is not None else {})
).only(*attrs)
return [{'id': ds.id, **{attr: getattr(ds, attr) for attr in attrs}, 'uploadplan': json.loads(ds.uploadplan) if ds.uploadplan else None} for ds in dss]
return []

# raise_404: Whether to raise 404 or return http 404.
# lock_object: Whether to run a "select for update" or "select"
Expand Down Expand Up @@ -112,3 +112,29 @@ def get_dataset_as_dict(self):

def was_uploaded(self) -> bool:
return self.uploadresult and self.uploadresult['success']

class SpdatasetAttachment(models.Model):
specify_model = datamodel.get_table_strict('spdatasetattachment')

# ID Field
id = models.AutoField(primary_key=True, db_column='spdatasetattachmentid')

# TODO: Dont't use lazy references
# Fields
ordinal = models.IntegerField(blank=False, null=False, unique=False, db_column='Ordinal', db_index=False)
remarks = models.TextField(blank=True, null=True, unique=False, db_column='Remarks', db_index=False)
timestampcreated = models.DateTimeField(blank=False, null=False, unique=False, db_column='TimestampCreated', db_index=False, default=timezone.now)
timestampmodified = models.DateTimeField(blank=True, null=True, unique=False, db_column='TimestampModified', db_index=False, default=timezone.now) # auto_now=True
version = models.IntegerField(blank=True, null=True, unique=False, db_column='Version', db_index=False, default=0)

# Relationships: Many-to-One
spdataset = models.ForeignKey('Spdataset', db_column='id', related_name='spdatasetattachments', null=False, on_delete=models.CASCADE)
attachment = models.ForeignKey('Attachment', db_column='AttachmentID', related_name='spdatasetattachments', null=False, on_delete=protect_with_blockers)
createdbyagent = models.ForeignKey('Agent', db_column='CreatedByAgentID', related_name='+', null=True, on_delete=protect_with_blockers)
modifiedbyagent = models.ForeignKey('Agent', db_column='ModifiedByAgentID', related_name='+', null=True, on_delete=protect_with_blockers)

class Meta:
db_table = 'spdatasetattachment'
ordering = ()

save = partialmethod(custom_save)

0 comments on commit e422e17

Please sign in to comment.