def unspoken_languages(self): """Return a formatted string of unspoken question languages. The string summarizes the questions that are in languages that no answer contact speaks. The string takes the form of an inline list with links to see the questions for each language: '_Hungarian_ (2), _Romanian_ (1)'. An empty string is returned when all questions are in a language spoken by the answer contacts. This method is relevant to QuestionTargets. Subclasses of this View that want to list unspoken languages for other objects must provide their own implementation. """ if not IQuestionTarget.providedBy(self.context): return '' language_counts = {} questions = self.context.searchQuestions(unsupported=self.context, status=[QuestionStatus.OPEN]) for question in questions: lang = question.language language_counts[lang] = language_counts.get(lang, 0) + 1 if len(language_counts) == 0: return '' url = canonical_url(self.context, rootsite='answers') format = (u'%s in <a href="' + url + u'/+by-language' u'?field.language=%s&field.status=Open">%s</a>') links = [ format % (language_counts[key], key.code, key.englishname) for key in language_counts ] return u', '.join(links)
def unspoken_languages(self): """Return a formatted string of unspoken question languages. The string summarizes the questions that are in languages that no answer contact speaks. The string takes the form of an inline list with links to see the questions for each language: '_Hungarian_ (2), _Romanian_ (1)'. An empty string is returned when all questions are in a language spoken by the answer contacts. This method is relevant to QuestionTargets. Subclasses of this View that want to list unspoken languages for other objects must provide their own implementation. """ if not IQuestionTarget.providedBy(self.context): return "" language_counts = {} questions = self.context.searchQuestions(unsupported=self.context, status=[QuestionStatus.OPEN]) for question in questions: lang = question.language language_counts[lang] = language_counts.get(lang, 0) + 1 if len(language_counts) == 0: return "" url = canonical_url(self.context, rootsite="answers") format = u'%s in <a href="' + url + u"/+by-language" u'?field.language=%s&field.status=Open">%s</a>' links = [format % (language_counts[key], key.code, key.englishname) for key in language_counts] return u", ".join(links)
def _getQuestionTarget(cls, target_name): """Return the `IQuestionTarget` to use. It returns the pillar with the target_name and makes sure it provides `IQuestionTarget`. """ assert isinstance(target_name, basestring), ("expected a project name: %r", target_name) target = getUtility(IPillarNameSet).getByName(target_name) assert target is not None, "No project with name %s" % target_name assert IQuestionTarget.providedBy(target), "%r doesn't provide IQuestionTarget" % target return target
def _getQuestionTarget(cls, target_name): """Return the `IQuestionTarget` to use. It returns the pillar with the target_name and makes sure it provides `IQuestionTarget`. """ assert isinstance(target_name, basestring), ("expected a project name: %r", target_name) target = getUtility(IPillarNameSet).getByName(target_name) assert target is not None, ('No project with name %s' % target_name) assert IQuestionTarget.providedBy(target), ( "%r doesn't provide IQuestionTarget" % target) return target
def __call__(self): # Check if the context has an +addquestion view available... if queryMultiAdapter((self.context, self.request), name='+addquestion'): target = self.context else: # otherwise find an adapter to IQuestionTarget which will. target = IQuestionTarget(self.context) return """ <div id="involvement" class="portlet involvement"> <ul> <li class="single"> <a class="menu-link-ask_question sprite answers" href="%s">Ask a question</a> </li> </ul> </div> """ % canonical_url( target, view_name='+addquestion', rootsite='answers')
def answercontact_data_js(self): """Return subscriber_ids in a form suitable for JavaScript use.""" questiontarget = IQuestionTarget(self.context) data = self.answercontact_data(questiontarget) return dumps(data)