no longer use model_to_dict
- fix cof status on k-psul
This commit is contained in:
parent
e4ccd88dfd
commit
e4dd434608
1 changed files with 12 additions and 21 deletions
|
@ -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.contrib.auth.models import User, Permission, Group
|
||||||
from django.http import JsonResponse, Http404
|
from django.http import JsonResponse, Http404
|
||||||
from django.forms import formset_factory
|
from django.forms import formset_factory
|
||||||
from django.forms.models import model_to_dict
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import F, Sum, Prefetch, Count
|
from django.db.models import F, Sum, Prefetch, Count
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
|
@ -390,13 +389,11 @@ def account_read(request, trigramme):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
if request.GET.get('format') == 'json':
|
if request.GET.get('format') == 'json':
|
||||||
data = model_to_dict(
|
export_keys = ['id', 'trigramme', 'first_name', 'last_name', 'name',
|
||||||
account,
|
'email', 'is_cof', 'promo', 'balance', 'is_frozen',
|
||||||
fields=['id', 'trigramme', 'firstname', 'lastname', 'email',
|
'departement', 'nickname']
|
||||||
'is_cof', 'promo', 'balance', 'is_frozen', 'departement',
|
print(account.first_name)
|
||||||
'nickname', 'trigramme']
|
data = {k: getattr(account, k) for k in export_keys}
|
||||||
)
|
|
||||||
data['name'] = account.name
|
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
addcosts = (
|
addcosts = (
|
||||||
|
@ -663,20 +660,14 @@ class CheckoutRead(JSONResponseMixin, DetailView):
|
||||||
|
|
||||||
def render_to_response(self, context, **kwargs):
|
def render_to_response(self, context, **kwargs):
|
||||||
if self.request.GET.get('format') == 'json':
|
if self.request.GET.get('format') == 'json':
|
||||||
data = model_to_dict(
|
export_keys = ['id', 'name', 'balance', 'valid_from', 'valid_to']
|
||||||
context['checkout'],
|
data = {k: getattr(self.object, k) for k in export_keys}
|
||||||
fields=['id', 'name', 'balance', 'valid_from', 'valid_to']
|
|
||||||
)
|
|
||||||
if 'laststatement' in context:
|
if 'laststatement' in context:
|
||||||
last_statement = context['laststatement']
|
last_st = context['laststatement']
|
||||||
last_statement_data = model_to_dict(
|
export_keys = ['id', 'at', 'balance_new', 'balance_old']
|
||||||
last_statement,
|
last_st_data = {k: getattr(last_st, k) for k in export_keys}
|
||||||
fields=['id', 'at', 'balance_new', 'balance_old', 'by']
|
last_st_data['by'] = str(last_st.by)
|
||||||
)
|
data['laststatement'] = last_st_data
|
||||||
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
|
|
||||||
return self.render_to_json_response(data)
|
return self.render_to_json_response(data)
|
||||||
else:
|
else:
|
||||||
return super().render_to_response(context, **kwargs)
|
return super().render_to_response(context, **kwargs)
|
||||||
|
|
Loading…
Reference in a new issue