Commits

jonas  committed 987c386

Further clearsilver work

  • Participants
  • Parent commits 14e00a3
  • Branches trunk

Comments (0)

Files changed (7)

File svntrac/Module.py

         self.pool = pool
         self.cgi = neo_cgi.CGI()
         
+        sql_to_hdf("SELECT name FROM enum WHERE type='priority' ORDER BY name",
+                   self.cgi.hdf, 'enums.priority')
+        sql_to_hdf("SELECT name FROM enum WHERE type='severity' ORDER BY name",
+                   self.cgi.hdf, 'enums.severity')
         self.toolbar = Toolbar()
         self.cgi.hdf.setValue('title', '')
         self.cgi.hdf.setValue('svntrac_url', 'http://svntrac.edgewall.com/')

File svntrac/Ticket.py

         default_version   = self.config['ticket']['default_version']
         
         self.cgi.hdf.setValue('newticket.newtitle.title', 'create a new ticket')
-        self.cgi.hdf.setValue('newticket.component_select',
-                              enum_selector ('SELECT name FROM component ORDER by name',
-                                             'component',
-                                             default_component))
-        self.cgi.hdf.setValue('newticket.milestone_select',
-                              enum_selector ('SELECT name FROM milestone ORDER BY name',
-                                             'milestone',
-                                             default_milestone))
-        self.cgi.hdf.setValue('newticket.severity_select',
-                              enum_selector ('SELECT name FROM enum WHERE type=\'severity\' ORDER BY name',
-                                             'severity',
-                                             default_severity))
-        self.cgi.hdf.setValue('newticket.priority_select',
-                              enum_selector ('SELECT name FROM enum WHERE type=\'priority\' ORDER BY name',
-                                             'priority',
-                                             default_priority))
-        self.cgi.hdf.setValue('newticket.version_select',
-                              enum_selector ('SELECT name FROM version ORDER BY name',
-                                             'version'))
+        sql_to_hdf('SELECT name FROM component ORDER BY name',
+                   self.cgi.hdf, 'newticket.components')
+        sql_to_hdf('SELECT name FROM milestone ORDER BY name',
+                   self.cgi.hdf, 'newticket.milestones')
+        sql_to_hdf('SELECT name FROM version ORDER BY name',
+                   self.cgi.hdf, 'newticket.versions')
         if auth.get_authname() == 'anonymous':
             self.cgi.hdf.setValue('newticket.reporter', '')
         else:
         # redirect to the Ticket module to get a GET request
         redirect (href.ticket(id))
         
-    def get_changes(self, id):
+    def insert_ticket_data(self, hdf, id):
+        """Inserts ticket data into the hdf"""
         cnx = db.get_connection ()
         cursor = cnx.cursor()
         cursor.execute('SELECT time, author, field, oldvalue, newvalue '
             old    = row[3]
             new    = row[4]
 
-            self.cgi.hdf.setValue('ticket.changes.%d.date' % idx,
+            hdf.setValue('ticket.changes.%d.date' % idx,
                                   time.strftime('%F %H:%M',
                                                 time.localtime(date)))
             
-            self.cgi.hdf.setValue('ticket.changes.%d.author' % idx,
+            hdf.setValue('ticket.changes.%d.author' % idx,
                                   author)
-            self.cgi.hdf.setValue('ticket.changes.%d.field' % idx,
+            hdf.setValue('ticket.changes.%d.field' % idx,
                                   field)
-            self.cgi.hdf.setValue('ticket.changes.%d.old' % idx, old)
+            hdf.setValue('ticket.changes.%d.old' % idx, old)
             if field == 'comment':
-                self.cgi.hdf.setValue('ticket.changes.%d.new' % idx,
+                hdf.setValue('ticket.changes.%d.new' % idx,
                                       wiki_to_html(new))
             else:
-                self.cgi.hdf.setValue('ticket.changes.%d.new' % idx, new)
+                hdf.setValue('ticket.changes.%d.new' % idx, new)
             idx = idx + 1
 
     def get_actions(self, info):
         perm.assert_permission (perm.TICKET_VIEW)
         
         info = self.get_ticket(id)
-	#for key in info.keys():
-	#    self.namespace[key] = info[key]
         add_dict_to_hdf(info, self.cgi.hdf, 'ticket')
+        
+        sql_to_hdf('SELECT name FROM component ORDER BY name',
+                   self.cgi.hdf, 'ticket.components')
+        sql_to_hdf('SELECT name FROM milestone ORDER BY name',
+                   self.cgi.hdf, 'ticket.milestones')
+        sql_to_hdf('SELECT name FROM version ORDER BY name',
+                   self.cgi.hdf, 'ticket.versions')
         self.cgi.hdf.setValue('ticket.title', 'Ticket #%d' % id)
-        self.cgi.hdf.setValue('ticket.component_select',
-                              enum_selector ('SELECT name FROM component ORDER BY name',
-                                             'component',
-                                             info['component']))
-        self.cgi.hdf.setValue('ticket.milestone_select',
-                              enum_selector ('SELECT name FROM milestone ORDER BY name',
-                                             'milestone',
-                                             info['milestone']))
-        self.cgi.hdf.setValue('ticket.severity_select',
-                              enum_selector ('SELECT name FROM enum WHERE type=\'severity\' ORDER BY name',
-                                             'severity',
-                                             info['severity']))
-        self.cgi.hdf.setValue('ticket.priority_select',
-                              enum_selector ('SELECT name FROM enum WHERE type=\'priority\' ORDER BY name',
-                                             'priority',
-                                             info['priority']))
-        self.cgi.hdf.setValue('ticket.version_select',
-                              enum_selector ('SELECT name FROM version ORDER BY name',
-                                             'version',
-                                             info['version']))
-
         self.cgi.hdf.setValue('ticket.actions', self.get_actions(info))
-        self.get_changes(id)
-        self.cgi.hdf.setValue('ticket.description', wiki_to_html(info['description']))
-        self.cgi.hdf.setValue('ticket.opened', time.strftime('%F %H:%M',
-                                                             time.localtime(int(info['time']))))
+        self.insert_ticket_data(self.cgi.hdf, id)
+        self.cgi.hdf.setValue('ticket.description',
+                              wiki_to_html(info['description']))
+        self.cgi.hdf.setValue('ticket.opened',
+                              time.strftime('%F %H:%M',
+                                            time.localtime(int(info['time']))))
        

File svntrac/util.py

 def add_dict_to_hdf(dict, hdf, prefix):
     for key in dict.keys():
         hdf.setValue('%s.%s' % (prefix, key), str(dict[key]))
+
+def sql_to_hdf (sql, hdf, prefix):
+    """
+    executes a sql query and insert the first result column
+    into the hdf at the given prefix
+    """
+    cnx = get_connection()
+    cursor = cnx.cursor ()
+    cursor.execute (sql)
+#    cursor.execute ('SELECT type, name, value FROM enum ORDER BY type,value,name')
+    idx = 0
+    while 1:
+	row = cursor.fetchone()
+        if not row:
+            break
+        hdf.setValue('%s.%d.name' % (prefix, idx), row[0])
+        idx = idx + 1
+

File templates/macros.cs

+<?cs def:hdf_select(enum, name, selected) ?>
+  <select size="1" name="<?cs var:name ?>">
+  <?cs each:item = $enum ?>
+    <?cs if item.name == $selected ?>
+      <option selected><?cs var:item.name ?></option>
+    <?cs else ?>
+      <option><?cs var:item.name ?></option>
+    <?cs /if ?>
+  <?cs /each ?>
+  </select>
+<?cs /def?>
+

File templates/newticket.cs

 <?cs include "../templates/header.cs" ?>
+<?cs include "../templates/macros.cs" ?>
 
 <h3>New ticket:</h3>
 
 <tr>
 <td align="right">reporter:</td><td><input type="text" name="reporter" value="<?cs var:newticket.reporter ?>"></td>
 <td align="right">priority:</td>
-<td><?cs var:newticket.priority_select ?></td>
+<td><?cs call:hdf_select(enums.priority, "priority", "p2") ?>
+</td>
 </tr>
 <tr>
 <td align="right">component:</td>
-<td><?cs var:newticket.component_select ?></td>
+<td><?cs call:hdf_select(newticket.components, "component", "") ?>
 <td align="right">milestone:</td>
-<td<?cs var:newticket.milestone_select ?></td>
+<td><?cs call:hdf_select(newticket.milestones, "milestone", "") ?>
 </tr>
 <tr>
 <td align="right">version:</td>
-<td><?cs var:newticket.version_select ?></td>
+<td><?cs call:hdf_select(newticket.versions, "version", "") ?>
 <td align="right">assign to:</td>
 <td><input type="text" name="owner"></td>
 </tr>
 <tr>
-<td align="right">severity:</td><td><?cs var:newticket.severity_select ?></td>
+<td align="right">severity:</td>
+<td><?cs call:hdf_select(enums.severity, "severity", "normal") ?>
+</td>
 </tr>
 <tr>
 <td align="right">cc:</td>

File templates/ticket.cs

 <?cs include "../templates/header.cs" ?>
+<?cs include "../templates/macros.cs" ?>
 
 <h3>ticket: #<?cs var:ticket.id ?></h3>
 
   </tr>
   <tr>
     <td align="right">component:</td>
-    <td><?cs var:ticket.component_select ?></td>
-    <td align="right">priority:</td><td>
-    <?cs var:ticket.priority_select ?></td>
+    <td><?cs call:hdf_select(ticket.components, 
+                             "component",
+                             ticket.component) ?>
+    </td>
+    <td align="right">priority:</td>
+    <td><?cs call:hdf_select(enums.priority, 
+                             "priority",
+                             ticket.priority) ?>
+    </td>
   </tr>
   <tr>
     <td align="right">version:</td>
-    <td><?cs var:ticket.version_select ?></td>
+    <td><?cs call:hdf_select(ticket.versions, 
+                             "version",
+                             ticket.version) ?>
+    </td>
     <td align="right">milestone:</td>
-    <td><?cs var:ticket.milestone_select ?></td>
+    <td><?cs call:hdf_select(ticket.milestones, 
+                             "milestone",
+                             ticket.milestone) ?>
+    </td>
   </tr>
   <tr>
-    <td align="right">severity:</td><td><?cs var:ticket.severity_select ?></td>
+    <td align="right">severity:</td>
+    <td><?cs call:hdf_select(enums.severity, 
+                             "severity",
+                             ticket.severity) ?>
+    </td>
     <td align="right">assigned to:</td><td><?cs var:ticket.owner ?></td>
   </tr>
   <tr>
-<td align="right">status:</td><td><?cs var:ticket.status ?></td>
+    <td align="right">status:</td>
+    <td><?cs var:ticket.status ?></td>
 <td align="right">resolution:</td><td><?cs var:ticket.resolution ?></td>
 </tr>
 <tr>

File templates/timeline.cs

   <?cs elif:item.type == #2 ?>
     <tr>
       <td><?cs var:item.time?></td>
-      <td>ticket [<a href="<?cs var:item.ticket_href ?>"><?cs var:item.data?></a>] created: <?cs var:item.message?></td>
+      <td>ticket <a href="<?cs var:item.ticket_href ?>">#<?cs var:item.data?></a> created: <?cs var:item.message?></td>
     </tr>
 <!-- Closed ticket -->
   <?cs elif:item.type == #3 ?>
     <tr>
       <td><?cs var:item.time?></td>
-      <td>ticket [<a href="<?cs var:item.ticket_href ?>"><?cs var:item.data?></a>] closed.</td>
+      <td>ticket <a href="<?cs var:item.ticket_href ?>">#<?cs var:item.data?></a> closed.</td>
     </tr>
   <?cs /if ?>
 <?cs /each ?>