Changes between Version 37 and Version 38 of TracTicketsCustomTimeFields
- Timestamp:
- May 18, 2010, 9:47:20 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracTicketsCustomTimeFields
v37 v38 1 1 = Custom Ticket Time Fields = 2 This page presents information on adding a new type 'time' to the list of all currently available [wiki:TracTicketsCustomFields custom ticket fields]. 3 4 == Alternative approaches == 5 Making a long story short: They are there for years to cure the lack of custom time fields for various project management purposes. I've seen them, but I don't like all the string manipulation, at least, if it comes to queries and report generation. I met others feeling the same. 6 7 Believe me, it's time for a sane extension of current custom fields support. And custom time fields backed by true POSIX microsecond time stamps stored in ticket_custom db table is the best way I could think of. Read on and, if you like it, join in to make it happen, please. 8 9 == Proposed Implementation == 10 === Changes to Trac === 11 * add 'time' to available types, inheriting most of the definition from 'text', a simple (one line) text field[[BR]] 12 13 At that point TracQuery already shows from..to input fields on selection of custom time fields for query as desired. 14 Praise to the flexible, modularized software design of Trac developers! Making it actually work and display results in pretty date/time format is a different thing. 15 16 But now more than basic knowledge on how ticket data is handled inside Trac is needed.[[BR]] 17 (I found not much hints so had to study the code and initially did most things wrong. A multiple dozen not working or buggy local code revisions later, after discussion in #python, etc. I decided on the implementation detailed below. Please discuss, if you know better, I'm still a Python beginner.) 18 19 * extend ''ticket.model'', ''ticket.web_ui'', ''util.datefmt'' and ''ticket/templates/ticket.html'' to 20 * allow for reading POSIX microsecond time stamps from db table ''ticket_custom'' 21 * stored there as string for full compatibility with current custom fields implementation 22 * convert to datetime.datetime values and go on using that values internally like is done for core time values ''time'' and ''changetime'' 23 * prepare time field display in ticket view (ticket.html) 24 * convert datetime.datetime time stamps to localized time strings 25 * add single quote arround strings read from db, i.e. left from former string based date field definitions 26 * add time format hint for input form fields 27 * parse user input and consolidate different flavors of time stamps 28 * initially done with help of ''mxDateTime.Parser'' 29 * prepared for internal fall back to datetime based parser logic (still to be done) like is done for pytz with some basic internal logic 30 * write back POSIX microsecond time stamps to db 31 * take care for data used to send out properly formatted notification 32 * patched version of [th:wiki:AnnouncerPlugin AnnouncerPlugin] for now 33 * still unsure on patching Trac Ticket Notifications itself, since it looks like almost dead code (sorry, but Announcer is years ahead) and Announcer is already officially attempting to replace Trac Ticket Notifications (see below) 34 * extend ''ticket.query'' and ''ticket/templates/query_results.html'' to 35 * convert custom time strings with POSIX microsecond time stamps from ticket_custom db table to datetime.datetime values 36 * format custom time values for display differently than standard time values 37 38 === Status of Development === 39 ==== Screenshot ==== 40 [[Image(TracQuery_on_CustomTimeField.2.png)]][[BR]] 41 Trac 0.12dev screenshot with ticket list from query based on custom time field 42 43 ==== Code ==== 44 ''base'': patches apply cleanly to Trac trunk ~~r9443~~ r9478[[BR]] 45 ''quality'': beta - read: code flaws should have not much effect, at least not to trac db, '''start of testing announced on 21-Apr-2010''', now expect on only minor changes to core of implementation until my stable release[[BR]] 46 ''focus'': bug-fixes, working ticket change notification for both [TracNotification Trac Notification] system and [th:wiki:AnnouncerPlugin AnnouncerPlugin][[BR]] 47 ''reviews'': so far just me, I need your help now[[BR]] 48 ''prospect'': since 0.12 is on the way (congrats!) and considering all the new features coming in here, it's more likely to go for 0.13 right away 49 50 This is work in progress. Proposed code changes for Trac trunk reside in a Mercurial repository at bitbucket.org ^note 1^. The Mercurial Queue (MQ) aside that repo is the patch stack itself with some meta-data ^note 2^: 2 This page presents information on adding a new type 'time' to the list of all currently available [wiki:TracTicketsCustomFields custom ticket fields].[[BR]] 3 You may want to start by reading the [wiki:TracDev/Proposals/TracTicketsCustomTimeFields proposal page], that has more general information on this project. 4 5 == Code review == 6 Proposed code changes for Trac trunk reside in a Mercurial repository at bitbucket.org ^note 1^. The Mercurial Queue (MQ) aside that repo is the patch stack itself with some meta-data ^note 2^: 51 7 52 8 http://bitbucket.org/hasienda/custom-time/ … … 66 22 I urge you to report back on any failure from code review or your testing. For test results, as always, mention your local setup (Trac version/revision, if not taken from my repo, Mercurial revision id of the patches). Any feedback will help to make the patches ready for production and later bring the code into Trac itself. That was my goal right from the start, not to produce just another [http://trac-hacks.org Trac hack]. 67 23 68 === == Notes =====24 === Notes === 69 25 1. My repository is a clone of rblank's Mercurial repository, that in turn consists of changesets imported from Trac SVN repo. 70 26 2. The common setup for Mercurial Queue puts the patches into a Mercurial repo on their own. So looking at [http://bitbucket.org/hasienda/custom-time/changesets the changes] during development is easy. 71 27 3. Since there is no other sane way to push the changes to a public repository without making them irreversible, I'll not dare to push real revisions before substantial clearing with core Trac developers. Some of the patches will get forwarded independently for early, stepwise adoption into Trac, like that published in #9209). 72 28 73 == == !HowTo testing ====29 == !HowTo testing == 74 30 For help on applying the patches to Trac trunk source the traditional way, i.e. with {{{patch}}}, look at the patch documentation in the [http://bitbucket.org/hasienda/custom-time/src/tip/series series] file. 75 31 76 32 But you'll see, Mercurial will save you and me some time and hassle, even more for true collaboration on bugs and feature requests. For the lazy or impatient ones not familiar with Mercurial I recommend to go along the lines of the following walk-through (Debian way). 77 33 78 === == Before you start =====34 === Before you start === 79 35 I tested this on my own, really, but can't guarantee and so can't be responsible on behalf of you for any action on your system. Please try to understand, what you type and think twice. Look at documentation I referenced as [#Externalrelatedresources external related resources] at the bottom of this page. Be careful especially while you act as root, and at the very least '''don't blame me''' for any mess YOU did. 80 36 81 === == Quickstart =====37 === Quickstart === 82 38 I assume that you'll have all pre-requisites like Python, setup-tools, Genshi and optionally Babel for the i18n support in place. If you're unsure or have issues with following procedure, look at the current [wiki:TracInstall Trac Install Guide] before crying at me. 83 39 … … 112 68 * fire up the standalone webserver tracd hosting a trac environment you've prepared before. 113 69 114 '''Notes for Ubuntu users'''115 116 On Ubuntu, you will have to ''apt-get install mercurial mercurial-common'' in order to get it working. In addition, you will have to add the following entries to ''/etc/mercurial/hgrc'':117 118 {{{119 # system-wide mercurial configuration file120 # See hgrc(5) for more information121 [extensions]122 mq =123 bookmarks =124 }}}125 126 Without these two entries, the above sequence of commands will fail.127 128 70 You may have {{{/usr/bin/tracd}}} and {{{/usr/local/bin/tracd}}} than at different versions. Install to /usr/local will normally overrule the other Trac installation without replacing it. So calling just {{{tracd}}} will kick {{{/usr/local/bin/tracd}}}. However, just make sure, you always know, what is going on. (I mention all this because I messed up on my own and now refrain from having multiple versions at the same system at a time.) 129 71 … … 137 79 See [wiki:TracLogging Trac Logging] for more details on the matter. 138 80 139 ==== Known Bugs ==== 81 === Notes === 82 ==== Mercurial install/setup on Ubuntu 10.04 LTS ("Lucid Lynx") ==== 83 On Ubuntu, you will have to ''apt-get install mercurial mercurial-common'' in order to get mercurial working. 84 In addition, you will have to add the following entries to ''/etc/mercurial/hgrc'': 85 86 {{{ 87 # system-wide mercurial configuration file 88 # See hgrc(5) for more information 89 [extensions] 90 mq = 91 bookmarks = 92 }}} 93 94 Without these two entries, the above sequence of commands will fail. 95 96 === Known Bugs === 97 Issues (with priority) on new ticket creation 98 * (A) date/time stamp will not be saved, experience vary between failure on ticket creation (preventing ticket creation at all) and just trashing input silently 140 99 Issues (with priority) occurring around ticket changes 141 100 * (B) [TracNotification Trac Notification] system unpatched, need to test and investigate, if necessary at all - WiP here, code done, think I'll have it in soon, blocked only by inability to test it right now … … 159 118 * server internal exception turned out to be caused by different versions of trac installed in /usr and /usr/local on my test system interfering on build time 160 119 161 == == ToDo ====120 == ToDo == 162 121 * add jQuery datepicker function to custom time fields or even more general to input forms for time stamps like was requested in a [http://trac.edgewall.org/ticket/1942#comment:18 comment to ticket #1942] 163 122 164 == = Discussion ===165 === = Development questions ====123 == Discussion == 124 === Development questions === 166 125 In db table 'ticket_custom' a new row is created for every (custom time) field. Would it be worth the effort to delete this row, if the date/time is effectively purged? For now we end up with just an empty string {{{''}}}. 167 126 168 === = Time stamp format ====127 === Time stamp format === 169 128 There was no argument against storing time stamps as string to arrange with current type definition "string" for values in ticket_custom db table. But switching to microseconds time stamp format recently adopted for Trac internal time fields ''time'' and ''changetime'' seems to be better than sticking with the former Unix time stamp, even if I prepared support for fractions of seconds by converting custom timestamps to float before. 170 129 171 === = Migrating from date/time strings ====130 === Migrating from date/time strings === 172 131 I keep thinking of the case, where one already has a pile of date and wishes to switch to new date/time type now. Hope he/she finds it convenient that old values will be converted (silently) by current code, whenever a ticket is updated. But someone might come up with something like a db upgrade script for batch conversion/migration all a once. I think I'm not enough of a SQL guru to do that. So suggestions and contributions on the subject are very welcome. 173 132 … … 177 136 TracQuery based on custom time field ignores non-numeric time stamps from db but still displays values, that could be parsed to datetime.datetime in ticket list 178 137 179 === = Unit tests ====138 === Unit tests === 180 139 I got [ticket:1942#comment:23 advice], that presence of this would be a pre-requisite for inclusion into Trac. 181 140 182 === = ''No'' additional code dependency, but an option ====141 === ''No'' additional code dependency, but an option === 183 142 Amongst the few new dependencies use of ''eGenix.com'' time string parser ''mxDateTime.Parser'' for Python is the most notable one ![2]. ~~We need~~ I needed to add such a powerful tool to provide a mature parser right from the start. If handled with care, similar but incompatible classes ''datetime.datetime'' and ''mxDateTime.!DateTime'' are not much of an issue. In fact it doesn't matter at all, as long as we stick to ~~unix time stamp~~ POSIX time format for saving ~~times in the~~ time stamps to db for other (good) reasons as well. 184 143 (cboos): adding a new external dependency is a strong handicap for being considered for inclusion in Trac core. Have you really weighted the benefits of using mxDateTime? Maybe that helps to kick start the development, but you should really consider building your own utility functions, if you need functionality besides the one provided by the `datetime` classes. See for example how we integrate `pytz`: if present, we take benefit from it, if not, we provide our own replacement with reduced functionality. … … 188 147 While there was working code for parser functions before and I was especially satisfied with the performance of the needed date/time parser I've re-arranged the implementation. Now ''mxDateTime.Parser'' is not a dependency but an option. This was suggested by cboos and others for the sake of maintaining Trac code highly self-sufficient, and I understood this a feature on its own. Still ''mxDateTime.Parser'' has superior performance, if it comes to more unusual date/time user input, so it is still a recommended for maximum user satisfaction. 189 148 190 === = Considering demand for custom time field defaults ====149 === Considering demand for custom time field defaults === 191 150 I can imagine various needs for defaults: 192 151 pre-seed with … … 199 158 Each one looks like a perfectly reasonable way to preset a suitable default for one of different demands. But only a preset, of course, still subject to change on ticket creation as well during ticket life. It looks like a discussion would help to possibly strip nonsense from sense. We'll see then, how generic or special, simple or complex a default configuration satisfying most/all real world demand would have to become. 200 159 201 === = Considering demand for (custom) time field format settings ====160 === Considering demand for (custom) time field format settings === 202 161 As I learned from the discussion within ticket #2182 support for implicitly setting date and time formats by locale selection is not enough for some users. I'd like to make this enhancement available for custom time fields first. Than we might be prepared to go on extending it to an implementation for all time fields. Maintaining changes for custom and standard time field in different patched should be desired to allow for an independed application as [ticket:2182#comment:73 proposed by me]. 203 162 204 === = Handling ticket changed notification ====163 === Handling ticket changed notification === 205 164 I plan to let the notification system handle the conversion of unix time stamp values to date/time strings on it's own. I tested with a patched version of [th:wiki:AnnouncerPlugin AnnouncerPlugin] that worked. This is a good start for the [wiki:TracDev/Proposals/Announcer proposed replacement] of current Trac Notification System by Code from [th:wiki:AnnouncerPlugin AnnouncerPlugin]. This might even make per-user preference-based date/time formatting possible in the future. 206 165 As adoption of code from [th:wiki:AnnouncerPlugin AnnouncerPlugin] is far from ready to replace current Ticket Notification, I feel the need to patch it as well. Right? 207 166 208 === = Development traces ====167 === Development traces === 209 168 Happened to have access to !SourceForge, so I choose to go and push code into a Mercurial repository there to enable collaboration based on a distributed VCS as per suggestion from IRC channel #trac at freenode.net. 210 169 rblank offered to rebase my code on top of code from his own repository, so a least he would be able to rewiev more easily. I'll try it and combine this move with a trial on Mercurial patch queue. … … 224 183 == Related Trac plugins == 225 184 * [th:wiki:CustomFieldAdminPlugin CustomFieldAdminPlugin], modified version to ease the setup for new field type ^*^ 226 * [th:wiki:DateFieldPlugin DateFieldPlugin] working flawlessly with custom time fields, since these are still simple text input form fields 185 * [th:wiki:CalendarPopUpPlugin CalendarPopUpPlugin] is working flawlessly with custom time fields, since these are still simple text input form fields 186 * [th:wiki:DateFieldPlugin DateFieldPlugin] does content validation to enforce it's idea of proper date/time string formatting, that will in most cases conflict with the input rewrite done by the parser of the time field implementation, however comparing date picker with that of [th:wiki:CalendarPopUpPlugin CalendarPopUpPlugin] this one looks superior in general (integration of an external, stable code base, easy customization support, i18n/l10n support, etc.), so it qualified for this project (see [#ToDo ToDo section]) 227 187 * [th:wiki:AnnouncerPlugin AnnouncerPlugin], modified version produces reports with pretty date/time strings according to locale setting of trac(d) proccess ^*^ 228 188 ^*^ patch is available inside repo, see subdirectory ./plugin 229 230 == Related tickets ==231 #710 asking for basic time tracking in Trac, especially missing native ''due_date'' and custom field type 'numeric'[[BR]]232 '''#1942 the main resource''' on requests and considerations '''related to the topic'''[[BR]]233 #1943 asking for time based calculations in queries, essentially based on #1943[[BR]]234 #1962 asking for due dates on tickets & email notification on overdue dates, several tricks and workarounds needed for using date strings the way you'd expect true time values to match, sort, etc.[[BR]]235 #2182 asking for better, directly (user- and system-)configurable date and time formats in contrast to current selection via locale[[BR]]236 #2288 asked for date/time based ticket query functions, that exist by now[[BR]]237 #6466 asked for higher time stamp precision introduced with microseconds for ''time'' and ''changetime'' in r9210[[BR]]238 #8354 seeking to get more date/time related information from queries, following #2288[[BR]]239 #9209 suggests code cleanup for trac/ticket/model.py, as side effect of my code review for this project[[BR]]240 [th:ticket:3565 th#3565] asking for periodical email notification per ticket after certain inactivity time, comment points to [th:wiki:TracReminderScript TracReminderScript][[BR]]241 [th:ticket:5620 th#5620] asking for reminder function sending notification before/on current date passing a due_date set as ticket field242 189 243 190 == External related resources == … … 257 204 [http://ches.nausicaamedia.com/articles/technogeekery/using-mercurial-queues-and-bitbucket-org Using Mercurial Queues and bitbucket.org] - a semi-official guide[[BR]] 258 205 [http://www.urbandictionary.com/ Define your world] - explaining internet slang at urbandictionary.com[[BR]] 259 [http://www.noslang.com/ Internet Slang Dictionary & Translator] at noslang.com 206 [http://www.noslang.com/ Internet Slang Dictionary & Translator] at noslang.com[[BR]]