#coding: utf8 from datetime import datetime from tracim.models.data import VirtualEvent from tracim.models.data import ContentType from tracim.models import data # FIXME: fix temporaire ... style = """ .title { background:#F5F5F5; padding-right:15px; padding-left:15px; padding-top:10px; border-bottom:1px solid #CCCCCC; overflow:auto; } .title h1 { margin-top:0; } .content { padding: 15px; } #left{ padding:0; } #right { background:#F5F5F5; border-left:1px solid #CCCCCC; border-bottom: 1px solid #CCCCCC; padding-top:15px; } @media (max-width: 1200px) { #right { border-top:1px solid #CCCCCC; border-left: none; border-bottom: none; } } body { overflow:auto; } .btn { text-align: left; } .table tbody tr .my-align { vertical-align:middle; } .title-icon { font-size:2.5em; float:left; margin-right:10px; } .title.page, .title-icon.page { color:#00CC00; } .title.thread, .title-icon.thread { color:#428BCA; } /* ****************************** */ .description-icon { color:#999; font-size:3em; } .description { border-left: 5px solid #999; padding-left: 10px; margin-left: 10px; margin-bottom:10px; } .description-text { display:block; overflow:hidden; color:#999; } .comment-row:nth-child(2n) { background-color:#F5F5F5; } .comment-row:nth-child(2n+1) { background-color:#FFF; } .comment-icon { color:#CCC; font-size:3em; display:inline-block; margin-right: 10px; float:left; } .comment-content { display:block; overflow:hidden; } .comment, .comment-revision { padding:10px; border-top: 1px solid #999; } .comment-revision-icon { color:#777; margin-right: 10px; } .title-text { display: inline-block; } """ _LABELS = { 'archiving': 'Item archived', 'content-comment': 'Item commented', 'creation': 'Item created', 'deletion': 'Item deleted', 'edition': 'item modified', 'revision': 'New revision', 'status-update': 'New status', 'unarchiving': 'Item unarchived', 'undeletion': 'Item undeleted', 'move': 'Item moved', 'comment': 'Comment', 'copy' : 'Item copied', } def create_readable_date(created, delta_from_datetime: datetime = None): if not delta_from_datetime: delta_from_datetime = datetime.now() delta = delta_from_datetime - created if delta.days > 0: if delta.days >= 365: aff = '%d year%s ago' % (delta.days / 365, 's' if delta.days / 365 >= 2 else '') elif delta.days >= 30: aff = '%d month%s ago' % (delta.days / 30, 's' if delta.days / 30 >= 2 else '') else: aff = '%d day%s ago' % (delta.days, 's' if delta.days >= 2 else '') else: if delta.seconds < 60: aff = '%d second%s ago' % (delta.seconds, 's' if delta.seconds > 1 else '') elif delta.seconds / 60 < 60: aff = '%d minute%s ago' % (delta.seconds / 60, 's' if delta.seconds / 60 >= 2 else '') else: aff = '%d hour%s ago' % (delta.seconds / 3600, 's' if delta.seconds / 3600 >= 2 else '') return aff def designPage(content: data.Content, content_revision: data.ContentRevisionRO) -> str: hist = content.get_history(drop_empty_revision=False) histHTML = '' for event in hist: if isinstance(event, VirtualEvent): date = event.create_readable_date() label = _LABELS[event.type.id] histHTML += ''' ''' % ('warning' if event.id == content_revision.revision_id else '', event.type.icon, label, date, event.owner.display_name, # NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0 ' shown' if event.id == content_revision.revision_id else '' # '''(View revision)''' % ( # content.label, event.id, event.type.id, event.ref_object.label) if event.type.id in ['revision', 'creation', 'edition'] else '') ) histHTML += '
%s %s %s %s
' page = ''' %s

%s

page created on %s by %s
%s
''' % (content_revision.label, style, content_revision.label, content.created.strftime("%B %d, %Y at %H:%m"), content.owner.display_name, content_revision.description, histHTML) return page def designThread(content: data.Content, content_revision: data.ContentRevisionRO, comments) -> str: hist = content.get_history(drop_empty_revision=False) allT = [] allT += comments allT += hist allT.sort(key=lambda x: x.created, reverse=True) disc = '' participants = {} for t in allT: if t.type == ContentType.Comment: disc += '''
%s wrote :
%s
%s
''' % (t.owner.display_name, create_readable_date(t.created), t.description) if t.owner.display_name not in participants: participants[t.owner.display_name] = [1, t.created] else: participants[t.owner.display_name][0] += 1 else: if isinstance(t, VirtualEvent) and t.type.id != 'comment': label = _LABELS[t.type.id] disc += '''
%s
%s
%s %s
''' % ('warning' if t.id == content_revision.revision_id else '', t.type.icon, t.owner.display_name, t.create_readable_date(), label, # NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0 ' shown' if t.id == content_revision.revision_id else '' # else '''(View revision)''' % ( # content.label, # t.id, # t.ref_object.label) if t.type.id in ['revision', 'creation', 'edition'] else '') ) thread = ''' %s

%s

thread created on %s by %s
%s
%s
''' % (content_revision.label, style, content_revision.label, content.created.strftime("%B %d, %Y at %H:%m"), content.owner.display_name, content_revision.description, disc) return thread