Override users admin change list and add IBAN export

parent cf29cc4f
......@@ -91,6 +91,7 @@ class AgeListFilter(admin.SimpleListFilter):
class UserAdmin(BaseUserAdmin):
change_list_template = 'admin/members/change_list.html'
form = forms.UserChangeForm
add_form = forms.UserCreationForm
......
{% extends "admin/change_list.html" %}
{% load i18n admin_urls static compress %}
{% block object-tools-items %}
<li>
<a href="{% url 'members:iban-export' %}">{% trans "Export IBANs for Direct Debit" %}</a>
</li>
{{ block.super }}
{% endblock %}
......@@ -10,5 +10,6 @@ urlpatterns = [
name='become-a-member-document'),
url('^profile/(?P<pk>[0-9]*)$', views.profile, name='profile'),
url('^profile/edit/$', views.edit_profile, name='edit-profile'),
url('^members/iban-export/$', views.iban_export, name='iban-export'),
url('^$', views.index, name='index'),
]
import csv
import json
import os
from datetime import date, datetime
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import login_required, permission_required
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.utils.text import slugify
from django.utils.translation import gettext as _
from sendfile import sendfile
from members.models import Member
from members.services import member_achievements
from . import models
from .forms import MemberForm
......@@ -135,6 +138,32 @@ def edit_profile(request):
{'form': form, 'saved': saved})
@permission_required('auth.change_user')
def iban_export(request):
header_fields = ['name', 'username', 'iban']
rows = []
members = Member.active_members.filter(direct_debit_authorized=True)
for member in members:
rows.append({
'name': member.get_full_name(),
'username': member.user.username,
'iban': member.bank_account
})
response = HttpResponse(content_type='text/csv')
writer = csv.DictWriter(response, header_fields)
writer.writeheader()
for row in rows:
writer.writerow(row)
response['Content-Disposition'] = (
'attachment; filename="iban-export.csv"')
return response
def become_a_member(request):
context = {'documents': models.BecomeAMemberDocument.objects.all()}
return render(request, 'singlepages/become_a_member.html', context)
......
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