From 5819a9ef66ee6cf97ed90a341a1442973b373b8d Mon Sep 17 00:00:00 2001 From: shimilgithub Date: Mon, 11 Sep 2023 12:50:52 +0530 Subject: [PATCH] changes in reference validation --- app/crud/contents_crud.py | 34 ++++++++++++++++++++-------------- app/schema/schema_content.py | 7 ++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/crud/contents_crud.py b/app/crud/contents_crud.py index 06edd9b7..15cc4317 100644 --- a/app/crud/contents_crud.py +++ b/app/crud/contents_crud.py @@ -410,7 +410,7 @@ def get_parascripturals(db_:Session, resource_name, category=None, title=None,** } return response -def upload_parascripturals(db_: Session, resource_name, parascriptural, user_id=None): +def upload_parascripturals(db_: Session, resource_name, parascriptural, user_id=None):#pylint: disable=too-many-branches '''Adds rows to the parascripturals table specified by resource_name''' resource_db_content = db_.query(db_models.Resource).filter( db_models.Resource.resourceName == resource_name).first() @@ -431,13 +431,16 @@ def upload_parascripturals(db_: Session, resource_name, parascriptural, user_id= #setting verseNumber to 000 if its not present ref_start = utils.create_decimal_ref_id(db_,ref['book'],ref['chapter'],0) ref['verseNumber'] = 0 - if ref['verseEnd'] is not None: - ref_end = utils.create_decimal_ref_id( - db_,ref['bookEnd'],ref['chapterEnd'],ref['verseEnd']) + if ref['bookEnd'] is not None: + if ref['chapterEnd'] is not None and ref['verseEnd'] is not None: + ref_end = utils.create_decimal_ref_id( + db_,ref['bookEnd'],ref['chapterEnd'],ref['verseEnd']) + else: + #setting verseEnd to 999 if its not present + ref_end = utils.create_decimal_ref_id(db_,ref['bookEnd'],ref['chapterEnd'],999) + ref['verseEnd'] = 999 else: - #setting verseEnd to 999 if its not present - ref_end = utils.create_decimal_ref_id(db_,ref['bookEnd'],ref['chapterEnd'],999) - ref['verseEnd'] = 999 + ref_end = None else: ref = None ref_end = None @@ -596,7 +599,7 @@ def get_audio_bible(db_:Session, resource_name, name=None,**kwargs): #pylint: di } return response -def upload_audio_bible(db_: Session, resource_name, audiobibles, user_id=None): +def upload_audio_bible(db_: Session, resource_name, audiobibles, user_id=None):#pylint: disable=too-many-branches '''Adds rows to the audio bibles table specified by resource_name''' resource_db_content = db_.query(db_models.Resource).filter( db_models.Resource.resourceName == resource_name).first() @@ -617,13 +620,16 @@ def upload_audio_bible(db_: Session, resource_name, audiobibles, user_id=None): #setting verseNumber to 000 if its not present ref_start = utils.create_decimal_ref_id(db_,ref['book'],ref['chapter'],0) ref['verseNumber'] = 0 - if ref['verseEnd'] is not None: - ref_end = utils.create_decimal_ref_id( - db_,ref['bookEnd'],ref['chapterEnd'],ref['verseEnd']) + if ref['bookEnd'] is not None: + if ref['chapterEnd'] is not None and ref['verseEnd'] is not None: + ref_end = utils.create_decimal_ref_id( + db_,ref['bookEnd'],ref['chapterEnd'],ref['verseEnd']) + else: + #setting verseEnd to 999 if its not present + ref_end = utils.create_decimal_ref_id(db_,ref['bookEnd'],ref['chapterEnd'],999) + ref['verseEnd'] = 999 else: - #setting verseEnd to 999 if its not present - ref_end = utils.create_decimal_ref_id(db_,ref['bookEnd'],ref['chapterEnd'],999) - ref['verseEnd'] = 999 + ref_end = None else: ref = None ref_end = None diff --git a/app/schema/schema_content.py b/app/schema/schema_content.py index 173d1bab..4a4e357c 100644 --- a/app/schema/schema_content.py +++ b/app/schema/schema_content.py @@ -55,9 +55,10 @@ def check_verses(cls, val, values): # pylint: disable=E0213 @validator('chapterEnd') def check_chapter_range(cls, val, values): # pylint: disable=E0213 '''chapter start should be less than or equal to chapter end''' - if 'chapter' in values and val < values['chapter']: - raise ValueError('chapter start should be less than or equal to chapter end') - return val + if val is not None: + if 'chapter' in values and val < values['chapter']: + raise ValueError('chapter start should be less than or equal to chapter end') + return val def check_verse_range(cls, val, values): # pylint: disable=E0213 '''verse start should be less than or equal to verse end''' if 'verseNumber' in values and val < values['verseNumber']: