예제 #1
0
def get_edit_unit(request, unit):
    """
    Given a store path C{pootle_path} and unit id C{uid}, gathers all the
    necessary information to build the editing widget.

    @return: A templatised editing widget is returned within the C{editor}
    variable and paging information is also returned if the page number has
    changed.
    """

    json = {}

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None
    form_class = unit_form_factory(language, snplurals)
    form = form_class(instance=unit)
    store = unit.store
    directory = store.parent
    profile = request.profile
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    suggestions, suggestion_details = get_sugg_list(unit)
    template_vars = {'unit': unit,
                     'form': form,
                     'store': store,
                     'directory': directory,
                     'profile': profile,
                     'user': request.user,
                     'language': language,
                     'source_language': translation_project.project.source_language,
                     'cantranslate': check_profile_permission(profile, "translate", directory),
                     'cansuggest': check_profile_permission(profile, "suggest", directory),
                     'canreview': check_profile_permission(profile, "review", directory),
                     'altsrcs': find_altsrcs(unit, alt_src_langs, store=store, project=project),
                     'suggestions': suggestions,
                     'suggestion_detail': suggestion_details,
    }

    if translation_project.project.is_terminology or store.is_terminology:
        t = loader.get_template('unit/term_edit.html')
    else:
        t = loader.get_template('unit/edit.html')
    c = RequestContext(request, template_vars)
    json['editor'] = t.render(c)
    t = loader.get_template('store/dircrumbs.html')
    json['dircrumbs'] = t.render(c)
    t = loader.get_template('store/storecrumbs.html')
    json['storecrumbs'] = t.render(c)

    rcode = 200
    # Return context rows if filtering is applied
    if _is_filtered(request) or request.GET.get('filter', 'all') != 'all':
        json['ctxt'] = _filter_ctxt_units(store.units, unit, 2)
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
예제 #2
0
def get_edit_unit(request, pootle_path, uid):
    """
    Given a store path C{pootle_path} and unit id C{uid}, gathers all the
    necessary information to build the editing widget.

    @return: A templatised editing widget is returned within the C{editor}
    variable and paging information is also returned if the page number has
    changed.
    """
    if pootle_path[0] != '/':
        pootle_path = '/' + pootle_path

    unit = get_object_or_404(Unit, id=uid, store__pootle_path=pootle_path)
    translation_project = unit.store.translation_project
    language = translation_project.language
    form_class = unit_form_factory(language, len(unit.source.strings))
    form = form_class(instance=unit)
    store = unit.store
    directory = store.parent
    profile = get_profile(request.user)
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    template_vars = {'unit': unit,
                     'form': form,
                     'store': store,
                     'profile': profile,
                     'user': request.user,
                     'language': language,
                     'source_language': translation_project.project.source_language,
                     'cantranslate': check_profile_permission(profile, "translate", directory),
                     'cansuggest': check_profile_permission(profile, "suggest", directory),
                     'canreview': check_profile_permission(profile, "review", directory),
                     'altsrcs': find_altsrcs(unit, alt_src_langs, store=store, project=project),
                     'suggestions': get_sugg_list(unit)}

    t = loader.get_template('unit/edit.html')
    c = RequestContext(request, template_vars)
    json = {'success': True,
            'editor': t.render(c)}

    current_page = int(request.GET.get('page', 1))
    all_units = unit.store.units
    units_qs = _filter_queryset(request.GET, all_units)
    unit_rows = profile.get_unit_rows()
    current_unit = unit
    if current_unit is not None:
        current_index = _get_index_in_qs(units_qs, current_unit)
        preceding = units_qs[:current_index].count()
        page = preceding / unit_rows + 1
        if page != current_page:
            pager = paginate(request, units_qs, items=unit_rows, page=page)
            json["pager"] = _build_pager_dict(pager)
        # Return context rows if filtering is applied
        if 'filter' in request.GET and request.GET.get('filter', 'all') != 'all':
            edit_index = _get_index_in_qs(all_units, current_unit)
            json["ctxt"] = _filter_ctxt_units(all_units, edit_index, 2)

    response = simplejson.dumps(json)
    return HttpResponse(response, mimetype="application/json")
예제 #3
0
파일: views.py 프로젝트: peterbe/pootle
def get_edit_unit(request, unit):
    """Given a store path ``pootle_path`` and unit id ``uid``, gathers all the
    necessary information to build the editing widget.

    :return: A templatised editing widget is returned within the ``editor``
             variable and paging information is also returned if the page
             number has changed.
    """
    json = {}

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(instance=unit)
    comment_form_class = unit_comment_form_factory(language)
    comment_form = comment_form_class({}, instance=unit)

    store = unit.store
    directory = store.parent
    profile = request.profile
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    report_target = ensure_uri(project.report_target)

    suggestions = get_sugg_list(unit)
    template_vars = {
        'unit': unit,
        'form': form,
        'comment_form': comment_form,
        'store': store,
        'directory': directory,
        'profile': profile,
        'user': request.user,
        'language': language,
        'source_language': translation_project.project.source_language,
        'cantranslate': check_profile_permission(profile, "translate",
                                                 directory),
        'cansuggest': check_profile_permission(profile, "suggest", directory),
        'canreview': check_profile_permission(profile, "review", directory),
        'altsrcs': find_altsrcs(unit, alt_src_langs, store=store,
                                project=project),
        'report_target': report_target,
        'suggestions': suggestions,
    }

    if translation_project.project.is_terminology or store.is_terminology:
        t = loader.get_template('unit/term_edit.html')
    else:
        t = loader.get_template('unit/edit.html')
    c = RequestContext(request, template_vars)
    json['editor'] = t.render(c)
    t = loader.get_template('store/dircrumbs.html')
    json['dircrumbs'] = t.render(c)
    t = loader.get_template('store/storecrumbs.html')
    json['storecrumbs'] = t.render(c)

    rcode = 200

    # Return context rows if filtering is applied but
    # don't return any if the user has asked not to have it
    current_filter = request.GET.get('filter', 'all')
    show_ctx = request.COOKIES.get('ctxShow', 'true')

    if ((_is_filtered(request) or current_filter not in ('all',)) and
        show_ctx == 'true'):
        # TODO: review if this first 'if' branch makes sense
        if translation_project.project.is_terminology or store.is_terminology:
            json['ctx'] = _filter_ctx_units(store.units, unit, 0)
        else:
            ctx_qty = int(request.COOKIES.get('ctxQty', 1))
            json['ctx'] = _filter_ctx_units(store.units, unit, ctx_qty)
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
예제 #4
0
파일: views.py 프로젝트: julen/pootle
def get_edit_unit(request, unit):
    """
    Given a store path C{pootle_path} and unit id C{uid}, gathers all the
    necessary information to build the editing widget.

    @return: A templatised editing widget is returned within the C{editor}
    variable and paging information is also returned if the page number has
    changed.
    """

    json = {}

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(instance=unit)
    store = unit.store
    directory = store.parent
    profile = request.profile
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    report_target = ensure_uri(project.report_target)

    suggestions, suggestion_details = get_sugg_list(unit)
    template_vars = {
        'unit': unit,
        'form': form,
        'store': store,
        'directory': directory,
        'profile': profile,
        'user': request.user,
        'language': language,
        'source_language': translation_project.project.source_language,
        'cantranslate': check_profile_permission(profile, "translate",
                                                 directory),
        'cansuggest': check_profile_permission(profile, "suggest", directory),
        'canreview': check_profile_permission(profile, "review", directory),
        'altsrcs': find_altsrcs(unit,
                                alt_src_langs,
                                store=store,
                                project=project),
        'report_target': report_target,
        'suggestions': suggestions,
        'suggestion_detail': suggestion_details,
    }

    if translation_project.project.is_terminology or store.is_terminology:
        t = loader.get_template('unit/term_edit.html')
    else:
        t = loader.get_template('unit/edit.html')
    c = RequestContext(request, template_vars)
    json['editor'] = t.render(c)
    t = loader.get_template('store/dircrumbs.html')
    json['dircrumbs'] = t.render(c)
    t = loader.get_template('store/storecrumbs.html')
    json['storecrumbs'] = t.render(c)

    rcode = 200
    # Return context rows if filtering is applied
    if _is_filtered(request) or request.GET.get('filter', 'all') != 'all':
        if translation_project.project.is_terminology or store.is_terminology:
            json['ctxt'] = _filter_ctxt_units(store.units, unit, 0)
        else:
            json['ctxt'] = _filter_ctxt_units(store.units, unit, 2)
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
예제 #5
0
파일: views.py 프로젝트: julen/pootle
def get_edit_unit(request, unit):
    """
    Given a store path C{pootle_path} and unit id C{uid}, gathers all the
    necessary information to build the editing widget.

    @return: A templatised editing widget is returned within the C{editor}
    variable and paging information is also returned if the page number has
    changed.
    """

    json = {}

    translation_project = request.translation_project
    language = translation_project.language

    if unit.hasplural():
        snplurals = len(unit.source.strings)
    else:
        snplurals = None

    form_class = unit_form_factory(language, snplurals, request)
    form = form_class(instance=unit)
    store = unit.store
    directory = store.parent
    profile = request.profile
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    report_target = ensure_uri(project.report_target)

    suggestions, suggestion_details = get_sugg_list(unit)
    template_vars = {
        "unit": unit,
        "form": form,
        "store": store,
        "directory": directory,
        "profile": profile,
        "user": request.user,
        "language": language,
        "source_language": translation_project.project.source_language,
        "cantranslate": check_profile_permission(profile, "translate", directory),
        "cansuggest": check_profile_permission(profile, "suggest", directory),
        "canreview": check_profile_permission(profile, "review", directory),
        "altsrcs": find_altsrcs(unit, alt_src_langs, store=store, project=project),
        "report_target": report_target,
        "suggestions": suggestions,
        "suggestion_detail": suggestion_details,
    }

    if translation_project.project.is_terminology or store.is_terminology:
        t = loader.get_template("unit/term_edit.html")
    else:
        t = loader.get_template("unit/edit.html")
    c = RequestContext(request, template_vars)
    json["editor"] = t.render(c)
    t = loader.get_template("store/dircrumbs.html")
    json["dircrumbs"] = t.render(c)
    t = loader.get_template("store/storecrumbs.html")
    json["storecrumbs"] = t.render(c)

    rcode = 200
    # Return context rows if filtering is applied
    if _is_filtered(request) or request.GET.get("filter", "all") != "all":
        if translation_project.project.is_terminology or store.is_terminology:
            json["ctxt"] = _filter_ctxt_units(store.units, unit, 0)
        else:
            json["ctxt"] = _filter_ctxt_units(store.units, unit, 2)
    response = jsonify(json)
    return HttpResponse(response, status=rcode, mimetype="application/json")
예제 #6
0
def get_edit_unit(request, pootle_path, uid):
    """
    Given a store path C{pootle_path} and unit id C{uid}, gathers all the
    necessary information to build the editing widget.

    @return: A templatised editing widget is returned within the C{editor}
    variable and paging information is also returned if the page number has
    changed.
    """
    if pootle_path[0] != '/':
        pootle_path = '/' + pootle_path

    unit = get_object_or_404(Unit, id=uid, store__pootle_path=pootle_path)
    translation_project = unit.store.translation_project
    language = translation_project.language
    form_class = unit_form_factory(language, len(unit.source.strings))
    form = form_class(instance=unit)
    store = unit.store
    directory = store.parent
    profile = get_profile(request.user)
    alt_src_langs = get_alt_src_langs(request, profile, translation_project)
    project = translation_project.project
    template_vars = {
        'unit': unit,
        'form': form,
        'store': store,
        'profile': profile,
        'user': request.user,
        'language': language,
        'source_language': translation_project.project.source_language,
        'cantranslate': check_profile_permission(profile, "translate",
                                                 directory),
        'cansuggest': check_profile_permission(profile, "suggest", directory),
        'canreview': check_profile_permission(profile, "review", directory),
        'altsrcs': find_altsrcs(unit,
                                alt_src_langs,
                                store=store,
                                project=project),
        'suggestions': get_sugg_list(unit)
    }

    t = loader.get_template('unit/edit.html')
    c = RequestContext(request, template_vars)
    json = {'success': True, 'editor': t.render(c)}

    current_page = int(request.GET.get('page', 1))
    all_units = unit.store.units
    units_qs = _filter_queryset(request.GET, all_units)
    unit_rows = profile.get_unit_rows()
    current_unit = unit
    if current_unit is not None:
        current_index = _get_index_in_qs(units_qs, current_unit)
        preceding = units_qs[:current_index].count()
        page = preceding / unit_rows + 1
        if page != current_page:
            pager = paginate(request, units_qs, items=unit_rows, page=page)
            json["pager"] = _build_pager_dict(pager)
        # Return context rows if filtering is applied
        if 'filter' in request.GET and request.GET.get('filter',
                                                       'all') != 'all':
            edit_index = _get_index_in_qs(all_units, current_unit)
            json["ctxt"] = _filter_ctxt_units(all_units, edit_index, 2)

    response = simplejson.dumps(json)
    return HttpResponse(response, mimetype="application/json")