diff options
author | mahesh | 2016-04-15 12:25:00 +0530 |
---|---|---|
committer | mahesh | 2016-04-15 12:25:00 +0530 |
commit | cfb82095fd3ff8329c567d5bae3d0d07775ef044 (patch) | |
tree | 8a3438dd4403f52adcd058dcc449652f3a90bb48 | |
parent | 8de5f21df9da33ce863cb30cc938f5a99412c745 (diff) | |
download | Python-TBC-Interface-cfb82095fd3ff8329c567d5bae3d0d07775ef044.tar.gz Python-TBC-Interface-cfb82095fd3ff8329c567d5bae3d0d07775ef044.tar.bz2 Python-TBC-Interface-cfb82095fd3ff8329c567d5bae3d0d07775ef044.zip |
refined a hacky function
-rw-r--r-- | tbc_error_page/models.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/tbc_error_page/models.py b/tbc_error_page/models.py index ceab789..82c4da6 100644 --- a/tbc_error_page/models.py +++ b/tbc_error_page/models.py @@ -40,36 +40,36 @@ class Error(models.Model): def update_error_data(self, error_json_data): - # Agreeably hacky at the moment. Will refine it. + # a little more refined. for error_details in error_json_data: + original_value = Error.objects.get(chapter_url = error_details["chapter_urls"]).number_of_errors # if number of errors have increased - if Error.objects.filter(chapter_url = error_details["chapter_urls"], - number_of_errors__lt = error_details["number_of_errors"]): - + if original_value < error_details["number_of_errors"]: + Error.objects.filter(chapter_url = error_details["chapter_urls"])\ - .update(number_of_errors = error_details["number_of_errors"], + .update(number_of_errors = error_details["number_of_errors"], is_deliberate = 0 ) # if number of errors have decreased - elif Error.objects.filter(chapter_url = error_details["chapter_urls"], - number_of_errors__gt = error_details["number_of_errors"]): - + elif original_value > error_details["number_of_errors"]: Error.objects.filter(chapter_url = error_details["chapter_urls"])\ .update(number_of_errors = error_details["number_of_errors"], is_deliberate = 0) else: # if new errors have been added. - Error.objects.get_or_create(chapter_url = error_details["chapter_urls"], + Error.objects.get_or_create(chapter_url = error_details["chapter_urls"], number_of_errors = error_details["number_of_errors"] ) - Error.objects.filter(chapter_url = error_details["chapter_urls"])\ + Error.objects.filter(chapter_url = error_details["chapter_urls"])\ .update(chapter_url = error_details["chapter_urls"], number_of_errors = error_details["number_of_errors"], chapter_name = error_details["chapter_name"] ) + + def update_deliberate_error(self, deliberate_error_list): |