def handle(request, comm_id, topic_id):
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect('/login.htm')
    
    community = models.Community.objects.select_related().get(id=comm_id)
    if community.is_moderated:
        if (community.members.filter(id=myself.id).count() == 0):
            return siteaction.render_to_response('showmessage.htm', { 
                'msg_heading':'Error',
                'msg_html':'Access denied.'})
                
    page_num = dataplus.dictGetVal(request.REQUEST, 'page', 1, string.atoi)
    topic = models.CommunityTopic.objects.select_related().get(id=topic_id)
    paginator = Paginator(topic.posts.all().order_by('-posted_on'), config.posts_per_page)
    page = paginator.page(page_num)
    
    if paginator.count == 0:
        showing_howmany = '0 of 0 posts'
    else:
        showing_howmany = str(page.start_index()) + '-' + str(page.end_index()) + ' of ' + str(paginator.count) 
    for post in page.object_list:
        post.text = dataplus.replaceHtmlLineBreaks(post.text)
        post.posted_by.image_url = dataplus.getStaticUrl(post.posted_by.image_size1_file_path)
        post.posted_by.profile_url = config.profiles_url + '/' + post.posted_by.username
        post.posted_on_relative = dataplus.getRelativeDateTime(post.posted_on)
    
    prev_btn = ''
    next_btn = ''
    if page_num != 1:
        prev_btn = '<td><input class="medium-btn" type="button" name="prev-btn" value="Prev" onclick="javascript:window.location.href=\'?page=' + str(page_num-1) + '\';" /></td>'
    if page.has_next():
        next_btn = '<td><input class="medium-btn" type="button" name="next-btn" value="Next" onclick="javascript:window.location.href=\'?page=' + str(page_num+1) + '\';" /></td>'

    buttons = prev_btn + next_btn
    community.image_url = dataplus.getStaticUrl(community.image_size2_file_path)
    
    return siteaction.render_to_response('communities/posts.htm',
                        { 'myself': myself,
                            'community': community,
                            'topic': topic,
                            'posts': page.object_list,
                            'community_snapshot': getCommunitySnapshotHtml(community),
                            'showing_howmany': showing_howmany,
                            'buttons': buttons,
                        })
    
Beispiel #2
0
def getMessageBoxHtml(msgs):
    if not msgs:
        return ''
    
    html = ''    
    for msg in msgs:
        msg_row_id = 'email' + str(msg.id)
        msg_row_xp_id = 'emailxp' + str(msg.id)
        msg_reply_box = 'email_reply_box-' + str(msg.id)
        
        if msg.message_type == 'SA':
            html += '<div id="' + msg_row_id + '" class="email-msg-item">\r\n'
            html += '<table class="msg-item-table"><tr>\r\n' + \
                        '<td class="msg-from-field">Socialray </td>\r\n' + \
                        '<td class="msg-subject"><span class="linkless" onclick="javascript:viewMessage(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');">'
            if not msg.read:
                html += '<strong>' + msg.subject + '</strong>'
            else:
                html += msg.subject
            html += '</span>'
            if msg.body.strip():    html += '<span class="dimmed-text"> ' + dataplus.getPreviewText(msg.body) + '</span>'
            html += '</td>\r\n' + \
                    '<td class="msg-datetime-field">' + dataplus.getShortRelativeDateTime(msg.sent_at) + '</td>\r\n' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'
            
            html += '<div id="' + msg_row_xp_id + '" class="email-msg-xp" style="display:none">\r\n'
            html += '<div style="font-size:12px;font-weight:bold">\r\nSocialray - ' \
                        '<span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');">'+ msg.subject +'</span>' + \
                    '</div>\r\n<div class="small-text" style="color:#999999;">' + \
                    dataplus.getRelativeDateTime(msg.sent_at) + '</div>\r\n'  + msg.body + '\r\n' \
                    '<table><tr>\r\n' + \
                        '<td><input class="small-btn" type="button" name="finish" value="Hide" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');" /></td>' + \
                        '<td><input class="small-btn" type="button" name="finish" value="Delete" onclick="javascript:deleteMessage(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\');" /></td>' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'
            
        elif msg.message_type == 'TM':
            if msg.sender.account_type == 'U':
                sender_url = config.profiles_url + '/' + msg.sender.username
            elif msg.sender.account_type == 'R':
                rec = msg.sender.recruiter.all()[0]
                sender_url = config.recruiters_url + '/' + str(rec.id)

            html += '<div id="' + msg_row_id + '" class="email-msg-item">\r\n'
            html += '<table class="msg-item-table"><tr>\r\n' + \
                        '<td class="msg-from-field"><a href="' + sender_url + '">' + msg.sender.name + ' </a></td>\r\n' + \
                        '<td class="msg-subject"><span class="linkless" onclick="javascript:viewMessage(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');">'
            if not msg.read:
                html += '<strong>' + msg.subject + '</strong>'
            else:
                html += msg.subject
            html += '</span>'
            if msg.body.strip():    html += '<span class="dimmed-text"> ' + dataplus.getPreviewText(msg.body) + '</span>'
            html += '</td>\r\n' + \
                    '<td class="msg-datetime-field">' + dataplus.getShortRelativeDateTime(msg.sent_at) + '</td>\r\n' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'
            
            reply_subject = msg.subject.replace("'", "\\'")
            if not reply_subject.startswith('Re: Re: '):
                reply_subject = 'Re: ' + reply_subject
            html += '<div id="' + msg_row_xp_id + '" class="email-msg-xp" style="display:none">\r\n'
            html += '<div style="font-size:12px;font-weight:bold">\r\n' + \
                        '<a href="' + sender_url + '">' + msg.sender.name + '</a> - ' \
                        '<span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');">'+ msg.subject +'</span>' + \
                    '</div>\r\n<div class="small-text" style="color:#999999;">' + \
                    dataplus.getRelativeDateTime(msg.sent_at) + '</div>\r\n' + msg.body + '\r\n' \
                    '<table><tr>\r\n' + \
                        '<td><input class="small-btn" type="button" name="finish" value="Reply" onclick="javascript:showSendMsgBox(\'' + msg_reply_box + '\', \'' + msg.sender.username + '\', \'' + reply_subject + '\', \'' + str(msg.id) + '\');" /></td>' + \
                        '<td><input class="small-btn" type="button" name="finish" value="Hide" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');" /></td>' + \
                        '<td><input class="small-btn" type="button" name="finish" value="Delete" onclick="javascript:deleteMessage(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\');" /></td>' + \
                    '</tr></table>\r\n'
            html += '<div id="' + msg_reply_box + '"></div>\r\n'
            html += '</div>\r\n'
    return html
def getMessageBoxHtml(request, tom):
    page_num = dataplus.dictGetVal(request.REQUEST, 'page', 1, string.atoi)

    paginator = Paginator(models.Message.objects.filter \
        (account__id=tom.account.id, folder='outbox') \
        .order_by('-sent_at'), config.messages_per_page)

    if paginator.num_pages == 0: return ''
    
    page = paginator.page(page_num)
    
    html = ''
    ctr = 0
    html += '<div>'
    for msg in page.object_list:
        ctr = ctr + 1
        chk_id = 'chkMsg_' + str(msg.id)
        peers = mailman.getReceiverList(msg)
        peers_html = string.join(['<a href="' + siteaction.getDetailsUrl(x) + '">' + x.name + '</a>' for x in peers], ', ')
        
        if msg.message_type == 'JR':
            #TODO: Finish this ......
            pass
        if msg.message_type == 'TM':
            msg_row_id = 'email' + str(ctr)
            msg_row_xp_id = 'emailxp' + str(ctr)

            html += '<div id="' + msg_row_id + '" class="email-msg-item">\r\n'
            html += '<table class="msg-item-table"><tr>\r\n' + \
                        '<td class="msg-selection"><input id="' + chk_id + '" class="msg-selection-check" name="' + chk_id + '" type="checkbox" value="checked" /></td>\r\n' + \
                        '<td class="msg-from-field">' + peers_html.split('</a>')[0] + '</a>...' + '</td>\r\n' + \
                        '<td class="msg-subject"><span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_id + '\', \'' + msg_row_xp_id + '\');">' + msg.subject + '</span>'
            if msg.body.strip():
                html += '<span class="dimmed-text"> ' + dataplus.getPreviewText(msg.body) + '</span>'
            html += '</td>\r\n' + \
                         '<td class="msg-datetime-field">' + dataplus.getShortRelativeDateTime(msg.sent_at) + '</td>' + \
                   '</tr></table>\r\n'
            html += '</div>\r\n'
           
            html += '<div id="' + msg_row_xp_id + '" class="email-msg-xp" style="display:none">\r\n'
            html += '<div style="font-size:12px;font-weight:bold">\r\n' + peers_html + ' - ' \
                        '<span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');">'+ msg.subject + '</span>' + \
                    '</div>\r\n<div class="small-text" style="color:#999999;">' + \
                    dataplus.getRelativeDateTime(msg.sent_at) + '</div>\r\n' + msg.body + '\n' \
                    '<table><tr>\r\n' + \
                        '<td><input class="small-btn" type="button" name="hide-btn" value="Hide" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');" /></td>' + \
                        '<td><input class="small-btn" type="button" name="delete-btn" value="Delete" onclick="javascript:deleteMessage(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\');" /></td>' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'            
                    
    html += '</div>\r\n'        
    html += '<div>'
    if paginator.count > 0:
        html += '<p><span style="color:#999999">Showing ' + str(page.start_index()) + '-' + str(page.end_index()) + \
            ' of ' + str(paginator.count) + ' </span></p>'

    html += '<table class="button-box"><tr>\r\n'
    if page_num != 1:
        html += '<td><input class="medium-btn" type="button" name="prev-btn" value="Prev" onclick="javascript:window.location.href=\'/mailbox/sentitems.htm?page=' + str(page_num-1) + '\';" /></td>\r\n'
    if page.has_next():
        html += '<td><input class="medium-btn" type="button" name="prev-btn" value="Next" onclick="javascript:window.location.href=\'/mailbox/sentitems.htm?page=' + str(page_num+1) + '\';" /></td>\r\n'
    html += '</tr></table>\r\n'

    html += '</div>'
    return html
def getMessageBoxHtml(request, tom):
    page_num = dataplus.dictGetVal(request.REQUEST, 'page', 1, string.atoi)

    paginator = Paginator(models.Message.objects.filter \
        (account__id=tom.account.id, folder='trashcan') \
        .order_by('-sent_at'), config.messages_per_page)

    if paginator.num_pages == 0: return ''
    
    page = paginator.page(page_num)
    
    html = ''
    ctr = 0
    html += '<div>'
    for msg in page.object_list:
        ctr = ctr + 1
        chk_id = 'chkMsg_' + str(msg.id)
       
        if msg.message_type == 'SA':
            msg_row_id = 'email' + str(ctr)
            msg_row_xp_id = 'emailxp' + str(ctr)

            html += '<div id="' + msg_row_id + '" class="email-msg-item">\r\n'
            html += '<table class="msg-item-table"><tr>\r\n' + \
                        '<td class="msg-selection" ><input id="' + chk_id + '" name="' + chk_id + '" class="msg-selection-check" type="checkbox" value="checked" /></td>\r\n' + \
                        '<td class="msg-from-field">Socialray </td>\r\n' + \
                        '<td class="msg-subject"><span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_id + '\', \'' + msg_row_xp_id + '\');">' + msg.subject + '</span>'
            if msg.body.strip():
                html += '<span class="dimmed-text"> ' + dataplus.getPreviewText(msg.body) + '</span>'
            html += '</td>\r\n' + \
                        '<td class="msg-datetime-field">' + dataplus.getShortRelativeDateTime(msg.sent_at) + '</td>' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'
            
            html += '<div id="' + msg_row_xp_id + '" class="email-msg-xp" style="display:none">\r\n'
            html += '<div style="font-size:12px;font-weight:bold">\r\nSocialray - ' + \
                        '<span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');">'+ msg.subject + '</span>' + \
                    '</div>\r\n<div class="small-text" style="color:#999999;">' + \
                    dataplus.getRelativeDateTime(msg.sent_at) + '</div>\r\n' + msg.body + '\n' \
                    '<table><tr>\r\n' + \
                        '<td><input class="small-btn" type="button" name="hide-btn" value="Hide" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');" /></td>' + \
                        '<td><input class="medium-btn" type="button" name="inbox-btn" value="Move to Inbox" onclick="javascript:moveToInbox(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\');" /></td>' + \
                        '<td><input class="small-btn" type="button" name="delete-btn" value="Delete" onclick="javascript:deleteMessage(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\');" /></td>' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'
            
        elif msg.message_type == 'TM':
            msg_row_id = 'email' + str(ctr)
            msg_row_xp_id = 'emailxp' + str(ctr)
            
            if msg.sender.account_type == 'U':
                sender_url = config.profiles_url + '/' + msg.sender.username
            elif msg.sender.account_type == 'R':
                rec = msg.sender.recruiter.all()[0]
                sender_url = config.recruiters_url + '/' + str(rec.id)

            html += '<div id="' + msg_row_id + '" class="email-msg-item">\r\n'
            html += '<table class="msg-item-table"><tr>\r\n' + \
                        '<td class="msg-selection" ><input id="' + chk_id + '" name="' + chk_id + '" class="msg-selection-check" type="checkbox" value="checked" /></td>\r\n' + \
                        '<td class="msg-from-field"><a href="' + sender_url + '">' + msg.sender.name + ' </a></td>\r\n' + \
                        '<td class="msg-subject"><span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_id + '\', \'' + msg_row_xp_id + '\');">' + msg.subject + '</span><span class="dimmed-text"> ' + dataplus.getPreviewText(msg.body) + '</span></td>\r\n' + \
                        '<td class="msg-datetime-field">' + dataplus.getShortRelativeDateTime(msg.sent_at) + '</td>' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'
            
            html += '<div id="' + msg_row_xp_id + '" class="email-msg-xp" style="display:none">\r\n'
            html += '<div style="font-size:12px;font-weight:bold">\r\n' + \
                        '<a href="' + sender_url + '">' + msg.sender.name + '</a> - ' + \
                        '<span class="linkless" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');">'+ msg.subject + '</span>' + \
                    '</div>\r\n<div class="small-text" style="color:#999999;">' + \
                    dataplus.getRelativeDateTime(msg.sent_at) + '</div>\r\n' + msg.body + '\n' \
                    '<table><tr>\r\n' + \
                        '<td><input class="small-btn" type="button" name="hide-btn" value="Hide" onclick="javascript:fx_flipElem(\'' + msg_row_xp_id + '\', \'' + msg_row_id + '\');" /></td>' + \
                        '<td><input class="medium-btn" type="button" name="inbox-btn" value="Move to Inbox" onclick="javascript:moveToInbox(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\');" /></td>' + \
                        '<td><input class="small-btn" type="button" name="delete-btn" value="Delete" onclick="javascript:deleteMessage(\'' + str(msg.id) + '\', \'' + msg_row_xp_id + '\');" /></td>' + \
                    '</tr></table>\r\n'
            html += '</div>\r\n'            
                    
    html += '</div>\r\n'        
    html += '<div>'
    if paginator.count > 0:
        html += '<p><span style="color:#999999">Showing ' + str(page.start_index()) + '-' + str(page.end_index()) + \
            ' of ' + str(paginator.count) + ' </span></p>'

    html += '<table class="button-box"><tr>\r\n'
    if page_num != 1:
        html += '<td><input class="medium-btn" type="button" name="prev-btn" value="Prev" onclick="javascript:window.location.href=\'/mailbox/trashcan.htm?page=' + str(page_num-1) + '\';" /></td>\r\n'
    if page.has_next():
        html += '<td><input class="medium-btn" type="button" name="prev-btn" value="Next" onclick="javascript:window.location.href=\'/mailbox/trashcan.htm?page=' + str(page_num+1) + '\';" /></td>\r\n'
    html += '</tr></table>\r\n'

    html += '</div>'
    return html
def getTopicBoxHtml(topic, can_post):
    topic_div_id = "topic_" + str(topic.id)  # full enclosure
    lastpost_div_id = "lastpost_" + str(topic.id)  # this shows the last post; ON by default
    xp_div_id = "xp_posts_" + str(topic.id)  # flips last post with last 5, OFF by default
    post_box_id = "post_box_" + str(topic.id)  # reply to the post right there

    last_posts = topic.posts.order_by("-posted_on")[:5]

    html = ""
    # topic box starts hear hear!
    html += '<div id="' + topic_div_id + '" class="community-topic-item">\r\n'

    # header....
    html += (
        '<div><span><strong><a href="/communities/'
        + str(topic.community.id)
        + "/topics/"
        + str(topic.id)
        + '">'
        + topic.title
        + "</a></strong> ("
        + str(topic.posts.count())
        + " posts)</span>\r\n"
    )
    html += (
        ' <span class="dimmed-text">started by <a href="'
        + config.profiles_url
        + "/"
        + topic.started_by.username
        + '">'
        + topic.started_by.name
        + "</a></span></div>\r\n"
    )

    if topic.posts.count() > 0:
        last_post = last_posts[0]
        # last post div - can be empty
        html += '<div id="' + lastpost_div_id + '">'
        html += (
            '<span class="small-text">Last Post ' + dataplus.getRelativeDateTime(last_post.posted_on) + "</span><br />"
        )
        html += dataplus.getPreviewText(last_post.text)
        html += (
            '<div class="small-text"><span class="linkless" onclick="fx_flipElem(\''
            + lastpost_div_id
            + "', '"
            + xp_div_id
            + "');\">Expand</span></div>\r\n"
        )
        html += "</div>"

        html += '<div id="' + xp_div_id + '" style="display:none;">\r\n'
        for post in last_posts:
            posted_by_url = config.profiles_url + "/" + post.posted_by.account.username
            html += (
                '<div class="community-post" style="padding:5px;border:solid;border-width: 1px;border-color:#dddddd;">\r\n'
                + '<table style="width:100%">\r\n'
                + "<tr>\r\n"
                + '<td style="width:60px;text-align:center;vertical-align:top;">\r\n'
                + '<a href="'
                + posted_by_url
                + '"><img src="'
                + dataplus.getStaticUrl(post.posted_by.image_size1_file_path)
                + '" alt="'
                + post.posted_by.name
                + '" /></a>\r\n'
                + "</td>\r\n"
                + '<td style="vertical-align:top;">\r\n'
                + '<div><a href="'
                + config.profiles_url
                + "/"
                + post.posted_by.username
                + '">\r\n'
                + post.posted_by.name
                + "</a> "
                + dataplus.getRelativeDateTime(post.posted_on)
                + "\r\n"
                + "</div>\r\n"
                + '<div class="community-post-text">'
                + dataplus.replaceHtmlLineBreaks(post.text)
                + "</div>\r\n"
                + "</td>\r\n"
                + "</tr>\r\n"
                + "</table>\r\n"
                + "</div>\r\n"
            )

        html += "<table><tr>\r\n"
        if can_post:
            html += (
                '<td><input class="small-btn" type="button" name="reply-btn" value="Reply" onclick="showTopicReplyBox(\''
                + post_box_id
                + "', '"
                + str(topic.id)
                + "', true, function(topicId, html){ reloadTopic(topicId, html); });\" /></td>"
            )
        html += (
            '<td><input class="small-btn" type="button" name="hide-btn" value="Hide" onclick="fx_flipElem(\''
            + xp_div_id
            + "', '"
            + lastpost_div_id
            + "');\" /></td>"
        )
        html += "</tr></table>\r\n"
        html += '<div id="' + post_box_id + '"></div>\r\n'
        html += "</div></div>"
    else:
        if can_post:
            html += (
                '<div><span class="linkless" onclick="showTopicReplyBox(\''
                + post_box_id
                + "', '"
                + str(topic.id)
                + "', true, function(topicId, html){ reloadTopic(topicId, html); });\" />Reply</span></div>\r\n"
            )
            html += '<div id="' + post_box_id + '"></div></div>\r\n'

    return html