Commits

Nikolaj Sjujskij committed 965f4a4

Add opening date to ticket popup title

Comments (0)

Files changed (4)

 )
 
 # list of developers
-DEVS = (
-        ('John Doe', 'johndoe'),
-        )
+DEVS = {
+        'johndoe': 'John Doe',
+        }
 
 # interface where development/debug server would run
 DEBUG_HOST = '127.0.0.1'
 except ImportError:
     pass
 
+DEVLIST = DEVS.items()
+DEVLIST.sort(cmp=lambda x,y: cmp(x[1], y[1]))
+
 # query to fetch month data (with DATE_FIELD set)
-QUERY_MONTH = """SELECT ticket.id, ticket.owner, ticket.summary, ticket.reporter,
-                        ticket.status, ticket_custom.value AS due_date
+QUERY_MONTH = """SELECT ticket.id, ticket.owner, ticket.summary,
+                        ticket.reporter, ticket.status, ticket.time,
+                        ticket_custom.value AS due_date
                 FROM ticket INNER JOIN ticket_custom
                 ON ticket.id = ticket_custom.ticket
                 WHERE ticket_custom.name='{0}' AND
 
 # query to fetch tickets closed this month without DATE_FIELD set
 QUERY_UNSET_DATE = """SELECT DISTINCT ON (ticket.id)
-                            ticket.id, ticket.owner,
+                            ticket.id, ticket.owner, ticket.time,
                             ticket.summary, ticket.reporter,
                             ticket_change.time AS closed_at
                         FROM ticket INNER JOIN ticket_change
                     """.format(DATE_FIELD)
 
 # query to fetch open tickets
-QUERY_OPEN = """SELECT id, owner, summary, reporter
+QUERY_OPEN = """SELECT id, owner, summary, reporter, time
                 FROM ticket WHERE status!='closed'"""
 # query to fetch tickets close not earlier than a week ago
-QUERY_CLSD_WEEK = """SELECT id, owner, summary,reporter FROM ticket
+QUERY_CLSD_WEEK = """SELECT id, owner, summary,reporter, time FROM ticket
                      WHERE status='closed' AND changetime>%s"""
 
 # prepare dictionary of DB connections
 # remove not to import them
 del trac, TRAC_DATA, DATE_FIELD
 del ISOLATION_LEVEL_AUTOCOMMIT, UNICODE, UNICODEARRAY
-
-# sort developer list
-DEVS.sort(cmp=lambda x,y: cmp(x[0], y[0]))
-
 app = Flask(__name__)
 
 from defaults import *
-from utils import dictify
-
-# prepare dictionary of DEVS: {login: name}
-DEVDICT = {}
-for dev in DEVS:
-    DEVDICT[dev[1]] = dev[0]
-del dev
+from utils import dictify, get_tckt_title
 
 def other_colour(colour):
     return 'dark' if colour == 'light' else 'light'
             user_tckt_list.append({'id': tckt['id'],
                                    'due_date': due_date,
                                    'summary': tckt['summary'],
+                                   'time': tckt['time'],
+                                   'reporter': tckt['reporter'],
                                    'status': 'closed',
                                    'trac': trac['name'],
                                    'base_url': trac['base_url']})
 
     # total dictification of month data
     for user, tickets in month_data_raw.items():
+        for ticket in tickets:
+            ##TODO: do it within utils.dictify (pass function in add_data)
+            ticket['title'] = get_tckt_title(ticket)
         month_data[user] = dictify(tickets, 'due_date')
         for due_date in month_data[user].keys():
             tickets = month_data[user].pop(due_date)
     cal_year = year
     month, year = (basedate.month, basedate.year)
     context = {
-               'devs': DEVS,
-               'devdict': DEVDICT,
+               'devs': DEVLIST,
+               'devlist': DEVS,
                'month_data': month_data,
                'calendar': calendar.monthcalendar(year, month),
                'weekhdr': calendar.weekheader(3).split(' '),

templates/index.html

     <div id="contents">
         <span>Оглавление</span>
         <ul>
-        {% for name, login in devs %}
+        {% for login, name in devs %}
         <li><a href="#{{ login }}">{{ name }}</a></li>
         {% endfor %}
         </ul>
     </div>
-    {% for name, login in devs %}
+    {% for login, name in devs %}
     {% set usertckts = month_data.pop(login, {}) %}
     <h2 id="{{ login }}">{{ name }}</h2>
     <h3>
                     {% for ticket in tickets %}
                     <p class="{{ ticket.status }}">
                     <a href="{{ ticket.base_url }}/ticket/{{ ticket.id }}"
-                       title="{{ devdict.get(ticket.reporter, ticket.reporter) }}">
+                        title="{{ ticket.title }}">
                         <span class="num">#{{ ticket.id }}</span>:
                         {{ ticket.summary }}</a>
                     </p>
             {% for ticket in tickets %}
                 <li>
                 <a href="{{ ticket.base_url }}/ticket/{{ ticket.id }}"
-                   title="{{ devdict.get(ticket.reporter, ticket.reporter) }}">
+                   title="{{ ticket.title }}">
                         <span class="num">#{{ ticket.id }}</span>:
                         {{ ticket.summary }}</a>
                 </li>
             {% for ticket in tickets %}
                 <li>
                     <a href="{{ ticket.base_url }}/ticket/{{ ticket.id }}"
-                       title="{{ devdict.get(ticket.reporter, ticket.reporter) }}">
+                        title="{{ ticket.title }}">
                         <span class="num">#{{ ticket.id }}</span>:
                         {{ ticket.summary }}</a>
                 </li>
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
+from datetime import date
+from settings import DEVS
+
 def dictify(dicts, key, dict2up={}, add_data={}):
     ''' Rearranges iterable of dictionaries to dictionary of lists
     ({'key': val1, 'otherkey': otherval1, ...},
         result[value].append(d)
     return result
 
+def get_tckt_title(tckt_dict):
+    ''' Composes title for ticket '''
+    created_on = tckt_dict['time']
+    created_on = date.fromtimestamp(created_on // (10**6))
+    reporter = DEVS.get(tckt_dict['reporter'], tckt_dict['reporter'])
+    return '{0} ({1})'.format(reporter, created_on.strftime("%d.%m.%Y"))
+
+
 if __name__ == "__main__":
     test = ({'key': 'val1', 'otherkey': 'otherval1'},
             {'key': 'val2', 'otherkey': 'otherval2'},