now on index, choose a natlang and a conlang

parent 3c60d75a
......@@ -3,7 +3,7 @@ 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")
natlang = forms.ModelChoiceField(
queryset=Language.objects.all(), label="Natural Language:", to_field_name="code")
conlang = forms.ModelChoiceField(
queryset=Language.objects.all(), label="Constructed Language:", to_field_name="code")
......@@ -69,18 +69,22 @@ message {
margin: 0 20px;
}
h2 {
padding: 20px;
}
sidebar {
display: block;
}
sidebar > ul {
sidebar ul {
padding-inline-start: 0;
margin: 40px;
display: block;
list-style: none;
}
sidebar > ul >li {
sidebar ul li {
font-size: 1.1em;
margin: 20px;
}
......@@ -12,12 +12,21 @@
{% endblock %}
{% block sidebarcontent %}
<h1 class="sidebar-title">List of available languages</h1>
<ul class="sidebar-content">
{% for lang in all_languages %}
<li>{{lang}}</li>
{% endfor %}
</ul>
<h1 class="sidebar-title">Available Languages</h1>
<div class="sidebar-content">
<h2>Available natlangs</h1>
<ul>
{% for lang in natlangs %}
<li>{{lang}}</li>
{% endfor %}
</ul>
<h2>Available conlangs</h1>
<ul>
{% for lang in conlangs %}
<li>{{lang}}</li>
{% endfor %}
</ul>
</div>
{% endblock %}
{% block body %}
......@@ -25,20 +34,20 @@
<form method="post" id="langselect" action="/" enctype="multipart/form-data">
{% csrf_token %}
<sourcelang>
<label for="source" class="p">Translate from</label>
<label for="source" class="p">Natural Language:</label>
<div class="form-style">
<select id="source" name="from_lang">
{% for lang in all_languages %}
<select id="source" name="natlang">
{% for lang in natlangs %}
<option value="{{lang.code}}">{{lang.name}}</option>
{% endfor %}
</select>
</div>
</sourcelang>
<destlang>
<label for="dest" class="p">to</label>
<div class="form-style" >
<select id="dest" name="to_lang">
{% for lang in all_languages %}
<label for="dest" class="p">Constructed Language:</label>
<div class="form-style">
<select id="dest" name="conlang">
{% for lang in conlangs %}
<option value="{{lang.code}}">{{lang.name}}</option>
{% endfor %}
</select>
......@@ -46,6 +55,6 @@
</destlang>
<submit class="form-style">
<input type="submit" value="Let’s Go!">
</div>
</div>
</form>
{% endblock %}
......@@ -21,7 +21,7 @@ urlpatterns = [
# renvoie à la liste des mots de la première initiale de <from_lang>
# /search/<from_lang>/<to_lang>/<initial>
# /search/HJP/FRA/a
url(r'^search/(?P<from_lang>\w+)/(?P<to_lang>\w+)/(?P<initial>\w)/*$',
url(r'^search/(?P<natlang>\w+)/(?P<conlang>\w+)/(?P<initial>\w)/*$',
views.list_initial,
name='index_initial'),
......
......@@ -20,20 +20,20 @@ def index(request):
if request.method == 'POST':
form = SelectLangForm(request.POST)
if form.is_valid():
from_lang = form.cleaned_data['from_lang']
to_lang = form.cleaned_data['to_lang']
if from_lang.conlang != to_lang.conlang:
return HttpResponseRedirect('/search/' + from_lang.code + '/' +
to_lang.code)
error_message = "You cannot select two natural languages or two conlangs."
else:
print(form.errors)
error_message = form.errors
natlang = form.cleaned_data['natlang']
conlang = form.cleaned_data['conlang']
return HttpResponseRedirect('/search/' + natlang.code + '/' +
conlang.code)
print(form.errors)
error_message = form.errors
else:
form = SelectLangForm()
all_languages = Language.objects.all()
# all_languages = Language.objects.all()
conlangs = Language.objects.filter(conlang=True)
natlangs = Language.objects.filter(conlang=False)
return render(request, 'dictionary/index.html', {
'all_languages': all_languages,
'conlangs': conlangs,
'natlangs': natlangs,
'error_message': error_message
})
......@@ -49,12 +49,13 @@ def index_lang(request, natlang, conlang):
conwords = Word.objects.filter(language__code=conlang)
natlang = Language.objects.get(code=natlang)
conlang = Language.objects.get(code=conlang)
return render(request, 'dictionary/language.html', {
'natwords': natwords,
'conwords': conwords,
'natlang': natlang,
'conlang': conlang,
})
return render(
request, 'dictionary/language.html', {
'natwords': natwords,
'conwords': conwords,
'natlang': natlang,
'conlang': conlang,
})
def list_initial(request, from_lang, to_lang, initial):
......
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