Commit 42d9980a authored by Michal Čihař's avatar Michal Čihař

Adding words to dictionary

parent 353f99b9
......@@ -13,6 +13,8 @@
{% if words.object_list %}
<h2>{% trans "Dictionary" %}</h2>
<table>
<thead>
<tr>
......@@ -49,5 +51,15 @@
</ul>
{% endif %}
<h2>{% trans "Add new word" %}</h2>
<form method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="{% trans "Add" %}" />
</form>
{% endblock %}
......@@ -113,3 +113,7 @@ class AutoForm(forms.Form):
choices = [(s.slug, s.name) for s in obj.subproject.project.subproject_set.exclude(id = obj.subproject.id)]
super(AutoForm, self).__init__(*args, **kwargs)
self.fields['subproject'].choices = [('', _('All subprojects'))] + choices
class WordForm(forms.Form):
source = forms.CharField(label = _('Source'))
target = forms.CharField(label = _('Translation'))
......@@ -13,7 +13,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from trans.models import Project, SubProject, Translation, Unit, Suggestion, Check, Dictionary, Change
from lang.models import Language
from trans.forms import TranslationForm, UploadForm, SimpleUploadForm, ExtraUploadForm, SearchForm, MergeForm, AutoForm
from trans.forms import TranslationForm, UploadForm, SimpleUploadForm, ExtraUploadForm, SearchForm, MergeForm, AutoForm, WordForm
from util import is_plural, split_plural, join_plural
from accounts.models import Profile
from whoosh.analysis import StandardAnalyzer, StemmingAnalyzer
......@@ -137,6 +137,19 @@ 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':
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()
words = Dictionary.objects.filter(project = prj, language = lang).order_by('source')
limit = request.GET.get('limit', 25)
......@@ -158,6 +171,7 @@ def show_dictionary(request, project, lang):
'project': prj,
'language': lang,
'words': words,
'form': form,
}))
def show_project(request, project):
......
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