Example #1
0
def make_generic_item(request, path_obj, action, include_suggestions=False,
                      terminology=False):
    """Template variables for each row in the table.

    make_directory_item() and make_store_item() will add onto these variables."""
    try:
        stats = get_raw_stats(path_obj, include_suggestions)
        quick_stats = add_percentages(path_obj.getquickstats())
        info = {
            'href': action,
            '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,
            'summary': get_item_stats(request, quick_stats, path_obj, terminology),
        }

        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},
            }
Example #2
0
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},
            }
Example #3
0
File: views.py Project: kant/pootle
def path_summary_more(request, translation_project, dir_path, filename=None):
    """Returns an HTML snippet with more detailed summary information
       for the current path."""
    current_path = translation_project.directory.pootle_path + dir_path

    if filename:
        current_path = current_path + filename
        store = get_object_or_404(Store, pootle_path=current_path)
        directory = store.parent
    else:
        directory = get_object_or_404(Directory, pootle_path=current_path)
        store = None

    path_obj = store or directory

    path_stats = get_raw_stats(path_obj)
    translation_stats = get_translation_stats(path_obj, path_stats)
    quality_checks = get_quality_check_failures(path_obj, path_stats)

    context = {
        'check_failures': quality_checks,
        'trans_stats': translation_stats,
    }

    return render_to_response('translation_project/xhr-path_summary.html',
                              context, RequestContext(request))
Example #4
0
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
Example #5
0
def make_project_item(translation_project):
    project = translation_project.project
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(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
Example #6
0
def make_language_item(request, translation_project):
    href = '/%s/%s/' % (translation_project.language.code,
                        translation_project.project.code)
    href_todo = dispatch.translate(translation_project, state='incomplete')

    project_stats = get_raw_stats(translation_project)

    info = {
        'code':
        translation_project.language.code,
        'href':
        href,
        '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
Example #7
0
def get_items(request, model, get_last_action, name_func):
    items = []
    if not check_permission('view', request):
        return items

    for item in model.objects.iterator():
        stats = get_raw_stats(item)

        translated_percentage = stats['translated']['percentage']
        items.append({
            'code':
            item.code,
            'name':
            name_func(item.fullname),
            'lastactivity':
            get_last_action(item),
            'stats':
            stats,
            'completed_title':
            _("%(percentage)d%% complete",
              {'percentage': translated_percentage}),
        })

    items.sort(lambda x, y: locale.strcoll(x['name'], y['name']))

    return items
Example #8
0
def make_language_item(translation_project):
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(state='incomplete')

    project_stats = get_raw_stats(translation_project)

    tooltip_dict = {
        'percentage': project_stats['translated']['percentage']
    }

    info = {
        'project': translation_project.project.code,
        '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),
        'tags': translation_project.tag_like_objects,
        'pk': translation_project.pk,
        '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
Example #9
0
    def GET(self, template_vars, request, translation_project, directory):
        user_profile = get_profile(request.user)
        tp_dir = translation_project.directory

        project = translation_project.project
        language = translation_project.language
        is_terminology = project.is_terminology
        description = translation_project.description

        directory_stats = get_raw_stats(directory)
        directory_summary = get_directory_summary(directory, directory_stats)

        template_vars.update({
            'translation_project': translation_project,
            'description': description,
            'project': project,
            'language': language,
            'directory': directory,
            'children': get_children(request, translation_project, directory),
            'dir_summary': directory_summary,
            'stats': directory_stats,
            'stats_headings': get_stats_headings(),
            'topstats': gentopstats_translation_project(translation_project),
            'feed_path': directory.pootle_path[1:],
        })

        if check_permission('administrate', request):
            from pootle_translationproject.forms import DescriptionForm
            template_vars['form'] = DescriptionForm(instance=translation_project)

        return template_vars
Example #10
0
def path_summary_more(request, translation_project, dir_path, filename=None):
    """Returns an HTML snippet with more detailed summary information
       for the current path."""
    current_path = translation_project.directory.pootle_path + dir_path

    if filename:
        current_path = current_path + filename
        store = get_object_or_404(Store, pootle_path=current_path)
        directory = store.parent
    else:
        directory = get_object_or_404(Directory, pootle_path=current_path)
        store = None

    path_obj = store or directory

    path_stats = get_raw_stats(path_obj)
    translation_stats = get_translation_stats(path_obj, path_stats)
    quality_checks = get_quality_check_failures(path_obj, path_stats)

    context = {
        'check_failures': quality_checks,
        'trans_stats': translation_stats,
    }

    return render_to_response('translation_project/xhr-path_summary.html',
                              context, RequestContext(request))
Example #11
0
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
Example #12
0
def make_project_item(translation_project):
    project = translation_project.project
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(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
Example #13
0
def make_generic_item(path_obj):
    """Template variables for each row in the table.

    :func:`make_directory_item` and :func:`make_store_item` will add onto these
    variables.
    """
    action = path_obj.pootle_path
    try:
        stats = get_raw_stats(path_obj, include_suggestions=True)
        info = {
            "href": action,
            "href_all": path_obj.get_translate_url(),
            "href_todo": path_obj.get_translate_url(state="incomplete"),
            "href_sugg": path_obj.get_translate_url(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 as e:
        info = {"href": action, "errortooltip": e.strerror, "data": {"errors": 1}, "title": path_obj.name}

    return info
Example #14
0
def make_language_item(request, translation_project):
    href = translation_project.get_absolute_url()
    href_all = translation_project.get_translate_url()
    href_todo = translation_project.get_translate_url(state='incomplete')

    project_stats = get_raw_stats(translation_project)

    tooltip_dict = {'percentage': project_stats['translated']['percentage']}

    info = {
        'project': translation_project.project.code,
        '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),
        'tags': translation_project.tags.all().order_by('name'),
        'pk': translation_project.pk,
        '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
Example #15
0
    def GET(self, template_vars, request, translation_project, directory,
            store=None):
        can_edit = check_permission('administrate', request)

        project = translation_project.project
        language = translation_project.language

        path_obj = store or directory

        path_stats = get_raw_stats(path_obj, include_suggestions=True)
        path_summary = get_path_summary(path_obj, path_stats)
        actions = action_groups(request, path_obj, path_stats=path_stats)

        template_vars.update({
            'translation_project': translation_project,
            'project': project,
            'language': language,
            'directory': directory,
            'path_summary': path_summary,
            'stats': path_stats,
            'topstats': gentopstats_translation_project(translation_project),
            'feed_path': directory.pootle_path[1:],
            'action_groups': actions,
            'can_edit': can_edit,
        })

        if store is not None:
            template_vars.update({
                'store': store
            })
        else:
            table_fields = ['name', 'progress', 'total', 'need-translation',
                            'suggestions']
            template_vars.update({
                'table': {
                    'id': 'tp',
                    'proportional': True,
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'items': get_children(translation_project, directory),
                }
            })

            # If current directory is the TP root directory.
            if not directory.path:
                template_vars.update({
                    'latest_action': translation_project.get_latest_submission()
                })
            else:
                template_vars.update({
                    'latest_action': Submission.get_latest_for_dir(path_obj)
                })

        if can_edit:
            from pootle_translationproject.forms import DescriptionForm
            template_vars['form'] = DescriptionForm(instance=translation_project)

        return template_vars
Example #16
0
    def GET(self,
            template_vars,
            request,
            translation_project,
            directory,
            store=None):
        can_edit = check_permission('administrate', request)

        project = translation_project.project
        language = translation_project.language

        path_obj = store or directory

        path_stats = get_raw_stats(path_obj, include_suggestions=True)
        path_summary = get_path_summary(path_obj, path_stats)
        actions = action_groups(request, path_obj, path_stats=path_stats)

        template_vars.update({
            'translation_project':
            translation_project,
            'project':
            project,
            'language':
            language,
            'directory':
            directory,
            'path_summary':
            path_summary,
            'stats':
            path_stats,
            'stats_headings':
            get_stats_headings(),
            'topstats':
            gentopstats_translation_project(translation_project),
            'feed_path':
            directory.pootle_path[1:],
            'action_groups':
            actions,
            'can_edit':
            can_edit,
        })

        if store is not None:
            template_vars.update({'store': store})
        else:
            template_vars.update({
                'children':
                get_children(request, translation_project, directory)
            })

        if can_edit:
            from pootle_translationproject.forms import DescriptionForm
            template_vars['form'] = DescriptionForm(
                instance=translation_project)

        return template_vars
Example #17
0
def project_language_index(request, project_code):
    """page listing all languages added to project"""
    project = get_object_or_404(Project, code=project_code)
    request.permissions = get_matching_permissions(
            get_profile(request.user), project.directory
    )

    if not check_permission('view', request):
        raise PermissionDenied

    can_edit = check_permission('administrate', request)

    translation_projects = project.translationproject_set.all()

    items = [make_language_item(request, translation_project) \
            for translation_project in translation_projects.iterator()]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    languagecount = len(translation_projects)
    project_stats = get_raw_stats(project)
    average = project_stats['translated']['percentage']

    topstats = gentopstats_project(project)

    table_fields = ['name', 'progress', 'total', 'need-translation', 'activity']
    table = {
        'id': 'project',
        'proportional': False,
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    templatevars = {
        'project': {
          'code': project.code,
          'name': project.fullname,
          'description': project.description,
          'summary': ungettext('%(languages)d language, %(average)d%% translated',
                               '%(languages)d languages, %(average)d%% translated',
                               languagecount, {"languages": languagecount,
                                               "average": average}),
        },
        'topstats': topstats,
        'can_edit': can_edit,
        'table': table,
    }

    if can_edit:
        from pootle_project.forms import DescriptionForm
        templatevars['form'] = DescriptionForm(instance=project)

    return render_to_response('project/project.html', templatevars,
                              context_instance=RequestContext(request))
Example #18
0
def get_project_base_template_vars(request, project, can_edit):
    """Get the base template vars for project overview view."""
    translation_projects = project.translationproject_set.all()

    filters, tags_filter_form = handle_tags_filter_form(
        request, translation_projects)

    if filters is not None:
        for tag in filters:
            # This looks pretty scary, but couldn't manage to get it working
            # using Q objects in a single filter.
            translation_projects = translation_projects.filter(tags__in=[tag])
        translation_projects = translation_projects.distinct()

    items = [make_language_item(request, translation_project) \
            for translation_project in translation_projects.iterator()]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    languagecount = len(translation_projects)
    project_stats = get_raw_stats(project)

    summary_dict = {
        "languages": languagecount,
        "average": project_stats['translated']['percentage'],
    }

    summary = ungettext('%(languages)d language, %(average)d%% translated',
                        '%(languages)d languages, %(average)d%% translated',
                        languagecount, summary_dict)

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'activity', 'tags'
    ]

    template_vars = {
        'project': {
            'code': project.code,
            'name': project.fullname,
            'description': project.description,
            'summary': summary,
        },
        'topstats': gentopstats_project(project),
        'can_edit': can_edit,
        'table': {
            'id': 'project',
            'proportional': False,
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'tags_filter_form': tags_filter_form,
    }

    return template_vars
Example #19
0
def get_project_base_template_vars(request, project, can_edit):
    """Get the base template vars for project overview view."""
    translation_projects = project.translationproject_set.all()

    filters, tags_filter_form = handle_tags_filter_form(request,
                                                        translation_projects)

    if filters is not None:
        for tag in filters:
            # This looks pretty scary, but couldn't manage to get it working
            # using Q objects in a single filter.
            translation_projects = translation_projects.filter(tags__in=[tag])
        translation_projects = translation_projects.distinct()

    items = [make_language_item(translation_project) \
            for translation_project in translation_projects.iterator()]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    languagecount = len(translation_projects)
    project_stats = get_raw_stats(project)

    summary_dict = {
        "languages": languagecount,
        "average": project_stats['translated']['percentage'],
    }

    summary = ungettext('%(languages)d language, %(average)d%% translated',
                        '%(languages)d languages, %(average)d%% translated',
                        languagecount, summary_dict)

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'activity', 'tags']

    template_vars = {
        'project': {
            'code': project.code,
            'name': project.fullname,
            'description': project.description,
            'summary': summary,
        },
        'topstats': gentopstats_project(project),
        'can_edit': can_edit,
        'table': {
            'id': 'project',
            'proportional': False,
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'tags_filter_form': tags_filter_form,
    }

    return template_vars
Example #20
0
def get_failing_checks(request, pathobj):
    """Gets a list of failing checks for the current object.

    :return: JSON string with a list of failing check categories which
             include the actual checks that are failing.
    """
    stats = get_raw_stats(pathobj)
    failures = get_quality_check_failures(pathobj, stats, include_url=False)

    response = jsonify(failures)

    return HttpResponse(response, mimetype="application/json")
Example #21
0
def project_language_index(request, project_code):
    """page listing all languages added to project"""
    project = get_object_or_404(Project, code=project_code)
    request.permissions = get_matching_permissions(get_profile(request.user),
                                                   project.directory)

    if not check_permission('view', request):
        raise PermissionDenied

    can_edit = check_permission('administrate', request)

    translation_projects = project.translationproject_set.all()

    items = [make_language_item(request, translation_project) \
            for translation_project in translation_projects.iterator()]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    languagecount = len(translation_projects)
    project_stats = get_raw_stats(project)
    average = project_stats['translated']['percentage']

    topstats = gentopstats_project(project)

    templatevars = {
        'project': {
            'code':
            project.code,
            'name':
            project.fullname,
            'description_html':
            project.description_html,
            'summary':
            ungettext('%(languages)d language, %(average)d%% translated',
                      '%(languages)d languages, %(average)d%% translated',
                      languagecount, {
                          "languages": languagecount,
                          "average": average
                      }),
        },
        'languages': items,
        'topstats': topstats,
        'statsheadings': get_stats_headings(),
        'can_edit': can_edit,
    }

    if can_edit:
        from pootle_project.forms import DescriptionForm
        templatevars['form'] = DescriptionForm(instance=project)

    return render_to_response('project/project.html',
                              templatevars,
                              context_instance=RequestContext(request))
Example #22
0
    def GET(self, template_vars, request, translation_project, directory,
            store=None):
        user_profile = get_profile(request.user)
        tp_dir = translation_project.directory
        can_edit = check_permission('administrate', request)

        project = translation_project.project
        language = translation_project.language
        is_terminology = project.is_terminology

        path_obj = store or directory

        # Build URL for getting more summary information for the current path
        url_args = [language.code, project.code, directory.path]
        if store:
            url_args.append(store.name)
        url_path_summary_more = reverse('tp.path_summary_more', args=url_args)

        path_stats = get_raw_stats(path_obj, include_suggestions=True)
        path_summary = get_path_summary(path_obj, path_stats)

        template_vars.update({
            'translation_project': translation_project,
            'project': project,
            'language': language,
            'directory': directory,
            'path_summary': path_summary,
            'url_path_summary_more': url_path_summary_more,
            'stats': path_stats,
            'stats_headings': get_stats_headings(),
            'topstats': gentopstats_translation_project(translation_project),
            'feed_path': directory.pootle_path[1:],
            'action_groups': action_groups(request, path_obj),
            'can_edit': can_edit,
        })

        if store is not None:
            template_vars.update({
                'store': store
            })
        else:
            template_vars.update({
                'children': get_children(request, translation_project,
                                         directory)
            })

        if can_edit:
            from pootle_translationproject.forms import DescriptionForm
            template_vars['form'] = DescriptionForm(instance=translation_project)

        return template_vars
Example #23
0
def tp_dir_summary(request, translation_project, dir_path):
    current_path = translation_project.directory.pootle_path + dir_path
    directory = get_object_or_404(Directory, pootle_path=current_path)

    directory_stats = get_raw_stats(directory)
    translation_stats = get_translation_stats(directory, directory_stats)
    quality_checks = get_quality_check_failures(directory, directory_stats)

    context = {
        'check_failures': quality_checks,
        'trans_stats': translation_stats,
    }

    return render_to_response('translation_project/xhr-dir_summary.html',
                              context, RequestContext(request))
Example #24
0
def get_failing_checks(request, path_obj):
    """Gets a list of failing checks for the current object.

    :return: JSON string with a list of failing check categories which
             include the actual checks that are failing.
    """
    if "goal" in request.GET and request.GET["goal"]:
        try:
            goal = Goal.objects.get(slug=request.GET["goal"])
        except Goal.DoesNotExist:
            raise Http404
        failures = goal.get_failing_checks_for_path(path_obj.pootle_path)
    else:
        stats = get_raw_stats(path_obj)
        failures = get_quality_check_failures(path_obj, stats, include_url=False)

    response = jsonify(failures)

    return HttpResponse(response, mimetype="application/json")
Example #25
0
def get_items(request, model, get_last_action, name_func):

    items = []
    if not check_permission('view', request):
        return items

    for item in model.objects.iterator():
        stats = get_raw_stats(item)

        items.append({
            'code': item.code,
            'name': name_func(item.fullname),
            'lastactivity': get_last_action(item),
            'stats': stats,
            'completed_title': _("%(percentage)d%% complete",
                                 {'percentage': stats['translated']['percentage']}),
            })
    items.sort(lambda x, y: locale.strcoll(x['name'], y['name']))
    return items
Example #26
0
def get_project_base_template_vars(request, project, can_edit):
    """Get the base template vars for project overview view."""
    translation_projects = project.translationproject_set.all()

    items = [make_language_item(translation_project) \
            for translation_project in translation_projects.iterator()]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    languagecount = len(translation_projects)
    project_stats = get_raw_stats(project)

    summary_dict = {
        "languages": languagecount,
        "average": project_stats['translated']['percentage'],
    }

    summary = ungettext('%(languages)d language, %(average)d%% translated',
                        '%(languages)d languages, %(average)d%% translated',
                        languagecount, summary_dict)

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'activity', 'tags']

    template_vars = {
        'project': {
            'code': project.code,
            'name': project.fullname,
            'description': project.description,
            'summary': summary,
        },
        'topstats': gentopstats_project(project),
        'can_edit': can_edit,
        'table': {
            'id': 'project',
            'proportional': False,
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
    }

    return template_vars
Example #27
0
File: views.py Project: notz/pootle
    def GET(self, template_vars, request, translation_project, directory,
            store=None):
        can_edit = check_permission('administrate', request)

        project = translation_project.project
        language = translation_project.language

        path_obj = store or directory

        path_stats = get_raw_stats(path_obj, include_suggestions=True)
        path_summary = get_path_summary(path_obj, path_stats)
        actions = action_groups(request, path_obj, path_stats=path_stats)

        template_vars.update({
            'translation_project': translation_project,
            'project': project,
            'language': language,
            'directory': directory,
            'path_summary': path_summary,
            'stats': path_stats,
            'stats_headings': get_stats_headings(),
            'topstats': gentopstats_translation_project(translation_project),
            'feed_path': directory.pootle_path[1:],
            'action_groups': actions,
            'can_edit': can_edit,
        })

        if store is not None:
            template_vars.update({
                'store': store
            })
        else:
            template_vars.update({
                'children': get_children(request, translation_project,
                                         directory)
            })

        if can_edit:
            from pootle_translationproject.forms import DescriptionForm
            template_vars['form'] = DescriptionForm(instance=translation_project)

        return template_vars
Example #28
0
def make_generic_item(request, path_obj, action, include_suggestions=False, terminology=False):
    """Template variables for each row in the table.

    make_directory_item() and make_store_item() will add onto these variables."""
    try:
        stats = get_raw_stats(path_obj, include_suggestions)
        info = {
            "href": action,
            "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,
            "summary": get_item_stats(request, stats, path_obj, terminology),
        }

        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}}
Example #29
0
def overview(request, translation_project, dir_path, filename=None,
             goal=None, in_goal_overview=False):
    current_path = translation_project.directory.pootle_path + dir_path

    if filename:
        current_path = current_path + filename
        store = get_object_or_404(Store, pootle_path=current_path)
        directory = store.parent
        template_vars = {
            'store_tags': store.tag_like_objects,
        }
        template = "translation_project/store_overview.html"
    else:
        store = None
        directory = get_object_or_404(Directory, pootle_path=current_path)
        template_vars = {
            'tp_tags': translation_project.tag_like_objects,
        }
        template = "translation_project/overview.html"

    if (check_permission('translate', request) or
        check_permission('suggest', request) or
        check_permission('overwrite', request)):

        template_vars.update({
            'upload_form': _handle_upload_form(request, current_path,
                                               translation_project, directory),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    path_obj = store or directory

    latest_action = ''
    # If current directory is the TP root directory.
    if not directory.path:
        latest_action = translation_project.get_latest_submission()
    elif store is None:  # If this is not a file.
        latest_action = Submission.get_latest_for_dir(path_obj)

    path_stats = get_raw_stats(path_obj, include_suggestions=True)
    path_summary = get_path_summary(path_obj, path_stats, latest_action)

    #TODO enable again some actions when drilling down a goal.
    if goal is None:
        actions = action_groups(request, path_obj, path_stats=path_stats)
    else:
        actions = []

    action_output = ''
    running = request.GET.get(EXTDIR, '')

    #TODO enable the following again when drilling down a goal.
    if running and goal is None:
        if store:
            act = StoreAction
        else:
            act = TranslationProjectAction
        try:
            action = act.lookup(running)
        except KeyError:
            messages.error(request, _("Unable to find '%(action)s' in '%(extdir)s'") %
                                      {'action': act, 'extdir': running})
        else:
            if not getattr(action, 'nosync', False):
                (store or translation_project).sync()
            if action.is_active(request):
                vcs_dir = settings.VCS_DIRECTORY
                po_dir = settings.PODIRECTORY
                tp_dir = directory.get_real_path()
                store_fn = '*'
                if store:
                    tp_dir_slash = add_trailing_slash(tp_dir)
                    if store.file.name.startswith(tp_dir_slash):
                        # Note: store_f used below in reverse() call.
                        store_f = store.file.name[len(tp_dir_slash):]
                        store_fn = store_f.replace('/', os.sep)

                # Clear possibly stale output/error (even from other path_obj).
                action.set_output('')
                action.set_error('')
                try:
                    action.run(path=path_obj, root=po_dir, tpdir=tp_dir,
                               project=project.code, language=language.code,
                               store=store_fn,
                               style=translation_project.file_style,
                               vc_root=vcs_dir)
                except StandardError:
                    err = (_("Error while running '%s' extension action") %
                           action.title)
                    logging.exception(err)
                    if (action.error):
                        messages.error(request, action.error)
                    else:
                        messages.error(request, err)
                else:
                    if (action.error):
                        messages.warning(request, action.error)

                action_output = action.output
                if getattr(action, 'get_download', None):
                    export_path = action.get_download(path_obj)
                    if export_path:
                        import mimetypes
                        abs_path = absolute_real_path(export_path)
                        filename = os.path.basename(export_path)
                        mimetype, encoding = mimetypes.guess_type(filename)
                        mimetype = mimetype or 'application/octet-stream'
                        with open(abs_path, 'rb') as f:
                            response = HttpResponse(f.read(),
                                                    mimetype=mimetype)
                        response['Content-Disposition'] = (
                                'attachment; filename="%s"' % filename)
                        return response

                if not action_output:
                    if not store:
                        rev_args = [language.code, project.code, '']
                        overview_url = reverse('pootle-tp-overview',
                                               args=rev_args)
                    else:
                        slash = store_f.rfind('/')
                        store_d = ''
                        if slash > 0:
                            store_d = store_f[:slash]
                            store_f = store_f[slash + 1:]
                        elif slash == 0:
                            store_f = store_f[1:]
                        rev_args = [language.code, project.code, store_d,
                                    store_f]
                        overview_url = reverse('pootle-tp-overview',
                                               args=rev_args)
                    return HttpResponseRedirect(overview_url)

    if goal is None:
        description = translation_project.description
    else:
        description = goal.description

    template_vars.update({
        'translation_project': translation_project,
        'description': description,
        'project': project,
        'language': language,
        'path_obj': path_obj,
        'resource_path': request.resource_path,
        'path_summary': path_summary,
        'stats': path_stats,
        'topstats': gentopstats_translation_project(translation_project),
        'feed_path': directory.pootle_path[1:],
        'action_groups': actions,
        'action_output': action_output,
        'can_edit': can_edit,
    })

    tp_pootle_path = translation_project.pootle_path

    if store is None:
        path_obj_goals = Goal.get_goals_for_path(path_obj.pootle_path)
        path_obj_has_goals = len(path_obj_goals) > 0

        if in_goal_overview and path_obj_has_goals:
            # Then show the goals tab.
            table_fields = ['name', 'progress', 'priority', 'total',
                            'need-translation', 'suggestions']
            items = [make_goal_item(path_obj_goal, path_obj.pootle_path)
                     for path_obj_goal in path_obj_goals]
            template_vars.update({
                'table': {
                    'id': 'tp-goals',
                    'proportional': False,
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'items': items,
                },
                'path_obj_has_goals': True,
            })
        elif goal in path_obj_goals:
            # Then show the drill down view for the specified goal.
            table_fields = ['name', 'progress', 'total', 'need-translation',
                            'suggestions']

            template_vars.update({
                'table': {
                    'id': 'tp-goals',
                    'proportional': True,
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'items': get_goal_children(directory, goal),
                },
                'goal': goal,
                'goal_url': goal.get_drill_down_url_for_path(tp_pootle_path),
                'path_obj_has_goals': True,
            })
        else:
            # Then show the files tab.
            table_fields = ['name', 'progress', 'total', 'need-translation',
                            'suggestions']
            template_vars.update({
                'table': {
                    'id': 'tp-files',
                    'proportional': True,
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'items': get_children(directory),
                },
                'path_obj_has_goals': path_obj_has_goals,
            })
    elif goal is not None:
        template_vars.update({
            'goal': goal,
            'goal_url': goal.get_drill_down_url_for_path(tp_pootle_path),
        })

    if can_edit:
        if store is None:
            url_kwargs = {
                'language_code': language.code,
                'project_code': project.code,
            }
            add_tag_action_url = reverse('tp.ajax_add_tag', kwargs=url_kwargs)
        else:
            add_tag_action_url = reverse('pootle-store-ajax-add-tag',
                                         args=[path_obj.pk])

        if goal is None:
            edit_form = DescriptionForm(instance=translation_project)
            edit_form_action = reverse('pootle-tp-ajax-edit-settings',
                                       args=[language.code, project.code])
        else:
            edit_form = GoalForm(instance=goal)
            edit_form_action = reverse('pootle-tagging-ajax-edit-goal',
                                       args=[goal.slug])

        template_vars.update({
            'form': edit_form,
            'form_action': edit_form_action,
            'add_tag_form': TagForm(),
            'add_tag_action_url': add_tag_action_url,
        })

    return render_to_response(template, template_vars,
                              context_instance=RequestContext(request))
Example #30
0
def overview(request, translation_project, dir_path, filename=None):
    current_path = translation_project.directory.pootle_path + dir_path

    if filename:
        current_path = current_path + filename
        store = get_object_or_404(Store, pootle_path=current_path)
        directory = store.parent
        template_vars = {
            'store_tags': store.tags.all().order_by('name'),
        }
        template = "translation_project/store_overview.html"
    else:
        store = None
        directory = get_object_or_404(Directory, pootle_path=current_path)
        template_vars = {
            'tp_tags': translation_project.tags.all().order_by('name'),
        }
        template = "translation_project/overview.html"

    if (check_permission('translate', request)
            or check_permission('suggest', request)
            or check_permission('overwrite', request)):

        template_vars.update({
            'upload_form':
            _handle_upload_form(request, current_path, translation_project,
                                directory),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    path_obj = store or directory

    latest_action = ''
    # If current directory is the TP root directory.
    if not directory.path:
        latest_action = translation_project.get_latest_submission()
    elif store is None:  # If this is not a file.
        latest_action = Submission.get_latest_for_dir(path_obj)

    path_stats = get_raw_stats(path_obj, include_suggestions=True)
    path_summary = get_path_summary(path_obj, path_stats, latest_action)
    actions = action_groups(request, path_obj, path_stats=path_stats)
    action_output = ''
    running = request.GET.get(EXTDIR, '')
    if running:
        if store:
            act = StoreAction
        else:
            act = TranslationProjectAction
        try:
            action = act.lookup(running)
        except KeyError:
            messages.error(request, _("Unable to find %s %s") % (act, running))
        else:
            if not getattr(action, 'nosync', False):
                (store or translation_project).sync()
            if action.is_active(request):
                vcs_dir = settings.VCS_DIRECTORY
                po_dir = settings.PODIRECTORY
                tp_dir = directory.get_real_path()
                store_fn = '*'
                if store:
                    tp_dir_slash = add_trailing_slash(tp_dir)
                    if store.file.name.startswith(tp_dir_slash):
                        # Note: store_f used below in reverse() call.
                        store_f = store.file.name[len(tp_dir_slash):]
                        store_fn = store_f.replace('/', os.sep)

                # Clear possibly stale output/error (even from other path_obj).
                action.set_output('')
                action.set_error('')
                try:
                    action.run(path=path_obj,
                               root=po_dir,
                               tpdir=tp_dir,
                               project=project.code,
                               language=language.code,
                               store=store_fn,
                               style=translation_project.file_style,
                               vc_root=vcs_dir)
                except StandardError:
                    err = (_("Exception while running '%s' extension action") %
                           action.title)
                    logging.exception(err)
                    if (action.error):
                        messages.error(request, action.error)
                    else:
                        messages.error(request, err)
                else:
                    if (action.error):
                        messages.warning(request, action.error)

                action_output = action.output
                if getattr(action, 'get_download', None):
                    export_path = action.get_download(path_obj)
                    if export_path:
                        response = HttpResponse('/export/' + export_path)
                        response['Content-Disposition'] = (
                            'attachment; filename="%s"' %
                            os.path.basename(export_path))
                        return response

                if not action_output:
                    if not store:
                        rev_args = [language.code, project.code, '']
                        overview_url = reverse('tp.overview', args=rev_args)
                    else:
                        slash = store_f.rfind('/')
                        store_d = ''
                        if slash > 0:
                            store_d = store_f[:slash]
                            store_f = store_f[slash + 1:]
                        elif slash == 0:
                            store_f = store_f[1:]
                        rev_args = [
                            language.code, project.code, store_d, store_f
                        ]
                        overview_url = reverse('tp.overview', args=rev_args)
                    return HttpResponseRedirect(overview_url)

    template_vars.update({
        'translation_project':
        translation_project,
        'project':
        project,
        'language':
        language,
        'path_obj':
        path_obj,
        'resource_path':
        request.resource_path,
        'path_summary':
        path_summary,
        'stats':
        path_stats,
        'topstats':
        gentopstats_translation_project(translation_project),
        'feed_path':
        directory.pootle_path[1:],
        'action_groups':
        actions,
        'action_output':
        action_output,
        'can_edit':
        can_edit,
    })

    if store is None:
        table_fields = [
            'name', 'progress', 'total', 'need-translation', 'suggestions'
        ]
        template_vars.update({
            'table': {
                'id': 'tp',
                'proportional': True,
                'fields': table_fields,
                'headings': get_table_headings(table_fields),
                'items': get_children(translation_project, directory),
            }
        })

    if can_edit:
        if store is None:
            url_kwargs = {
                'language_code': language.code,
                'project_code': project.code,
            }
            add_tag_action_url = reverse('tp.ajax_add_tag', kwargs=url_kwargs)
        else:
            add_tag_action_url = reverse('pootle-store-ajax-add-tag',
                                         args=[path_obj.pk])

        template_vars.update({
            'form':
            DescriptionForm(instance=translation_project),
            'add_tag_form':
            TagForm(),
            'add_tag_action_url':
            add_tag_action_url,
        })

    return render_to_response(template,
                              template_vars,
                              context_instance=RequestContext(request))
Example #31
0
def overview(request, translation_project, dir_path, filename=None):
    current_path = translation_project.directory.pootle_path + dir_path

    if filename:
        current_path = current_path + filename
        store = get_object_or_404(Store, pootle_path=current_path)
        directory = store.parent
        template_vars = {
            'store_tags': store.tags.all().order_by('name'),
        }
        template = "translation_project/store_overview.html"
    else:
        store = None
        directory = get_object_or_404(Directory, pootle_path=current_path)
        template_vars = {
            'tp_tags': translation_project.tags.all().order_by('name'),
        }
        template = "translation_project/overview.html"

    if (check_permission('translate', request) or
        check_permission('suggest', request) or
        check_permission('overwrite', request)):

        template_vars.update({
            'upload_form': _handle_upload_form(request, current_path,
                                               translation_project, directory),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    path_obj = store or directory

    latest_action = ''
    # If current directory is the TP root directory.
    if not directory.path:
        latest_action = translation_project.get_latest_submission()
    elif store is None:  # If this is not a file.
        latest_action = Submission.get_latest_for_dir(path_obj)

    path_stats = get_raw_stats(path_obj, include_suggestions=True)
    path_summary = get_path_summary(path_obj, path_stats, latest_action)
    actions = action_groups(request, path_obj, path_stats=path_stats)
    action_output = ''
    running = request.GET.get(EXTDIR, '')
    if running:
        if store:
            act = StoreAction
        else:
            act = TranslationProjectAction
        try:
            action = act.lookup(running)
        except KeyError:
            messages.error(request, _("Unable to find %s %s") % (act, running))
        else:
            if not getattr(action, 'nosync', False):
                (store or translation_project).sync()
            if action.is_active(request):
                vcs_dir = settings.VCS_DIRECTORY
                po_dir = settings.PODIRECTORY
                tp_dir = directory.get_real_path()
                store_fn = '*'
                if store:
                    tp_dir_slash = add_trailing_slash(tp_dir)
                    if store.file.name.startswith(tp_dir_slash):
                        # Note: store_f used below in reverse() call.
                        store_f = store.file.name[len(tp_dir_slash):]
                        store_fn = store_f.replace('/', os.sep)

                # Clear possibly stale output/error (even from other path_obj).
                action.set_output('')
                action.set_error('')
                try:
                    action.run(path=path_obj, root=po_dir, tpdir=tp_dir,
                               project=project.code, language=language.code,
                               store=store_fn,
                               style=translation_project.file_style,
                               vc_root=vcs_dir)
                except StandardError:
                    err = (_("Exception while running '%s' extension action") %
                           action.title)
                    logging.exception(err)
                    if (action.error):
                        messages.error(request, action.error)
                    else:
                        messages.error(request, err)
                else:
                    if (action.error):
                        messages.warning(request, action.error)

                action_output = action.output
                if getattr(action, 'get_download', None):
                    export_path = action.get_download(path_obj)
                    if export_path:
                        response = HttpResponse('/export/' + export_path)
                        response['Content-Disposition'] = (
                                'attachment; filename="%s"' %
                                os.path.basename(export_path))
                        return response

                if not action_output:
                    if not store:
                        rev_args = [language.code, project.code, '']
                        overview_url = reverse('tp.overview', args=rev_args)
                    else:
                        slash = store_f.rfind('/')
                        store_d = ''
                        if slash > 0:
                            store_d = store_f[:slash]
                            store_f = store_f[slash + 1:]
                        elif slash == 0:
                            store_f = store_f[1:]
                        rev_args = [language.code, project.code, store_d,
                                    store_f]
                        overview_url = reverse('tp.overview', args=rev_args)
                    return HttpResponseRedirect(overview_url)

    template_vars.update({
        'translation_project': translation_project,
        'project': project,
        'language': language,
        'path_obj': path_obj,
        'resource_path': request.resource_path,
        'path_summary': path_summary,
        'stats': path_stats,
        'topstats': gentopstats_translation_project(translation_project),
        'feed_path': directory.pootle_path[1:],
        'action_groups': actions,
        'action_output': action_output,
        'can_edit': can_edit,
    })

    if store is None:
        table_fields = ['name', 'progress', 'total', 'need-translation',
                        'suggestions']
        template_vars.update({
            'table': {
                'id': 'tp',
                'proportional': True,
                'fields': table_fields,
                'headings': get_table_headings(table_fields),
                'items': get_children(translation_project, directory),
            }
        })

    if can_edit:
        if store is None:
            url_kwargs = {
                'language_code': language.code,
                'project_code': project.code,
            }
            add_tag_action_url = reverse('tp.ajax_add_tag', kwargs=url_kwargs)
        else:
            add_tag_action_url = reverse('pootle-store-ajax-add-tag',
                                         args=[path_obj.pk])

        template_vars.update({
            'form': DescriptionForm(instance=translation_project),
            'add_tag_form': TagForm(),
            'add_tag_action_url': add_tag_action_url,
        })

    return render_to_response(template, template_vars,
                              context_instance=RequestContext(request))
Example #32
0
 def retrieve_statistics(self, bundle):
     """Retrieve the statistics for the current resource object."""
     return get_raw_stats(bundle.obj, include_suggestions=True)
Example #33
0
 def retrieve_statistics(self, bundle):
     """Given a ``Bundle``, return the statistics for it."""
     return get_raw_stats(bundle.obj, include_suggestions=True)
Example #34
0
 def retrieve_statistics(self, bundle):
     """Retrieve the statistics for the current resource object."""
     return get_raw_stats(bundle.obj, include_suggestions=True)