Beispiel #1
0
def overview(request, project, dir_path, filename):
    """Languages overview for a given project."""
    item_func = (make_xlanguage_item if dir_path or filename
                                     else make_language_item)
    items = [item_func(item) for item in request.resource_obj.children]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

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

    ctx = get_overview_context(request)
    ctx.update({
        'project': project,
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),

        'browser_extends': 'projects/base.html',
    })

    return render(request, 'browser/overview.html', ctx)
Beispiel #2
0
def projects_overview(request, project_set):
    """Page listing all projects"""
    items = [make_project_list_item(project)
             for project in project_set.children]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'projects',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),

        'browser_extends': 'projects/all/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', 'projects')

    return response
Beispiel #3
0
def overview(request, project, dir_path, filename):
    """Languages overview for a given project."""
    item_func = (make_xlanguage_item
                 if dir_path or filename else make_language_item)
    items = [item_func(item) for item in request.resource_obj.children]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

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

    ctx = get_overview_context(request)
    ctx.update({
        'project': project,
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),
        'browser_extends': 'projects/base.html',
    })

    return render(request, 'browser/overview.html', ctx)
Beispiel #4
0
def projects_overview(request, project_set):
    """Page listing all projects"""
    items = [
        make_project_list_item(project) for project in project_set.children
    ]
    items.sort(lambda x, y: locale.strcoll(x['title'], y['title']))

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'projects',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),
        'browser_extends': 'projects/all/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', 'projects')

    return response
Beispiel #5
0
def projects_overview(request, project_set):
    """Page listing all projects."""
    items = [
        make_project_list_item(project)
        for project in project_set.get_children()
    ]

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]

    ctx = get_overview_context(request)
    ctx.update({
        'table': {
            'id': 'projects',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'browser_extends': 'projects/all/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', 'projects')

    return response
Beispiel #6
0
def overview(request, language):
    translation_projects = language.children \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
        },
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),
        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
Beispiel #7
0
def overview(request, language):
    translation_projects = language.children \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
        },
        'table': table,
        'stats': jsonify(request.resource_obj.get_stats()),

        'browser_extends': 'languages/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', language.code)

    return response
Beispiel #8
0
def overview(request, project):
    """Page listing all languages added to project."""
    from locale import strcoll

    items = [make_language_item(translation_project) for translation_project in project.get_children().iterator()]
    items.sort(lambda x, y: strcoll(x["title"], y["title"]))

    table_fields = [
        "name",
        "progress",
        "total",
        "need-translation",
        "suggestions",
        "critical",
        "last-updated",
        "activity",
    ]

    ctx = get_overview_context(request)
    ctx.update(
        {
            "project": project,
            "can_edit": check_permission("administrate", request),
            "table": {
                "id": "project",
                "fields": table_fields,
                "headings": get_table_headings(table_fields),
                "items": items,
            },
            "browser_extends": "projects/base.html",
            "browser_body_id": "projectoverview",
        }
    )

    if ctx["can_edit"]:
        from pootle_project.forms import DescriptionForm

        tag_action_url = reverse("pootle-xhr-tag-tp-in-project", kwargs={"project_code": project.code})
        ctx.update(
            {
                "form": DescriptionForm(instance=project),
                "form_action": reverse("pootle-project-admin-settings", args=[project.code]),
                "add_tag_form": TranslationProjectTagForm(project=project),
                "add_tag_action_url": tag_action_url,
            }
        )

    return render(request, "browser/overview.html", ctx)
Beispiel #9
0
def overview(request, language):
    can_edit = check_permission("administrate", request)

    translation_projects = language.get_children().order_by("project__fullname")
    user_tps = filter(lambda x: x.is_accessible_by(request.user), translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = [
        "name",
        "progress",
        "total",
        "need-translation",
        "suggestions",
        "critical",
        "last-updated",
        "activity",
    ]
    table = {"id": "language", "fields": table_fields, "headings": get_table_headings(table_fields), "items": items}

    ctx = get_overview_context(request)
    ctx.update(
        {
            "language": {
                "code": language.code,
                "name": tr_lang(language.fullname),
                "description": language.description,
            },
            "feed_path": "%s/" % language.code,
            "can_edit": can_edit,
            "table": table,
            "browser_extends": "languages/base.html",
        }
    )

    if can_edit:
        from pootle_language.forms import DescriptionForm

        ctx.update(
            {
                "form": DescriptionForm(instance=language),
                "form_action": reverse("pootle-language-admin-settings", args=[language.code]),
            }
        )

    response = render_to_response("browser/overview.html", ctx, context_instance=RequestContext(request))
    response.set_cookie("pootle-language", language.code)

    return response
Beispiel #10
0
def overview(request, language):
    can_edit = check_permission('administrate', request)

    translation_projects = language.get_children() \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
            'code': language.code,
            'name': tr_lang(language.fullname),
            'description': language.description,
        },
        'feed_path': '%s/' % language.code,
        'can_edit': can_edit,
        'table': table,
        'browser_extends': 'languages/base.html',
        'browser_body_id': 'languageoverview',
    })

    if can_edit:
        from pootle_language.forms import DescriptionForm
        ctx.update({
            'form':
            DescriptionForm(instance=language),
            'form_action':
            reverse('pootle-language-admin-settings', args=[language.code]),
        })

    return render_to_response("browser/overview.html",
                              ctx,
                              context_instance=RequestContext(request))
Beispiel #11
0
def overview(request, project):
    """Page listing all languages added to project."""
    from locale import strcoll

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

    table_fields = [
        'name', 'progress', 'total', 'need-translation', 'suggestions',
        'critical', 'last-updated', 'activity'
    ]

    ctx = get_overview_context(request)
    ctx.update({
        'project': project,
        'can_edit': check_permission("administrate", request),
        'table': {
            'id': 'project',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },
        'browser_extends': 'projects/base.html',
        'browser_body_id': 'projectoverview',
    })

    if ctx['can_edit']:
        from pootle_project.forms import DescriptionForm
        tag_action_url = reverse('pootle-xhr-tag-tp-in-project',
                                 kwargs={'project_code': project.code})
        ctx.update({
            'form':
            DescriptionForm(instance=project),
            'form_action':
            reverse('pootle-project-admin-settings', args=[project.code]),
            'add_tag_form':
            TranslationProjectTagForm(project=project),
            'add_tag_action_url':
            tag_action_url,
        })

    return render(request, 'browser/overview.html', ctx)
Beispiel #12
0
def overview(request, language):
    can_edit = check_permission('administrate', request)

    translation_projects = language.get_children() \
                                   .order_by('project__fullname')
    user_tps = filter(lambda x: x.is_accessible_by(request.user),
                      translation_projects)
    items = (make_project_item(tp) for tp in user_tps)

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']
    table = {
        'id': 'language',
        'fields': table_fields,
        'headings': get_table_headings(table_fields),
        'items': items,
    }

    ctx = get_overview_context(request)
    ctx.update({
        'language': {
          'code': language.code,
          'name': tr_lang(language.fullname),
          'description': language.description,
        },
        'feed_path': '%s/' % language.code,
        'can_edit': can_edit,
        'table': table,

        'browser_extends': 'languages/base.html',
    })

    if can_edit:
        from pootle_language.forms import DescriptionForm
        ctx.update({
            'form': DescriptionForm(instance=language),
            'form_action': reverse('pootle-language-admin-settings',
                                   args=[language.code]),
        })

    response = render(request, "browser/overview.html", ctx)
    response.set_cookie('pootle-language', language.code)

    return response
Beispiel #13
0
def overview(request, project, dir_path, filename):
    """Languages overview for a given project."""
    from locale import strcoll

    item_func = (make_xlanguage_item if dir_path or filename
                                     else make_language_item)
    items = [item_func(item) for item in request.resource_obj.get_children()]
    items.sort(lambda x, y: strcoll(x['title'], y['title']))

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']

    ctx = get_overview_context(request)
    ctx.update({
        'project': project,
        'can_edit': check_permission("administrate", request),
        'table': {
            'id': 'project',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },

        'browser_extends': 'projects/base.html',
    })

    if ctx['can_edit']:
        from pootle_project.forms import DescriptionForm
        tag_action_url = reverse('pootle-xhr-tag-tp-in-project',
                                 kwargs={'project_code': project.code})
        ctx.update({
            'form': DescriptionForm(instance=project),
            'form_action': reverse('pootle-project-admin-settings',
                                   args=[project.code]),
            'add_tag_form': TranslationProjectTagForm(project=project),
            'add_tag_action_url': tag_action_url,
        })

    return render(request, 'browser/overview.html', ctx)
Beispiel #14
0
def projects_overview(request, project_set):
    """Page listing all projects."""
    items = [make_project_list_item(project)
             for project in project_set.get_children()]

    table_fields = ['name', 'progress', 'total', 'need-translation',
                    'suggestions', 'critical', 'last-updated', 'activity']

    ctx = get_overview_context(request)
    ctx.update({
        'table': {
            'id': 'projects',
            'fields': table_fields,
            'headings': get_table_headings(table_fields),
            'items': items,
        },

        'browser_extends': 'projects/all/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)
    response.set_cookie('pootle-language', 'projects')

    return response
Beispiel #15
0
def overview(request, translation_project, dir_path, filename=None,
             goal=None, in_goal_overview=False):

    if filename:
        ctx = {
            'store_tags': request.store.tag_like_objects,
        }
        template_name = "translation_projects/store_overview.html"
    else:
        ctx = {
            'tp_tags': translation_project.tag_like_objects,
        }
        template_name = "browser/overview.html"

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

        ctx.update({
            'upload_form': _handle_upload_form(request, translation_project),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    resource_obj = request.store or request.directory

    #TODO enable again some actions when drilling down a goal.
    if goal is None:
        actions = action_groups(request, resource_obj)
    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 request.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):
                (request.store or translation_project).sync()
            if action.is_active(request):
                vcs_dir = settings.VCS_DIRECTORY
                po_dir = settings.PODIRECTORY
                tp_dir = request.directory.get_real_path()
                store_fn = '*'
                if request.store:
                    tp_dir_slash = add_trailing_slash(tp_dir)
                    if request.store.file.name.startswith(tp_dir_slash):
                        # Note: store_f used below in reverse() call.
                        store_f = request.store.file.name[len(tp_dir_slash):]
                        store_fn = store_f.replace('/', os.sep)

                # Clear possibly stale output/error (even from other
                # resource_obj).
                action.set_output('')
                action.set_error('')
                try:
                    action.run(path=resource_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(resource_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 request.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

    ctx.update(get_overview_context(request))
    ctx.update({
        'resource_obj': request.store or request.directory,  # Dirty hack.
        'translation_project': translation_project,
        'description': description,
        'project': project,
        'language': language,
        'feed_path': request.directory.pootle_path[1:],
        'action_groups': actions,
        'action_output': action_output,
        'can_edit': can_edit,

        'browser_extends': 'translation_projects/base.html',
        'browser_body_id': 'tpoverview',
    })

    tp_pootle_path = translation_project.pootle_path

    if request.store is None:
        resource_obj_goals = Goal.get_goals_for_path(resource_obj.pootle_path)
        resource_obj_has_goals = len(resource_obj_goals) > 0

        if in_goal_overview and resource_obj_has_goals:
            # Then show the goals tab.
            table_fields = ['name', 'progress', 'priority', 'total',
                            'need-translation', 'suggestions']
            items = [make_goal_item(resource_obj_goal, resource_obj.pootle_path)
                     for resource_obj_goal in resource_obj_goals]
            ctx.update({
                'table': {
                    'id': 'tp-goals',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_parent(request.directory),
                    'items': items,
                },
                'resource_obj_has_goals': True,
            })
        elif goal in resource_obj_goals:
            # Then show the drill down view for the specified goal.
            table_fields = ['name', 'progress', 'total', 'need-translation',
                            'suggestions', 'critical', 'activity']

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

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

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

        ctx.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_name, ctx,
                              context_instance=RequestContext(request))
Beispiel #16
0
def overview(request, translation_project, dir_path, filename=None, goal=None, in_goal_overview=False):

    if filename:
        ctx = {"store_tags": request.store.tag_like_objects}
        template_name = "translation_projects/store_overview.html"
    else:
        ctx = {"tp_tags": translation_project.tag_like_objects}
        template_name = "browser/overview.html"

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

        ctx.update({"upload_form": _handle_upload_form(request, translation_project)})

    can_edit = check_permission("administrate", request)

    project = translation_project.project
    language = translation_project.language

    resource_obj = request.store or request.directory

    # TODO enable again some actions when drilling down a goal.
    if goal is None:
        actions = action_groups(request, resource_obj)
    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 request.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):
                (request.store or translation_project).sync()
            if action.is_active(request):
                vcs_dir = settings.VCS_DIRECTORY
                po_dir = settings.PODIRECTORY
                tp_dir = request.directory.get_real_path()
                store_fn = "*"
                if request.store:
                    tp_dir_slash = add_trailing_slash(tp_dir)
                    if request.store.file.name.startswith(tp_dir_slash):
                        # Note: store_f used below in reverse() call.
                        store_f = request.store.file.name[len(tp_dir_slash) :]
                        store_fn = store_f.replace("/", os.sep)

                # Clear possibly stale output/error (even from other
                # resource_obj).
                action.set_output("")
                action.set_error("")
                try:
                    action.run(
                        path=resource_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(resource_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 request.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

    ctx.update(get_overview_context(request))
    ctx.update(
        {
            "resource_obj": request.store or request.directory,  # Dirty hack.
            "translation_project": translation_project,
            "description": description,
            "project": project,
            "language": language,
            "feed_path": request.directory.pootle_path[1:],
            "action_groups": actions,
            "action_output": action_output,
            "can_edit": can_edit,
            "browser_extends": "translation_projects/base.html",
            "browser_body_id": "tpoverview",
        }
    )

    tp_pootle_path = translation_project.pootle_path

    if request.store is None:
        resource_obj_goals = Goal.get_goals_for_path(resource_obj.pootle_path)
        resource_obj_has_goals = len(resource_obj_goals) > 0

        if in_goal_overview and resource_obj_has_goals:
            # Then show the goals tab.
            table_fields = ["name", "progress", "priority", "total", "need-translation", "suggestions"]
            items = [
                make_goal_item(resource_obj_goal, resource_obj.pootle_path) for resource_obj_goal in resource_obj_goals
            ]
            ctx.update(
                {
                    "table": {
                        "id": "tp-goals",
                        "fields": table_fields,
                        "headings": get_table_headings(table_fields),
                        "parent": get_parent(request.directory),
                        "items": items,
                    },
                    "resource_obj_has_goals": True,
                }
            )
        elif goal in resource_obj_goals:
            # Then show the drill down view for the specified goal.
            table_fields = ["name", "progress", "total", "need-translation", "suggestions", "critical", "activity"]

            ctx.update(
                {
                    "table": {
                        "id": "tp-goals",
                        "fields": table_fields,
                        "headings": get_table_headings(table_fields),
                        "parent": get_goal_parent(request.directory, goal),
                        "items": get_goal_children(request.directory, goal),
                    },
                    "goal": goal,
                    "goal_url": goal.get_drill_down_url_for_path(tp_pootle_path),
                    "resource_obj_has_goals": True,
                }
            )
        else:
            # Then show the files tab.
            table_fields = ["name", "progress", "total", "need-translation", "suggestions", "critical", "activity"]
            ctx.update(
                {
                    "table": {
                        "id": "tp-files",
                        "fields": table_fields,
                        "headings": get_table_headings(table_fields),
                        "parent": get_parent(request.directory),
                        "items": get_children(request.directory),
                    },
                    "resource_obj_has_goals": resource_obj_has_goals,
                }
            )
    elif goal is not None:
        ctx.update({"goal": goal, "goal_url": goal.get_drill_down_url_for_path(tp_pootle_path)})

    if can_edit:
        if request.store is None:
            url_kwargs = {"language_code": language.code, "project_code": project.code}
            add_tag_action_url = reverse("pootle-xhr-tag-tp", kwargs=url_kwargs)
        else:
            add_tag_action_url = reverse("pootle-xhr-tag-store", args=[resource_obj.pk])

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

        ctx.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_name, ctx, context_instance=RequestContext(request))
Beispiel #17
0
def overview(request, translation_project, dir_path, filename=None):
    project = translation_project.project
    language = translation_project.language

    directory = request.directory
    store = request.store

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/projects/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path, )
    except StaticPage.DoesNotExist:
        announcement = None

    display_announcement = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if ANN_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[ANN_COOKIE_NAME])
        cookie_data = json.loads(json_str)

        if 'isOpen' in cookie_data:
            display_announcement = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if announcement is not None:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            display_announcement = True
            new_mtime = ann_mtime

    ctx = get_overview_context(request)
    ctx.update({
        'translation_project': translation_project,
        'project': project,
        'language': language,
        'stats': jsonify(request.resource_obj.get_stats()),
        'browser_extends': 'translation_projects/base.html',
        'announcement': announcement,
        'announcement_displayed': display_announcement,
    })

    if store is None:
        table_fields = [
            'name', 'progress', 'total', 'need-translation', 'suggestions',
            'critical', 'last-updated', 'activity'
        ]
        ctx.update({
            'table': {
                'id': 'tp',
                'fields': table_fields,
                'headings': get_table_headings(table_fields),
                'parent': get_parent(directory),
                'items': get_children(directory),
            }
        })

    response = render(request, 'browser/overview.html', ctx)

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(json.dumps(cookie_data))
        response.set_cookie(ANN_COOKIE_NAME, cookie_data)

    return response
Beispiel #18
0
def overview(request, translation_project, dir_path, filename=None, goal=None):
    from django.utils import dateformat
    from staticpages.models import StaticPage
    from .actions import action_groups

    if filename:
        ctx = {
            'store_tags': request.store.tag_like_objects,
        }
        template_name = "translation_projects/store_overview.html"
    else:
        ctx = {
            'tp_tags': translation_project.tag_like_objects,
        }
        template_name = "browser/overview.html"

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

        ctx.update({
            'upload_form': _handle_upload_form(request, translation_project),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    resource_obj = request.store or request.directory

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

    action_output = ''

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path,
        )
    except StaticPage.DoesNotExist:
        announcement = None

    display_announcement = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if ANN_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[ANN_COOKIE_NAME])
        cookie_data = json.loads(json_str)

        if 'isOpen' in cookie_data:
            display_announcement = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if announcement is not None:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            display_announcement = True
            new_mtime = ann_mtime

    tp_goals = translation_project.all_goals

    ctx.update(get_overview_context(request))
    ctx.update({
        'resource_obj': request.store or request.directory,  # Dirty hack.
        'translation_project': translation_project,
        'description': translation_project.description,
        'project': project,
        'language': language,
        'tp_goals': tp_goals,
        'goal': goal,
        'feed_path': request.directory.pootle_path[1:],
        'action_groups': actions,
        'action_output': action_output,
        'can_edit': can_edit,

        'browser_extends': 'translation_projects/base.html',

        'announcement': announcement,
        'announcement_displayed': display_announcement,
    })

    tp_pootle_path = translation_project.pootle_path

    if request.store is None:
        table_fields = ['name', 'progress', 'total', 'need-translation',
                        'suggestions', 'critical', 'last-updated', 'activity']

        if goal is not None:
            # Then show the drill down view for the specified goal.
            continue_url = goal.get_translate_url_for_path(request.pootle_path,
                                                           state='incomplete')
            critical_url = goal.get_critical_url_for_path(request.pootle_path)
            review_url = goal.get_translate_url_for_path(request.pootle_path,
                                                         state='suggestions')
            all_url = goal.get_translate_url_for_path(request.pootle_path)

            ctx.update({
                'table': {
                    'id': 'tp-goals',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_goal_parent(request.directory, goal),
                    'items': get_goal_children(request.directory, goal),
                },
                'url_action_continue': continue_url,
                'url_action_fixcritical': critical_url,
                'url_action_review': review_url,
                'url_action_view_all': all_url,
            })
        else:
            # Then show the files tab.
            ctx.update({
                'table': {
                    'id': 'tp-files',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_parent(request.directory),
                    'items': get_children(request.directory),
                },
            })

    if can_edit:
        if request.store is None:
            add_tag_action_url = reverse('pootle-xhr-tag-tp',
                                         args=[language.code, project.code])
        else:
            add_tag_action_url = reverse('pootle-xhr-tag-store',
                                         args=[resource_obj.pk])

        ctx.update({
            'form': DescriptionForm(instance=translation_project),
            'form_action': reverse('pootle-tp-admin-settings',
                                   args=[language.code, project.code]),
            'add_tag_form': TagForm(),
            'add_tag_action_url': add_tag_action_url,
        })

        if goal is not None:
            ctx.update({
                'goal_form': GoalForm(instance=goal),
                'goal_form_action': reverse('pootle-xhr-edit-goal',
                                            args=[goal.slug]),
            })

    response = render(request, template_name, ctx)

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(json.dumps(cookie_data))
        response.set_cookie(ANN_COOKIE_NAME, cookie_data)

    return response
Beispiel #19
0
def overview(request, translation_project, dir_path, filename=None):
    project = translation_project.project
    language = translation_project.language

    directory = request.directory
    store = request.store

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/projects/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path, )
    except StaticPage.DoesNotExist:
        announcement = None

    has_announcement = announcement is not None
    has_sidebar = has_announcement
    is_sidebar_open = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if SIDEBAR_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[SIDEBAR_COOKIE_NAME])
        cookie_data = json.loads(json_str)

        if 'isOpen' in cookie_data:
            is_sidebar_open = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if has_announcement:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            is_sidebar_open = True
            new_mtime = ann_mtime

    ctx = get_overview_context(request)

    # TODO improve plugin logic
    if "import_export" in settings.INSTALLED_APPS and request.user.is_authenticated(
    ):
        from import_export.views import handle_upload_form
        from pootle_app.models.permissions import check_permission

        ctx.update(handle_upload_form(request))

        has_download = (check_permission('translate', request)
                        or check_permission('suggest', request))
        ctx.update({
            'display_download': has_download,
        })
        has_sidebar = True

    if store is None:
        table_fields = [
            'name', 'progress', 'total', 'need-translation', 'suggestions',
            'critical', 'last-updated', 'activity'
        ]
        ctx.update({
            'table': {
                'id': 'tp',
                'fields': table_fields,
                'headings': get_table_headings(table_fields),
                'parent': get_parent(directory),
                'items': get_children(directory),
            }
        })

    ctx.update({
        'translation_project': translation_project,
        'project': project,
        'language': language,
        'stats': jsonify(request.resource_obj.get_stats()),
        'browser_extends': 'translation_projects/base.html',
        'announcement': announcement,
        'is_sidebar_open': is_sidebar_open,
        'has_sidebar': has_sidebar,
    })

    response = render(request, 'browser/overview.html', ctx)

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(json.dumps(cookie_data))
        response.set_cookie(SIDEBAR_COOKIE_NAME, cookie_data)

    return response
Beispiel #20
0
def overview(request, translation_project, dir_path, filename=None):
    project = translation_project.project
    language = translation_project.language

    directory = request.directory
    store = request.store

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path,
        )
    except StaticPage.DoesNotExist:
        announcement = None

    display_announcement = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if ANN_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[ANN_COOKIE_NAME])
        cookie_data = json.loads(json_str)

        if 'isOpen' in cookie_data:
            display_announcement = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if announcement is not None:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            display_announcement = True
            new_mtime = ann_mtime

    ctx = get_overview_context(request)
    ctx.update({
        'translation_project': translation_project,
        'project': project,
        'language': language,
        'stats': jsonify(request.resource_obj.get_stats()),

        'browser_extends': 'translation_projects/base.html',

        'announcement': announcement,
        'announcement_displayed': display_announcement,
    })

    if store is None:
        table_fields = ['name', 'progress', 'total', 'need-translation',
                        'suggestions', 'critical', 'last-updated', 'activity']
        ctx.update({
            'table': {
                'id': 'tp',
                'fields': table_fields,
                'headings': get_table_headings(table_fields),
                'parent': get_parent(directory),
                'items': get_children(directory),
            }
        })

    response = render(request, 'browser/overview.html', ctx)

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(json.dumps(cookie_data))
        response.set_cookie(ANN_COOKIE_NAME, cookie_data)

    return response
Beispiel #21
0
def overview(request, translation_project, dir_path, filename=None):
    project = translation_project.project
    language = translation_project.language

    directory = request.directory
    store = request.store
    is_admin = check_permission('administrate', request)

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/projects/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path,
        )
    except StaticPage.DoesNotExist:
        announcement = None

    has_announcement = announcement is not None
    has_sidebar = has_announcement
    is_sidebar_open = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if SIDEBAR_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[SIDEBAR_COOKIE_NAME])
        cookie_data = json.loads(json_str)

        if 'isOpen' in cookie_data:
            is_sidebar_open = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if has_announcement:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            is_sidebar_open = True
            new_mtime = ann_mtime

    ctx = get_overview_context(request)

    # TODO improve plugin logic
    if "import_export" in settings.INSTALLED_APPS and request.user.is_authenticated():
        from import_export.views import handle_upload_form

        ctx.update(handle_upload_form(request))

        has_download = (check_permission('translate', request) or
                        check_permission('suggest', request))
        ctx.update({
            'display_download': has_download,
        })
        has_sidebar = True

    stats = request.resource_obj.get_stats()

    if store is None:
        table_fields = ['name', 'progress', 'total', 'need-translation',
                        'suggestions', 'critical', 'last-updated', 'activity']
        ctx.update({
            'table': {
                'id': 'tp',
                'fields': table_fields,
                'headings': get_table_headings(table_fields),
                'parent': get_parent(directory),
                'items': get_children(directory),
            }
        })

        vfolders = get_vfolders(directory)
        if len(vfolders) > 0:
            table_fields = ['name', 'priority', 'progress', 'total',
                            'need-translation', 'suggestions', 'critical',
                            'activity']
            ctx.update({
                'vfolders': {
                    'id': 'vfolders',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'items': get_vfolders(directory, all_vfolders=is_admin),
                },
            })

            #FIXME: set vfolders stats in the resource, don't inject them here.
            stats['vfolders'] = VirtualFolder.get_stats_for(
                directory.pootle_path,
                all_vfolders=is_admin
            )

    ctx.update({
        'translation_project': translation_project,
        'project': project,
        'language': language,
        'stats': jsonify(stats),
        'is_admin': is_admin,

        'browser_extends': 'translation_projects/base.html',

        'announcement': announcement,
        'is_sidebar_open': is_sidebar_open,
        'has_sidebar': has_sidebar,
    })

    response = render(request, 'browser/overview.html', ctx)

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(json.dumps(cookie_data))
        response.set_cookie(SIDEBAR_COOKIE_NAME, cookie_data)

    return response
Beispiel #22
0
def overview(request, translation_project, dir_path, filename=None, goal=None):
    from django.utils import dateformat
    from staticpages.models import StaticPage
    from pootle.scripts.actions import EXTDIR, StoreAction, TranslationProjectAction
    from .actions import action_groups

    if filename:
        ctx = {
            'store_tags': request.store.tag_like_objects,
        }
        template_name = "translation_projects/store_overview.html"
    else:
        ctx = {
            'tp_tags': translation_project.tag_like_objects,
        }
        template_name = "browser/overview.html"

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

        ctx.update({
            'upload_form': _handle_upload_form(request, translation_project),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    resource_obj = request.store or request.directory

    #TODO enable again some actions when drilling down a goal.
    if goal is None:
        actions = action_groups(request, resource_obj)
    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 request.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):
                (request.store or translation_project).sync()
            if action.is_active(request):
                vcs_dir = settings.VCS_DIRECTORY
                po_dir = settings.PODIRECTORY
                tp_dir = request.directory.get_real_path()
                store_fn = '*'
                if request.store:
                    tp_dir_slash = add_trailing_slash(tp_dir)
                    if request.store.file.name.startswith(tp_dir_slash):
                        # Note: store_f used below in reverse() call.
                        store_f = request.store.file.name[len(tp_dir_slash):]
                        store_fn = store_f.replace('/', os.sep)

                # Clear possibly stale output/error (even from other
                # resource_obj).
                action.set_output('')
                action.set_error('')
                try:
                    action.run(path=resource_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(resource_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 request.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 redirect(overview_url)

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path,
        )
    except StaticPage.DoesNotExist:
        announcement = None

    display_announcement = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if ANN_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[ANN_COOKIE_NAME])
        cookie_data = json.loads(json_str)

        if 'isOpen' in cookie_data:
            display_announcement = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if announcement is not None:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            display_announcement = True
            new_mtime = ann_mtime

    tp_goals = translation_project.all_goals

    ctx.update(get_overview_context(request))
    ctx.update({
        'resource_obj': request.store or request.directory,  # Dirty hack.
        'translation_project': translation_project,
        'description': translation_project.description,
        'project': project,
        'language': language,
        'tp_goals': tp_goals,
        'goal': goal,
        'feed_path': request.directory.pootle_path[1:],
        'action_groups': actions,
        'action_output': action_output,
        'can_edit': can_edit,

        'browser_extends': 'translation_projects/base.html',

        'announcement': announcement,
        'announcement_displayed': display_announcement,
    })

    tp_pootle_path = translation_project.pootle_path

    if request.store is None:
        table_fields = ['name', 'progress', 'total', 'need-translation',
                        'suggestions', 'critical', 'last-updated', 'activity']

        if goal is not None:
            # Then show the drill down view for the specified goal.
            ctx.update({
                'table': {
                    'id': 'tp-goals',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_goal_parent(request.directory, goal),
                    'items': get_goal_children(request.directory, goal),
                },
            })
        else:
            # Then show the files tab.
            ctx.update({
                'table': {
                    'id': 'tp-files',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_parent(request.directory),
                    'items': get_children(request.directory),
                },
            })

    if can_edit:
        if request.store is None:
            add_tag_action_url = reverse('pootle-xhr-tag-tp',
                                         args=[language.code, project.code])
        else:
            add_tag_action_url = reverse('pootle-xhr-tag-store',
                                         args=[resource_obj.pk])

        ctx.update({
            'form': DescriptionForm(instance=translation_project),
            'form_action': reverse('pootle-tp-admin-settings',
                                   args=[language.code, project.code]),
            'add_tag_form': TagForm(),
            'add_tag_action_url': add_tag_action_url,
        })

        if goal is not None:
            ctx.update({
                'goal_form': GoalForm(instance=goal),
                'goal_form_action': reverse('pootle-xhr-edit-goal',
                                            args=[goal.slug]),
            })

    response = render(request, template_name, ctx)

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(json.dumps(cookie_data))
        response.set_cookie(ANN_COOKIE_NAME, cookie_data)

    return response
Beispiel #23
0
def overview(request, translation_project, dir_path, filename=None, goal=None):
    from django.utils import dateformat
    from staticpages.models import StaticPage
    from .actions import action_groups

    if filename:
        ctx = {
            'store_tags': request.store.tag_like_objects,
        }
        template_name = "translation_projects/store_overview.html"
    else:
        ctx = {
            'tp_tags': translation_project.tag_like_objects,
        }
        template_name = "browser/overview.html"

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

        ctx.update({
            'upload_form':
            _handle_upload_form(request, translation_project),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    resource_obj = request.store or request.directory

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

    action_output = ''

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path, )
    except StaticPage.DoesNotExist:
        announcement = None

    display_announcement = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if ANN_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[ANN_COOKIE_NAME])
        cookie_data = json.loads(json_str)

        if 'isOpen' in cookie_data:
            display_announcement = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if announcement is not None:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            display_announcement = True
            new_mtime = ann_mtime

    tp_goals = translation_project.all_goals

    ctx.update(get_overview_context(request))
    ctx.update({
        'resource_obj': request.store or request.directory,  # Dirty hack.
        'translation_project': translation_project,
        'description': translation_project.description,
        'project': project,
        'language': language,
        'tp_goals': tp_goals,
        'goal': goal,
        'feed_path': request.directory.pootle_path[1:],
        'action_groups': actions,
        'action_output': action_output,
        'can_edit': can_edit,
        'browser_extends': 'translation_projects/base.html',
        'announcement': announcement,
        'announcement_displayed': display_announcement,
    })

    tp_pootle_path = translation_project.pootle_path

    if request.store is None:
        table_fields = [
            'name', 'progress', 'total', 'need-translation', 'suggestions',
            'critical', 'last-updated', 'activity'
        ]

        if goal is not None:
            # Then show the drill down view for the specified goal.
            continue_url = goal.get_translate_url_for_path(request.pootle_path,
                                                           state='incomplete')
            critical_url = goal.get_critical_url_for_path(request.pootle_path)
            review_url = goal.get_translate_url_for_path(request.pootle_path,
                                                         state='suggestions')
            all_url = goal.get_translate_url_for_path(request.pootle_path)

            ctx.update({
                'table': {
                    'id': 'tp-goals',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_goal_parent(request.directory, goal),
                    'items': get_goal_children(request.directory, goal),
                },
                'url_action_continue': continue_url,
                'url_action_fixcritical': critical_url,
                'url_action_review': review_url,
                'url_action_view_all': all_url,
            })
        else:
            # Then show the files tab.
            ctx.update({
                'table': {
                    'id': 'tp-files',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_parent(request.directory),
                    'items': get_children(request.directory),
                },
            })

    if can_edit:
        if request.store is None:
            add_tag_action_url = reverse('pootle-xhr-tag-tp',
                                         args=[language.code, project.code])
        else:
            add_tag_action_url = reverse('pootle-xhr-tag-store',
                                         args=[resource_obj.pk])

        ctx.update({
            'form':
            DescriptionForm(instance=translation_project),
            'form_action':
            reverse('pootle-tp-admin-settings',
                    args=[language.code, project.code]),
            'add_tag_form':
            TagForm(),
            'add_tag_action_url':
            add_tag_action_url,
        })

        if goal is not None:
            ctx.update({
                'goal_form':
                GoalForm(instance=goal),
                'goal_form_action':
                reverse('pootle-xhr-edit-goal', args=[goal.slug]),
            })

    response = render(request, template_name, ctx)

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(json.dumps(cookie_data))
        response.set_cookie(ANN_COOKIE_NAME, cookie_data)

    return response
Beispiel #24
0
def overview(request, translation_project, dir_path, filename=None,
             goal=None, in_goal_overview=False):

    if filename:
        ctx = {
            'store_tags': request.store.tag_like_objects,
        }
        template_name = "translation_projects/store_overview.html"
    else:
        ctx = {
            'tp_tags': translation_project.tag_like_objects,
        }
        template_name = "browser/overview.html"

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

        ctx.update({
            'upload_form': _handle_upload_form(request, translation_project),
        })

    can_edit = check_permission('administrate', request)

    project = translation_project.project
    language = translation_project.language

    resource_obj = request.store or request.directory

    #TODO enable again some actions when drilling down a goal.
    if goal is None:
        actions = action_groups(request, resource_obj)
    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 request.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):
                (request.store or translation_project).sync()
            if action.is_active(request):
                vcs_dir = settings.VCS_DIRECTORY
                po_dir = settings.PODIRECTORY
                tp_dir = request.directory.get_real_path()
                store_fn = '*'
                if request.store:
                    tp_dir_slash = add_trailing_slash(tp_dir)
                    if request.store.file.name.startswith(tp_dir_slash):
                        # Note: store_f used below in reverse() call.
                        store_f = request.store.file.name[len(tp_dir_slash):]
                        store_fn = store_f.replace('/', os.sep)

                # Clear possibly stale output/error (even from other
                # resource_obj).
                action.set_output('')
                action.set_error('')
                try:
                    action.run(path=resource_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(resource_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 request.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

    # TODO: cleanup and refactor, retrieve from cache
    try:
        ann_virtual_path = 'announcements/' + project.code
        announcement = StaticPage.objects.live(request.user).get(
            virtual_path=ann_virtual_path,
        )
    except StaticPage.DoesNotExist:
        announcement = None

    display_announcement = True
    stored_mtime = None
    new_mtime = None
    cookie_data = {}

    if ANN_COOKIE_NAME in request.COOKIES:
        json_str = unquote(request.COOKIES[ANN_COOKIE_NAME])
        cookie_data = simplejson.loads(json_str)

        if 'isOpen' in cookie_data:
            display_announcement = cookie_data['isOpen']

        if project.code in cookie_data:
            stored_mtime = cookie_data[project.code]

    if announcement is not None:
        ann_mtime = dateformat.format(announcement.modified_on, 'U')
        if ann_mtime != stored_mtime:
            display_announcement = True
            new_mtime = ann_mtime

    ctx.update(get_overview_context(request))
    ctx.update({
        'resource_obj': request.store or request.directory,  # Dirty hack.
        'translation_project': translation_project,
        'description': description,
        'project': project,
        'language': language,
        'feed_path': request.directory.pootle_path[1:],
        'action_groups': actions,
        'action_output': action_output,
        'can_edit': can_edit,

        'browser_extends': 'translation_projects/base.html',
        'browser_body_id': 'tpoverview',

        'announcement': announcement,
        'announcement_displayed': display_announcement,
    })

    tp_pootle_path = translation_project.pootle_path

    if request.store is None:
        resource_obj_goals = Goal.get_goals_for_path(resource_obj.pootle_path)
        resource_obj_has_goals = len(resource_obj_goals) > 0

        if in_goal_overview and resource_obj_has_goals:
            # Then show the goals tab.
            table_fields = ['name', 'progress', 'priority', 'total',
                            'need-translation', 'suggestions']
            items = [make_goal_item(resource_obj_goal, resource_obj.pootle_path)
                     for resource_obj_goal in resource_obj_goals]
            ctx.update({
                'table': {
                    'id': 'tp-goals',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_parent(request.directory),
                    'items': items,
                },
                'resource_obj_has_goals': True,
            })
        elif goal in resource_obj_goals:
            # Then show the drill down view for the specified goal.
            table_fields = ['name', 'progress', 'total', 'need-translation',
                            'suggestions', 'critical', 'last-updated',
                            'activity']

            ctx.update({
                'table': {
                    'id': 'tp-goals',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_goal_parent(request.directory, goal),
                    'items': get_goal_children(request.directory, goal),
                },
                'goal': goal,
                'goal_url': goal.get_drill_down_url_for_path(tp_pootle_path),
                'resource_obj_has_goals': True,
            })
        else:
            # Then show the files tab.
            table_fields = ['name', 'progress', 'total', 'need-translation',
                            'suggestions', 'critical', 'last-updated',
                            'activity']
            ctx.update({
                'table': {
                    'id': 'tp-files',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'parent': get_parent(request.directory),
                    'items': get_children(request.directory),
                },
                'resource_obj_has_goals': resource_obj_has_goals,
            })
    elif goal is not None:
        ctx.update({
            'goal': goal,
            'goal_url': goal.get_drill_down_url_for_path(tp_pootle_path),
        })

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

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

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

    response = render_to_response(template_name, ctx,
                                  context_instance=RequestContext(request))

    if new_mtime is not None:
        cookie_data[project.code] = new_mtime
        cookie_data = quote(simplejson.dumps(cookie_data))
        response.set_cookie(ANN_COOKIE_NAME, cookie_data)

    return response
Beispiel #25
0
def overview(request, translation_project, dir_path, filename=None):
    project = translation_project.project
    language = translation_project.language

    directory = request.directory
    store = request.store
    is_admin = check_permission('administrate', request)

    ctx, cookie_data = get_sidebar_announcements_context(request, project.code,
                                                         language.code)

    ctx.update(get_overview_context(request))

    # TODO improve plugin logic
    if "import_export" in settings.INSTALLED_APPS and request.user.is_authenticated():
        from import_export.views import handle_upload_form

        ctx.update(handle_upload_form(request))

        has_download = (check_permission('translate', request) or
                        check_permission('suggest', request))
        ctx.update({
            'display_download': has_download,
            'has_sidebar': True,
        })

    stats = request.resource_obj.get_stats()

    if store is None:
        table_fields = ['name', 'progress', 'total', 'need-translation',
                        'suggestions', 'critical', 'last-updated', 'activity']
        ctx.update({
            'table': {
                'id': 'tp',
                'fields': table_fields,
                'headings': get_table_headings(table_fields),
                'items': get_children(directory),
            }
        })

        vfolders = get_vfolders(directory, all_vfolders=is_admin)
        if len(vfolders) > 0:
            table_fields = ['name', 'priority', 'progress', 'total',
                            'need-translation', 'suggestions', 'critical',
                            'activity']
            ctx.update({
                'vfolders': {
                    'id': 'vfolders',
                    'fields': table_fields,
                    'headings': get_table_headings(table_fields),
                    'items': vfolders,
                },
            })

            #FIXME: set vfolders stats in the resource, don't inject them here.
            stats['vfolders'] = VirtualFolder.get_stats_for(
                directory.pootle_path,
                all_vfolders=is_admin
            )

    ctx.update({
        'parent': get_parent(directory if store is None else store),
        'translation_project': translation_project,
        'project': project,
        'language': language,
        'stats': jsonify(stats),
        'is_admin': is_admin,

        'browser_extends': 'translation_projects/base.html',
    })

    response = render(request, 'browser/overview.html', ctx)

    if cookie_data:
        response.set_cookie(SIDEBAR_COOKIE_NAME, cookie_data)

    return response