当前位置: 首页>>代码示例>>Python>>正文


Python SearchForm.get_name方法代码示例

本文整理汇总了Python中weblate.trans.forms.SearchForm.get_name方法的典型用法代码示例。如果您正苦于以下问题:Python SearchForm.get_name方法的具体用法?Python SearchForm.get_name怎么用?Python SearchForm.get_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weblate.trans.forms.SearchForm的用法示例。


在下文中一共展示了SearchForm.get_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search

# 需要导入模块: from weblate.trans.forms import SearchForm [as 别名]
# 或者: from weblate.trans.forms.SearchForm import get_name [as 别名]
def search(translation, request):
    """Perform search or returns cached search results."""
    # Possible new search
    form = SearchForm(request.GET)

    # Process form
    form_valid = form.is_valid()
    if not form_valid:
        show_form_errors(request, form)

    search_result = {
        'form': form,
        'offset': form.cleaned_data.get('offset', 1),
        'checksum': form.cleaned_data.get('checksum'),
    }
    search_url = form.urlencode()
    session_key = 'search_{0}_{1}'.format(translation.pk, search_url)

    if (session_key in request.session and
            'offset' in request.GET and
            'items' in request.session[session_key]):
        search_result.update(request.session[session_key])
        return search_result

    allunits = translation.unit_set.search(
        form.cleaned_data,
        translation=translation,
    )

    search_query = form.get_search_query() if form_valid else ''
    name = form.get_name() if form_valid else ''

    # Grab unit IDs
    unit_ids = list(allunits.values_list('id', flat=True))

    # Check empty search results
    if not unit_ids:
        messages.warning(request, _('No string matched your search!'))
        return redirect(translation)

    # Remove old search results
    cleanup_session(request.session)

    store_result = {
        'query': search_query,
        'url': search_url,
        'items': form.items(),
        'key': session_key,
        'name': force_text(name),
        'ids': unit_ids,
        'ttl': int(time.time()) + 86400,
    }
    request.session[session_key] = store_result

    search_result.update(store_result)
    return search_result
开发者ID:nijel,项目名称:weblate,代码行数:58,代码来源:edit.py

示例2: search

# 需要导入模块: from weblate.trans.forms import SearchForm [as 别名]
# 或者: from weblate.trans.forms.SearchForm import get_name [as 别名]
def search(translation, request):
    '''
    Performs search or returns cached search results.
    '''

    # Already performed search
    if 'sid' in request.GET:
        # Grab from session storage
        search_id = 'search_%s' % request.GET['sid']

        # Check if we know the search
        if search_id not in request.session:
            messages.error(request, _('Invalid search string!'))
            return redirect(translation)

        return request.session[search_id]

    # Possible new search
    search_form = SearchForm(request.GET)
    review_form = ReviewForm(request.GET)

    search_query = None
    if review_form.is_valid():
        # Review
        allunits = translation.unit_set.review(
            review_form.cleaned_data['date'],
            request.user
        )

        formatted_date = formats.date_format(
            review_form.cleaned_data['date'],
            'SHORT_DATE_FORMAT'
        )
        name = _('Review of translations since %s') % formatted_date
    elif search_form.is_valid():
        # Apply search conditions
        allunits = translation.unit_set.search(
            translation,
            search_form.cleaned_data,
        )

        search_query = search_form.cleaned_data['q']
        name = search_form.get_name()
    else:
        # Error reporting
        if 'date' in request.GET:
            show_form_errors(request, review_form)
        elif 'q' in request.GET or 'type' in request.GET:
            show_form_errors(request, search_form)

        # Filtering by type
        allunits = translation.unit_set.all()
        name = _('All strings')

    # Grab unit IDs
    unit_ids = list(allunits.values_list('id', flat=True))

    # Check empty search results
    if len(unit_ids) == 0:
        messages.warning(request, _('No string matched your search!'))
        return redirect(translation)

    # Checksum unit access
    offset = 0
    if 'checksum' in request.GET:
        try:
            unit = allunits.filter(checksum=request.GET['checksum'])[0]
            offset = unit_ids.index(unit.id)
        except (Unit.DoesNotExist, IndexError):
            messages.warning(request, _('No string matched your search!'))
            return redirect(translation)

    # Remove old search results
    cleanup_session(request.session)

    if name is not None:
        name = unicode(name)

    # Store in cache and return
    search_id = str(uuid.uuid1())
    search_result = {
        'query': search_query,
        'name': name,
        'ids': unit_ids,
        'search_id': search_id,
        'ttl': int(time.time()) + 86400,
        'offset': offset,
    }

    request.session['search_%s' % search_id] = search_result

    return search_result
开发者ID:chervol,项目名称:weblate,代码行数:94,代码来源:edit.py

示例3: search

# 需要导入模块: from weblate.trans.forms import SearchForm [as 别名]
# 或者: from weblate.trans.forms.SearchForm import get_name [as 别名]
def search(translation, request):
    """
    Performs search or returns cached search results.
    """

    # Already performed search
    if "sid" in request.GET:
        # Grab from session storage
        search_id = "search_%s" % request.GET["sid"]

        # Check if we know the search
        if search_id not in request.session:
            messages.error(request, _("Invalid search string!"))
            return redirect(translation)

        return request.session[search_id]

    # Possible new search
    search_form = SearchForm(request.GET)
    review_form = ReviewForm(request.GET)

    search_query = None
    if "date" in request.GET:
        if review_form.is_valid():
            # Review
            allunits = translation.unit_set.review(review_form.cleaned_data["date"], request.user)

            formatted_date = formats.date_format(review_form.cleaned_data["date"], "SHORT_DATE_FORMAT")
            name = _("Review of translations since %s") % formatted_date
        else:
            show_form_errors(request, review_form)

            # Filtering by type
            allunits = translation.unit_set.all()
            name = _("All strings")
    elif search_form.is_valid():
        # Apply search conditions
        allunits = translation.unit_set.search(translation, search_form.cleaned_data)

        search_query = search_form.cleaned_data["q"]
        name = search_form.get_name()
    else:
        # Error reporting
        show_form_errors(request, search_form)

        # Filtering by type
        allunits = translation.unit_set.all()
        name = _("All strings")

    # Grab unit IDs
    unit_ids = list(allunits.values_list("id", flat=True))

    # Check empty search results
    if len(unit_ids) == 0:
        messages.warning(request, _("No string matched your search!"))
        return redirect(translation)

    # Checksum unit access
    offset = 0
    if "checksum" in request.GET:
        try:
            unit = allunits.filter(checksum=request.GET["checksum"])[0]
            offset = unit_ids.index(unit.id)
        except (Unit.DoesNotExist, IndexError):
            messages.warning(request, _("No string matched your search!"))
            return redirect(translation)

    # Remove old search results
    cleanup_session(request.session)

    # Store in cache and return
    search_id = str(uuid.uuid1())
    search_result = {
        "query": search_query,
        "name": force_text(name) if name else None,
        "ids": unit_ids,
        "search_id": search_id,
        "ttl": int(time.time()) + 86400,
        "offset": offset,
    }

    request.session["search_%s" % search_id] = search_result

    return search_result
开发者ID:matejcik,项目名称:weblate,代码行数:86,代码来源:edit.py

示例4: search

# 需要导入模块: from weblate.trans.forms import SearchForm [as 别名]
# 或者: from weblate.trans.forms.SearchForm import get_name [as 别名]
def search(translation, request):
    """Perform search or returns cached search results."""
    # Possible new search
    search_form = SearchForm(request.GET)
    review_form = ReviewForm(request.GET)

    # Process form
    if 'date' in request.GET:
        if review_form.is_valid():
            form = review_form
        else:
            show_form_errors(request, review_form)
            # Use blank form
            form = SearchForm([])
            form.is_valid()
    elif search_form.is_valid():
        form = search_form
    else:
        show_form_errors(request, search_form)
        # Use blank form
        form = SearchForm([])
        form.is_valid()

    search_result = {
        'form': form,
        'offset': form.cleaned_data['offset'],
        'checksum': form.cleaned_data['checksum'],
    }
    search_url = form.urlencode()
    session_key = 'search_{0}_{1}'.format(translation.pk, search_url)

    if session_key in request.session:
        search_result.update(request.session[session_key])
        return search_result

    if form.cleaned_data['type'] == 'review':
        allunits = translation.unit_set.review(
            form.cleaned_data['date'],
            request.user
        )
    else:
        allunits = translation.unit_set.search(
            translation,
            form.cleaned_data,
        )
        if form.cleaned_data['type'] == 'random':
            allunits = allunits[:25]

    search_query = form.get_search_query()
    name = form.get_name()

    # Grab unit IDs
    unit_ids = list(allunits.values_list('id', flat=True))

    # Check empty search results
    if len(unit_ids) == 0:
        messages.warning(request, _('No string matched your search!'))
        return redirect(translation)

    # Remove old search results
    cleanup_session(request.session)

    store_result = {
        'query': search_query,
        'url': search_url,
        'key': session_key,
        'name': force_text(name),
        'ids': unit_ids,
        'ttl': int(time.time()) + 86400,
    }
    request.session[session_key] = store_result

    search_result.update(store_result)
    return search_result
开发者ID:saily,项目名称:weblate,代码行数:76,代码来源:edit.py


注:本文中的weblate.trans.forms.SearchForm.get_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。