callat-qcd / espressodb

Science database interface using Django as the content manager.
https://espressodb.readthedocs.io
BSD 3-Clause "New" or "Revised" License
8 stars 3 forks source link

Pre save hook #45

Closed ckoerber closed 4 years ago

ckoerber commented 4 years ago

On some occasions it might be desirable to programmatically default insert values for certain columns. One example would be code revision tags. If the model needs to digest data before making decisions, Django default insertions might not be enough.

A possible solution for this is to implement a Base model pre_save method which is run before inserting data into tables. This method should be called on the pre_save signal before check_consistency to update default information. For example if the user specifies version control information, this can be inserted in the default tag column

def get_version_tag() -> str:
    "Extracts version tag of repository"
    ...

class MyModel(Base):
    def pre_save(self):
        self.tag = get_version_tag()

Once this is implemented, we should also include documentation of this functionality in the doc pages (with versioning in mind).

Update related to the JOSS review process raised by @remram44.

https://github.com/openjournals/joss-reviews/issues/2007

ckoerber commented 4 years ago

This feature, docs and test have been implemented in the commit range https://github.com/callat-qcd/espressodb/compare/19ac1c8..ceef601

ckoerber commented 4 years ago

Closed with #48