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'], }))
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, 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 }), })
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 }), } )
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 }), } )
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 }), } )
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), )), }, )
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 }), } )
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}), }, )