本文整理汇总了Python中weblate.trans.forms.WordForm类的典型用法代码示例。如果您正苦于以下问题:Python WordForm类的具体用法?Python WordForm怎么用?Python WordForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WordForm类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_dictionary
def edit_dictionary(request, project, lang):
prj = get_project(request, project)
lang = get_object_or_404(Language, code=lang)
word = get_object_or_404(Dictionary, project=prj, language=lang, id=request.GET.get("id"))
if request.method == "POST":
form = WordForm(request.POST)
if form.is_valid():
word.edit(request, form.cleaned_data["source"], form.cleaned_data["target"])
return redirect("show_dictionary", project=prj.slug, lang=lang.code)
else:
form = WordForm(initial={"source": word.source, "target": word.target})
last_changes = Change.objects.last_changes(request.user).filter(dictionary=word)[:10]
return render(
request,
"edit_dictionary.html",
{
"title": dict_title(prj, lang),
"project": prj,
"language": lang,
"form": form,
"last_changes": last_changes,
"last_changes_url": urlencode({"project": prj.slug, "lang": lang.code, "glossary": 1}),
},
)
示例2: add_dictionary
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}
)
示例3: edit_dictionary
def edit_dictionary(request, project, lang, pk):
prj = get_project(request, project)
if not request.user.has_perm('glossary.edit', prj):
raise PermissionDenied()
lang = get_object_or_404(Language, code=lang)
word = get_object_or_404(
Dictionary,
project=prj,
language=lang,
id=pk,
)
if request.method == 'POST':
form = WordForm(request.POST)
if form.is_valid():
word.edit(
request,
form.cleaned_data['source'],
form.cleaned_data['target']
)
return redirect(
'show_dictionary',
project=prj.slug,
lang=lang.code
)
else:
form = WordForm(
initial={'source': word.source, 'target': word.target}
)
last_changes = Change.objects.last_changes(request.user).filter(
dictionary=word,
)[:10]
return render(
request,
'edit_dictionary.html',
{
'title': dict_title(prj, lang),
'project': prj,
'language': lang,
'form': form,
'last_changes': last_changes,
'last_changes_url': urlencode({
'project': prj.slug,
'lang': lang.code,
'glossary': 1
}),
}
)
示例4: show_dictionary
def show_dictionary(request, project, lang):
prj = get_object_or_404(Project, slug = project)
lang = get_object_or_404(Language, code = lang)
if request.method == 'POST' and request.user.has_perm('trans.add_dictionary'):
form = WordForm(request.POST)
if form.is_valid():
Dictionary.objects.create(
project = prj,
language = lang,
source = form.cleaned_data['source'],
target = form.cleaned_data['target']
)
return HttpResponseRedirect(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'])
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)
return render_to_response('dictionary.html', RequestContext(request, {
'title': _('%(language)s dictionary for %(project)s') % {'language': lang, 'project': prj},
'project': prj,
'language': lang,
'words': words,
'form': form,
'uploadform': uploadform,
'letterform': letterform,
'letter': letterform.cleaned_data['letter'],
}))
示例5: edit_dictionary
def edit_dictionary(request, project, lang):
prj = get_project(request, project)
lang = get_object_or_404(Language, code=lang)
word = get_object_or_404(
Dictionary,
project=prj,
language=lang,
id=request.GET.get('id')
)
if request.method == 'POST':
form = WordForm(request.POST)
if form.is_valid():
word.edit(
request,
form.cleaned_data['source'],
form.cleaned_data['target']
)
return redirect(
'show_dictionary',
project=prj.slug,
lang=lang.code
)
else:
form = WordForm(
initial={'source': word.source, 'target': word.target}
)
last_changes = Change.objects.last_changes(request.user).filter(
dictionary=word,
)[:10]
return render(
request,
'edit_dictionary.html',
{
'title': _('%(language)s dictionary for %(project)s') %
{'language': lang, 'project': prj},
'project': prj,
'language': lang,
'form': form,
'last_changes': last_changes,
'last_changes_url': urlencode({
'project': prj.slug,
'lang': lang.code,
'glossary': 1
}),
}
)
示例6: add_dictionary
def add_dictionary(request, unit_id):
unit = get_object_or_404(Unit, pk=int(unit_id))
request.user.check_access(unit.translation.component.project)
prj = unit.translation.component.project
lang = unit.translation.language
code = 403
results = ''
words = []
if request.method == 'POST' and request.user.has_perm('glossary.add', 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])
}
)
示例7: edit_dictionary
def edit_dictionary(request, project, lang):
prj = get_object_or_404(Project, slug = project)
lang = get_object_or_404(Language, code = lang)
word = get_object_or_404(Dictionary, project = prj, language = lang, id = request.GET.get('id'))
if request.method == 'POST':
form = WordForm(request.POST)
if form.is_valid():
word.source = form.cleaned_data['source']
word.target = form.cleaned_data['target']
word.save()
return HttpResponseRedirect(reverse('weblate.trans.views.show_dictionary', kwargs = {'project': prj.slug, 'lang': lang.code}))
else:
form = WordForm(initial = {'source': word.source, 'target': word.target })
return render_to_response('edit_dictionary.html', RequestContext(request, {
'title': _('%(language)s dictionary for %(project)s') % {'language': lang, 'project': prj},
'project': prj,
'language': lang,
'form': form,
}))
示例8: show_dictionary
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
}),
}
)
示例9: show_dictionary
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('trans.add_dictionary')):
form = WordForm(request.POST)
if form.is_valid():
Dictionary.objects.create(
request,
project=prj,
language=lang,
source=form.cleaned_data['source'],
target=form.cleaned_data['target']
)
return HttpResponseRedirect(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,
'words': 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
}),
}
)
示例10: show_dictionary
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'))
page, limit = get_page_limit(request, 25)
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 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,
'query_string': 'letter={}'.format(letter) if letter else '',
'uploadform': uploadform,
'letterform': letterform,
'letter': letter,
'limit': limit,
'page': page,
'last_changes': last_changes,
'last_changes_url': urlencode({
'project': prj.slug,
'lang': lang.code,
'glossary': 1
}),
}
)
示例11: show_dictionary
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("trans.add_dictionary"):
form = WordForm(request.POST)
if form.is_valid():
Dictionary.objects.create(
request,
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}),
},
)