Commit 180af7e0 authored by ibuler's avatar ibuler

Update csv

parent 205c11df
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
{% load common_tags %} {% load common_tags %}
{% block content_left_head %} {% block content_left_head %}
<link href="{% static "css/plugins/footable/footable.core.css" %}" rel="stylesheet"> <link href="{% static "css/plugins/footable/footable.core.css" %}" rel="stylesheet">
<link href="{% static 'css/plugins/datepicker/datepicker3.css' %}" rel="stylesheet">
<style> <style>
#search_btn { #search_btn {
margin-bottom: 0; margin-bottom: 0;
...@@ -91,6 +92,7 @@ ...@@ -91,6 +92,7 @@
{% block custom_foot_js %} {% block custom_foot_js %}
<script src="{% static "js/plugins/footable/footable.all.min.js" %}"></script> <script src="{% static "js/plugins/footable/footable.all.min.js" %}"></script>
<script src="{% static 'js/plugins/datepicker/bootstrap-datepicker.js' %}"></script>
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$('.footable').footable(); $('.footable').footable();
......
...@@ -40,4 +40,5 @@ urlpatterns = [ ...@@ -40,4 +40,5 @@ urlpatterns = [
name='user-group-asset-permission-create'), name='user-group-asset-permission-create'),
url(r'^user-group/(?P<pk>[0-9]+)/assets', views.UserGroupGrantedAssetView.as_view(), url(r'^user-group/(?P<pk>[0-9]+)/assets', views.UserGroupGrantedAssetView.as_view(),
name='user-group-granted-asset'), name='user-group-granted-asset'),
url(r'down-csv/', views.down_csv),
] ]
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals from __future__ import unicode_literals
from io import BytesIO
import csv import unicodecsv as csv
from django import forms from django import forms
from django.conf import settings from django.utils import timezone
from django.contrib.auth import login as auth_login, logout as auth_logout from django.contrib.auth import login as auth_login, logout as auth_logout
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
...@@ -19,8 +20,7 @@ from django.views.decorators.csrf import csrf_protect ...@@ -19,8 +20,7 @@ from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, DeleteView, UpdateView, FormView, SingleObjectMixin, \ from django.views.generic.edit import CreateView, DeleteView, UpdateView, FormView, SingleObjectMixin, FormMixin
FormMixin
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from formtools.wizard.views import SessionWizardView from formtools.wizard.views import SessionWizardView
...@@ -533,12 +533,16 @@ class BulkImportUserView(AdminUserRequiredMixin, JSONResponseMixin, FormView): ...@@ -533,12 +533,16 @@ class BulkImportUserView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
return self.render_json_response(data) return self.render_json_response(data)
def down_csv(request, xx): def down_csv(request):
print(xx)
response = HttpResponse(content_type='application/csv') response = HttpResponse(content_type='application/csv')
response['Content-Disposition'] = 'attachment; filename="somefile.csv"' response['Content-Disposition'] = 'attachment; filename="users-%s.csv"' % \
timezone.localtime(timezone.now()).strftime('%Y-%m-%d')
writer = csv.writer(response) writer = csv.writer(response)
writer.writerow(['First row', 'Foo', 'Bar', 'Baz']) header = [u"你好", 'username', 'email',
writer.writerow(['Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"]) _('user group'), _('role'), _('phone'), _('wechat'), _('comment')]
writer.writerow(header)
for user in User.objects.all():
writer.writerow([user.name, user.username, user.email, ','.join([group.name for group in user.groups.all()]),
user.role, user.phone, user.wechat, user.comment])
return response return response
...@@ -15,3 +15,4 @@ paramiko==2.0.2 ...@@ -15,3 +15,4 @@ paramiko==2.0.2
django-redis-cache==1.7.1 django-redis-cache==1.7.1
requests==2.11.1 requests==2.11.1
itsdangerous==0.24 itsdangerous==0.24
unicodecsv==0.14.1
\ No newline at end of file
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