Created loadCSV to memberlist

This commit is contained in:
henu
2016-11-16 18:12:03 +02:00
parent 42336f088e
commit 52bdac5fd9
4 changed files with 30 additions and 8 deletions
+1
View File
@@ -1,5 +1,6 @@
<h1> Jäsenlista (jäseniä {{members.length}})</h1>
<div>
<input type="button" value="Lataa CSV" class="btn btn-info" ng-click="loadCSV()"/>
<table id="choose-address-table" class="table table-striped">
<thead>
<tr class="ui-widget-header">
+9 -6
View File
@@ -2,7 +2,7 @@
function notyfication(type,timeout){
return function(msg){
noty({
noty({
'text': msg,
'layout': "bottomRight",
'type': type,
@@ -22,7 +22,7 @@ function editor(returnpath){
$scope.send = function() {
$http.put("/members/api/member/"+$scope.member.id, $scope.member).then(function(data){
notySuccess("Jäsentiedot tallennettu");
notySuccess("Jäsentiedot tallennettu");
$location.path(returnpath);
});
}
@@ -31,14 +31,14 @@ function editor(returnpath){
}
}
}
app.directive('ngConfirmClick',
app.directive('ngConfirmClick',
[
function()
{ return {
link: function (scope, element, attr)
link: function (scope, element, attr)
{
var clickAction = attr.confirmedClick;
element.bind('click',function (event)
element.bind('click',function (event)
{
noty({
text: 'Oletko aivan varma? T. Lasse Lehtinen',
@@ -82,7 +82,10 @@ app.controller("getController", function($scope, $http, $window, $location){
$http.put("/members/api/member/"+id,{paid:moment().format("YYYY-MM-DD kk:mm:ss") }).then(function(resp){
$scope.getFunction();
});
}
};
$scope.loadCSV = function() {
window.location = "/members/api/getCSV";
};
$scope.delete_member = function(id) {
$http.delete("/members/api/member/" + id).then(
function(response) {
+18 -2
View File
@@ -47,7 +47,7 @@ def applicationindex(request, *args, **kwargs):
@ensure_csrf_cookie
def applicationSuccessIndex(request, *args, **kwargs):
return render(request, 'application_success.html',{})
@ensure_csrf_cookie
@require_http_methods(["GET"])
@permission_required('members.change_member', login_url='/login')
@@ -172,4 +172,20 @@ def handle_mem_request(request, idx, *args, **kwargs):
else: # method == POST because other aren't allowed here
req.delete()
return HttpResponse('{"status":"success"}')
@ensure_csrf_cookie
@require_http_methods(["GET"])
@permission_required('members.change_member', login_url='/login')
def export_csv(request, *args, **kwargs):
import csv
response = HttpResponse()
response['Content-type'] = 'text/csv'
response['Accept'] = 'text/csv'
response['Content-Disposition'] = 'filename; filename=members.csv'
writer = csv.writer(response, csv.excel)
response.write(u'\ufeff'.encode('utf8')) # BOM (optional...Excel needs it to open UTF-8 file properly)
for obj in Member.objects.all():
data = obj.get_dict()
field_list = [str(data['id']), str(data['first_name']), str(data['last_name']), str(data['email']), str(data['POR']), str(data['AYY']), str(data['jas']), str(data['created']), str(data['paid'])]
writer.writerow(field_list)
return response