plomino / Plomino

Powerful and flexible web-based application builder
33 stars 37 forks source link

Displaying dates in Plomino views using Formula #812

Closed AshRaghav closed 7 years ago

AshRaghav commented 7 years ago

Hi @ebrehault,

I am not sure what I might be missing here but when trying to display a date in a View using Formulas rather than selecting from the field list renders the date in full DateTime format.

For example, the column in view display 2017/03/29 00:00:00 UTC instead of 29/03/2017.

I have to tried both conversions (StringToDate and DateToString) and both end up with syntax error. The problem I have is to understand the data type of a particular field when being invoked through a column's formula.

Any suggestions here is appreciated.

Thanks

ebrehault commented 7 years ago

Use something like: DateToString(yourdatevalue, "%Y-%m-%d")

AshRaghav commented 7 years ago

Thanks @ebrehault - For some reason it doesn't seem to be working. This is the code for the column

db = context.getParentDatabase()
PdtAvlDateUTC = DateToString(plominoDocument.getItem('PdtAvlStartDate'),"%d/%m/%Y",db)
EvtAvlDateUTC = DateToString(plominoDocument.getItem('EvtStrtDate'),"%d/%m/%Y",db)
return PdtAvlDateUTC or EvtAvlDateUTC
ebrehault commented 7 years ago

Maybe your value is not a DateTime value. What error do you get ?

Note: the db param is not needed in your case

AshRaghav commented 7 years ago

@ebrehault - Thanks.

That's the weird part. It is stored as DateTime and I have refreshed the Database a number of times to ensure any column changes are not cached. I have attached screenshots of the data stored here. I can't see any visible errors on the screen now and the logs are clean as well.

I just added db param for additional safety as I usually use DateToString(my_value,None,db) as DB has the universal format we use.

date format issue - 1 date format issue - 2

AshRaghav commented 7 years ago

Just to ensure that you have enough information in case this is a bug, this is the Plone environment we are using.

Plone 4.3.3 (4308) CMF 2.2.7 Zope 2.13.22 Python 2.7.6 (default, Jun 2 2016, 08:50:13) [GCC 4.8.4] PIL 2.3.0 (Pillow)

ebrehault commented 7 years ago

put your db in debug mode and look the server log to see if you get errors

AshRaghav commented 7 years ago

@ebrehault - yes I had done that the logs are still clean with no script errors.

DateToString appears to be working elsewhere in the database but not in this column view. Secondly, when I select the Field from Fields list, the date is appearing correctly in the format set in the database. It is only when I use formula it stops working.

AshRaghav commented 7 years ago

Finally getting this error

AttributeError: 'str' object has no attribute 'toZone' Context is

However, it doesn't make sense because these are DateTime fields but somehow it is being seen as a string object.

I have another database in the same instance and that seems to work correctly. It was picking up the DateToString conversion without any issues in a view.

Given that - could this be a plomino database issue of some sort? Like something not right with the setup?

AshRaghav commented 7 years ago

@ebrehault - just a quick update.

It has finally started to convert the dates. I mainly changed the Date widget from jQuery one to default, not sure if that helped it. I liked the jQuery version because it looked better.

After several database refresh, the dates have somehow picked up now.

date format issue - resolved

Thanks for your time and suggestions