Exemplo n.º 1
0
 def unit_info(self):
     info = {}
     if self.unit is None:
         return info
     info.update(
         dict(unit_source=truncatechars(self.unit_source, 50),
              unit_url=self.unit_translate_url))
     if self.qc_name is None:
         return info
     info.update(
         dict(check_name=self.qc_name,
              check_display_name=check_names.get(self.qc_name, self.qc_name),
              checks_url=reverse('pootle-checks-descriptions')))
     return info
Exemplo n.º 2
0
 def unit_info(self):
     info = {}
     if self.unit is None:
         return info
     info.update(
         dict(unit_source=truncatechars(self.unit_source, 50),
              unit_url=self.unit_translate_url))
     if self.qc_name is None:
         return info
     info.update(
         dict(check_name=self.qc_name,
              check_display_name=check_names.get(self.qc_name, self.qc_name),
              checks_url=reverse('pootle-checks-descriptions')))
     return info
Exemplo n.º 3
0
 def unit_info(self):
     info = {}
     if self.unit is None:
         return info
     info.update(
         dict(source=truncatechars(self.unit_source, 50),
              unit_url=self.unit_translate_url))
     if self.qc_name is None:
         return info
     info.update(
         dict(check_name=self.qc_name,
              check_displayname=check_names.get(self.qc_name,
                                                self.qc_name)))
     return info
Exemplo n.º 4
0
def test_get_qualitycheck_list(tp0):
    result = []
    checks = get_qualitychecks()
    for check, cat in checks.items():
        result.append({
            'code': check,
            'is_critical': cat == Category.CRITICAL,
            'title': u"%s" % check_names.get(check, check),
            'url': tp0.get_translate_url(check=check)
        })

    def alphabetical_critical_first(item):
        sort_prefix = 0 if item['is_critical'] else 1
        return "%d%s" % (sort_prefix, item['title'].lower())

    result = sorted(result, key=alphabetical_critical_first)

    assert result == get_qualitycheck_list(tp0)
Exemplo n.º 5
0
def test_get_qualitycheck_list(tp0):
    result = []
    checks = get_qualitychecks()
    for check, cat in checks.items():
        result.append({
            'code': check,
            'is_critical': cat == Category.CRITICAL,
            'title': u"%s" % check_names.get(check, check),
            'url': tp0.get_translate_url(check=check)
        })

    def alphabetical_critical_first(item):
        sort_prefix = 0 if item['is_critical'] else 1
        return "%d%s" % (sort_prefix, item['title'].lower())

    result = sorted(result, key=alphabetical_critical_first)

    assert result == get_qualitycheck_list(tp0)
Exemplo n.º 6
0
def get_filter_name(GET):
    """Gets current filter's human-readable name.

    :param GET: A copy of ``request.GET``.
    :return: Two-tuple with the filter name, and a list of extra arguments
        passed to the current filter.
    """
    filter = extra = None

    if "filter" in GET:
        filter = GET["filter"]

        if filter.startswith("user-"):
            extra = [GET.get("user", _("User missing"))]
        elif filter == "checks" and "checks" in GET:
            extra = [
                check_names.get(check, check)
                for check in GET["checks"].split(",")
            ]
    elif "search" in GET:
        filter = "search"

        extra = [GET["search"]]
        if "sfields" in GET:
            extra.extend(GET["sfields"].split(","))

    filter_name = {
        "all": _("All"),
        "translated": _("Translated"),
        "untranslated": _("Untranslated"),
        "fuzzy": _("Needs work"),
        "incomplete": _("Incomplete"),
        # Translators: This is the name of a filter
        "search": _("Search"),
        "checks": _("Checks"),
        "my-submissions": _("My submissions"),
        "user-submissions": _("Submissions"),
        "my-submissions-overwritten": _("My overwritten submissions"),
        "user-submissions-overwritten": _("Overwritten submissions"),
    }.get(filter)

    return (filter_name, extra)
Exemplo n.º 7
0
    def get_failing_checks_for_path(self, pootle_path):
        """Return a failed quality checks list sorted by importance.

        :param pootle_path: A string with a valid pootle path.
        """
        checks = []
        path_stats = self.get_raw_stats_for_path(pootle_path)
        goal_stores_for_path = self.get_stores_for_path(pootle_path)
        property_stats = completestatssum(goal_stores_for_path)
        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,
                    }
                    checks[i]['checks'].append(check)

        return checks
Exemplo n.º 8
0
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                "code": cat,
                "name": get_category_code(cat),
                "title": get_category_name(cat),
                "checks": [],
            }
        d[cat]["checks"].append(
            {"code": check, "title": u"%s" % check_names.get(check, check)}
        )
        d[cat]["checks"] = sorted(d[cat]["checks"], key=lambda x: x["code"])

    result = sorted(
        [item for item in d.values()], key=lambda x: x["code"], reverse=True
    )

    assert result == get_qualitycheck_schema()
Exemplo n.º 9
0
def get_filter_name(GET):
    """Get current filter's human-readable name.

    :param GET: A copy of ``request.GET``.
    :return: Two-tuple with the filter name, and a list of extra arguments
        passed to the current filter.
    """
    filter = extra = None

    if 'filter' in GET:
        filter = GET['filter']

        if filter.startswith('user-'):
            extra = [GET.get('user', _('User missing'))]
        elif filter == 'checks' and 'checks' in GET:
            extra = map(lambda check: check_names.get(check, check),
                        GET['checks'].split(','))
    elif 'search' in GET:
        filter = 'search'

        extra = [GET['search']]
        if 'sfields' in GET:
            extra.extend(GET['sfields'].split(','))

    filter_name = {
        'all': _('All'),
        'translated': _('Translated'),
        'untranslated': _('Untranslated'),
        'fuzzy': _('Needs work'),
        'incomplete': _('Incomplete'),
        # Translators: This is the name of a filter
        'search': _('Search'),
        'checks': _('Checks'),
        'my-submissions': _('My submissions'),
        'user-submissions': _('Submissions'),
        'my-submissions-overwritten': _('My overwritten submissions'),
        'user-submissions-overwritten': _('Overwritten submissions'),
    }.get(filter)

    return (filter_name, extra)
Exemplo n.º 10
0
def get_filter_name(GET):
    """Gets current filter's human-readable name.

    :param GET: A copy of ``request.GET``.
    :return: Two-tuple with the filter name, and a list of extra arguments
        passed to the current filter.
    """
    filter = extra = None

    if 'filter' in GET:
        filter = GET['filter']

        if filter.startswith('user-'):
            extra = [GET.get('user', _('User missing'))]
        elif filter == 'checks' and 'checks' in GET:
            extra = map(lambda check: check_names.get(check, check),
                        GET['checks'].split(','))
    elif 'search' in GET:
        filter = 'search'

        extra = [GET['search']]
        if 'sfields' in GET:
            extra.extend(GET['sfields'].split(','))

    filter_name = {
        'all': _('All'),
        'translated': _('Translated'),
        'untranslated': _('Untranslated'),
        'fuzzy': _('Needs work'),
        'incomplete': _('Incomplete'),
        # Translators: This is the name of a filter
        'search': _('Search'),
        'checks': _('Checks'),
        'my-submissions': _('My submissions'),
        'user-submissions': _('Submissions'),
        'my-submissions-overwritten': _('My overwritten submissions'),
        'user-submissions-overwritten': _('Overwritten submissions'),
    }.get(filter)

    return (filter_name, extra)
Exemplo n.º 11
0
def get_filter_name(GET):
    """Gets current filter's human-readable name.

    :param GET: A copy of ``request.GET``.
    :return: Two-tuple with the filter name, and a list of extra arguments
        passed to the current filter.
    """
    filter = extra = None

    if "filter" in GET:
        filter = GET["filter"]

        if filter.startswith("user-"):
            extra = [GET.get("user", _("User missing"))]
        elif filter == "checks" and "checks" in GET:
            extra = map(lambda check: check_names.get(check, check), GET["checks"].split(","))
    elif "search" in GET:
        filter = "search"

        extra = [GET["search"]]
        if "sfields" in GET:
            extra.extend(GET["sfields"].split(","))

    filter_name = {
        "all": _("All"),
        "translated": _("Translated"),
        "untranslated": _("Untranslated"),
        "fuzzy": _("Needs work"),
        "incomplete": _("Incomplete"),
        # Translators: This is the name of a filter
        "search": _("Search"),
        "checks": _("Checks"),
        "my-submissions": _("My submissions"),
        "user-submissions": _("Submissions"),
        "my-submissions-overwritten": _("My overwritten submissions"),
        "user-submissions-overwritten": _("Overwritten submissions"),
    }.get(filter)

    return (filter_name, extra)
Exemplo n.º 12
0
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                'code': cat,
                'name': get_category_code(cat),
                'title': get_category_name(cat),
                'checks': []
            }
        d[cat]['checks'].append({
            'code': check,
            'title': u"%s" % check_names.get(check, check),
            'url': ''
        })

    result = sorted([item for code, item in d.items()],
                    key=lambda x: x['code'],
                    reverse=True)

    assert result == get_qualitycheck_schema()
Exemplo n.º 13
0
def test_get_qualitycheck_schema():
    d = {}
    checks = get_qualitychecks()
    for check, cat in checks.items():
        if cat not in d:
            d[cat] = {
                'code': cat,
                'name': get_category_code(cat),
                'title': get_category_name(cat),
                'checks': []
            }
        d[cat]['checks'].append({
            'code': check,
            'title': u"%s" % check_names.get(check, check),
        })
        d[cat]['checks'] = sorted(d[cat]['checks'], key=lambda x: x['code'])

    result = sorted([item for item in d.values()],
                    key=lambda x: x['code'],
                    reverse=True)

    assert result == get_qualitycheck_schema()
Exemplo n.º 14
0
 def display_name(self):
     return check_names.get(self.name, self.name)
Exemplo n.º 15
0
    def get_submission_message(self):
        """Returns a message describing the submission.

        The message includes the user (with link to profile and gravatar), a
        message describing the action performed, and when it was performed.
        """
        unit = {}
        source = {}

        if self.unit is not None:
            unit = {
                'source': escape(truncatechars(self.unit, 50)),
                'url': self.unit.get_translate_url(),
            }
            source = {
                'source_string': '<i><a href="%(url)s">%(source)s</a></i>' %
                    unit,
            }

            if self.quality_check is not None:
                check_name = self.quality_check.name
                unit.update({
                    'check_name': check_name,
                    'check_display_name': check_names.get(check_name, check_name),
                    'checks_url': reverse('pootle-checks-descriptions'),
                })
                source.update({
                    'check_name': '<a href="%(checks_url)s#%(check_name)s">'
                                  '%(check_display_name)s</a>' % unit,
                })

        if (self.suggestion and
            self.type in (SubmissionTypes.SUGG_ACCEPT, SubmissionTypes.SUGG_REJECT)):
            displayuser = self.suggestion.reviewer
        else:
            # Sadly we may not have submitter information in all the
            # situations yet
            # TODO check if it is true
            if self.submitter:
                displayuser = self.submitter
            else:
                User = get_user_model()
                displayuser = User.objects.get_nobody_user()

        action_bundle = {
            "profile_url": displayuser.get_absolute_url(),
            "gravatar_url": displayuser.gravatar_url(20),
            "displayname": escape(displayuser.display_name),
            "username": displayuser.username,
            "display_datetime": dateformat.format(self.creation_time),
            "iso_datetime": self.creation_time.isoformat(),
            "action": "",
        }

        msg = {
            SubmissionTypes.REVERT: _(
                'reverted translation for %(source_string)s',
                source
            ),
            SubmissionTypes.SUGG_ACCEPT: _(
                'accepted suggestion for %(source_string)s',
                source
            ),
            SubmissionTypes.SUGG_ADD: _(
                'added suggestion for %(source_string)s',
                source
            ),
            SubmissionTypes.SUGG_REJECT: _(
                'rejected suggestion for %(source_string)s',
                source
            ),
            SubmissionTypes.UPLOAD: _(
                'uploaded a file'
            ),
            SubmissionTypes.MUTE_CHECK: _(
                'muted %(check_name)s for %(source_string)s',
                source
            ),
            SubmissionTypes.UNMUTE_CHECK: _(
                'unmuted %(check_name)s for %(source_string)s',
                source
            ),
        }.get(self.type, None)

        #TODO Look how to detect submissions for "sent suggestion", "rejected
        # suggestion"...

        #TODO Fix bug 3011 and replace the following code with the appropiate
        # one in the dictionary above.

        if msg is None:
            try:
                if self.field == SubmissionFields.TARGET:
                    if self.new_value != '':
                        # Note that we analyze current unit state:
                        # if this submission is not last unit state
                        # can be changed
                        if self.unit.state == TRANSLATED:
                            if self.old_value == '':
                                msg = _('translated %(source_string)s', source)
                            else:
                                msg = _('edited %(source_string)s', source)
                        elif self.unit.state == FUZZY:
                            if self.old_value == '':
                                msg = _('pre-translated %(source_string)s',
                                        source)
                            else:
                                msg = _('edited %(source_string)s', source)
                    else:
                        msg = _('removed translation for %(source_string)s',
                                source)
                elif self.field == SubmissionFields.STATE:
                    # Note that a submission where field is STATE
                    # should be created before a submission where
                    # field is TARGET
                    msg = {
                        TRANSLATED: _('reviewed %(source_string)s', source),
                        FUZZY: _('marked as needs work %(source_string)s', source)
                    }.get(int(to_python(self.new_value)), '')
                else:
                    msg = _('unknown action %(source_string)s', source)
            except AttributeError:
                return ''

        action_bundle['action'] = msg

        return mark_safe(
            u'<div class="last-action">'
            '  <a href="%(profile_url)s">'
            '    <img src="%(gravatar_url)s" />'
            '    <span title="%(username)s">%(displayname)s</span>'
            '  </a>'
            '  <span class="action-text">%(action)s</span>'
            '  <time class="extra-item-meta js-relative-date"'
            '    title="%(display_datetime)s" datetime="%(iso_datetime)s">&nbsp;'
            '  </time>'
            '</div>'
            % action_bundle)
Exemplo n.º 16
0
 def display_name(self):
     return check_names.get(self.name, self.name)
Exemplo n.º 17
0
    def get_submission_info(self):
        """Returns a dictionary describing the submission.

        The dict includes the user (with link to profile and gravatar),
        a type and translation_action_type describing the action performed,
        and when it was performed.
        """
        result = {}

        if self.unit is not None:
            result.update({
                'source': truncatechars(self.unit, 50),
                'uid': self.unit.id,
            })

            if self.quality_check is not None:
                check_name = self.quality_check.name
                result.update({
                    'check':
                    check_name,
                    'check_displayname':
                    check_names.get(check_name, check_name),
                })

        if (self.suggestion and self.type
                in (SubmissionTypes.SUGG_ACCEPT, SubmissionTypes.SUGG_REJECT)):
            displayuser = self.suggestion.reviewer
        else:
            # Sadly we may not have submitter information in all the
            # situations yet
            # TODO check if it is true
            if self.submitter:
                displayuser = self.submitter
            else:
                User = get_user_model()
                displayuser = User.objects.get_nobody_user()

        result.update({
            "email": displayuser.email_hash,
            "displayname": displayuser.display_name,
            "username": displayuser.username,
            "type": self.type,
            "mtime": int(dateformat.format(self.creation_time, 'U')),
        })

        # TODO Fix bug 3011 and remove the following code related to
        # TranslationActionTypes.

        if self.type in SubmissionTypes.EDIT_TYPES:
            translation_action_type = None
            try:
                if self.field == SubmissionFields.TARGET:
                    if self.new_value != '':
                        # Note that we analyze current unit state:
                        # if this submission is not last unit state
                        # can be changed
                        if self.unit.state == TRANSLATED:

                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                        elif self.unit.state == FUZZY:
                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.PRE_TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                    else:
                        translation_action_type = \
                            TranslationActionTypes.REMOVED
                elif self.field == SubmissionFields.STATE:
                    # Note that a submission where field is STATE
                    # should be created before a submission where
                    # field is TARGET

                    translation_action_type = {
                        TRANSLATED: TranslationActionTypes.REVIEWED,
                        FUZZY: TranslationActionTypes.NEEDS_WORK
                    }.get(int(to_python(self.new_value)), None)

            except AttributeError:
                return result

            result['translation_action_type'] = translation_action_type

        return result
Exemplo n.º 18
0
    def get_submission_info(self):
        """Returns a dictionary describing the submission.

        The dict includes the user (with link to profile and gravatar),
        a type and translation_action_type describing the action performed,
        and when it was performed.
        """
        result = {}

        if self.unit is not None:
            result.update({
                'unit_source': truncatechars(self.unit, 50),
                'unit_url': self.unit.get_translate_url(),
            })

            if self.quality_check is not None:
                check_name = self.quality_check.name
                result.update({
                    'check_name': check_name,
                    'check_display_name': check_names.get(check_name, check_name),
                    'checks_url': reverse('pootle-checks-descriptions'),
                })

        if (self.suggestion and
            self.type in (SubmissionTypes.SUGG_ACCEPT, SubmissionTypes.SUGG_REJECT)):
            displayuser = self.suggestion.reviewer
        else:
            # Sadly we may not have submitter information in all the
            # situations yet
            # TODO check if it is true
            if self.submitter:
                displayuser = self.submitter
            else:
                User = get_user_model()
                displayuser = User.objects.get_nobody_user()

        result.update({
            "profile_url": displayuser.get_absolute_url(),
            "email": displayuser.email_hash,
            "displayname": displayuser.display_name,
            "username": displayuser.username,
            "display_datetime": dateformat.format(self.creation_time),
            "iso_datetime": self.creation_time.isoformat(),
            "type": self.type,
            "mtime": int(dateformat.format(self.creation_time, 'U')),
        })

        #TODO Fix bug 3011 and remove the following code related
        # to TranslationActionTypes.

        if self.type in SubmissionTypes.EDIT_TYPES:
            translation_action_type = None
            try:
                if self.field == SubmissionFields.TARGET:
                    if self.new_value != '':
                        # Note that we analyze current unit state:
                        # if this submission is not last unit state
                        # can be changed
                        if self.unit.state == TRANSLATED:

                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                        elif self.unit.state == FUZZY:
                            if self.old_value == '':
                                translation_action_type = \
                                    TranslationActionTypes.PRE_TRANSLATED
                            else:
                                translation_action_type = \
                                    TranslationActionTypes.EDITED
                    else:
                        translation_action_type = TranslationActionTypes.REMOVED
                elif self.field == SubmissionFields.STATE:
                    # Note that a submission where field is STATE
                    # should be created before a submission where
                    # field is TARGET

                    translation_action_type = {
                        TRANSLATED: TranslationActionTypes.REVIEWED,
                        FUZZY: TranslationActionTypes.NEEDS_WORK
                    }.get(int(to_python(self.new_value)), None)

            except AttributeError:
                return result

            result['translation_action_type'] = translation_action_type

        return result