Ejemplo n.º 1
0
def add_dictionary(request, unit_id):
    unit = get_object_or_404(Unit, pk=int(unit_id))
    check_access(request, unit.translation.subproject.project)

    prj = unit.translation.subproject.project
    lang = unit.translation.language

    code = 403
    results = ''

    if request.method == 'POST' and can_add_dictionary(request.user, 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'])
            code = 200
            results = render_to_string(
                'glossary-embed.html', {
                    'glossary': Dictionary.objects.get_words(unit),
                    'unit': unit,
                    'user': request.user,
                })

    return JsonResponse(data={'responseCode': code, 'results': results})
Ejemplo n.º 2
0
def add_dictionary(request, unit_id):
    unit = get_object_or_404(Unit, pk=int(unit_id))
    check_access(request, unit.translation.subproject.project)

    prj = unit.translation.subproject.project
    lang = unit.translation.language

    code = 403
    results = ''

    if request.method == 'POST' and can_add_dictionary(request.user, 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']
            )
            code = 200
            results = render_to_string(
                'glossary-embed.html',
                {
                    'glossary': Dictionary.objects.get_words(unit),
                    'unit': unit,
                    'user': request.user,
                }
            )

    return JsonResponse(
        data={'responseCode': code, 'results': results}
    )
Ejemplo n.º 3
0
def add_dictionary(request, unit_id):
    unit = get_object_or_404(Unit, pk=int(unit_id))
    check_access(request, unit.translation.subproject.project)

    prj = unit.translation.subproject.project
    lang = unit.translation.language

    code = 403
    results = ''
    words = []

    if request.method == 'POST' and can_add_dictionary(request.user, prj):
        form = WordForm(request.POST)
        if form.is_valid():
            word = Dictionary.objects.create(
                request.user,
                project=prj,
                language=lang,
                source=form.cleaned_data['source'],
                target=form.cleaned_data['target']
            )
            words = form.cleaned_data['words']
            words.append(word.id)
            code = 200
            results = render_to_string(
                'glossary-embed.html',
                {
                    'glossary': (
                        Dictionary.objects.get_words(unit) |
                        Dictionary.objects.filter(project=prj, pk__in=words)
                    ),
                    'unit': unit,
                    'user': request.user,
                }
            )

    return JsonResponse(
        data={
            'responseCode': code,
            'results': results,
            'words': ','.join([str(x) for x in words])
        }
    )
Ejemplo n.º 4
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 can_add_dictionary(request.user, 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 HttpResponseRedirect(
            request.POST.get('next', request.get_full_path()))
    else:
        form = WordForm()

    uploadform = DictUploadForm()

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

    limit = request.GET.get('limit', 25)
    page = request.GET.get('page', 1)

    letterform = LetterForm(request.GET)

    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 = ''

    paginator = Paginator(words, limit)

    try:
        words = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        words = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        words = paginator.page(paginator.num_pages)

    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,
            'uploadform':
            uploadform,
            'letterform':
            letterform,
            'letter':
            letter,
            'last_changes':
            last_changes,
            'last_changes_url':
            urlencode({
                'project': prj.slug,
                'lang': lang.code,
                'glossary': 1
            }),
        })
Ejemplo n.º 5
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 can_add_dictionary(request.user, 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('source')

    limit = request.GET.get('limit', 25)
    page = request.GET.get('page', 1)

    letterform = LetterForm(request.GET)

    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 = ''

    paginator = Paginator(words, limit)

    try:
        words = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        words = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        words = paginator.page(paginator.num_pages)

    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,
            'uploadform': uploadform,
            'letterform': letterform,
            'letter': letter,
            'last_changes': last_changes,
            'last_changes_url': urlencode({
                'project': prj.slug,
                'lang': lang.code,
                'glossary': 1
            }),
        }
    )