r13754 - in Products.DataGridField/branches/lepri-datetime-column: . Products/DataGridField Products/DataGridField/skins/DataGridWidget
"Gustavo Alves Lepri" <[email protected]> Thu, 18 Aug 2011 16:28:21 +0000
| Newsgroups | gmane.comp.web.zope.plone.archetypes.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: lepri
Date: Thu Aug 18 16:28:19 2011
New Revision: 13754
Added:
Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/DateTimeColumn.py
Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/skins/DataGridWidget/datagrid_datetime_cell.pt
Modified:
Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/DataGridField.py
Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/skins/DataGridWidget/datagridwidget.js
Products.DataGridField/branches/lepri-datetime-column/setup.py
Log:
added datetime column
Modified: Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/DataGridField.py
==============================================================================
--- Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/DataGridField.py (original)
+++ Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/DataGridField.py Thu Aug 18 16:28:19 2011
@@ -106,7 +106,6 @@
doSort = False
logging.debug("Setting DGF value to " + str(value))
-
if value == ({},):
# With some Plone versions, it looks like that AT init
# causes DGF to get one empty dictionary as the base value
Added: Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/DateTimeColumn.py
==============================================================================
--- (empty file)
+++ Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/DateTimeColumn.py Thu Aug 18 16:28:19 2011
@@ -0,0 +1,80 @@
+"""
+"""
+
+__author__ = 'Gustavo Lepri <[email protected]>'
+__docformat__ = 'restructuredtext'
+
+import time
+from DateTime.DateTime import DateTime
+
+from AccessControl import ClassSecurityInfo
+from App.class_init import InitializeClass
+from Products.DataGridField.Column import Column
+
+from collective.js.jqueryui.utils import get_python_date_format
+
+class DateTimeColumn(Column):
+ """ Defines DataGridField column with DateTime
+ """
+
+ security = ClassSecurityInfo()
+
+ def __init__(self, title, with_time=False):
+ """ Create a DateTime column
+
+ @param with_time True or False to show time (hour and minute)
+
+ """
+ Column.__init__(self, title)
+ self.with_time = with_time
+
+ security.declarePublic('getShow_hm')
+ def getWith_time(self):
+ return self.with_time
+
+ security.declarePublic('getMacro')
+ def getMacro(self):
+ """ Return macro used to render this column in view/edit """
+ return "datagrid_datetime_cell"
+
+ security.declarePublic('hours_minutes')
+ def hours_minutes(self, date):
+ """Return (hour, date) from a given DateTime instance.
+ """
+ if date:
+ return date.hour(), date.minute()
+ return '', ''
+
+ security.declarePublic('datestr')
+ def datestr(self, context, date):
+ """Return formated date string from a given DateTime instance.
+ """
+ if date:
+ format = get_python_date_format(context.REQUEST)
+ return date.strftime(format)
+ return ''
+
+ security.declarePublic('processCellData')
+ def processCellData(self, form, value, context, field, columnId):
+ """ Read cell values from raw form data
+ """
+ newValue = []
+ fieldname = field.getName()
+ for row in value:
+ newRow = {}
+ for key in row.keys():
+ newRow[key] = row[key]
+ datestr = row[columnId]
+ if datestr:
+ hours = int(form.get(fieldname + '_hour', 0))
+ minutes = int(form.get(fieldname + '_minute', 0))
+ datestr = '%s %s:%s:00' % (datestr, hours, minutes)
+ date_format = get_python_date_format(context.REQUEST)
+ tp = time.strptime(datestr, date_format + ' %H:%M:%S')
+ newRow[columnId] = DateTime(time.mktime(tp))
+ newValue.append(newRow)
+
+ return newValue
+
+# Initializes class security
+InitializeClass(DateTimeColumn)
Added: Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/skins/DataGridWidget/datagrid_datetime_cell.pt
==============================================================================
--- (empty file)
+++ Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/skins/DataGridWidget/datagrid_datetime_cell.pt Thu Aug 18 16:28:19 2011
@@ -0,0 +1,98 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
+ xmlns:metal="http://xml.zope.org/namespaces/metal"
+ xmlns:i18n="http://xml.zope.org/namespaces/i18n"
+ i18n:domain="plone">
+
+
+<!-- View/edit datetime cells -->
+
+<body>
+ <!-- VIEW -->
+ <metal:view_cell_macro define-macro="view_cell">
+ <span tal:define="d cell_value;
+ d python:test(d and d=='None','',d);
+ tlt nocall:context/toLocalizedTime|nothing;
+ result python:(d and tlt and tlt(d, long_format=1)) or None;"
+ tal:replace="result"/>
+ </metal:view_cell_macro>
+
+
+
+ <!-- EDIT -->
+ <metal:edit_cell_macro define-macro="edit_cell"
+ tal:define="wholeDay context/getWholeDay|nothing;
+ datestr_method nocall: column_definition/datestr;
+ hm_method nocall: column_definition/hours_minutes;
+ hours_minutes python: hm_method(cell_value);
+ hours python: hours_minutes[0];
+ minutes python: hours_minutes[1];">
+ <input tal:define="date_str request/?fieldName | nothing;
+ date_str python: date_str or datestr_method(context,cell_value)"
+ style="width: 100%"
+ class="calendarInput"
+ type="text"
+ value=""
+ tal:attributes="name string:${fieldName}.${column}:records;
+ id string:${column}_${fieldId};
+ value date_str" />
+
+ <tal:if condition="column_definition/getWith_time|nothing">
+
+ <span class="calendarwidget-time"
+ tal:attributes="style python: test(wholeDay, 'display: none', '')">
+ <select class="calendarInput" tal:attributes="name string:${fieldName}_hour;
+ id string:${fieldName}_hour; ">
+ <option tal:repeat="hour python: range(24)"
+ tal:attributes="value hour;
+ selected python: str(hour)==str(hours)"
+ tal:content="python: '%02d' % hour" />
+ </select> :
+ <select class="calendarInput" tal:attributes="name string:${fieldName}_minute;
+ id string:${fieldName}_minute">
+ <option tal:repeat="minute python: range(0, 60)"
+ tal:attributes="value minute;
+ selected python: str(minute)==str(minutes)"
+ tal:content="python: '%02d' % minute" />
+ </select>
+ </span>
+ </tal:if>
+ </metal:edit_cell_macro>
+
+
+ <!-- EMPTY EDIT -->
+ <metal:edit_cell_macro define-macro="edit_empty_cell"
+ tal:define="wholeDay context/getWholeDay|nothing;">
+ <input tal:define="date_str request/?fieldName | nothing;"
+ style="width: 100%"
+ class="calendarInput"
+ type="text"
+ value=""
+ tal:attributes="name string:${fieldName}.${column}:records;
+ id string:${column}_${fieldId};" />
+ <tal:if condition="column_definition/getWith_time|nothing">
+
+ <span class="calendarwidget-time"
+ tal:attributes="style python: test(wholeDay, 'display: none', '')">
+ <select class="calendarInput" tal:attributes="name string:${fieldName}_hour;
+ id string:${fieldName}_hour; ">
+ <option tal:repeat="hour python: range(24)"
+ tal:attributes="value hour;
+ selected python: str(hour)==str(hours)"
+ tal:content="python: '%02d' % hour" />
+ </select> :
+ <select class="calendarInput" tal:attributes="name string:${fieldName}_minute;
+ id string:${fieldName}_minute">
+ <option tal:repeat="minute python: range(0, 60)"
+ tal:attributes="value minute;
+ selected python: str(minute)==str(minutes)"
+ tal:content="python: '%02d' % minute" />
+ </select>
+ </span>
+ </tal:if>
+ </metal:edit_cell_macro>
+
+</body>
+
+</html>
+
Modified: Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/skins/DataGridWidget/datagridwidget.js
==============================================================================
--- Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/skins/DataGridWidget/datagridwidget.js (original)
+++ Products.DataGridField/branches/lepri-datetime-column/Products/DataGridField/skins/DataGridWidget/datagridwidget.js Thu Aug 18 16:28:19 2011
@@ -349,4 +349,16 @@
}
return parent;
-}
\ No newline at end of file
+}
+
+var $j = jQuery.noConflict();
+
+$j(document).ready(function() {
+
+ $j('input.calendarInput').datepicker({showButtonPanel: true});
+
+ $j('input.calendarInput').each(function(f) {
+ this.readonly = '1';
+ });
+
+})
Modified: Products.DataGridField/branches/lepri-datetime-column/setup.py
==============================================================================
--- Products.DataGridField/branches/lepri-datetime-column/setup.py (original)
+++ Products.DataGridField/branches/lepri-datetime-column/setup.py Thu Aug 18 16:28:19 2011
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '1.8b2'
+version = '1.8b2-datetime'
readme = open(os.path.join("Products", "DataGridField", "README.txt")).read()
history = open(os.path.join("Products", "DataGridField", "HISTORY.txt")).read()
long_description = readme + "\n" + history
@@ -32,7 +32,7 @@
zip_safe=False,
install_requires=[
'setuptools',
- # -*- Extra requirements: -*-
+ 'collective.js.jqueryui',
],
entry_points="""
# -*- Entry points: -*-
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2