Пример #1
0
def show_dictionary(request, project, lang):
    prj = get_project(request, project)
    lang = get_object_or_404(Language, code=lang)

    if request.method == 'POST' and request.user.has_perm('glossary.add', prj):
        form = WordForm(request.POST)
        if form.is_valid():
            Dictionary.objects.create(
                request.user,
                project=prj,
                language=lang,
                source=form.cleaned_data['source'],
                target=form.cleaned_data['target']
            )
        return redirect_next(
            request.POST.get('next'), request.get_full_path()
        )
    form = WordForm()

    uploadform = DictUploadForm()

    words = Dictionary.objects.filter(
        project=prj, language=lang
    ).order_by(Lower('source'))

    letterform = LetterForm(request.GET)

    searchform = OneWordForm(request.GET)

    if searchform.is_valid() and searchform.cleaned_data['term'] != '':
        words = words.filter(
            source__icontains=searchform.cleaned_data['term']
        )
        search = searchform.cleaned_data['term']
    else:
        search = ''

    if letterform.is_valid() and letterform.cleaned_data['letter'] != '':
        words = words.filter(
            source__istartswith=letterform.cleaned_data['letter']
        )
        letter = letterform.cleaned_data['letter']
    else:
        letter = ''

    words = get_paginator(request, words)

    last_changes = Change.objects.last_changes(request.user).filter(
        dictionary__project=prj,
        dictionary__language=lang
    )[:10]

    return render(
        request,
        'dictionary.html',
        {
            'title': dict_title(prj, lang),
            'project': prj,
            'language': lang,
            'page_obj': words,
            'form': form,
            'query_string': urlencode({
                'term': search,
                'letter': letter
            }),
            'uploadform': uploadform,
            'letterform': letterform,
            'searchform': searchform,
            'letter': letter,
            'last_changes': last_changes,
            'last_changes_url': urlencode({
                'project': prj.slug,
                'lang': lang.code,
                'glossary': 1
            }),
        }
    )
Пример #2
0
def show_dictionary(request, project, lang):
    prj = get_project(request, project)
    lang = get_object_or_404(Language, code=lang)

    if request.method == 'POST' and request.user.has_perm('glossary.add', prj):
        form = WordForm(request.POST)
        if form.is_valid():
            Dictionary.objects.create(
                request.user,
                project=prj,
                language=lang,
                source=form.cleaned_data['source'],
                target=form.cleaned_data['target']
            )
        return redirect_next(
            request.POST.get('next'), request.get_full_path()
        )
    else:
        form = WordForm()

    uploadform = DictUploadForm()

    words = Dictionary.objects.filter(
        project=prj, language=lang
    ).order_by(Lower('source'))

    letterform = LetterForm(request.GET)

    searchform = OneWordForm(request.GET)

    if searchform.is_valid() and searchform.cleaned_data['term'] != '':
        words = words.filter(
            source__icontains=searchform.cleaned_data['term']
        )
        search = searchform.cleaned_data['term']
    else:
        search = ''

    if letterform.is_valid() and letterform.cleaned_data['letter'] != '':
        words = words.filter(
            source__istartswith=letterform.cleaned_data['letter']
        )
        letter = letterform.cleaned_data['letter']
    else:
        letter = ''

    words = get_paginator(request, words)

    last_changes = Change.objects.last_changes(request.user).filter(
        dictionary__project=prj,
        dictionary__language=lang
    )[:10]

    return render(
        request,
        'dictionary.html',
        {
            'title': dict_title(prj, lang),
            'project': prj,
            'language': lang,
            'page_obj': words,
            'form': form,
            'query_string': urlencode({
                'term': search,
                'letter': letter
            }),
            'uploadform': uploadform,
            'letterform': letterform,
            'searchform': searchform,
            'letter': letter,
            'last_changes': last_changes,
            'last_changes_url': urlencode({
                'project': prj.slug,
                'lang': lang.code,
                'glossary': 1
            }),
        }
    )
Пример #3
0
def show_dictionary(request, project, lang):
    prj = get_project(request, project)
    lang = get_object_or_404(Language, code=lang)

    if request.method == "POST" and request.user.has_perm("glossary.add", prj):
        form = WordForm(request.POST)
        if form.is_valid():
            Dictionary.objects.create(
                request.user,
                project=prj,
                language=lang,
                source=form.cleaned_data["source"],
                target=form.cleaned_data["target"],
            )
        return redirect_next(request.POST.get("next"), request.get_full_path())
    form = WordForm()

    uploadform = DictUploadForm()

    words = Dictionary.objects.filter(project=prj, language=lang).order()

    letterform = LetterForm(request.GET)

    searchform = OneWordForm(request.GET)

    if searchform.is_valid() and searchform.cleaned_data["term"] != "":
        words = words.filter(source__search=searchform.cleaned_data["term"])
        search = searchform.cleaned_data["term"]
    else:
        search = ""

    if letterform.is_valid() and letterform.cleaned_data["letter"] != "":
        words = words.filter(
            source__istartswith=letterform.cleaned_data["letter"])
        letter = letterform.cleaned_data["letter"]
    else:
        letter = ""

    words = get_paginator(request, words)

    last_changes = (Change.objects.last_changes(request.user).filter(
        project=prj, language=lang).exclude(dictionary=None)[:10])

    return render(
        request,
        "dictionary.html",
        {
            "title":
            dict_title(prj, lang),
            "project":
            prj,
            "language":
            lang,
            "page_obj":
            words,
            "form":
            form,
            "query_string":
            urlencode({
                "term": search,
                "letter": letter
            }),
            "uploadform":
            uploadform,
            "letterform":
            letterform,
            "searchform":
            searchform,
            "letter":
            letter,
            "last_changes":
            last_changes,
            "last_changes_url":
            urlencode((
                ("project", prj.slug),
                ("lang", lang.code),
                ("action", Change.ACTION_DICTIONARY_NEW),
                ("action", Change.ACTION_DICTIONARY_EDIT),
                ("action", Change.ACTION_DICTIONARY_UPLOAD),
            )),
        },
    )