Skip to content

Commit

Permalink
Merge pull request #214 from Brown-University-Library/db-change/recor…
Browse files Browse the repository at this point in the history
…d-volume-page

Volume and Pages fields on Records
  • Loading branch information
prashleigh authored Jul 16, 2024
2 parents bde57fe + fbcaa80 commit 1b52057
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 9 deletions.
4 changes: 2 additions & 2 deletions disa_app/disa_app_templates/forms/citation.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ <h2 id="optional-fields-header" hidden>
<label for="libraryCatalog-value">Library Catalog</label>
</div>
<div class="citation-field form-floating" id="pages">
<input type="text" class="form-control" id="pages-value" name="pages-value" aria-label="Pages" placeholder="Pages" v-model="formData.doc.fields.pages" v-on:blur="saveSourceToServer">
<label for="pages-value">Pages</label>
<input type="text" class="form-control" id="pages-value" name="pages-value" aria-label="Number of pages" placeholder="Number of pages" v-model="formData.doc.fields.pages" v-on:blur="saveSourceToServer">
<label for="pages-value">Number of pages</label>
</div>
<div class="citation-field form-floating" id="place">
<input type="text" class="form-control" id="place-value" name="place-value" aria-label="Place" placeholder="Place" v-model="formData.doc.fields.place" v-on:blur="saveSourceToServer">
Expand Down
13 changes: 13 additions & 0 deletions disa_app/disa_app_templates/forms/record_metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ <h3>Record content</h3>
<label for="formInputDISAItemType">Record type</label>
</div>
</div>
<!-- Volume & pages -->
<div class="col-sm-2">
<div class="form-floating">
<input type="text" class="form-control" id="formInputDISAItemVolume" aria-label="Record volume" placeholder="Volume" v-model="currentItem.citation_fields.z105" v-on:blur="saveItemDataToServer">
<label for="formInputDISAItemVolume">Volume</label>
</div>
</div>
<div class="col-sm-2">
<div class="form-floating">
<input type="text" class="form-control" id="formInputDISAItemPages" aria-label="Record pages" placeholder="Pages" v-model="currentItem.citation_fields.z67" v-on:blur="saveItemDataToServer">
<label for="formInputDISAItemPages">Page(s)</label>
</div>
</div>
<!-- Image URL -->
<div class="col-md">
<div class="form-floating">
Expand Down
21 changes: 18 additions & 3 deletions disa_app/lib/view_data_records_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def query_record( rec_id: str, db_session: AlchSession ) -> dict:
'value': rec.reference_type.name,
'id':rec.reference_type.id }

data['rec']['citation_fields'] = { str(f.field_id): f.field_data for f in rec.citation_fields }

data['entrants'] = [ {
'name_id': ent.primary_name.id,
'first': ent.primary_name.first,
Expand Down Expand Up @@ -117,6 +119,22 @@ def manage_reference_put( rec_id: str, payload: bytes, request_user_id: int, db_
rfrnc.reference_type_id = reference_type.id
rfrnc.national_context_id = data['national_context']
rfrnc.transcription = data['transcription']

# Add Record-level citation fields
# Delete old ones, then add new ones from incoming form data

session.query(models_alch.ReferenceCitationField).filter_by(reference_id=rec_id).delete()

citation_entries = []
for field_id, field_data in data['record_citation_fields'].items():
citation_entries.append(models_alch.ReferenceCitationField(
reference_id=int(rec_id),
field_id=int(field_id),
field_data=field_data
))

session.bulk_save_objects(citation_entries)

rfrnc.researcher_notes = data['researcher_notes']

if 'image_url' in data.keys():
Expand Down Expand Up @@ -145,9 +163,6 @@ def manage_reference_put( rec_id: str, payload: bytes, request_user_id: int, db_
'id': l.location.id } for l in rfrnc.locations ]
data['rec']['record_type'] = {'label': rfrnc.reference_type.name,
'value': rfrnc.reference_type.name, 'id':rfrnc.reference_type.id }

# context = { 'redirect': reverse( 'edit_record_url', kwargs={'rec_id': rfrnc.id} ) }
# log.debug( f'data, ```{data}```' )
log.debug( f'data, ```{pprint.pformat(data)}```' )
except:
log.exception( '\n\nexception...' )
Expand Down
16 changes: 15 additions & 1 deletion disa_app/models_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ def dictify( self ):
'researcher_notes': self.researcher_notes,
'referents': jsn_referents,
'last_edit': last_edit_str,
'location_info': self.display_location_info()
'location_info': self.display_location_info(),
'citation_fields': { str(f.field_id): f.field_data for f in self.citation_fields }
}
return data

Expand Down Expand Up @@ -392,6 +393,19 @@ def dictify( self ):
}
return data

class ReferenceCitationField(Base):
__tablename__ = '4_citation_fields_reference'

id = Column(Integer, primary_key=True)
reference_id = Column(Integer, ForeignKey('4_references.id'))
field_id = Column(Integer, ForeignKey('1_zotero_fields.id'))
field_data = Column(String(255))
reference = relationship(Reference,
primaryjoin=(reference_id == Reference.id),
backref='citation_fields')
field = relationship(ZoteroField,
primaryjoin=(field_id == ZoteroField.id),
backref='references')

class Location(Base):
__tablename__ = '1_locations'
Expand Down
4 changes: 4 additions & 0 deletions disa_app/static/js/entry_form_data_in.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ function preprocessItemData(itemData, oldItemData, relationshipsData, referentDa
groups: itemData.groups.group_data,
transcription: 'IGNORE ME', // itemData.rec.transcription,
image_url: itemData.rec.image_url,
// Citation field IDs (which are integers) need to be prefixed with
// a letter for Vue to accept them (I chose 'z' for 'zotero')
citation_fields: Object.entries(itemData.rec.citation_fields)
.reduce((acc, [key, value]) => { acc['z' + key] = value; return acc }, {}),
researcher_notes: itemData.rec.researcher_notes,

// I have no idea why this works -- without these properties being inside of a
Expand Down
1 change: 1 addition & 0 deletions disa_app/static/js/entry_form_data_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const ITEM_TEMPLATE = {
researcher_notes: '',
groups:[],
transcription: 'IGNORE ME',
citation_fields: {},
// image_url: '',
kludge:{
transcription: '',
Expand Down
6 changes: 6 additions & 0 deletions disa_app/static/js/entry_form_vue-item_mixin_save.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ async function saveItemDataToServer() {
national_context: this.currentItem.national_context_id,
citation_id: this.formData.doc.id,
image_url: this.currentItem.kludge.image_url,
// Citation fields for the Record: compile into a hash between
// Zotero field ID (without leading 'z') and value;
// Only add if not empty
record_citation_fields: Object.entries(this.currentItem.citation_fields)
.filter(([k, v]) => v !== '')
.reduce((acc, [k, v]) => { acc[k.substring(1)] = v; return acc }, {}),
researcher_notes: this.currentItem.researcher_notes,
};

Expand Down
6 changes: 3 additions & 3 deletions disa_app/tests/test_data_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_get_single_good(self):
sorted(resp_dct.keys()) )
record_keys = sorted( resp_dct['rec'].keys() )
self.assertEqual(
['date', 'header', 'id', 'image_url', 'locations', 'national_context', 'record_type', 'researcher_notes', 'transcription'],
['citation_fields', 'date', 'header', 'id', 'image_url', 'locations', 'national_context', 'record_type', 'researcher_notes', 'transcription'],
record_keys )
if self.random_new_record_date:
date_object = datetime.datetime.strptime( self.random_new_record_date, '%m/%d/%Y')
Expand Down Expand Up @@ -292,8 +292,8 @@ def test_put_good(self):
'national_context': self.random_put_national_context,
'record_type': self.random_put_record_type,
'transcription': self.random_put_transcription,
'researcher_notes': self.random_put_researcher_notes

'researcher_notes': self.random_put_researcher_notes,
'record_citation_fields': { '67': 'test-1', '105': 'test-2' }
}
jsn = json.dumps( put_payload )
put_response = self.client.put( put_url, data=jsn, content_type='application/json' )
Expand Down

0 comments on commit 1b52057

Please sign in to comment.