From 0cdba05f09201b6db129ebaa787e960be9ecb851 Mon Sep 17 00:00:00 2001 From: Alvin Li Date: Fri, 16 Aug 2013 01:20:52 +0800 Subject: * updated 'indicator/templates/indicator/NewDeleteIndex.html': o page_condition: "all", "category", "search" o make use of django templates to generate contents * updated 'indicator.views': GET, POST methods for NewDeleteIndex page * indicator.search_indexes: changed 'categories' to 'categories_id' --- 97suifangqa/apps/indicator/search_indexes.py | 2 +- .../templates/indicator/NewDeleteIndex.html | 327 +++------------------ .../apps/indicator/templates/indicator/test.html | 14 +- 97suifangqa/apps/indicator/views.py | 58 +++- 4 files changed, 111 insertions(+), 290 deletions(-) diff --git a/97suifangqa/apps/indicator/search_indexes.py b/97suifangqa/apps/indicator/search_indexes.py index b7a8437..67d5723 100644 --- a/97suifangqa/apps/indicator/search_indexes.py +++ b/97suifangqa/apps/indicator/search_indexes.py @@ -33,7 +33,7 @@ class IndicatorIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) addByUser = indexes.CharField(model_attr='addByUser') dataType = indexes.CharField(model_attr='dataType') - categories = indexes.MultiValueField() + categories_id = indexes.MultiValueField() def get_model(self): return im.Indicator diff --git a/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html b/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html index 8fd3e4c..c2a219a 100644 --- a/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html +++ b/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html @@ -79,7 +79,7 @@
-
+
所有指标
A
@@ -110,10 +110,13 @@
Z
+ {# display all indicators if in 'all' condition #} + {# NOTE: 'indicators' is in 'P[inyin] dict format #} + {% if page_condition == "all" %}
- {# display all indicator by letter index #} + {# display all indicators by letter index #} {% for l in letters %} - {% with l_inds=indicators_pdict|dict_get:l %} + {% with l_inds=indicators|dict_get:l %} {% if l_inds|length >= 1 %}
{{ l|upper }}
@@ -128,267 +131,56 @@
{% endif %} {% endwith %} - {% endfor %} - {# end: display all indicator #} - - {% comment %}{# vim: {{{ #} - -
-
A
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
B
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
C
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
D
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
E
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
F
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
G
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
H
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
I
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
J
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
K
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
L
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
M
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
N
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
O
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
P
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
Q
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
R
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
S
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
T
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
U
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
V
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
W
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
X
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
Y
-
-
乙肝病毒表面抗原
-
两对半
-
-
-
-
-
-
Z
-
-
乙肝病毒表面抗原
-
两对半
+ {% endfor %} {# end: display all indicators #} +
+ {% endif %} {# end: page_condition == all #} +
+ + + + {# page_condition == "category" #} +
+
+
{{ selected_category.name }}
+
仿真化验单
+
+
+ +
+ {% for ind in indicators %} +
+
{{ ind.name }}
+
-
- - {% endcomment %}{# vim: }}} #} + {% endfor %} +
+
-
-
- - +
+ + +
diff --git a/97suifangqa/apps/indicator/templates/indicator/test.html b/97suifangqa/apps/indicator/templates/indicator/test.html index 65340b9..d7b349f 100644 --- a/97suifangqa/apps/indicator/templates/indicator/test.html +++ b/97suifangqa/apps/indicator/templates/indicator/test.html @@ -13,7 +13,12 @@
  • {{ l }}
    • {% for i in indicators %} -
    • id: {{ i|dict_get:"id" }}; name: {{ i|dict_get:"name" }}
    • +
    • + id: {{ i|dict_get:"id" }}; + name: {{ i|dict_get:"name" }}; + category_id: {{ i|dict_get:"categories_id"|first }}; + category_name: {{ i|dict_get:"categories_name"|first }}; +
    • {% endfor %}
    {% endif %} @@ -27,6 +32,13 @@
  • id: {{ fi|dict_get:"id" }}; name: {{ fi|dict_get:"name" }}
  • {% endfor %} + +

    ul 3

    +
      + {% for i in list %} +
    • i
    • + {% endfor %} +
    diff --git a/97suifangqa/apps/indicator/views.py b/97suifangqa/apps/indicator/views.py index 8f2cf88..f222d10 100644 --- a/97suifangqa/apps/indicator/views.py +++ b/97suifangqa/apps/indicator/views.py @@ -456,6 +456,11 @@ def indicator_status(request): def follow_indicator(request): """ follow/unfollow indicator + + Note: + * when 'page_condition == all', + indicators -> indicators_pdict, in 'P[inyin] dict' format + * other 'page_condition', 'indicators' a object list """ template = 'indicator/NewDeleteIndex.html' letters = map(chr, range(ord('a'), ord('z')+1)) @@ -463,6 +468,9 @@ def follow_indicator(request): # get 7 categories (page can only contains 1+7 categories) categories = im.IndicatorCategory.objects.all().\ order_by('id')[:7] + # set default value for 'selected_cat*' + selected_catid = None + selected_category = None # get indicators, P[inyin] dict format indicators_pdict = get_indicator() # get followed indicator, P[inyin] dict format @@ -472,22 +480,51 @@ def follow_indicator(request): for l in letters: followed_indicators += followed_indicators_pdict[l] - # selected category, default "all" - if request.GET.get('tab'): - selected_catid = request.GET.get('tab') - if selected_catid != "all": - selected_catid = int(selected_catid) + # get/post views + if request.method == 'GET': + if request.GET.get('tab'): + # tab: selected category, default "all" + selected_catid = request.GET.get('tab') + if selected_catid == "all": + page_condition = "all" + indicators = indicators_pdict + else: + selected_catid = int(selected_catid) + selected_category = get_object_or_404( + im.IndicatorCategory, id=selected_catid) + page_condition = "category" + # get indicators of the category + indicators = selected_category.indicators.\ + all().order_by('pinyin') + elif request.GET.get('kw'): + # kw: search keyword to find indicator + search_kw = request.GET.get('kw') + page_condition = "search" + # TODO + indicators = [] + else: + # default page_condition: "all" + selected_catid = "all" + page_condition = "all" + indicators = indicators_pdict + elif request.method == 'POST': + # do post process + # TODO + pass else: - selected_catid = "all" + # XXX + raise Http404 data = { + 'page_condition': page_condition, 'categories': categories, + 'selected_category': selected_category, 'selected_catid': selected_catid, 'letters': letters, - 'indicators_pdict': indicators_pdict, + 'indicators': indicators, 'followed_indicators': followed_indicators, } - + # render page return render(request, template, data) # }}} @@ -644,13 +681,16 @@ def test_view(request, **kwargs): followed_indicators_pdict = get_followed_indicator(request.user.id) # convert to list followed_indicators = [] - for l in letters: + for l in all_letters: followed_indicators += followed_indicators_pdict[l] + list = [] + data = { 'all_letters': all_letters, 'all_indicators': all_indicators, 'followed_indicators': followed_indicators, + 'list': list, } return render(request, template, data) -- cgit v1.2.2