def make_project_item(translation_project): project = translation_project.project href = translation_project.pootle_path href_all = dispatch.translate(translation_project) href_todo = dispatch.translate(translation_project, state='incomplete') project_stats = get_raw_stats(translation_project) info = { 'code': project.code, 'href': href, 'href_all': href_all, 'href_todo': href_todo, 'title': project.fullname, 'description_html': project.description_html, 'stats': project_stats, 'lastactivity': get_last_action(translation_project), 'isproject': True, 'tooltip': _('%(percentage)d%% complete', {'percentage': project_stats['translated']['percentage']}), } errors = project_stats.get('errors', 0) if errors: info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors) info.update(stats_descriptions(project_stats)) return info
def make_generic_item(path_obj, action): """Template variables for each row in the table. :func:`make_directory_item` and :func:`make_store_item` will add onto these variables. """ try: stats = get_raw_stats(path_obj, include_suggestions=True) info = { 'href': action, 'href_all': dispatch.translate(path_obj), 'href_todo': dispatch.translate(path_obj, state='incomplete'), 'href_sugg': dispatch.translate(path_obj, state='suggestions'), 'stats': stats, 'tooltip': _('%(percentage)d%% complete', {'percentage': stats['translated']['percentage']}), 'title': path_obj.name, } errors = stats.get('errors', 0) if errors: info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors) info.update(stats_descriptions(stats)) except IOError, e: info = { 'href': action, 'title': path_obj.name, 'errortooltip': e.strerror, 'data': {'errors': 1}, }
def make_project_item(translation_project): project = translation_project.project href = translation_project.pootle_path href_all = dispatch.translate(translation_project) href_todo = dispatch.translate(translation_project, state='incomplete') project_stats = get_raw_stats(translation_project) info = { 'code': project.code, 'href': href, 'href_all': href_all, 'href_todo': href_todo, 'title': project.fullname, 'description': project.description, 'stats': project_stats, 'lastactivity': get_last_action(translation_project), 'isproject': True, 'tooltip': _('%(percentage)d%% complete', {'percentage': project_stats['translated']['percentage']}), } errors = project_stats.get('errors', 0) if errors: info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors) info.update(stats_descriptions(project_stats)) return info
def make_language_item(request, translation_project): href = '/%s/%s/' % (translation_project.language.code, translation_project.project.code) href_all = dispatch.translate(translation_project) href_todo = dispatch.translate(translation_project, state='incomplete') project_stats = get_raw_stats(translation_project) tooltip_dict = { 'percentage': project_stats['translated']['percentage'] } info = { 'code': translation_project.language.code, 'href': href, 'href_all': href_all, 'href_todo': href_todo, 'title': tr_lang(translation_project.language.fullname), 'stats': project_stats, 'lastactivity': get_last_action(translation_project), 'tooltip': _('%(percentage)d%% complete', tooltip_dict), } errors = project_stats.get('errors', 0) if errors: info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors) info.update(stats_descriptions(project_stats)) return info
def get_quality_check_failures(path_obj, path_stats, include_url=True): """Returns a list of the failed checks sorted by their importance. :param path_obj: An object which has the ``getcompletestats`` method. :param path_stats: A dictionary of raw stats, as returned by :func:`pootle_misc.stats.get_raw_stats`. :param include_url: Whether to include URLs in the returning result or not. """ checks = [] try: property_stats = path_obj.getcompletestats() total = path_stats['total']['units'] keys = property_stats.keys() keys.sort(reverse=True) for i, category in enumerate(keys): checks.append({ 'checks': [] }) if category != Category.NO_CATEGORY: checks[i].update({ 'name': category, 'display_name': unicode(category_names[category]), }) cat_keys = property_stats[category].keys() cat_keys.sort() for checkname in cat_keys: checkcount = property_stats[category][checkname] if total and checkcount: check_display = unicode(check_names.get(checkname, checkname)) check = { 'name': checkname, 'display_name': check_display, 'count': checkcount } if include_url: check['url'] = dispatch.translate(path_obj, check=checkname) checks[i]['checks'].append(check) except IOError: pass return checks
def get_quality_check_failures(path_obj, path_stats, include_url=True): """Returns a list of the failed checks sorted by their importance. :param path_obj: An object which has the ``getcompletestats`` method. :param path_stats: A dictionary of raw stats, as returned by :func:`pootle_misc.stats.get_raw_stats`. :param include_url: Whether to include URLs in the returning result or not. """ checks = [] try: property_stats = path_obj.getcompletestats() total = path_stats['total']['units'] keys = property_stats.keys() keys.sort(reverse=True) for i, category in enumerate(keys): checks.append({'checks': []}) if category != Category.NO_CATEGORY: checks[i].update({ 'name': category, 'display_name': unicode(category_names[category]), }) cat_keys = property_stats[category].keys() cat_keys.sort() for checkname in cat_keys: checkcount = property_stats[category][checkname] if total and checkcount: check_display = unicode( check_names.get(checkname, checkname)) check = { 'name': checkname, 'display_name': check_display, 'count': checkcount } if include_url: check['url'] = dispatch.translate(path_obj, check=checkname) checks[i]['checks'].append(check) except IOError: pass return checks
def make_language_item(request, translation_project): href = '/%s/%s/' % (translation_project.language.code, translation_project.project.code) href_all = dispatch.translate(translation_project) href_todo = dispatch.translate(translation_project, state='incomplete') project_stats = get_raw_stats(translation_project) info = { 'code': translation_project.language.code, 'href': href, 'href_all': href_all, 'href_todo': href_todo, 'title': tr_lang(translation_project.language.fullname), 'stats': project_stats, 'lastactivity': get_last_action(translation_project), 'tooltip': _('%(percentage)d%% complete', {'percentage': project_stats['translated']['percentage']}), } errors = project_stats.get('errors', 0) if errors: info['errortooltip'] = ungettext('Error reading %d file', 'Error reading %d files', errors, errors) info.update(stats_descriptions(project_stats)) return info
def make_stats_dict(title, state, filter_url=True): filter_name = filter_url and state or None return { 'title': title, 'words': ungettext('<a href="%(url)s">%(num)d word</a>', '<a href="%(url)s">%(num)d words</a>', path_stats['untranslated']['words'], {'url': dispatch.translate(path_obj, state=filter_name), 'num': path_stats[state]['words']}), 'percentage': _("%(num)d%%", {'num': path_stats[state]['percentage']}), 'units': ungettext("(%(num)d string)", "(%(num)d strings)", path_stats[state]['units'], {'num': path_stats[state]['units']}) }
def make_stats_dict(title, state, filter_url=True): filter_name = filter_url and state or None return { 'title': title, 'words': ungettext( '<a href="%(url)s">%(num)d word</a>', '<a href="%(url)s">%(num)d words</a>', path_stats['untranslated']['words'], { 'url': dispatch.translate(path_obj, state=filter_name), 'num': path_stats[state]['words'] }), 'percentage': _("%(num)d%%", {'num': path_stats[state]['percentage']}), 'units': ungettext("(%(num)d string)", "(%(num)d strings)", path_stats[state]['units'], {'num': path_stats[state]['units']}) }
def get_path_summary(path_obj, path_stats): """Returns a list of sentences to be displayed for each ``path_obj``.""" summary = [] incomplete = [] suggestions = [] if path_obj.is_dir: summary.append( ungettext("This folder has %(num)d word, %(percentage)d%% of " "which is translated.", "This folder has %(num)d words, %(percentage)d%% of " "which are translated.", path_stats['total']['words'], { 'num': path_stats['total']['words'], 'percentage': path_stats['translated']['percentage'] }) ) else: summary.append( ungettext("This file has %(num)d word, %(percentage)d%% of " "which is translated.", "This file has %(num)d words, %(percentage)d%% of " "which are translated.", path_stats['total']['words'], { 'num': path_stats['total']['words'], 'percentage': path_stats['translated']['percentage'] }) ) tp = path_obj.translation_project project = tp.project language = tp.language # Build URL for getting more summary information for the current path url_args = [language.code, project.code, path_obj.path] url_path_summary_more = reverse('tp.path_summary_more', args=url_args) summary.append(u''.join([ ' <a id="js-path-summary" data-target="js-path-summary-more" ' 'href="%s">' % url_path_summary_more, force_unicode(_(u'Expand details')), '</a>' ])) if path_stats['untranslated']['words'] > 0 or path_stats['fuzzy']['words'] > 0: num_words = path_stats['untranslated']['words'] + path_stats['fuzzy']['words'] incomplete.extend([ u'<a class="path-incomplete" href="%(url)s">' % { 'url': dispatch.translate(path_obj, state='incomplete') }, ungettext(u'Continue translation (%(num)d word left)', u'Continue translation (%(num)d words left)', num_words, {'num': num_words,}), ]) else: incomplete.extend([ u'<a class="path-incomplete" href="%(url)s">' % { 'url': dispatch.translate(path_obj, state='all') }, force_unicode(_('Translation is complete')), ]) incomplete.append(u'</a>') if path_stats['suggestions'] > 0: suggestions.append(u'<a class="path-incomplete" href="%(url)s">' % { 'url': dispatch.translate(path_obj, state='suggestions') }) suggestions.append( ungettext(u'Review suggestion (%(num)d left)', u'Review suggestions (%(num)d left)', path_stats['suggestions'], {'num': path_stats['suggestions'],}) ) suggestions.append(u'</a>') return [u''.join(summary), u''.join(incomplete), u''.join(suggestions)]
def contributions(self): """Get user contributions grouped by language and project. :return: List of tuples containing the following information:: [ ('Language 1', [ ('Project 1', [ { 'id': 'foo-bar', 'count': 0, 'url': 'foo/bar', }, { 'id': 'bar-foo', 'count': 3, 'url': 'baz/blah', }, { 'id': 'baz-blah', 'count': 5, 'url': 'bar/baz', }, ]), ('Project 2', [ ... ]), ]), ('LanguageN', [ ('Project N', [ ... ]), ('Project N+1', [ ... ]), ]), ] """ # TODO: optimize — we need a schema that helps reduce the number # of needed queries for these kind of data retrievals contributions = [] username = self.user.username languages = Language.objects.filter( translationproject__submission__submitter=self, translationproject__submission__type=SubmissionTypes.NORMAL, ).distinct() for language in languages: translation_projects = TranslationProject.objects.filter( language=language, submission__submitter=self, submission__type=SubmissionTypes.NORMAL, ).distinct().order_by('project__fullname') tp_user_stats = [] # Retrieve tp-specific stats for this user for tp in translation_projects: tp_stats = [ { 'id': 'suggestions-pending', 'count': self.pending_suggestion_count(tp), 'url': dispatch.translate(tp, 'user-suggestions', user=username), }, { 'id': 'suggestions-accepted', 'count': self.accepted_suggestion_count(tp), 'url': dispatch.translate( tp, 'user-suggestions-accepted', user=username, ), }, { 'id': 'suggestions-rejected', 'count': self.rejected_suggestion_count(tp), 'url': dispatch.translate( tp, 'user-suggestions-rejected', user=username, ), }, { 'id': 'submissions-total', 'count': self.total_submission_count(tp), 'url': dispatch.translate(tp, 'user-submissions', user=username), }, { 'id': 'submissions-overwritten', 'count': self.overwritten_submission_count(tp), 'url': dispatch.translate( tp, 'user-submissions-overwritten', user=username, ), }, ] tp_user_stats.append((tp, tp_stats)) contributions.append((language, tp_user_stats)) return contributions
def get_path_summary(path_obj, path_stats): """Returns a list of sentences to be displayed for each ``path_obj``.""" summary = [] incomplete = [] suggestions = [] if path_obj.is_dir: summary.append( ungettext( "This folder has %(num)d word, %(percentage)d%% of " "which is translated.", "This folder has %(num)d words, %(percentage)d%% of " "which are translated.", path_stats['total']['words'], { 'num': path_stats['total']['words'], 'percentage': path_stats['translated']['percentage'] })) else: summary.append( ungettext( "This file has %(num)d word, %(percentage)d%% of " "which is translated.", "This file has %(num)d words, %(percentage)d%% of " "which are translated.", path_stats['total']['words'], { 'num': path_stats['total']['words'], 'percentage': path_stats['translated']['percentage'] })) tp = path_obj.translation_project project = tp.project language = tp.language # Build URL for getting more summary information for the current path url_args = [language.code, project.code, path_obj.path] url_path_summary_more = reverse('tp.path_summary_more', args=url_args) summary.append(u''.join([ ' <a id="js-path-summary" data-target="js-path-summary-more" ' 'href="%s">' % url_path_summary_more, force_unicode(_(u'Expand details')), '</a>' ])) if path_stats['untranslated']['words'] > 0 or path_stats['fuzzy'][ 'words'] > 0: num_words = path_stats['untranslated']['words'] + path_stats['fuzzy'][ 'words'] incomplete.extend([ u'<a class="path-incomplete" href="%(url)s">' % { 'url': dispatch.translate(path_obj, state='incomplete') }, ungettext(u'Continue translation (%(num)d word left)', u'Continue translation (%(num)d words left)', num_words, { 'num': num_words, }), ]) else: incomplete.extend([ u'<a class="path-incomplete" href="%(url)s">' % { 'url': dispatch.translate(path_obj, state='all') }, force_unicode(_('Translation is complete')), ]) incomplete.append(u'</a>') if path_stats['suggestions'] > 0: suggestions.append( u'<a class="path-incomplete" href="%(url)s">' % {'url': dispatch.translate(path_obj, state='suggestions')}) suggestions.append( ungettext(u'Review suggestion (%(num)d left)', u'Review suggestions (%(num)d left)', path_stats['suggestions'], { 'num': path_stats['suggestions'], })) suggestions.append(u'</a>') return [u''.join(summary), u''.join(incomplete), u''.join(suggestions)]