no longer use model_to_dict

- fix cof status on k-psul
This commit is contained in:
Aurélien Delobelle 2017-04-05 23:33:45 +02:00
parent e4ccd88dfd
commit e4dd434608

View file

@ -17,7 +17,6 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.models import User, Permission, Group
from django.http import JsonResponse, Http404
from django.forms import formset_factory
from django.forms.models import model_to_dict
from django.db import transaction
from django.db.models import F, Sum, Prefetch, Count
from django.db.models.functions import Coalesce
@ -390,13 +389,11 @@ def account_read(request, trigramme):
raise PermissionDenied
if request.GET.get('format') == 'json':
data = model_to_dict(
account,
fields=['id', 'trigramme', 'firstname', 'lastname', 'email',
'is_cof', 'promo', 'balance', 'is_frozen', 'departement',
'nickname', 'trigramme']
)
data['name'] = account.name
export_keys = ['id', 'trigramme', 'first_name', 'last_name', 'name',
'email', 'is_cof', 'promo', 'balance', 'is_frozen',
'departement', 'nickname']
print(account.first_name)
data = {k: getattr(account, k) for k in export_keys}
return JsonResponse(data)
addcosts = (
@ -663,20 +660,14 @@ class CheckoutRead(JSONResponseMixin, DetailView):
def render_to_response(self, context, **kwargs):
if self.request.GET.get('format') == 'json':
data = model_to_dict(
context['checkout'],
fields=['id', 'name', 'balance', 'valid_from', 'valid_to']
)
export_keys = ['id', 'name', 'balance', 'valid_from', 'valid_to']
data = {k: getattr(self.object, k) for k in export_keys}
if 'laststatement' in context:
last_statement = context['laststatement']
last_statement_data = model_to_dict(
last_statement,
fields=['id', 'at', 'balance_new', 'balance_old', 'by']
)
last_statement_data['by'] = str(last_statement.by)
# ``at`` is not editable, so skipped by ``model_to_dict``
last_statement_data['at'] = last_statement.at
data['laststatement'] = last_statement_data
last_st = context['laststatement']
export_keys = ['id', 'at', 'balance_new', 'balance_old']
last_st_data = {k: getattr(last_st, k) for k in export_keys}
last_st_data['by'] = str(last_st.by)
data['laststatement'] = last_st_data
return self.render_to_json_response(data)
else:
return super().render_to_response(context, **kwargs)