diff --git a/gazhdict/addentry/views.py b/gazhdict/addentry/views.py index 808bc33..d71075a 100644 --- a/gazhdict/addentry/views.py +++ b/gazhdict/addentry/views.py @@ -1,15 +1,18 @@ from django.shortcuts import render - +from django.contrib.auth.decorators import login_required from django.http import HttpResponse from datetime import datetime from .add_entry_form import EntryForm, MeaningForm from .models import Entry, Meaning +from django.forms import formset_factory + # Create your views here. def hello_world(request): return render(request, 'hello_world.html', {'current_time' : str(datetime.now()),}) +@login_required #登入必要 def add_entry(request): # it becomes true when stored successfully @@ -22,30 +25,42 @@ def add_entry(request): latest_entry_id = Entry.objects.latest('id').id - meaning_form = MeaningForm(request.POST) + MeaningFormSet = formset_factory(MeaningForm, extra=5) + meaning_form_set = MeaningFormSet(data=request.POST or None) + + meaning_form_valid_length = len(list(filter(lambda x : x == {} , meaning_form_set.errors))) - if meaning_form.is_valid: - meaning_form.save() + i = 0 + for form in meaning_form_set: + if i < meaning_form_valid_length: + form.save() + raise Exception("Form Saved!") + i += 1 + else: + break - latest_meaning_id = Meaning.objects.latest('id').id + latest_meaning_id = Meaning.objects.latest('id').id - # update the entry id of meaning - Meaning.objects.filter(id=latest_meaning_id).update(Entry=latest_entry_id) + # update the entry id of meaning + valid_meaning_list = Meaning.objects.all().order_by('-id')[:meaning_form_valid_length] + for meaning in valid_meaning_list: + Meaning.objects.filter(id=meaning.id).update(Entry=latest_entry_id) - is_saved = True + is_saved = True - entry_list = Entry.objects.all() - meaning_list = Meaning.objects.all() + entry_list = list(Entry.objects.all())[-10:] + meaning_list = list(Meaning.objects.all())[-20:] entry_form = EntryForm() - meaning_form = MeaningForm() + meaning_form_set = formset_factory(MeaningForm, extra=5) + context = { 'is_saved' : is_saved, 'entry_form' : entry_form, - 'meaning_form' : meaning_form, + 'meaning_form_set' : meaning_form_set, 'entry_list' : entry_list, 'meaning_list' : meaning_list, diff --git a/gazhdict/static/addentry/add_entry.css b/gazhdict/static/addentry/add_entry.css index 63b2d5f..e4cb7ce 100644 --- a/gazhdict/static/addentry/add_entry.css +++ b/gazhdict/static/addentry/add_entry.css @@ -1,9 +1,13 @@ +.entry-modify-input{ + display : none; +} + + #id_Entry { display: none; } - label[for=id_Entry]{ display: none; } diff --git a/gazhdict/static/addentry/add_entry.js b/gazhdict/static/addentry/add_entry.js index 451934f..9b69116 100644 --- a/gazhdict/static/addentry/add_entry.js +++ b/gazhdict/static/addentry/add_entry.js @@ -1,6 +1,13 @@ // setting the option value of the entry selection list to 1 -var options = document.getElementById("id_Entry"); -options.value = "1"; +var formBox = document.getElementById("form-box"); +var options = document.getElementsByTagName("select"); +for (var i = 0; i < options.length; i++) { + options[i].value = "1"; + options[i].style.display = "none"; + var label = document.querySelector("label[for=id_form-" + i + "-Entry]"); + label.style.display = "none"; +} +//options.value="1"; // setting saved_successed position var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; @@ -16,3 +23,18 @@ var SuccSaved = document.getElementById("successful-saved"); closeSuccSaved.addEventListener("click", function (e) { SuccSaved.style["display"] = "none"; }); +var editBottonList = document.getElementsByClassName('entry-edit-button'); +for (var i = 0; i < editBottonList.length; i++) { + editBottonList[i].addEventListener("click", function (e) { + console.log(123); + var tgt = e.target; + var bottonId = tgt.id; + var entryEditRegexp = /entry-edit-(\d+)/; + var IdNum = entryEditRegexp.exec(bottonId)[1]; + var inputBoxClassName = ".ent-mod-inp-" + IdNum; // ent-mod-inp = entry-modify-input + var inputBoxList = document.querySelectorAll(inputBoxClassName); + for (var j = 0; j < inputBoxList.length; j++) { + inputBoxList[j].style['display'] = 'block'; + } + }, false); +} diff --git a/gazhdict/static/addentry/add_entry.ts b/gazhdict/static/addentry/add_entry.ts index 8eb5d8b..6522077 100644 --- a/gazhdict/static/addentry/add_entry.ts +++ b/gazhdict/static/addentry/add_entry.ts @@ -1,8 +1,15 @@ // setting the option value of the entry selection list to 1 -var options = document.getElementById("id_Entry"); +var formBox = document.getElementById("form-box"); +var options = document.getElementsByTagName("select"); +for(var i=0; i document.querySelector("label[for=id_form-" + i + "-Entry]"); + label.style.display = "none"; +} -options.value="1"; +//options.value="1"; // setting saved_successed position @@ -27,4 +34,23 @@ closeSuccSaved.addEventListener("click",(e)=>{ SuccSaved.style["display"] = "none"; }) +var editBottonList = document.getElementsByClassName('entry-edit-button') + +for (var i=0; i< editBottonList.length; i++){ + editBottonList[i].addEventListener("click",(e)=>{ + console.log(123); + let tgt = e.target; + let bottonId = tgt.id; + let entryEditRegexp = /entry-edit-(\d+)/; + let IdNum = entryEditRegexp.exec(bottonId)[1]; + let inputBoxClassName = ".ent-mod-inp-" + IdNum; // ent-mod-inp = entry-modify-input + + let inputBoxList = document.querySelectorAll(inputBoxClassName); + for (var j=0; j愛爾蘭語—華語線上辭典 - 增加條目{% endblock %} +{% block content %} - - - - - 增加條目 - - - - -{% if is_saved == True %} -
+
[X]
儲存成功!
-{% endif %} +

線上愛爾蘭語—華語辭典

增加項目與解釋

-{% block content %} +
{% csrf_token %}
@@ -29,22 +22,26 @@ {{field.label_tag}} {{field}}
{% endfor %}

-

解釋

- {% for field in meaning_form %} - - {{field.label_tag}} {{field}}
- + {{meaning_form_set.management_form}} + {% for meaning in meaning_form_set %} +

解釋{{forloop.counter}}

+ {% for field in meaning %} + {{field.label_tag}} {{field}}
+ {% endfor %} {% endfor %} -
+

-{% endblock %} -

詞條一覽

+{% for entry in entry_list reversed%} +
+{% endfor %} + +

詞條一覽(最後10筆倒著顯示)

@@ -57,19 +54,52 @@ -{% for entry in entry_list%} + +{% for entry in entry_list reversed%} - - - - - - - + + + + + + + + +{% endfor %} +
編輯
{{entry.id}}{{entry.Gaeilge}}{% if entry.Pronoun != None %}{{entry.Pronoun}}{% endif %}{% if entry.PoS != None %}{{entry.PoS}}{% endif %}{% if entry.PreScript != None %}{{entry.PreScript}}{% endif %}{% if entry.PostScript != None %}{{entry.PostScript}}{% endif %}編輯 刪除{{entry.id}}{{entry.Gaeilge}}{% if entry.Pronoun != None %}{{entry.Pronoun}}{% endif %}{% if entry.PoS != None %}{{entry.PoS}}{% endif %}{% if entry.PreScript != None %}{{entry.PreScript}}{% endif %}{% if entry.PostScript != None %}{{entry.PostScript}}{% endif %} 刪除
+ +

釋義一覽

+ + + + + + + + + + + + + + + +{% for m in meaning_list reversed%} + + + + + + + + + + + {% endfor %}
id條目id
Entry Id
意思
Meaning_content
例句1
Exam_Sentence1
例句中譯1
Exam_Sentence1_zh
例句2
Exam_Sentence2
例句中譯2
Exam_Sentence2_zh
例句3
Exam_Sentence3
例句中譯3
Exam_Sentence3_zh
編輯
{{m.id}}{{m.Entry.id}}{{m.Meaning_content}}{% if m.Exam_Sentence1 != None %}{{m.Exam_Sentence1}}{% endif %}{% if m.Exam_Sentence1_zh != None %}{{m.Exam_Sentence1_zh}}{% endif %}{% if m.Exam_Sentence2 != None %}{{m.Exam_Sentence2}}{% endif %}{% if m.Exam_Sentence2_zh != None %}{{m.Exam_Sentence2_zh}}{% endif %}{% if m.Exam_Sentence3 != None %}{{m.Exam_Sentence3}}{% endif %}{% if m.Exam_Sentence3_zh != None %}{{m.Exam_Sentence3_zh}}{% endif %}編輯 更新 刪除
- - + +{% endblock %} diff --git a/gazhdict/templates/base_generic.html b/gazhdict/templates/base_generic.html index 8f2f9cf..769043d 100644 --- a/gazhdict/templates/base_generic.html +++ b/gazhdict/templates/base_generic.html @@ -1,3 +1,4 @@ +{% load static %} @@ -5,7 +6,40 @@ - +
+ +

愛爾蘭語—華語線上辭典

+

An Fócloir Gaeilge-Mandairinis ar Líne

+
+
+
+
+
    +
  • 不規則動詞、繫詞表
  • +
    • abair
    • +
    • beir
    • +
    • +
    • clois
    • +
    • dein
    • +
    • is
    • +
    • faigh
    • +
    • gabh
    • +
    • inis
    • +
    • ith
    • +
    • righ
    • +
    • tabhair
    • +
    • tar
    • +
    • téigh
    • +
    +
  • 關於本站
  • +
+
+
{% block content %}{% endblock %} +
+ + + + diff --git a/gazhdict/templates/ga_search.html b/gazhdict/templates/ga_search.html index e03d818..a4ac9ff 100644 --- a/gazhdict/templates/ga_search.html +++ b/gazhdict/templates/ga_search.html @@ -1,28 +1,24 @@ - - - - 線上愛爾蘭語—漢語辭典 - 愛爾蘭語搜尋 {{entry}} 的結果 - - - +{% extends "base_generic.html" %} +{% load static %} +{% block title %} +愛爾蘭語—華語線上辭典 - 首頁{% endblock %} +{% block content %} + - - + +{% endblock %} diff --git a/gazhdict/templates/index.html b/gazhdict/templates/index.html index 961b07c..22b003e 100644 --- a/gazhdict/templates/index.html +++ b/gazhdict/templates/index.html @@ -1,15 +1,6 @@ - - - - - 線上愛爾蘭語—漢語辭典 - - - - +{% load static %} +{% block title %}愛爾蘭語—華語線上辭典 - 首頁{% endblock %} +{% extends "base_generic.html" %} - - - \ No newline at end of file +{% endblock %} diff --git a/gazhdict/templates/registration/login.html b/gazhdict/templates/registration/login.html index 0f9690b..7377489 100644 --- a/gazhdict/templates/registration/login.html +++ b/gazhdict/templates/registration/login.html @@ -1,13 +1,9 @@ - - - -線上愛爾蘭語—華語辭典 - 登入 - - -

線上愛爾蘭語—華語辭典

-

管理後台登入畫面

- +{% extends "base_generic.html" %} +{% load static %} +{% block title %} +愛爾蘭語—華語線上辭典 - 登入{% endblock %} {% block content %} +

後台登入

{% if form.errors %}

帳號或密碼不符合,請重新輸入。

{% endif %} @@ -42,5 +38,3 @@

忘記密碼?

{% endblock %} - -