def send_total(request, account_id): charges = getTotalTable(account_id) response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="Totalstat.csv"' writer = csv.writer(response) writer.writerow(['Year', 'Month', 'Total']) for charge in charges: writer.writerow([charge['year'], charge['mon'], charge['subtotal']]) return response
def total(request, account_id): acc = Account.objects.get(account_number=account_id) charges = list(Charge.objects.filter(account=acc.id).order_by('date')) file_name = getTotalLine(charges, acc) charges = getTotalTable(account_id) acc = Account.objects.get(account_number=account_id) return render(request, 'total_table.html', { 'account': charges, 'account_id': account_id, 'acc': acc })
def send_total(request, account_id): acc = Account.objects.get(account_number=account_id) if request.user.id == acc.user_id: charges = getTotalTable(account_id) response = HttpResponse(content_type='text/csv') response[ 'Content-Disposition'] = 'attachment; filename="Totalstat.csv"' writer = csv.writer(response) writer.writerow(['Year', 'Month', 'Total']) for charge in charges: writer.writerow( [charge['year'], charge['mon'], charge['subtotal']]) return response else: return HttpResponseRedirect('/')
def get(self, request, pk=None, format=None): acc = Account.objects.get(account_number=pk) self.check_object_permissions(request, acc) charges = getTotalTable(pk) serializer = StatisticsSerializer(charges, many=True) return Response(serializer.data)