Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let 'DateTimeField' setter accept datetime.datetime objects and convert them. #369

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Changelog
- #364 Error on Manage Results view while Adding new Analyses from different Category
- #365 Lims Installation fails during setting client permissions in bika setup.
- #358 Merged updates for AR Add2
- #369 Let 'DateTimeField' setter accept datetime.datetime objects and convert them.
- #371 Reflex Rules don't have 'inactive_state' values set.


Expand Down
6 changes: 5 additions & 1 deletion bika/lims/browser/fields/datetimefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from Products.Archetypes.interfaces import IDateTimeField
from Products.Archetypes.public import *
from Products.Archetypes.public import DateTimeField as DTF
from Products.ATContentTypes.utils import dt2DT
from bika.lims import logger
from zope.interface import implements
import datetime


class DateTimeField(DTF):
Expand Down Expand Up @@ -46,7 +48,7 @@ def set(self, instance, value, **kwargs):
val = value
if not value:
val = None
elif not isinstance(value, DateTime):
elif isinstance(value, basestring):
for fmt in ['date_format_long', 'date_format_short']:
fmtstr = instance.translate(fmt, domain='bika', mapping={})
fmtstr = fmtstr.replace(r"${", '%').replace('}', '')
Expand All @@ -73,6 +75,8 @@ def set(self, instance, value, **kwargs):
except:
logger.warning("DateTimeField failed to format date "
"string '%s' with '%s'" % (value, fmtstr))
elif isinstance(value, datetime.datetime):
val = dt2DT(value)

super(DateTimeField, self).set(instance, val, **kwargs)

Expand Down