Skip to content

Commit

Permalink
Merge pull request #56 from ropable/master
Browse files Browse the repository at this point in the history
Refactor dewordify_txt util function to encode passed-in ASCII.
Simple logging formatter should include timestamp.
  • Loading branch information
dbca-asi committed Jul 18, 2016
2 parents 5d4c99d + 29247ef commit f2d6053
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions prs2/referral/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ def save(self, force_insert=False, force_update=False, *args, **kwargs):
'''
Overide the Note model save() to cleanse the HTML used.
'''
self.note_html = unidecode(unicode(dewordify_text(self.note_html)))
self.note_html = dewordify_text(self.note_html)
self.note_html = clean.clean_html(self.note_html)
# Strip HTML tags and save as plain text.
t = fromstring(self.note_html)
Expand Down Expand Up @@ -1160,15 +1160,15 @@ def save(self, force_insert=False, force_update=False, *args, **kwargs):
Overide the Condition models's save() to cleanse the HTML input.
'''
if self.condition_html:
self.condition_html = unidecode(unicode(dewordify_text(self.condition_html)))
self.condition_html = dewordify_text(self.condition_html)
self.condition_html = clean.clean_html(self.condition_html)
t = fromstring(self.condition_html)
self.condition = unicode(t.text_content())
else:
self.condition_html = ''
self.condition = ''
if self.proposed_condition_html:
self.proposed_condition_html = unidecode(unicode(dewordify_text(self.proposed_condition_html)))
self.proposed_condition_html = dewordify_text(self.proposed_condition_html)
self.proposed_condition_html = clean.clean_html(self.proposed_condition_html)
t = fromstring(self.proposed_condition_html)
self.proposed_condition = unicode(t.text_content())
Expand Down
8 changes: 5 additions & 3 deletions prs2/referral/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
from reversion.models import Version
import re
from unidecode import unidecode


def is_model_or_string(model):
Expand Down Expand Up @@ -72,16 +73,17 @@ def replacer(m):
return REPLACEMENTS[m.group(0)]


def dewordify_text(x):
def dewordify_text(txt):
'''
Function to strip some of the crufty HTML that results from copy-pasting from Word into the
RTF text fields in this application.
Source:
http://stackoverflow.com/questions/1175540/iterative-find-replace-from-a-list-of-tuples-in-python
'''
if x:
if txt:
txt = unidecode(unicode(txt))
r = re.compile('|'.join(REPLACEMENTS.keys()))
return r.sub(replacer, x)
return r.sub(replacer, txt)
else:
return ''

Expand Down
2 changes: 1 addition & 1 deletion prs2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(levelname)s %(message)s'
'format': '%(levelname)s %(asctime)s %(message)s'
},
},
'handlers': {
Expand Down

0 comments on commit f2d6053

Please sign in to comment.