From c9206d9912d0f9c0212968492804832985ddc99a Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 7 Mar 2017 13:00:53 +0100 Subject: [PATCH 2/2] add a date attribute kind (fixes #10606) --- src/authentic2/attribute_kinds.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index b29b6b5..a2d21aa 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -1,5 +1,6 @@ import string import json +import datetime from itertools import chain @@ -14,7 +15,7 @@ from rest_framework import serializers from .decorators import to_iter from .plugins import collect_from_plugins -from . import app_settings +from . import app_settings, widgets capfirst = allow_lazy(capfirst, unicode) @@ -50,6 +51,17 @@ DEFAULT_ATTRIBUTE_KINDS = [ 'serialize': lambda x: str(int(bool(x))), 'deserialize': lambda x: bool(int(x)), }, + { + 'label': _('date'), + 'name': 'date', + 'field_class': forms.DateField, + 'kwargs': { + 'widget': widgets.DateWidget, + }, + 'serialize': lambda x: x.isoformat(), + 'deserialize': lambda x: x and datetime.datetime.strptime(x, '%Y-%m-%d').date(), + 'rest_framework_field_class': serializers.DateField, + }, ] -- 2.1.4