def _update(self): context = self.context width = int(self._registry.get('%s.width' % self.name, 675)) height = int(self._registry.get('%s.height' % self.name, 380)) if hasImage(context): imageField = context.Schema()['image'] size = imageField.getSize(context) self.status = size == (width, height) else: self.status = False size = (0, 0) if self.status: self.description = _(u"Image field content has correct size.") else: symptom_description = _( u"Wrong size : image is " u"${actual_width} by ${actual_height} pixels. " u"It should be ${width} by ${height} pixels.") self.description = Message(symptom_description, mapping={ 'actual_width': size[0], 'actual_height': size[1], 'width': width, 'height': height })
def _update(self): context = self.context width = int(self._registry.get('%s.width' % self.name, 675)) height = int(self._registry.get('%s.height' % self.name, 380)) if hasImage(context): imageField = context.Schema()['image'] size = imageField.getSize(context) self.status = size == (width, height) else: self.status = False size = (0, 0) if self.status: self.description = _(u"Image field content has correct size.") else: symptom_description = _( u"Wrong size : image is " u"${actual_width} by ${actual_height} pixels. " u"It should be ${width} by ${height} pixels." ) self.description = Message( symptom_description, mapping={ 'actual_width': size[0], 'actual_height': size[1], 'width': width, 'height': height } )
class IJekyllSettings(Interface): activeSymptoms = List( title=_(u"Active Symptoms"), description=_(u"Select which symptoms will be taken in account " u"when diagnosing content quality."), required=False, missing_value=list(), value_type=Choice(vocabulary="collective.jekyll.SymptomsVocabulary"))
class JekyllControlPanel(ControlPanelForm): label = _("Content quality") description = _("You can activate / deactivate symptoms using this form.") form_name = _("Symptoms activation") form_fields = form.FormFields(IJekyllSettings) active_symptoms = form_fields['activeSymptoms'] active_symptoms.custom_widget = MultiCheckBoxThreeColumnWidget active_symptoms.custom_widget.cssClass = 'label'
class TitleFormatSymptom(SymptomBase): title = _(u"Title format") help = _(u"Title should begin with uppercase letter.") def _update(self): title = self.context.Title() if len(title): self.status = title[0].isupper() self.description = _(u"Title does not begin with uppercase letter.")
class ImagePresentSymptom(SymptomBase): title = _(u"Image present") help = _(u"Image field should have content.") def _update(self): self.status = hasImage(self.context) if self.status: self.description = _(u"Image field has content.") else: self.description = _(u"Image field does not have content.")
class BodyTextPresentSymptom(SymptomBaseWithCache): title = _(u"Body text") help = _(u"Body text should have content.") def _update(self): cooked = self.cache.setdefault( 'cooked_body', self.context.CookedBody(stx_level=2).strip()) self.status = len(cooked) if not self.status: self.description = _(u"Body text does not have content.")
class IdFormatSymptom(SymptomBase): title = _(u"Id format") help = (_(u"Id should not start with 'copy_of'.")) def _update(self): id = self.context.getId() copy = re.compile('^copy[0-9]*_of') match = copy.match(id) self.status = not bool(match) if match: symptom_description = _(u"Id starts with '${start}'.") self.description = Message(symptom_description, mapping={'start': match.group()})
def _update(self): self.status = True cooked = self.context.CookedBody(stx_level=2).strip() soup = BeautifulSoup(cooked) child_count = 0 for child in soup.children: child_count += 1 if not child.previousSibling and empty_or_spaces(child.text): self.status = False self.description = _(u"Body text starts with empty tags or BR.") if child_count != 0 and empty_or_spaces(child.text): self.status = False if child.previousSibling: self.description = _(u"Body text ends with empty tags or BR.")
class DescriptionLengthSymptom(SymptomBase): title = _(u"Summary length") @property def maximum(self): return int(self._registry.get('%s.maximum' % self.name, 20)) @property def help(self): symptom_help = _( u"The summary (or description) should not be empty " u"and should have at most ${maximum} significant words " u"(longer than 3 letters). ") return Message(symptom_help, mapping={'maximum': self.maximum}) EMPTY = dict( description=_(u"Description does not have content."), summary=_(u"Summary does not have content."), ) TOO_LONG = dict( description=_( u"The description counts ${word_count} significant words " u"(longer than 3 letters). " u"It should have at most ${maximum} significant words."), summary=_(u"The summary counts ${word_count} significant words " u"(longer than 3 letters). " u"It should have at most ${maximum} significant words."), ) def _update(self): maximum = self.maximum word_count = countWords(self.context.Description()) if 'summary' in self.context.Schema()['description'].widget.label: key = 'summary' else: key = 'description' if not len(self.context.Description()): self.status = False self.description = self.EMPTY[key] else: self.status = (word_count <= maximum) symptom_description = self.TOO_LONG[key] self.description = Message(symptom_description, mapping={ 'word_count': word_count, 'maximum': maximum })
def _update(self): cooked = self.cache.setdefault( 'cooked_body', self.context.CookedBody(stx_level=2).strip()) self.status = len(cooked) if not self.status: self.description = _(u"Body text does not have content.")
class TitleLengthSymptom(SymptomBase): title = _(u"Title length") @property def maximum(self): return int(self._registry.get('%s.maximum' % self.name, 5)) @property def help(self): symptom_help = _( u"The title should have at most ${maximum} significant words " u"(longer than 3 letters). ") return Message(symptom_help, mapping={'maximum': self.maximum}) def _update(self): maximum = self.maximum title = self.context.Title() word_count = countWords(title) self.status = word_count <= maximum symptom_description = _( u"The title counts ${word_count} significant words " u"(longer than 3 letters). " u"It should have at most ${maximum} significant words.") self.description = Message(symptom_description, mapping={ 'word_count': word_count, 'maximum': maximum })
def _update(self): cooked = self.context.CookedBody(stx_level=2).strip() soup = BeautifulSoup(cooked) links = soup.find_all('a') self.status = len(links) > 1 if not self.status: self.description = _(u"Body text has no links.")
def _update(self): maximum = int(self._registry.get('%s.maximum' % self.name, 20)) word_count = countWords(self.context.Description()) if not len(self.context.Description()): self.status = False self.description = _(u"Description does not have content.") else: self.status = (word_count <= maximum) symptom_description = _( u"The description counts ${word_count} significant words " u"(longer than 3 letters). " u"It should have at most ${maximum} significant words.") self.description = Message( symptom_description, mapping={'word_count': word_count, 'maximum': maximum} )
class LinksInBodySymptom(SymptomBaseWithCache): title = _(u"Links In Body") @property def minimum(self): return int(self._registry.get('%s.minimum' % self.name, 2)) @property def help(self): symptom_help = _( u"The body text should have at least ${minimum} links to other " u"pages. ") return Message(symptom_help, mapping={'minimum': self.minimum}) def _update(self): minimum = self.minimum cooked = self.cache.setdefault( 'cooked_body', self.context.CookedBody(stx_level=2).strip()) soup = self.cache.setdefault('cooked_body_soup', BeautifulSoup(cooked.decode('utf-8'))) links = soup.find_all('a') self.status = len(links) >= minimum if not self.status: symptom_description = _( u"The body text has less than ${minimum} links to other pages." ) self.description = Message(symptom_description, mapping={'minimum': minimum})
def _update(self): self.minimum = int(self._registry.get('%s.minimum' % self.name, 2)) cooked = self.context.CookedBody(stx_level=2).strip() soup = BeautifulSoup(cooked) links = soup.find_all('a') self.status = len(links) > 1 if not self.status: self.description = _(u"Body text does not have enough links.")
def _make_link(self): content = self.context.context if self.context.isIgnored: link_text = translate(_(u"Restore"), context=self.request) action = u"restore" else: link_text = translate(_(u"Ignore"), context=self.request) action = u"ignore" url = u'{url}/jekyll_{action}_symptom?symptomName={name}'.format( url=content.absolute_url(), name=self.context.name, action=action, ) return u'<a href="{url}">{text}</a>'.format( url=url, text=link_text, )
def _make_link(self): content = self.context.context if self.context.isIgnored: link_text = translate(_(u"Consider"), context=self.request) action = u"consider" else: link_text = translate(_(u"Ignore"), context=self.request) action = u"ignore" url = u'{url}/jekyll_{action}_symptom?symptomName={name}'.format( url=content.absolute_url(), name=self.context.name, action=action, ) return u'<a class="ignore" href="{url}">{text}</a>'.format( url=url, text=link_text, )
def _update(self): self.status = True cooked = self.cache.setdefault( 'cooked_body', self.context.CookedBody(stx_level=2).strip()) soup = self.cache.setdefault('cooked_body_soup', BeautifulSoup(cooked.decode('utf-8'))) child_count = 0 for child in soup.children: child_count += 1 if not child.previousSibling and empty_or_spaces(child.text): self.status = False self.description = _( u"Body text starts with empty tags or BR.") if child_count != 0 and empty_or_spaces(child.text): self.status = False if child.previousSibling: self.description = _(u"Body text ends with empty tags or BR.")
def _update(self): id = self.context.getId() copy = re.compile('^copy[0-9]*_of') match = copy.match(id) self.status = not bool(match) if match: symptom_description = _(u"Id starts with '${start}'.") self.description = Message(symptom_description, mapping={'start': match.group()})
def help(self): symptom_help = _( u"The body text should have at least ${minimum} links to other " u"pages. " ) return Message( symptom_help, mapping={'minimum': self.minimum} )
def help(self): symptom_help = _( u"The title should have at most ${maximum} significant words " u"(longer than 3 letters). " ) return Message( symptom_help, mapping={'maximum': self.maximum} )
def help(self): symptom_help = _( u"The summary (or description) should not be empty " u"and should have at most ${maximum} significant words " u"(longer than 3 letters). " ) return Message( symptom_help, mapping={'maximum': self.maximum} )
class DescriptionFormatSymptom(SymptomBase): title = _(u"Summary format") help = _(u"The summary (or description) should begin with " u"uppercase letter.") FORMAT = dict( description=_(u"Description does not begin with uppercase letter."), summary=_(u"Summary does not begin with uppercase letter."), ) def _update(self): description = self.context.Description() if 'summary' in self.context.Schema()['description'].widget.label: key = 'summary' else: key = 'description' if len(description): self.status = description[0].isupper() self.description = self.FORMAT[key]
def _update(self): id = self.context.getId() copy = re.compile('^copy[0-9]*_of') match = copy.match(id) self.status = not bool(match) if match: symptom_description = _(u"Id starts with '${start}'.") self.description = Message( symptom_description, mapping={'start': match.group()} )
def _update(self): id = self.context.getId() self.status = not len(str(id)) > self.maximum if not self.status: self.status = False symptom_description = _( u"Id is too long. " u"It should have at most ${maximum} characters.") self.description = Message(symptom_description, mapping={'maximum': self.maximum})
def _update(self): maximum = int(self._registry.get('%s.maximum' % self.name, 5)) title = self.context.Title() word_count = countWords(title) self.status = word_count <= maximum symptom_description = _( u"The title counts ${word_count} significant words " u"(longer than 3 letters). " u"It should have at most ${maximum} significant words.") self.description = Message( symptom_description, mapping={'word_count': word_count, 'maximum': maximum} )
def _update(self): minimum = self.minimum cooked = self.context.CookedBody(stx_level=2).strip() soup = BeautifulSoup(cooked) links = soup.find_all('a') self.status = len(links) > minimum if not self.status: symptom_description = _( u"The body text has less than ${minimum} links to other pages." ) self.description = Message( symptom_description, mapping={'minimum': minimum} )
def _update(self): maximum = self.maximum title = self.context.Title() word_count = countWords(title) self.status = word_count <= maximum symptom_description = _( u"The title counts ${word_count} significant words " u"(longer than 3 letters). " u"It should have at most ${maximum} significant words.") self.description = Message(symptom_description, mapping={ 'word_count': word_count, 'maximum': maximum })
def _update(self): context = self.context if hasImage(context): imageField = context.Schema()['image'] size = imageField.getSize(context) self.status = size == (675, 380) else: self.status = False size = (0, 0) if self.status: self.description = _(u"Image field content has correct size.") else: self.description = ( u"Image field content has wrong size : %d, %d" % (size[0], size[1]))
def _update(self): minimum = self.minimum cooked = self.cache.setdefault( 'cooked_body', self.context.CookedBody(stx_level=2).strip()) soup = self.cache.setdefault('cooked_body_soup', BeautifulSoup(cooked.decode('utf-8'))) links = soup.find_all('a') self.status = len(links) >= minimum if not self.status: symptom_description = _( u"The body text has less than ${minimum} links to other pages." ) self.description = Message(symptom_description, mapping={'minimum': minimum})
def _update(self): minimum = self.minimum cooked = self.cache.setdefault('cooked_body', self.context.CookedBody(stx_level=2).strip()) soup = self.cache.setdefault('cooked_body_soup', BeautifulSoup(cooked.decode('utf-8'))) links = soup.find_all('a') self.status = len(links) >= minimum if not self.status: symptom_description = _( u"The body text has less than ${minimum} links to other pages." ) self.description = Message( symptom_description, mapping={'minimum': minimum} )
def _update(self): context = self.context width = int(self._registry.get('%s.width' % self.name, 675)) height = int(self._registry.get('%s.width' % self.name, 380)) if hasImage(context): imageField = context.Schema()['image'] size = imageField.getSize(context) self.status = size == (width, height) else: self.status = False size = (0, 0) if self.status: self.description = _(u"Image field content has correct size.") else: self.description = ( u"Image field content has wrong size : %d, %d. Should be %d, %d" % (size[0], size[1]), width, height)
def getSymptomTypes(self): names = set() symptoms = set() URL = '{context_url}/diagnosis_view?symptom_name={name}' for item, diagnosis in self.items(): for symptom in diagnosis.symptoms: name = symptom.name if name not in names: context_url = self.context.absolute_url() url = URL.format(context_url=context_url, name=name) title = translate(_(symptom.title), context=self.request) data = SymptomData( title=title, help=symptom.help, name=name, url=url, ) names.add(name) symptoms.add(data) result = sorted(symptoms, key=lambda x: x.title) return result
class IdLengthSymptom(SymptomBase): title = _(u"Id length") @property def help(self): symptom_help = _(u"Id should not be more than ${maximum} chars long.") return Message(symptom_help, mapping={'maximum': self.maximum}) @property def maximum(self): return int(self._registry.get('%s.maximum' % self.name, 20)) def _update(self): id = self.context.getId() self.status = not len(str(id)) > self.maximum if not self.status: self.status = False symptom_description = _( u"Id is too long. " u"It should have at most ${maximum} characters.") self.description = Message(symptom_description, mapping={'maximum': self.maximum})
def help(self): symptom_help = _( u"The title should have at most ${maximum} significant words " u"(longer than 3 letters). ") return Message(symptom_help, mapping={'maximum': self.maximum})
def _update(self): title = self.context.Title() if len(title): self.status = title[0].isupper() self.description = _(u"Title does not begin with uppercase letter.")
def help(self): symptom_help = _( u"The summary (or description) should not be empty " u"and should have at most ${maximum} significant words " u"(longer than 3 letters). ") return Message(symptom_help, mapping={'maximum': self.maximum})
def status_title(self): return _(self.status_class)
def _update(self): self.status = hasImage(self.context) if self.status: self.description = _(u"Image field has content.") else: self.description = _(u"Image field does not have content.")
def _update(self): self.status = len(self.context.CookedBody(stx_level=2).strip()) if not self.status: self.description = _(u"Body text does not have content.")
def help(self): symptom_help = _( u"The body text should have at least ${minimum} links to other " u"pages. ") return Message(symptom_help, mapping={'minimum': self.minimum})
def _update(self): cooked = self.cache.setdefault('cooked_body', self.context.CookedBody(stx_level=2).strip()) self.status = len(cooked) if not self.status: self.description = _(u"Body text does not have content.")
def _update(self): description = self.context.Description() if len(description): self.status = description[0].isupper() self.description = _( u"Description does not begin with uppercase letter.")
def help(self): symptom_help = _(u"Id should not be more than ${maximum} chars long.") return Message(symptom_help, mapping={'maximum': self.maximum})