__filename__ = "webapp_column_right.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.1.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" import os from datetime import datetime from shutil import copyfile from content import removeLongWords from utils import removeHtml from utils import locatePost from utils import loadJson from utils import getConfigParam from utils import votesOnNewswireItem from utils import getNicknameFromActor from posts import isEditor from posts import isModerator from webapp_utils import getRightImageFile from webapp_utils import getImageFile from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_utils import getBannerFile from webapp_utils import htmlPostSeparator from webapp_utils import headerButtonsFrontScreen from webapp_utils import getIconsWebPath def votesIndicator(totalVotes: int, positiveVoting: bool) -> str: """Returns an indicator of the number of votes on a newswire item """ if totalVotes <= 0: return '' totalVotesStr = ' ' for v in range(totalVotes): if positiveVoting: totalVotesStr += '✓' else: totalVotesStr += '✗' return totalVotesStr def getRightColumnContent(baseDir: str, nickname: str, domainFull: str, httpPrefix: str, translate: {}, iconsPath: str, moderator: bool, editor: bool, newswire: {}, positiveVoting: bool, showBackButton: bool, timelinePath: str, showPublishButton: bool, showPublishAsIcon: bool, rssIconAtTop: bool, publishButtonAtTop: bool, authorized: bool, showHeaderImage: bool) -> str: """Returns html content for the right column """ htmlStr = '' domain = domainFull if ':' in domain: domain = domain.split(':') if authorized: # only show the publish button if logged in, otherwise replace it with # a login button publishButtonStr = \ ' ' + \ '\n' else: # if not logged in then replace the publish button with # a login button publishButtonStr = \ ' \n' # show publish button at the top if needed if publishButtonAtTop: htmlStr += '
' + \ '' + \ '' + title + \ '' + totalVotesStr if moderator: htmlStr += \ ' ' + dateShown + '' htmlStr += '
\n' else: htmlStr += ' ' htmlStr += dateShown + '\n' else: totalVotesStr = '' totalVotes = 0 if moderator: if moderatedItem: totalVotes = votesOnNewswireItem(item[2]) # show a number of ticks or crosses for how many # votes for or against totalVotesStr = \ votesIndicator(totalVotes, positiveVoting) title = removeLongWords(item[0], 16, []).replace('\n', '' + \ '' + \ title + '' + totalVotesStr htmlStr += ' ' + dateShown htmlStr += '' htmlStr += '' htmlStr += '
\n' else: htmlStr += '' + \ '' + \ title + '' + \ totalVotesStr htmlStr += ' ' htmlStr += dateShown + '
\n' return htmlStr def htmlCitations(baseDir: str, nickname: str, domain: str, httpPrefix: str, defaultTimeline: str, translate: {}, newswire: {}, cssCache: {}, blogTitle: str, blogContent: str, blogImageFilename: str, blogImageAttachmentMediaType: str, blogImageDescription: str) -> str: """Show the citations screen when creating a blog """ htmlStr = '' # create a list of dates for citations # these can then be used to re-select checkboxes later citationsFilename = \ baseDir + '/accounts/' + \ nickname + '@' + domain + '/.citations.txt' citationsSelected = [] if os.path.isfile(citationsFilename): citationsSeparator = '#####' with open(citationsFilename, "r") as f: citations = f.readlines() for line in citations: if citationsSeparator not in line: continue sections = line.strip().split(citationsSeparator) if len(sections) != 3: continue dateStr = sections[0] citationsSelected.append(dateStr) # the css filename cssFilename = baseDir + '/epicyon-profile.css' if os.path.isfile(baseDir + '/epicyon.css'): cssFilename = baseDir + '/epicyon.css' # iconsPath = getIconsWebPath(baseDir) htmlStr = htmlHeaderWithExternalStyle(cssFilename) # top banner bannerFile, bannerFilename = getBannerFile(baseDir, nickname, domain) htmlStr += \ '\n' htmlStr += '\n' htmlStr += \ '\n' return htmlStr + htmlFooter() def htmlNewswireMobile(cssCache: {}, baseDir: str, nickname: str, domain: str, domainFull: str, httpPrefix: str, translate: {}, newswire: {}, positiveVoting: bool, timelinePath: str, showPublishAsIcon: bool, authorized: bool, rssIconAtTop: bool, iconsAsButtons: bool, defaultTimeline: str) -> str: """Shows the mobile version of the newswire right column """ htmlStr = '' # the css filename cssFilename = baseDir + '/epicyon-profile.css' if os.path.isfile(baseDir + '/epicyon.css'): cssFilename = baseDir + '/epicyon.css' iconsPath = getIconsWebPath(baseDir) if nickname == 'news': editor = False moderator = False else: # is the user a moderator? moderator = isModerator(baseDir, nickname) # is the user a site editor? editor = isEditor(baseDir, nickname) showPublishButton = editor htmlStr = htmlHeaderWithExternalStyle(cssFilename) bannerFile, bannerFilename = getBannerFile(baseDir, nickname, domain) htmlStr += \ '' + \ '\n' htmlStr += '