PageRenderTime 31ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/shabti/templates/authplus/+package+/templates/widgets.mako

https://bitbucket.org/gawel/shabti
Mako | 167 lines | 158 code | 3 blank | 6 comment | 17 complexity | 044410ed27753c64ddedb3a6acafca0e MD5 | raw file
  1<%!
  2from datetime import datetime
  3from md5 import md5
  4import pytz
  5
  6from {{package}}.forms.user import *
  7
  8%>
  9<%def name="show_comments(doc_id, poster_id=None, message=None)">
 10<%
 11total = Comment.total_comments(doc_id)
 12if total > 0:
 13    comments = list(Comment.by_time(c.db, startkey=[doc_id], endkey=[doc_id, {}]))
 14else:
 15    comments = []
 16%>
 17<div class="comments">
 18    <a name="comments"></a>
 19    <h2>Comments <span class="subtle">(${total})</span></h2>
 20    % for comment in comments:
 21        ${show_comment(comment, extra_class=(poster_id and poster_id == comment.human_id and 'highlight'))}
 22    % endfor
 23    
 24    % if message:
 25    <p class="suggest_comment">${message}</p>        
 26    % endif
 27    % if c.user:
 28        <div style="display: none;" id="comment_preview">&nbsp;</div>
 29        <div class="comment_format">${h.link_to('Formatting Quick Reference', url="http://hobix.com/textile/quick.html")}</div>
 30        ${forms.comment_form(action='#') | n}
 31    % else:
 32        <p>You must ${h.link_to(_('login'), url=url('account_login', redir=url.current()))} before you can comment.</p>
 33    % endif
 34</div>
 35</%def>
 36##
 37<%def name="show_comment(comment, extra_class=None)">
 38<a name="${comment.id}" />
 39<div class="comment ${extra_class or ''}">
 40    ${user_post(comment.displayname, comment.email, comment.created, 'comments')}
 41    % if c.user and c.user.in_group('admin'):
 42    <div class="comment_delete commentid_${comment.id}">${h.link_to('Delete this comment', url='#', id_='comment_delete')}</div>
 43    % endif
 44    <div class="content">${h.textilize(comment.content)}</div>
 45</div>
 46</%def>
 47##
 48<%def name="user_post(displayname, email, post_date, extra_classes='')">
 49<div class="${extra_classes} user_post">
 50    <div class="user_icon">\
 51        % if email:
 52            <img src="http://www.gravatar.com/avatar/${md5(email).hexdigest()}?s=40">
 53        % else:
 54            <img src="http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802?s=40">
 55        % endif
 56    </div>
 57    <div class="username">${displayname or 'Anonymous'}</div>
 58    <div class="posted">${format_timestamp(post_date)}</div>
 59</div>
 60</%def>
 61##
 62<%def name="format_timestamp(date)">
 63<%
 64    diff = datetime.utcnow() - date
 65    date = pytz.UTC.localize(date).astimezone(timezone)
 66    now = pytz.UTC.localize(datetime.utcnow()).astimezone(timezone)
 67%>
 68% if diff.days < 3:
 69${h.distance_of_time_in_words(date, now, granularity='minute')} ago
 70% else:
 71${format.datetime(date)}
 72% endif
 73</%def>
 74##
 75<%def name="comment_js(doc_id)">
 76$('input#comment_form_preview').click(function() {
 77    var content = $('#comment_form_comment')[0].value;
 78    var preview_url = '${url('preview_comment')}';
 79    $.ajax({
 80        data: {content:content},
 81        type: "POST",
 82        url: preview_url,
 83        success: function(data, textStatus) {
 84            $('#comment_preview').html(data).slideDown();
 85        }
 86    });
 87    return false;
 88});
 89$('input#comment_form_submit').click(function() {
 90    var content = $('#comment_form_comment')[0].value;
 91    var submit_url = '${url('post_comment', doc_id=doc_id)}';
 92    $.ajax({
 93        data: {content:content},
 94        type: "POST",
 95        url: submit_url,
 96        success: function(data, textStatus) {
 97            window.location = location.pathname;
 98        }
 99    });
100    return false;
101});
102% if c.user and c.user.in_group('admin'):
103$('div.comment_delete a').click(function() {
104    var answer = window.confirm("Are you sure you want to delete this comment?");
105    var delete_url = '/comment/' + $(this).parent().attr('class').replace(/^.*commentid_(\w*)$/,'$1');
106    if (answer) {
107        $.ajax({
108            data: {'_method':'DELETE'},
109            type: "POST",
110            url: delete_url,
111            success: function(data, textStatus) {
112                window.location = location.pathname;
113            }
114        });
115    }
116    return false;
117});
118% endif
119</%def>
120##
121<%def name="comment_link(title, comment_id, doc, type, urlonly=False)">
122<%
123link = '#'
124if type == 'Documentation':
125    link = url('doc_view', version=doc['version'], language=doc['language'], url=doc['current_page_name'] + '/', anchor=comment_id)
126elif type == 'Traceback':
127    link = url('traceback', id=doc['_id'], anchor=comment_id)
128elif type == 'Paste':
129    link = url('paste', id=doc.get(old_id, doc['_id']), anchor=comment_id)
130elif type == 'Snippet':
131    link = url('snippet', id=doc['slug'], anchor=comment_id)
132%>
133% if urlonly:
134${link}
135% else:
136${h.link_to(title, url=link)}
137% endif
138</%def>
139##
140<%def name="pager(start, lst, total, keyname)">
141<%
142    start = int(start)
143    if total < start + 9:
144        end = total
145    else:
146        end = start + 9
147    startkey = lst[-1]._data[keyname]
148    if start > 10:
149        prevkey = lst[0]._data[keyname]
150%>
151<div id="paging">\
152    <div class="pger">
153    % if start > 10:
154    <a class="prev" href="${url.current(start=start-10, prevkey=prevkey)}">? Previous Page</a> | 
155    % else:
156    <a class="prev">? Previous Page</a> | 
157    % endif
158\
159    % if start + 9 < total:
160    <a class="next" href="${url.current(start=start+10, startkey=startkey)}">Next Page ?</a>
161    % else:
162    <a class="next">Next Page ?</a>
163    % endif
164    </div>
165    <div class="showing">Showing ${start}-${end} of ${total}</div>
166</div>
167</%def>