示例#1
0
文件: views.py 项目: denji/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,
            '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
示例#2
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
示例#3
0
文件: views.py 项目: SinSiXX/pootle
    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
示例#4
0
文件: views.py 项目: 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
示例#5
0
 def _get_path_summary(self):
     from pootle_misc.stats import get_path_summary
     return get_path_summary(self.directory)
示例#6
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))
示例#7
0
 def _get_path_summary(self):
     from pootle_misc.stats import get_path_summary
     return get_path_summary(self)
示例#8
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))
示例#9
0
文件: views.py 项目: Chipcius/pootle
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))