From 9a0cfb7b26b1d121e65c2e15c211ae5285dce938 Mon Sep 17 00:00:00 2001 From: Huarong Chen Date: Mon, 26 May 2014 23:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=BC=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 +- .../adminpage/static/js/activity_list.js | 5 ++- .../adminpage/templates/activity_detail.html | 2 +- .../adminpage/templates/activity_list.html | 8 ++-- urlhandler/adminpage/urls.py | 1 + urlhandler/adminpage/views.py | 40 +++++++++++++++++++ urlhandler/urlhandler/settings.py | 2 +- urlhandler/userpage/views.py | 2 +- 8 files changed, 54 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9bf5875..c6f1f8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ django==1.6.1 -MySQL-python==1.2.4 \ No newline at end of file +MySQL-python==1.2.4 +xlwt==0.7.5 \ No newline at end of file diff --git a/urlhandler/adminpage/static/js/activity_list.js b/urlhandler/adminpage/static/js/activity_list.js index bb21f57..26502e3 100644 --- a/urlhandler/adminpage/static/js/activity_list.js +++ b/urlhandler/adminpage/static/js/activity_list.js @@ -117,6 +117,9 @@ var tdMap = { return true; } }, + 'export': function(act) { + return true; + }, 'detail': function(act) { return true; } @@ -164,7 +167,7 @@ var tdMap = { return ''; } else{ - return ''; + return ''; } } }, smartTimeMap = { diff --git a/urlhandler/adminpage/templates/activity_detail.html b/urlhandler/adminpage/templates/activity_detail.html index 6c51f1c..561bbb2 100644 --- a/urlhandler/adminpage/templates/activity_detail.html +++ b/urlhandler/adminpage/templates/activity_detail.html @@ -337,8 +337,8 @@

处理结果


         
- 返回列表 + 返回列表
diff --git a/urlhandler/adminpage/templates/activity_list.html b/urlhandler/adminpage/templates/activity_list.html index 99a0a29..327ee4f 100644 --- a/urlhandler/adminpage/templates/activity_list.html +++ b/urlhandler/adminpage/templates/activity_list.html @@ -25,15 +25,15 @@ 'end_time': new Date('{{ activity.end_time|date:"r" }}'), 'place': '{{ activity.place|escapejs }}', {% if permission %}'delete':{{ activity.id }},{% endif %} - 'operations': {{% if permission %}'detail':'{% url "adminpage.views.activity_detail" actid=activity.id %}',{% endif %}'checkin':'{% url "adminpage.views.activity_checkin" actid=activity.id %}'}, + 'operations': {{% if permission %}'detail':'{% url "adminpage.views.activity_detail" actid=activity.id %}','export':'{% url "adminpage.views.activity_export_stunum" actid=activity.id %}', {% endif %}'checkin':'{% url "adminpage.views.activity_checkin" actid=activity.id %}'}, 'book_start': new Date('{{ activity.book_start|date:"r" }}'), 'book_end': new Date('{{ activity.book_end|date:"r" }}') }{% if forloop.last %}{% else %},{% endif %} {% endfor %} ]; - var operations_name = {{% if permission %}'detail':'详情',{% endif %}'checkin':'检票'}; - var operations_icon = {{% if permission %}'detail':'pencil',{% endif %}'checkin':'check'}; - var operations_target = {{% if permission %}'detail':'',{% endif %}'checkin':'_blank'}; + var operations_name = {{% if permission %}'detail':'详情', 'export':'导出', {% endif %}'checkin':'检票'}; + var operations_icon = {{% if permission %}'detail':'pencil', 'export':'export', {% endif %}'checkin':'check'}; + var operations_target = {{% if permission %}'detail':'', 'export':'_blank', {% endif %}'checkin':'_blank'}; {% endblock %} diff --git a/urlhandler/adminpage/urls.py b/urlhandler/adminpage/urls.py index ec76d63..2ba3e46 100644 --- a/urlhandler/adminpage/urls.py +++ b/urlhandler/adminpage/urls.py @@ -6,6 +6,7 @@ url(r'^detail/(?P\d+)/$', 'adminpage.views.activity_detail'), url(r'^checkin/(?P\d+)/$', 'adminpage.views.activity_checkin'), url(r'^checkin/(?P\d+)/check/', 'adminpage.views.activity_checkin_post'), + url(r'^export/(?P\d+)/$', 'adminpage.views.activity_export_stunum'), url(r'^add/$', 'adminpage.views.activity_add'), url(r'^delete/$', 'adminpage.views.activity_delete'), url(r'^modify/$', 'adminpage.views.activity_post'), diff --git a/urlhandler/adminpage/views.py b/urlhandler/adminpage/views.py index 2d3aa6e..751c2e3 100644 --- a/urlhandler/adminpage/views.py +++ b/urlhandler/adminpage/views.py @@ -20,6 +20,12 @@ from weixinlib.settings import get_custom_menu_with_book_acts, WEIXIN_BOOK_HEADER from adminpage.safe_reverse import * +import xlwt +import re +from django.utils.http import urlquote +from django.utils.encoding import smart_str + + @csrf_protect def home(request): @@ -450,3 +456,37 @@ def custom_menu_modify_post(request): content_type='application/json') +def activity_export_stunum(request, actid): + if not request.user.is_authenticated(): + return HttpResponseRedirect(s_reverse_admin_home()) + try: + activity = Activity.objects.get(id=actid) + except: + raise Http404 + + tickets = Ticket.objects.filter(activity=activity) + wb = xlwt.Workbook() + + def write_row(ws, row, data): + for index, cell in enumerate(data): + ws.write(row, index, cell) + + ws = wb.add_sheet(activity.name) + row = 1 + write_row(ws, 0, [u'学号', u'状态', u'座位']) + statusMap = [u'已取消', u'未入场', u'已入场'] + for ticket in tickets: + write_row(ws, row, [ticket.stu_id, statusMap[ticket.status], ticket.seat]) + row = row + 1 +##########################################定义Content-Disposition,让浏览器能识别,弹出下载框 + fname = 'activity' + actid + '.xls' + agent=request.META.get('HTTP_USER_AGENT') + if agent and re.search('MSIE',agent): + response = HttpResponse(content_type="application/vnd.ms-excel") # 解决ie不能下载的问题 + response['Content-Disposition'] = 'attachment; filename=%s' % urlquote(fname) # 解决文件名乱码/不显示的问题 + else: + response = HttpResponse(content_type="application/ms-excel") # 解决ie不能下载的问题 + response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(fname) # 解决文件名乱码/不显示的问题 + ##########################################保存 + wb.save(response) + return response \ No newline at end of file diff --git a/urlhandler/urlhandler/settings.py b/urlhandler/urlhandler/settings.py index 0eb67b3..6685676 100644 --- a/urlhandler/urlhandler/settings.py +++ b/urlhandler/urlhandler/settings.py @@ -91,7 +91,7 @@ 'ENGINE': 'django.db.backends.mysql', 'NAME': 'tsinghuatuan', 'USER': 'root', - 'PASSWORD': 'root', + 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '3306', } diff --git a/urlhandler/userpage/views.py b/urlhandler/userpage/views.py index 09e3b39..1dbf1a6 100644 --- a/urlhandler/userpage/views.py +++ b/urlhandler/userpage/views.py @@ -154,7 +154,7 @@ def ticket_view(request, uid): if act_endtime < now:#表示活动已经结束 ticket_status = 3 ticket_seat = ticket[0].seat - act_photo = "http://tsinghuaqr.duapp.com/fit/"+uid + act_photo = "http://qr.ssast.org/fit/"+uid variables=RequestContext(request,{'act_id':act_id, 'act_name':act_name,'act_place':act_place, 'act_begintime':act_begintime, 'act_endtime':act_endtime,'act_photo':act_photo, 'ticket_status':ticket_status, 'ticket_seat':ticket_seat,