Commits

Peter Suter  committed 7473427

In the database, pad custom time fields with 0 to avoid variable widths.
This makes sorting by the field easier.
http://trac.edgewall.org/ticket/1942#comment:71

  • Participants
  • Parent commits 30fbf0c

Comments (0)

Files changed (1)

File customtimefields.patch

 # HG changeset patch
-# Parent 1628a2734e25e8406dbec62cef693665e77cada8
+# Parent d501680c657df79afc64f2244b2e20dc1981a058
 Support custom time fields:
 Convert between DB time strings and datetime objects in the model.
 Parse ticket time input to datetime objects.
 Render time fields in notification emails.
 Support parsing relative time values in the future (e.g. ''tomorrow'', ''next month'' or ''in 3 hours'').
 
-diff -r 1628a2734e25 trac/ticket/api.py
---- a/trac/ticket/api.py	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/ticket/api.py	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/ticket/api.py
+--- a/trac/ticket/api.py	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/ticket/api.py	Sat Feb 11 07:52:06 2012 +0100
 @@ -351,9 +351,9 @@
          fields.append({'name': 'cc', 'type': 'text', 'label': N_('Cc')})
  
              fields.append(field)
  
          fields.sort(lambda x, y: cmp((x['order'], x['name']),
-diff -r 1628a2734e25 trac/ticket/model.py
---- a/trac/ticket/model.py	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/ticket/model.py	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/ticket/model.py
+--- a/trac/ticket/model.py	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/ticket/model.py	Sat Feb 11 07:52:06 2012 +0100
 @@ -28,7 +28,8 @@
  from trac.ticket.api import TicketSystem
  from trac.util import embedded_numbers, partition
  from trac.util.translation import _
  
  __all__ = ['Ticket', 'Type', 'Status', 'Resolution', 'Priority', 'Severity',
-@@ -44,6 +45,28 @@
+@@ -44,6 +45,31 @@
      return ', '.join(cclist)
  
  
 +
 +def _datetime_to_db_str(dt, is_custom_field):
 +    if not dt:
-+        return ''
-+    if is_custom_field:
-+        return str(to_utimestamp(dt))
-+    else:
-+        return to_utimestamp(dt)
++        return ''        
++    ts = to_utimestamp(dt) 
++    if is_custom_field: 
++        # Padding with '0' would be easy to sort in report page for a user 
++        fmt = '%018d' if ts >= 0 else '%+017d' 
++        return fmt % ts 
++    else: 
++        return ts
 +
 +
  class Ticket(object):
  
      # Fields that must not be modified directly by the user
-@@ -133,7 +156,9 @@
+@@ -133,7 +159,9 @@
                  SELECT name, value FROM ticket_custom WHERE ticket=%s
                  """, (tkt_id,)):
              if name in self.custom_fields:
                      self.values[name] = empty
                  else:
                      self.values[name] = value
-@@ -150,7 +175,7 @@
+@@ -150,7 +178,7 @@
              self._old[name] = self.values.get(name)
          elif self._old[name] == value: # Change of field reverted
              del self._old[name]
              if isinstance(value, list):
                  raise TracError(_("Multi-values fields not supported yet"))
              if self.fields.by_name(name, {}).get('type') != 'textarea':
-@@ -172,7 +197,7 @@
+@@ -172,7 +200,7 @@
          """Populate the ticket with 'suitable' values from a dictionary"""
          field_names = [f['name'] for f in self.fields]
          for name in [name for name in values.keys() if name in field_names]:
  
          # We have to do an extra trick to catch unchecked checkboxes
          for name in [name for name in values.keys() if name[9:] in field_names
-@@ -211,10 +236,7 @@
+@@ -211,10 +239,7 @@
              self['owner'] = default_to_owner
  
          # Perform type conversions
  
          # Insert ticket record
          std_fields = []
-@@ -231,16 +253,16 @@
+@@ -231,16 +256,16 @@
              cursor.execute("INSERT INTO ticket (%s) VALUES (%s)"
                             % (','.join(std_fields),
                                ','.join(['%s'] * len(std_fields))),
  
          self.id = tkt_id
          self.resource = self.resource(id=tkt_id)
-@@ -294,6 +316,10 @@
+@@ -294,6 +319,10 @@
                      # we just leave the owner as is.
                      pass
  
          with self.env.db_transaction as db:
              db("UPDATE ticket SET changetime=%s WHERE id=%s",
                 (when_ts, self.id))
-@@ -327,20 +353,20 @@
+@@ -327,20 +356,20 @@
                                       """, (self.id, name)):
                          db("""UPDATE ticket_custom SET value=%s
                                WHERE ticket=%s AND name=%s
  
              # always save comment, even if empty 
              # (numbering support for timeline)
-@@ -357,6 +383,14 @@
+@@ -357,6 +386,14 @@
              listener.ticket_changed(self, comment, author, old_values)
          return int(cnum.rsplit('.', 1)[-1])
  
      def get_changelog(self, when=None, db=None):
          """Return the changelog as a list of tuples of the form
          (time, author, field, oldvalue, newvalue, permanent).
-@@ -400,10 +434,15 @@
+@@ -400,10 +437,15 @@
                  ORDER BY time,permanent,author
                  """
              args = (self.id, sid, sid)
  
      def delete(self, db=None):
          """Delete the ticket.
-diff -r 1628a2734e25 trac/ticket/notification.py
---- a/trac/ticket/notification.py	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/ticket/notification.py	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/ticket/notification.py
+--- a/trac/ticket/notification.py	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/ticket/notification.py	Sat Feb 11 07:52:06 2012 +0100
 @@ -26,7 +26,8 @@
  from trac.config import *
  from trac.notification import NotifyEmail
      def get_recipients(self, tktid):
          notify_reporter = self.config.getbool('notification',
                                                'always_notify_reporter')
-diff -r 1628a2734e25 trac/ticket/query.py
---- a/trac/ticket/query.py	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/ticket/query.py	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/ticket/query.py
+--- a/trac/ticket/query.py	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/ticket/query.py	Sat Feb 11 07:52:06 2012 +0100
 @@ -34,8 +34,9 @@
  from trac.ticket.api import TicketSystem
  from trac.ticket.model import Milestone, group_milestones
                      values.append(unicode(value).encode('utf-8'))
                  writer.writerow(values)
          return (content.getvalue(), '%s;charset=utf-8' % mimetype)
-diff -r 1628a2734e25 trac/ticket/templates/query_results.html
---- a/trac/ticket/templates/query_results.html	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/ticket/templates/query_results.html	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/ticket/templates/query_results.html
+--- a/trac/ticket/templates/query_results.html	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/ticket/templates/query_results.html	Sat Feb 11 07:52:06 2012 +0100
 @@ -75,7 +75,7 @@
                          class="${classes(closed=result.status == 'closed')}">#$result.id</a></td>
                      <td py:otherwise="" class="$name" py:choose="">
                        <py:when test="name == 'reporter'">${authorinfo(value)}</py:when>
                        <py:when test="name == 'cc'">${format_emails(ticket_context, value)}</py:when>
                        <py:when test="name == 'owner' and value">${authorinfo(value)}</py:when>
-diff -r 1628a2734e25 trac/ticket/templates/ticket.html
---- a/trac/ticket/templates/ticket.html	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/ticket/templates/ticket.html	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/ticket/templates/ticket.html
+--- a/trac/ticket/templates/ticket.html	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/ticket/templates/ticket.html	Sat Feb 11 07:52:06 2012 +0100
 @@ -266,6 +266,8 @@
                                   checked="${value == option or None}" />
                            ${option}
                          <py:otherwise><!--! Text input fields -->
                            <py:choose>
                              <span py:when="field.cc_entry"><!--! Special case for Cc: field -->
-diff -r 1628a2734e25 trac/ticket/web_ui.py
---- a/trac/ticket/web_ui.py	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/ticket/web_ui.py	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/ticket/web_ui.py
+--- a/trac/ticket/web_ui.py	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/ticket/web_ui.py	Sat Feb 11 07:52:06 2012 +0100
 @@ -37,8 +37,9 @@
  from trac.ticket.notification import TicketNotifyEmail
  from trac.timeline.api import ITimelineEventProvider
  
      def _render_property_diff(self, req, ticket, field, old, new, 
                                resource_new=None):
-diff -r 1628a2734e25 trac/util/datefmt.py
---- a/trac/util/datefmt.py	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/util/datefmt.py	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/util/datefmt.py
+--- a/trac/util/datefmt.py	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/util/datefmt.py	Sat Feb 11 07:52:06 2012 +0100
 @@ -298,6 +298,23 @@
          weekdays[t.weekday()], t.day, months[t.month - 1], t.year,
          t.hour, t.minute, t.second)
          return dt
  
  # -- formatting/parsing helper functions
-diff -r 1628a2734e25 trac/web/chrome.py
---- a/trac/web/chrome.py	Sun Feb 05 10:01:25 2012 +0100
-+++ b/trac/web/chrome.py	Sun Feb 05 15:11:38 2012 +0100
+diff -r d501680c657d trac/web/chrome.py
+--- a/trac/web/chrome.py	Sat Feb 11 07:49:16 2012 +0100
++++ b/trac/web/chrome.py	Sat Feb 11 07:52:06 2012 +0100
 @@ -54,9 +54,9 @@
  from trac.util.text import pretty_size, obfuscate_email_address, \
                             shorten_line, unicode_quote_plus, to_unicode, \