Commit 492dad8b authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

AutoFillableModel can be autofilled during save when implementing is_autofill_done method

parent 6b173bc6
......@@ -31,12 +31,18 @@ class AutoFillableModel(models.Model):
abstract = True
def save(self, *args, **kwargs):
if kwargs.get('autofill') is True:
if kwargs.get('autofill') is True or not self.is_autofill_done():
self.autofill()
if 'autofill' in kwargs:
del kwargs['autofill']
super(AutoFillableModel, self).save(*args, **kwargs)
def autofill(self):
raise NotImplementedError()
def is_autofill_done(self):
return True
class Bibliography(AutoFillableModel):
"""
......@@ -85,6 +91,9 @@ class Bibliography(AutoFillableModel):
self.authors_list = info['authors_list']
self.biblio_year = info['biblio_year']
def is_autofill_done(self):
return len(self.title) > 0
def clean(self):
super().clean()
Bibliography.validate_source_id(self.id_source, self.source)
......@@ -204,6 +213,9 @@ class Protein(AutoFillableModel):
mol_function.save(autofill=True)
self.molecular_functions.add(mol_function)
def is_autofill_done(self):
return len(self.gene_name) > 0
def __str__(self):
return '{} ({})'.format(self.uniprot_id, self.recommended_name_long)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment