Currently moving from Gitlab to Gitea at https://labs.phundrak.com. Some features may not work anymore on this Gitlab instance.

language selection now works

parent cb940d36
Pipeline #121 passed with stage
from django import forms
from .models import Language
class SelectLangForm(forms.Form):
from_lang = forms.ModelChoiceField(
queryset=Language.objects.all(), label="Translate from:", to_field_name="code")
to_lang = forms.ModelChoiceField(
queryset=Language.objects.all(), label="to:", to_field_name="code")
......@@ -13,20 +13,24 @@
{% block body %}
<message>Please select the languages you want to translate from and to.</message>
<langselect>
<form method="post" id="" action="" enctype="multipart/form-data">
{% csrf_token %}
<select name="sourcelang">
<form method="post" id="langselect" action="/dictionary/" enctype="multipart/form-data">
{% csrf_token %}
<sourcelang>
<label for="source">Translate from:</label>
<select id="source" name="from_lang">
{% for lang in all_languages %}
<option value="{{lang.code}}">{{lang.name}}</option>
{% endfor %}
</select>
<select name="sourcelang">
</sourcelang>
<destlang>
<label for="dest" >to:</label>
<select id="dest" name="to_lang">
{% for lang in all_languages %}
<option value="{{lang.code}}">{{lang.name}}</option>
{% endfor %}
</select>
<button type="submit">Let’s Go!</button>
</form>
</langselect>
</destlang>
<input type="submit" value="Let’s Go!">
</form>
{% endblock %}
......@@ -2,13 +2,37 @@ from django.shortcuts import render
from django.utils.text import slugify
from django.views import generic
from django.views.generic import View
from django.http import HttpResponseRedirect
from .models import Language, Gender, Wordclass, Word
from .forms import SelectLangForm
def index(request):
error_message = ""
if request.method == 'POST':
print("POST")
form = SelectLangForm(request.POST)
if form.is_valid():
print("IS VALID")
from_lang = form.cleaned_data['from_lang']
to_lang = form.cleaned_data['to_lang']
print(from_lang.code + " and " + to_lang.code)
if from_lang.conlang != to_lang.conlang:
return HttpResponseRedirect('/dictionary/from=' + from_lang.code +
'/to=' + to_lang.code + '/')
error_message = "You cannot select two natural languages or two conlangs."
else:
print("NOT VALID")
print(form.errors)
error_message = form.errors
else:
print("GET")
form = SelectLangForm()
all_languages = Language.objects.all()
return render(request, 'dictionary/index.html',
{'all_languages': all_languages})
return render(request, 'dictionary/index.html', {
'all_languages': all_languages,
'error_message': error_message
})
def index_lang(request, from_lang, to_lang):
......@@ -23,17 +47,20 @@ def index_lang(request, from_lang, to_lang):
def listwords(request, from_lang, to_lang, initial):
initial_lang = Language.objects.get(code=from_lang)
target_lang = Language.objects.get(code=to_lang)
words = Word.objects.filter(language=initial_lang).filter(
word__startswith(initial))
# initial_lang = Language.objects.get(code=from_lang)
# target_lang = Language.objects.get(code=to_lang)
# words = Word.objects.filter(language=initial_lang).filter(
# word__startswith(initial))
pass
def details(request, from_lang, to_lang, word):
word = Word.objects.filter(language=from_lang).get(slug=slugify(word))
translations = word.translations.filter(language=to_lang)
# word = Word.objects.filter(language=from_lang).get(slug=slugify(word))
# translations = word.translations.filter(language=to_lang)
pass
def guessword(request, from_lang, word):
words = Word.object.filter(language=from_lang).filter(
slug__stratswith(slugify(word)))[:5]
# words = Word.object.filter(language=from_lang).filter(
# slug__stratswith(slugify(word)))[:5]
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment