fix some useranswer compare issuses

This commit is contained in:
Ross
2024-01-10 21:06:49 +00:00
parent 76b4746b13
commit 8d0ffbba06
12 changed files with 86 additions and 96 deletions
+6 -11
View File
@@ -35,6 +35,10 @@ def image_directory_path(instance, filename):
# file will be uploaded to MEDIA_ROOT/anatomy/picture/<filename>
return u"picture/anatomy/{0}".format(filename)
def get_answer_compare(s: str) -> str:
s = s.strip().translate(str.maketrans("", "", string.punctuation)).lower()
s = " ".join(s.split())
return s
class BodyPart(models.Model):
bodypart = models.CharField(max_length=200)
@@ -333,11 +337,7 @@ class Answer(models.Model):
def clean(self):
if self.answer:
self.answer = self.answer.strip()
s = " ".join(self.answer.lower().split())
s = s.translate(str.maketrans("", "", string.punctuation))
self.answer_compare = s
self.answer_compare = get_answer_compare(self.answer)
# def get_compare_string(self):
# s = self.answer.lower().strip()
@@ -506,12 +506,7 @@ class UserAnswer(UserAnswerBase):
def clean(self):
if self.answer:
self.answer = self.answer.strip()
s = self.answer.lower()
s = s.translate(str.maketrans("", "", string.punctuation)).strip()
self.answer_compare = s
self.answer_compare = get_answer_compare(self.answer)
# def get_compare_string(self):
# # strip here should be unneccasry (providing clean is now working)