Changeset 1466 in products for quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/keywords.py
- Timestamp:
- Dec 22, 2009 7:23:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/keywords.py
r1463 r1466 16 16 def validateKeywords(self, text): 17 17 """ see interface """ 18 ts = getToolByName(self.context, 'translation_service') 18 19 # extract keywords from text 19 if not text.strip(): 20 return _(u'Keywords list is empty!') 21 22 keywords = map(lambda x: x.strip(), text.lower().split('\n')) 23 if not keywords: 24 return _(u'Keywords list is empty!') 25 20 if text.lower().strip(): 21 keywords = map(lambda x: x.strip(), text.lower().strip().split('\n')) 22 else: 23 return ts.utranslate(None, _(u'Keywords list is empty!'), context=self.context) 26 24 # request html page of context object 27 25 url = '%s?qseo_without_additional_keywords=1' % self.context.absolute_url() … … 69 67 # check every keyword on appearing in body of html page 70 68 missing = [] 69 finding = [] 71 70 added = {} 71 finded = {} 72 72 for keyword in keywords: 73 if keyword not in added.keys() and not re.compile(r'\b%s\b' % keyword, re.I).search(page_text): 74 missing.append(keyword) 75 added[keyword] = 1 76 73 if keyword: 74 keyword_on_page = len(re.compile(r'\s%s\s' % keyword, re.I).findall(page_text)) 75 if keyword not in added.keys() and not keyword_on_page: 76 missing.append(keyword.decode('utf8')) 77 added[keyword] = 1 78 if keyword not in finded.keys() and keyword_on_page: 79 finding.append(keyword.decode('utf8')+' - '+repr(keyword_on_page)) 80 finded[keyword] = 1 77 81 # return list of missing keywords 78 82 if missing: 79 msg = u"""Next keywords did not appear on the page:\n%s""" % '\n'.join(missing)83 msg = ts.utranslate(None, _('missing_keywords', default=u'Next keywords did not appear on the page:\n${missing}', mapping={'missing':'\n'.join(missing)}), context=self.context) 80 84 else: 81 msg = u"""All keywords found on the page!"""82 return _(msg)85 msg = ts.utranslate(None, _('finded_keywords', default=u'All keywords found on the page!\nMore detailed:\n${found}', mapping={'found': '\n'.join(finding)}), context=self.context) 86 return msg 83 87 84 88 def walkTextNodes(self, parent, page_words=[]): … … 100 104 # pop everything from the the left-angle bracket until the right-angle bracket 101 105 s_list.pop(i) 102 106 103 107 # pops the right-angle bracket, too 104 108 s_list.pop(i) 105 109 else: 106 110 i=i+1 107 111 108 112 # convert the list back into text 109 113 join_char=''
Note: See TracChangeset
for help on using the changeset viewer.