Skip to content

Commit

Permalink
Do not assume that dates in user's properties are already as DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
frapell committed Nov 13, 2019
1 parent e9ce0a4 commit eb09590
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -5,7 +5,8 @@ Changelog
0.15.1 (unreleased)
-------------------

- Nothing changed yet.
- Do not assume that dates in user's properties are already as DateTime
[frapell]


0.15.0 (2019-08-01)
Expand Down
23 changes: 19 additions & 4 deletions collective/pwexpiry/browser/preferences/pwexpirycontrolpanel.py
Expand Up @@ -4,6 +4,7 @@
from collective.pwexpiry.config import DATETIME_FORMATSTRING
from collective.pwexpiry.events import UserUnlocked
from DateTime import DateTime
from DateTime.interfaces import SyntaxError
from plone.protect import CheckAuthenticator
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
Expand All @@ -24,6 +25,8 @@


class PwExpiryControlPanel(UsersGroupsControlPanelView):
whitelisted = None

def getWhitelisted(self):
if self.whitelisted:
return "\r\n".join(self.whitelisted)
Expand Down Expand Up @@ -156,8 +159,20 @@ def manageUser(self, users=None):
utils.addPortalMessage(_(u"No users were unlocked"))

def formatDate(self, date):
if date == DateTime("2000/01/01"):
result = _(u"Never")
else:
result = date.strftime(DATETIME_FORMATSTRING)
result = ""

if isinstance(date, str):
try:
date = DateTime(date)
except SyntaxError:
date = DateTime("2000/01/01")

if isinstance(date, DateTime):
# XXX: Do it like this to avoid issues with timezones
str_date = f"{date.year()}/{date.month()}/{date.day()}"
if str_date == "2000/01/01":
result = _(u"Never")
else:
result = date.strftime(DATETIME_FORMATSTRING)

return result

0 comments on commit eb09590

Please sign in to comment.