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

most of the linking done

parent e5707698
Pipeline #122 passed with stage
in 57 seconds
......@@ -18,20 +18,22 @@
<word>{{ word.word }}</word>
<fromlang>Language: {{ from_lang.name }}</fromlang>
<gender>Gender: {{ word.gender }}</gender>
<wordclass>Word class:{{ word.class }} ({{ word.class.code }})</wordclass>
<wordclass>Word class: {{word.wordclass}} </wordclass>
{% if translations %}
<listtrans>
<p>Translations of {{ word.word }} in {{ to_lang.name }}:</p>
<ul>
{% for translation in translations %}
<li>{{ translation.word }}</li>
<li><a href="{% url 'dictionary:details' to_lang.code from_lang.code translation.slug %}">{{ translation.word }}</a></li>
<!--TODO: link to the word's page-->
{% endfor %}
</ul>
</listtrans>
{% endif %}
{% if word.details %}
<transdetails>{{ word.details }}</transdetails>
{% endif %}
{% if word.etymology %}
<etymology>
......
......@@ -10,8 +10,18 @@
{% block body %}
<wordlist>
{% for word in words_initial %}
<wordblock>
{% for word in words %}
<!-- <wordblock> -->
<!-- <word>{{word.word}}</word> -->
<!-- <grammar> -->
<!-- <wclass>{{word.wordclass}}</wclass> -->
<!-- <gender>{{word.gender}}</gender> -->
<!-- </grammar> -->
<!-- {% for trans in word.translation.all %} -->
<!-- <translation>{{trans}} ({{trans.language.name}})</translation> -->
<!-- {% endfor %} -->
<!-- </wordblock> -->
<a href="{% url 'dictionary:details' from_lang.code to_lang.code word.slug %}" class="wordblock">
<word>{{word.word}}</word>
<grammar>
<wclass>{{word.wordclass}}</wclass>
......@@ -20,7 +30,7 @@
{% for trans in word.translation.all %}
<translation>{{trans}} ({{trans.language.name}})</translation>
{% endfor %}
</wordblock>
</a>
{% endfor %}
</wordlist>
......
......@@ -13,8 +13,8 @@ urlpatterns = [
# renvoie à la liste des mots de la première initiale de <from_lang>
# /dictionary/from=<from_lang>/to=<to_lang>/
# /dictionary/from=HJLP/to=FRA/
url(r'^from=(?P<from_lang>\w+)/to=(?P<to_lang>\w+)/$',
# /dictionary/from=HJLP/to=FRA
url(r'^from=(?P<from_lang>\w+)/to=(?P<to_lang>\w+)/*$',
views.index_lang,
name='listinitials'),
......@@ -22,22 +22,22 @@ urlpatterns = [
# `to_lang` commençant par la lettre `initial`
# /dictionary/from=<from_lang>/to=<to_lang>/init=<initial>
# /dictionary/from=HJLP/to=FRA/init=a
url(r'^from=(?P<from_lang>[:alpha:]+)/to=(?P<to_lang>[:alpha:]+)/init=(?P<initial>\S)/$',
url(r'^from=(?P<from_lang>\w+)/to=(?P<to_lang>\w+)/init=(?P<initial>\S)/*$',
views.listwords,
name='listwords'),
# renvoie le détail de la traduction de `word` en `from_lang` vers
# `to_lang`
# /dictionary/from=<from_lang>/to=<to_lang>/word=<word>/
# /dictionary/from=HJLP/to=FRA/hj-lp/
url(r'^from=(?P<from_lang>[:alpha:]+)/to=(?P<to_lang>[:alpha:]+)/(?P<word>[^\/]+)/$',
# /dictionary/from=HJLP/to=FRA/word=hj-lp
url(r'^from=(?P<from_lang>\w+)/to=(?P<to_lang>\w+)/word=(?P<word>[-\w0-9]+)/*$',
views.details,
name='details'),
# renvoie cinq mots de `from_lang` commençant par `word`
# /dictionary/from=<from_lang>/guess/<word>/
# /dictionary/from=HJLP/guess/hj/
url(r'^from=(?P<from_lang>[:alpha:]+)/guess/(?P<word>[^\/]+)/$',
# /dictionary/from=HJLP/guess=hj
url(r'^from=(?P<from_lang>\w+)/guess=(?P<word>[-\w0-9]+)/*$',
views.guessword,
name='guessword'),
]
from django.shortcuts import render
from django.utils.text import slugify
from django.views import generic
from django.views.generic import View
"""
Views for the dictionary
"""
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from .models import Language, Gender, Wordclass, Word
from .models import Language, Word
from .forms import SelectLangForm
def index(request):
"""
Will display the list of languages available and let the user choose which
language to get the words from and to which language it will be translated.
The two languages cannot be two natural languages or two conlangs.
"""
error_message = ""
if request.method == 'POST':
print("POST")
......@@ -18,8 +24,9 @@ def index(request):
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 + '/')
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")
......@@ -36,17 +43,27 @@ def index(request):
def index_lang(request, from_lang, to_lang):
words_initial = Word.objects.filter(language__code=from_lang)
"""
Will list all the words from the language `from_lang` translated to the
language `to_lang`
"""
words = Word.objects.filter(language__code=from_lang)
from_lang = Language.objects.get(code=from_lang)
to_lang = Language.objects.get(code=to_lang)
return render(request, 'dictionary/language.html', {
'words_initial': words_initial,
'words': words,
'from_lang': from_lang,
'to_lang': to_lang
'to_lang': to_lang,
})
def listwords(request, from_lang, to_lang, initial):
"""
This will list all the words from the language `from_lang` beginning with
the letter `initial` and translated to the language `to_lang`. It is similar
to `index_lang` but restricts the amount of words displayed on a single
page.
"""
# initial_lang = Language.objects.get(code=from_lang)
# target_lang = Language.objects.get(code=to_lang)
# words = Word.objects.filter(language=initial_lang).filter(
......@@ -55,12 +72,28 @@ def listwords(request, from_lang, to_lang, initial):
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)
pass
"""
Displays the details about the word `word` from the language `from_lang` if
this word is from a conlang and will display its translations to the
language `to_lang`
"""
from_lang = Language.objects.get(code=from_lang)
to_lang = Language.objects.get(code=to_lang)
word = get_object_or_404(Word, language=from_lang, slug=word)
translations = word.translation.filter(language=to_lang)
return render(request, 'dictionary/details.html', {
'word': word,
'translations': translations,
'from_lang': from_lang,
'to_lang': to_lang,
})
def guessword(request, from_lang, word):
"""
Is used to get five words from `from_lang` beginning with `word`. This will
be used for word suggestion when using the search bar.
"""
# 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