From 156b10363c5a1049571e6c1d88597309c7ceab49 Mon Sep 17 00:00:00 2001 From: Alvin Li Date: Thu, 15 Aug 2013 16:25:51 +0800 Subject: * updated 'indicator.views' for front pages * use 'render' instead of 'render_to_response' * updated 'indicator/templates/indicator/NewDeleteIndex.html' to show all indicators and followed indicators --- 97suifangqa/apps/indicator/models.py | 2 + .../apps/indicator/static/css/new_delete_index.css | 4 +- .../templates/indicator/NewDeleteIndex.html | 872 +++++++++++---------- .../apps/indicator/templates/indicator/test.html | 33 + .../apps/indicator/templatetags/__init__.py | 0 .../apps/indicator/templatetags/dict_get.py | 14 + 97suifangqa/apps/indicator/urls.py | 16 +- 97suifangqa/apps/indicator/views.py | 177 ++++- 97suifangqa/isuifangqa.db | Bin 392192 -> 392192 bytes 9 files changed, 681 insertions(+), 437 deletions(-) create mode 100644 97suifangqa/apps/indicator/templates/indicator/test.html create mode 100644 97suifangqa/apps/indicator/templatetags/__init__.py create mode 100644 97suifangqa/apps/indicator/templatetags/dict_get.py diff --git a/97suifangqa/apps/indicator/models.py b/97suifangqa/apps/indicator/models.py index f64f3db..615398f 100644 --- a/97suifangqa/apps/indicator/models.py +++ b/97suifangqa/apps/indicator/models.py @@ -230,6 +230,8 @@ class Indicator(models.Model): # {{{ 'dataType': self.dataType, 'categories_id': [c.id for c in self.categories.all()], + 'categories_name': [c.name + for c in self.categories.all()], 'units_id': [u.id for u in self.get_unit(type="all")] } diff --git a/97suifangqa/apps/indicator/static/css/new_delete_index.css b/97suifangqa/apps/indicator/static/css/new_delete_index.css index aaee1a6..0eb41d1 100644 --- a/97suifangqa/apps/indicator/static/css/new_delete_index.css +++ b/97suifangqa/apps/indicator/static/css/new_delete_index.css @@ -61,7 +61,7 @@ text-decoration: none; } .index_navigation #index_all { - margin-right: 0; + margin-right: 11px; } .index_navigation .selected { background-color: #99CC33; @@ -189,4 +189,4 @@ color: #4A4A4A; border-bottom: 1px solid #BFBFBF; height: 24px; -} \ No newline at end of file +} diff --git a/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html b/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html index 29c15d0..8fd3e4c 100644 --- a/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html +++ b/97suifangqa/apps/indicator/templates/indicator/NewDeleteIndex.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load static from staticfiles %} +{% load dict_get %} {% block title %} 指标状态 | 随访工具 | 97 随访 @@ -31,416 +32,473 @@ {% block page %} -
-
-
添加或删除关注指标
- +
+
+
+ + + + + + {% for cat in categories %} + + {% endfor %} +
+
+
+
+ + +
+
所有指标
+
+
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
+
+
+
+ {# display all indicator by letter index #} + {% for l in letters %} + {% with l_inds=indicators_pdict|dict_get:l %} + {% if l_inds|length >= 1 %} +
+
{{ l|upper }}
+ {% for ind in l_inds %} +
+
{{ ind|dict_get:"name" }}
+
+
+
+
+ {% endfor %} +
+ {% 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
+
+
乙肝病毒表面抗原
+
两对半
+
+
+
+
+ + {% endcomment %}{# vim: }}} #} + +
+
+ + + + +
+
+
+
+
已关注指标
+
+
+ {% csrf_token %} + + +
+
+
+
+
+ + {% for fi in followed_indicators %} +
+
{{ fi|dict_get:"name" }}
+
+
+
+ {% endfor %} + + {% comment %}{# vim: {{{ #} +
+
V-谷丙氨酰转氨酶
+
+
+
+
+
总胆红素
+
+
+
+
+
乙肝病毒表面抗原
+
+
+
+
+
乙肝病毒表面抗体
+
+
+
+
+
乙肝病毒e抗体
+
+
+
+
+
乙肝病毒核算定量(PCR)
+
+
+
+
+
乙肝病毒基因型C型
+
+
+
+
+
乙肝病毒型混合型
+
+
+
+ {% endcomment %}{# vim: }}} #} +
+ +
+
+
+
{% endblock page %} {# vim: set ts=2 sw=2 tw=0 fenc=utf-8 ft=htmldjango.html: #} diff --git a/97suifangqa/apps/indicator/templates/indicator/test.html b/97suifangqa/apps/indicator/templates/indicator/test.html new file mode 100644 index 0000000..65340b9 --- /dev/null +++ b/97suifangqa/apps/indicator/templates/indicator/test.html @@ -0,0 +1,33 @@ + +{% load dict_get %} + + + Test + + +

ul 1

+ + +

ul 2

+ + + + + diff --git a/97suifangqa/apps/indicator/templatetags/__init__.py b/97suifangqa/apps/indicator/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/97suifangqa/apps/indicator/templatetags/dict_get.py b/97suifangqa/apps/indicator/templatetags/dict_get.py new file mode 100644 index 0000000..49de3cd --- /dev/null +++ b/97suifangqa/apps/indicator/templatetags/dict_get.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from django import template + +register = template.Library() + +@register.filter +def dict_get(dict, key): + """ + filter to get the value of key in the dict: + return dict[key] + """ + return dict.get(key) + diff --git a/97suifangqa/apps/indicator/urls.py b/97suifangqa/apps/indicator/urls.py index 0a9532b..5818616 100644 --- a/97suifangqa/apps/indicator/urls.py +++ b/97suifangqa/apps/indicator/urls.py @@ -38,35 +38,35 @@ urlpatterns = patterns('indicator.views', ) ## UI pages -urlpatterns += patterns('', +urlpatterns += patterns('indicator.views', # indicator_index url(r'^$', - direct_to_template, {'template': 'indicator/index.html'}, + 'indicator_index', name='indicator_index'), # indicator_sidebar url(r'^sidebar/$', - direct_to_template, {'template': 'indicator/SideBar.html'}, + 'indicator_sidebar', name='indicator_sidebar'), # indicator_status, 指标状态 url(r'^status/$', - direct_to_template, {'template': 'indicator/SheetDefault.html'}, + 'indicator_status', name='indicator_status'), # follow_indicator, 关注指标 url(r'^follow/$', - direct_to_template, {'template': 'indicator/NewDeleteIndex.html'}, + 'follow_indicator', name='follow_indicator'), ## indicator: popup # DeleteCardTip url(r'^popup/deletecardtip/$', - direct_to_template, {'template': 'indicator/popup/DeleteCardTip.html'}, + 'indicator_deletecardtip', name='indicator_deletecardtip'), # EditHistoryData url(r'^popup/edithistorydata/$', - direct_to_template, {'template': 'indicator/popup/EditHistoryData.html'}, + 'indicator_edithistorydata', name='indicator_edithistorydata'), # IndexDesc url(r'^popup/indexdesc/$', - direct_to_template, {'template': 'indicator/popup/IndexDesc.html'}, + 'indicator_indexdesc', name='indicator_indexdesc'), ) diff --git a/97suifangqa/apps/indicator/views.py b/97suifangqa/apps/indicator/views.py index 73e1189..8f2cf88 100644 --- a/97suifangqa/apps/indicator/views.py +++ b/97suifangqa/apps/indicator/views.py @@ -7,9 +7,7 @@ apps/indicator views from django.contrib.auth.decorators import login_required from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404 -from django.shortcuts import render_to_response, get_object_or_404 -# json -from django.utils import simplejson as json +from django.shortcuts import render, get_object_or_404 # CRSF from django.template import RequestContext @@ -20,6 +18,14 @@ from indicator.tools import * import re import datetime +## json +# Django 1.5 deprecates 'django.utils.simplejson' +# in favor of Python 2.6's bulti-in 'json' module +try: + import json +except ImportError: + from django.utils import simplejson as json + def get_indicator_view(request, **kwargs): @@ -146,11 +152,11 @@ def add_edit_category(request, category_id=None, template='indicator/simple.html # form with data of the specified instance form = IndicatorCategoryForm(instance=category) - return render_to_response(template, { + return render(request, template, { 'object': 'IndicatorCategory', 'action': action, 'form': form, - }, context_instance=RequestContext(request)) + }) # }}} @@ -187,11 +193,11 @@ def add_edit_indicator(request, indicator_id=None, template='indicator/simple.ht # form with instance form = IndicatorForm(instance=indicator) - return render_to_response(template, { + return render(request, template, { 'object': 'Indicator', 'action': action, 'form': form, - }, context_instance=RequestContext(request)) + }) # }}} @@ -226,11 +232,11 @@ def add_edit_unit(request, unit_id=None, template='indicator/simple.html'): # form with instance form = UnitForm(instance=unit) - return render_to_response(template, { + return render(request, template, { 'object': 'Unit', 'action': action, 'form': form, - }, context_instance=RequestContext(request)) + }) # }}} @@ -266,11 +272,11 @@ def add_edit_confine(request, confine_id=None, template='indicator/simple.html') # form with instance form = InnateConfineForm(instance=confine) - return render_to_response(template, { + return render(request, template, { 'object': 'InnateConfine', 'action': action, 'form': form, - }, context_instance=RequestContext(request)) + }) # }}} @@ -318,11 +324,11 @@ def add_edit_record(request, record_id=None, template='indicator/simple.html'): # form with instance form = IndicatorRecordForm(instance=record) - return render_to_response(template, { + return render(request, template, { 'object': 'IndicatorRecord', 'action': action, 'form': form, - }, context_instance=RequestContext(request)) + }) # }}} @@ -366,11 +372,11 @@ def modify_record(request, record_id=None, template='indicator/simple.html'): # form with instance form = IndicatorRecordForm(instance=record) - return render_to_response(template, { + return render(request, template, { 'object': 'IndicatorRecord', 'action': action, 'form': form, - }, context_instance=RequestContext(request)) + }) ## }}} @@ -401,16 +407,128 @@ def add_recordhistory(request, record_id, template='indicator/simple.html'): # form with instance form = RecordHistoryForm(instance=recordhistory) - return render_to_response(template, { + return render(request, template, { 'object': 'RecordHistory', 'action': action, 'form': form, - }, context_instance=RequestContext(request)) + }) +# }}} + + +########################################################### +###### indicator UI pages ###### +# indicator/index.html {{{ +@login_required +def indicator_index(request): + """ + index page for indicator + """ + template = 'indicator/index.html' + return render(request, template) +# }}} + + +# indicator/SideBar.html {{{ +@login_required +def indicator_sidebar(request): + """ + sidebar page for indicator + """ + template = 'indicator/SideBar.html' + return render(request, template) +# }}} + + +# indicator/SheetDefault.html {{{ +@login_required +def indicator_status(request): + """ + status page for indicator + add/edit/view indicator data + """ + template = 'indicator/SheetDefault.html' + return render(request, template) +# }}} + + +# indicator/NewDeleteIndex.html {{{ +@login_required +def follow_indicator(request): + """ + follow/unfollow indicator + """ + template = 'indicator/NewDeleteIndex.html' + letters = map(chr, range(ord('a'), ord('z')+1)) + + # get 7 categories (page can only contains 1+7 categories) + categories = im.IndicatorCategory.objects.all().\ + order_by('id')[:7] + # get indicators, P[inyin] dict format + indicators_pdict = get_indicator() + # get followed indicator, P[inyin] dict format + followed_indicators_pdict = get_followed_indicator(request.user.id) + # convert to list + followed_indicators = [] + 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) + else: + selected_catid = "all" + + data = { + 'categories': categories, + 'selected_catid': selected_catid, + 'letters': letters, + 'indicators_pdict': indicators_pdict, + 'followed_indicators': followed_indicators, + } + + return render(request, template, data) +# }}} + + +## popup pages +# indicator/popup/DeleteCardTip.html {{{ +@login_required +def indicator_deletecardtip(request): + """ + prompted tip for deleting a card + """ + template = 'indicator/popup/DeleteCardTip.html' + return render_to_response(template) +# }}} + + +# indicator/popup/EditHistoryData.html {{{ +@login_required +def indicator_edithistorydata(request): + """ + popup page to edit history data for an indicator + """ + template = 'indicator/popup/EditHistoryData.html' + return render_to_response(template) +# }}} + + +# indicator/popup/IndexDesc.html {{{ +@login_required +def indicator_indexdesc(request): + """ + description for an indicator + """ + template = 'indicator/popup/IndexDesc.html' + return render_to_response(template) # }}} ########################################################### ###### ajax ###### +@login_required def ajax_act_index(request): """ index action (add/minus) @@ -442,6 +560,7 @@ def ajax_close_sub_title(request): return HttpResponse(result) +@login_required def ajax_edit_history_data(request): """ edit history data @@ -455,6 +574,7 @@ def ajax_edit_history_data(request): return HttpResponse(result) +@login_required def ajax_get_card_data_chart(request): """ 'indicator/static/javascripts/load_card.js' @@ -479,6 +599,7 @@ def ajax_get_card_data_chart(request): mimetype='application/json') +@login_required def ajax_get_card_data_table(request): """ get card data @@ -513,7 +634,23 @@ def ajax_get_card_data_table(request): ### test_view ### def test_view(request, **kwargs): - html = '%s' % u"正文测试内容" - text = u"中文测试" - return HttpResponse("%s" % request) + """ + test view + 'indicator/templates/indicator/test.html' + """ + template = 'indicator/test.html' + all_letters = map(chr, range(ord('a'), ord('z')+1)) + all_indicators = get_indicator() + followed_indicators_pdict = get_followed_indicator(request.user.id) + # convert to list + followed_indicators = [] + for l in letters: + followed_indicators += followed_indicators_pdict[l] + + data = { + 'all_letters': all_letters, + 'all_indicators': all_indicators, + 'followed_indicators': followed_indicators, + } + return render(request, template, data) diff --git a/97suifangqa/isuifangqa.db b/97suifangqa/isuifangqa.db index 2de1756..85205ae 100644 Binary files a/97suifangqa/isuifangqa.db and b/97suifangqa/isuifangqa.db differ -- cgit v1.2.2