forked from DGNum/gestioCOF
PEP8: Enforced other rules, including 80 cols
This commit is contained in:
parent
c7a3656ded
commit
88bccc0e60
23 changed files with 571 additions and 324 deletions
|
@ -7,7 +7,8 @@ from django.apps import apps
|
|||
def export(qs, fields=None):
|
||||
model = qs.model
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename=%s.csv' % slugify(model.__name__)
|
||||
response['Content-Disposition'] = 'attachment; filename=%s.csv' %\
|
||||
slugify(model.__name__)
|
||||
writer = csv.writer(response)
|
||||
# Write headers to CSV file
|
||||
if fields:
|
||||
|
@ -31,10 +32,12 @@ def export(qs, fields=None):
|
|||
return response
|
||||
|
||||
|
||||
def admin_list_export(request, model_name, app_label, queryset=None, fields=None, list_display=True):
|
||||
def admin_list_export(request, model_name, app_label, queryset=None,
|
||||
fields=None, list_display=True):
|
||||
"""
|
||||
Put the following line in your urls.py BEFORE your admin include
|
||||
(r'^admin/(?P<app_label>[\d\w]+)/(?P<model_name>[\d\w]+)/csv/', 'util.csv_view.admin_list_export'),
|
||||
(r'^admin/(?P<app_label>[\d\w]+)/(?P<model_name>[\d\w]+)/csv/',
|
||||
'util.csv_view.admin_list_export'),
|
||||
"""
|
||||
if not request.user.is_staff:
|
||||
return HttpResponseForbidden()
|
||||
|
@ -49,12 +52,17 @@ def admin_list_export(request, model_name, app_label, queryset=None, fields=None
|
|||
fields = None
|
||||
return export(queryset, fields)
|
||||
"""
|
||||
Create your own change_list.html for your admin view and put something like this in it:
|
||||
Create your own change_list.html for your admin view and put something
|
||||
like this in it:
|
||||
{% block object-tools %}
|
||||
<ul class="object-tools">
|
||||
<li><a href="csv/{%if request.GET%}?{{request.GET.urlencode}}{%endif%}" class="addlink">Export to CSV</a></li>
|
||||
<li><a href="csv/{%if request.GET%}?{{request.GET.urlencode}}
|
||||
{%endif%}" class="addlink">Export to CSV</a></li>
|
||||
{% if has_add_permission %}
|
||||
<li><a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">{% blocktrans with cl.opts.verbose_name|escape as name %}Add {{ name }}{% endblocktrans %}</a></li>
|
||||
<li><a href="add/{% if is_popup %}?_popup=1{% endif %}"
|
||||
class="addlink">
|
||||
{% blocktrans with cl.opts.verbose_name|escape as name %}
|
||||
Add {{ name }}{% endblocktrans %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue