Commits

Ben Bangert  committed c1ed2e6

Traceback template updates for pager

  • Participants
  • Parent commits 3631260

Comments (0)

Files changed (9)

File kai/controllers/accounts.py

 from kai.lib.base import BaseController, render
 from kai.lib.helpers import failure_flash, success_flash
 from kai.lib.mail import EmailMessage
-from kai.model import Human, forms
+from kai.model import Human, Traceback, forms
 
 log = logging.getLogger(__name__)
 
         user.email_token_issue = datetime.utcnow()
         user.store(self.db)
         
+        tracebacks = list(Traceback.by_session_id(self.db)[session.id])
+        if tracebacks:
+            for tb in tracebacks:
+                try:
+                    tb.session_id = None
+                    tb.human_id = user.id
+                    tb.displayname = user.displayname
+                    tb.store(self.db)
+                except:
+                    pass
+        
         # Send out the welcome email with the reg token
         message = EmailMessage(subject="PylonsHQ - Registration Confirmation",
                                body=render('/email/register.mako'),

File kai/controllers/tracebacks.py

 from pylons.decorators import jsonify
 
 from kai.lib.base import BaseController, render
+from kai.lib.helpers import success_flash
 from kai.model import Human, Traceback
 
 log = logging.getLogger(__name__)
         c.active_tab = 'Tools'
         c.active_sub = 'Tracebacks'
     
+    def index(self):
+        start = request.GET.get('start', '1')
+        startkey = request.GET.get('startkey')
+        prevkey = request.GET.get('prevkey')
+        if startkey:
+            c.tracebacks = Traceback.by_time(self.db, descending=True, startkey=startkey, count=11)
+        elif prevkey:
+            c.tracebacks = Traceback.by_time(self.db, startkey=prevkey, count=11)
+            c.reverse = True
+        else:
+            c.tracebacks = Traceback.by_time(self.db, descending=True, count=11)
+        c.start = start
+        return render('/tracebacks/index.mako')
+    
     @jsonify
     def create(self):
         """Create a new traceback in the system, pegged to the current
             abort(500)
         tb = Traceback.load(self.db, id) or abort(404)
         session.save()
-        tb.session_id = session.id
         if c.user:
             tb.displayname = c.user.displayname
             tb.human_id = c.user.id
+        else:
+            tb.session_id = session.id
         tb.uuid = None
         tb.store(self.db)
         return 'ok'
             c.author = Human.load(self.db, c.traceback.human_id)
         c.is_owner = c.traceback.is_owner(c.user, check_session=True)
         return render('/tracebacks/show.mako')
+    
+    def delete(self, id):
+        traceback = Traceback.load(self.db, id) or abort(404)
+        if traceback.is_owner(c.user, check_session=True):
+            self.db.delete(traceback)
+            success_flash('Traceback deleted')
+        else:
+            abort(401)

File kai/lib/base.py

                 user = None
                 pylons.session['logged_in'] = False
                 pylons.session.delete()
+                pylons.session.save()
         else:
             user = None
         if user:

File kai/model/traceback.py

           }
         }''', include_docs=True)
     
+    by_session_id = View('traceback', '''
+        function(doc) {
+          if (doc.type == 'Traceback' && doc.session_id) {
+            emit(doc.session_id, null);
+          }
+        }''', include_docs=True)
+    
     @classmethod
     def from_xml(cls, content):
         try:

File kai/public/css/tweaks.css

 div.traceback h3 { font-size: 1em; margin: 0 0 0.8em 0; }
 div.traceback ul { list-style: none; margin: 0; padding: 0 0 0 1em; }
 div.traceback ul li { list-style: none;}
-div.traceback h4 { font-size: 13px; font-weight: normal; margin: 0.7em 0 0.1em 0; }
+div.traceback h4 { font-size: 13px; font-weight: normal; margin: 0.7em 0 0.1em 0; padding: 0;}
 div.traceback ul li em { font-style: italic; }
-cite {font-style: italic;}
-div.traceback pre { margin: 0; padding: 5px 0 3px 15px;
+cite {font-style: italic;}
+div.traceback pre { margin: 0; padding: 3px 0 3px 10px;
  background-color: #ccc; border-top: 1px solid #aaa;
  border-left: 1px solid #aaa; border-right: 1px solid #fafafa;
- border-bottom: 1px solid #fafafa; }
+ border-bottom: 1px solid #fafafa; font-size: 93%;}
 .details {font-size: 14px;}
 .errormsg {font-weight: bold;}
 table.buildbot, table.buildbot tr td, table.buildbot tr th {border:none;}
     border-bottom: 1px solid #ddd;
 }
 
+
+div#paging {
+    float: right;
+    font-size: 77%;
+}
+div#paging div.showing {
+    text-align: right;
+}
+
 /* Traceback */
+
+div.exception {
+    border-bottom: 1px solid #ddd;
+}
+div.moduleline {
+    color: #00607b;
+    font-style:italic;
+}
+
+div.exception h2 {
+    font-size: 123.1%;
+    margin: 5px 0 0 0;
+    padding: 5px 0 0 0;
+    line-height: 1;
+}
 div.traceback_post.user_post {
 	float: right;
     width: 200px;
+}
+div.exception div.frame {
+    font-weight: bold;
 }
-
+div.exception_frame {
+    font-size: 85%;
+    padding: 0;
+    margin: 5px 0 0 0;
+    line-height: 1.2;
+}
 div.traceback_posted {
     font-size: 85%;
     color: #444;
     width: 100%;
 }
 div.sysinfo {
-	margin: 5px 0 0 550px;
+	margin: 20px 0 0 550px;
 	border: 1px solid #bbb;
     height: 200px;
     width: 350px;

File kai/templates/tracebacks/index.mako

-<div class="yui-b">
-    <h1>List Tracebacks <span class="subtle">(${c.tracebacks.results})</span></h1>
-    % for traceback in c.tracebacks.iterchildren(tag='traceback'):
-    <% frame = traceback.last_frame %>\
-    <h2 class="exception"><a href="${h.url_for('traceback', id=traceback.link.text.replace('.xml',''))}">\
-        ${traceback.exception}</a></h2>
-    <% date = h.parse_iso_date(traceback.created.text) %>\
-    <p class="date">Posted on ${date.strftime('%Y-%m-%d at %H:%M:%S')}</p>
-    <p class="moduleline">${frame.module}:\
-    <span class="lineno">${frame.line}</span>\
-     in ${frame.function}:<p>
-    % if hasattr(frame, 'operation'):
-    ${highlight(frame.operation.text, py_lexer, html_formatter) | n}\
-    % endif
+<div class="yui-b content">
+    <h1>List Tracebacks <span class="subtle">(${c.tracebacks.total_rows})</span></h1>
+    <%
+    results = list(c.tracebacks)
+    if c.reverse:
+        results.reverse()
+    %>
+    ${widgets.pager(c.start, results, c.tracebacks.total_rows, 'created')}
+    % for traceback in results[:10]:
+    <% frame = traceback.frames[-1] %>
+    <div class="exception">
+        <h2 class="exception"><a href="${url('traceback', id=traceback.id)}">\
+            ${traceback.exception_type} : ${traceback.exception_value}</a></h2>
+        <div class="traceback_posted">${widgets.format_timestamp(traceback.created)} by
+            <span class="traceback_author">${traceback.displayname or 'Anonymous'}</span>\
+            </div>
+        <div class="exception_frame">
+            <div class="frame">Last Frame:</div>
+            <div class="moduleline">${frame.module}:\
+                <span class="lineno">${frame.line}</span>\
+                in ${frame.function}
+            </div>
+            ${highlight(frame.operation, py_lexer, html_formatter) | n}\
+        </div>
+    </div>
     % endfor
 </div>
+<%namespace name="widgets" file="/widgets.mako"/>
 <%def name="title()">${parent.title()} - Traceback Listing</%def>\
 <%inherit file="../layout.mako" />\
 <%!

File kai/templates/tracebacks/show.mako

         <ul>
         % for frame in frames:
         <li><h4>
-            Module <cite>${frame['module']}</cite>, line <em>${frame['line']}</em>, in \
+            <cite>${frame['module']}</cite> : <em>${frame['line']}</em>, in \
 <code>${frame['function']}</code></h4>
             ${highlight(frame['operation'], py_lexer, html_formatter) | n}\
         </li>
 <%def name="javascript()">
 ${parent.javascript()}
 <script>
-
+$(document).ready(function() {
+    $('#delete_traceback').click(function() {
+        var answer = window.confirm("Are you sure you want to delete this traceback?");
+        if (answer) {
+            $.ajax({
+                data: {"_method":"DELETE"},
+                type: "POST",
+                url: location.pathname,
+                success: function(data, textStatus) {
+                    window.location = '/tracebacks';
+                }
+            });
+        }
+        return false;
+    });
+});
 </script>
 </%def>
 <%inherit file="../layout.mako" />\

File kai/templates/widgets.mako

 <%def name="format_timestamp(date)">
 <%
     diff = datetime.utcnow() - date
+    date = timezone.localize(date)
+    now = timezone.localize(datetime.utcnow())
 %>
 % if diff.days < 3:
-${h.distance_of_time_in_words(date, granularity='minute')} ago
+${h.distance_of_time_in_words(date, now, granularity='minute')} ago
 % else:
 ${format.datetime(date)}
 % endif
 </%def>
+<%def name="pager(start, lst, total, keyname)">
+<%
+    start = int(start)
+    if total < start + 9:
+        end = total
+    else:
+        end = start + 9
+    startkey = lst[-1]._data[keyname]
+    if start > 10:
+        prevkey = lst[0]._data[keyname]
+%>
+<div id="paging">\
+    <div class="pger">
+    % if start > 10:
+    <a class="prev" href="${url.current(start=start-10, prevkey=prevkey)}">← Previous Page</a> | 
+    % else:
+    <a class="prev">← Previous Page</a> | 
+    % endif
+\
+    % if start + 9 < total:
+    <a class="next" href="${url.current(start=start+10, startkey=startkey)}">Next Page →</a>
+    % else:
+    <a class="next">Next Page →</a>
+    % endif
+    </div>
+    <div class="showing">Showing ${start}-${end} of ${total}</div>
+</div>
+</%def>
 <%!
 from datetime import datetime
+import pytz
 %>

File kai/websetup.py

         Snippet.by_author_id, Snippet.by_tag, Snippet.all_tags,
         Snippet.author_totals,
         
-        Traceback.by_uuid, Traceback.by_time,
+        Traceback.by_uuid, Traceback.by_time, Traceback.by_session_id,
     ])