Editors can set a hashtag category

main
Bob Mottram 2020-12-01 21:44:27 +00:00
parent c4b81eb22d
commit c715d39b4a
9 changed files with 94 additions and 40 deletions

View File

@ -65,7 +65,6 @@ from person import canRemovePost
from person import personSnooze from person import personSnooze
from person import personUnsnooze from person import personUnsnooze
from posts import isModerator from posts import isModerator
from posts import isEditor
from posts import mutePost from posts import mutePost
from posts import unmutePost from posts import unmutePost
from posts import createQuestionPost from posts import createQuestionPost
@ -169,6 +168,7 @@ from shares import getSharesFeedForPerson
from shares import addShare from shares import addShare
from shares import removeShare from shares import removeShare
from shares import expireShares from shares import expireShares
from utils import isEditor
from utils import getImageExtensions from utils import getImageExtensions
from utils import mediaFileMimeType from utils import mediaFileMimeType
from utils import getCSS from utils import getCSS

View File

@ -92,34 +92,6 @@ def isModerator(baseDir: str, nickname: str) -> bool:
return False return False
def isEditor(baseDir: str, nickname: str) -> bool:
"""Returns true if the given nickname is an editor
"""
editorsFile = baseDir + '/accounts/editors.txt'
if not os.path.isfile(editorsFile):
adminName = getConfigParam(baseDir, 'admin')
if not adminName:
return False
if adminName == nickname:
return True
return False
with open(editorsFile, "r") as f:
lines = f.readlines()
if len(lines) == 0:
adminName = getConfigParam(baseDir, 'admin')
if not adminName:
return False
if adminName == nickname:
return True
for editor in lines:
editor = editor.strip('\n').strip('\r')
if editor == nickname:
return True
return False
def noOfFollowersOnDomain(baseDir: str, handle: str, def noOfFollowersOnDomain(baseDir: str, handle: str,
domain: str, followFile='followers.txt') -> int: domain: str, followFile='followers.txt') -> int:
"""Returns the number of followers of the given handle from the given domain """Returns the number of followers of the given handle from the given domain

View File

@ -19,6 +19,60 @@ from calendar import monthrange
from followingCalendar import addPersonToCalendar from followingCalendar import addPersonToCalendar
def getHashtagCategory(baseDir: str, hashtag: str) -> str:
"""Returns the category for the hashtag
"""
categoryFilename = baseDir + '/tags/' + hashtag + '.category'
if os.path.isfile(categoryFilename):
with open(categoryFilename, 'r') as fp:
categoryStr = fp.read()
if categoryStr:
return categoryStr
return ''
def setHashtagCategory(baseDir: str, hashtag: str, category: str) -> bool:
"""Sets the category for the hashtag
"""
hashtagFilename = baseDir + '/tags/' + hashtag + '.txt'
if not os.path.isfile(hashtagFilename):
return False
categoryFilename = baseDir + '/tags/' + hashtag + '.category'
if os.path.isfile(categoryFilename):
with open(categoryFilename, 'w+') as fp:
fp.write(category)
return True
return False
def isEditor(baseDir: str, nickname: str) -> bool:
"""Returns true if the given nickname is an editor
"""
editorsFile = baseDir + '/accounts/editors.txt'
if not os.path.isfile(editorsFile):
adminName = getConfigParam(baseDir, 'admin')
if not adminName:
return False
if adminName == nickname:
return True
return False
with open(editorsFile, "r") as f:
lines = f.readlines()
if len(lines) == 0:
adminName = getConfigParam(baseDir, 'admin')
if not adminName:
return False
if adminName == nickname:
return True
for editor in lines:
editor = editor.strip('\n').strip('\r')
if editor == nickname:
return True
return False
def getImageExtensions() -> []: def getImageExtensions() -> []:
"""Returns a list of the possible image file extensions """Returns a list of the possible image file extensions
""" """

View File

@ -10,7 +10,7 @@ import os
from shutil import copyfile from shutil import copyfile
from utils import getConfigParam from utils import getConfigParam
from utils import getNicknameFromActor from utils import getNicknameFromActor
from posts import isEditor from utils import isEditor
from webapp_utils import htmlPostSeparator from webapp_utils import htmlPostSeparator
from webapp_utils import getLeftImageFile from webapp_utils import getLeftImageFile
from webapp_utils import getImageFile from webapp_utils import getImageFile

View File

@ -16,7 +16,7 @@ from utils import loadJson
from utils import getConfigParam from utils import getConfigParam
from utils import votesOnNewswireItem from utils import votesOnNewswireItem
from utils import getNicknameFromActor from utils import getNicknameFromActor
from posts import isEditor from utils import isEditor
from posts import isModerator from posts import isModerator
from webapp_utils import getRightImageFile from webapp_utils import getRightImageFile
from webapp_utils import getImageFile from webapp_utils import getImageFile

View File

@ -90,6 +90,8 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str:
for subdir, dirs, files in os.walk(baseDir + '/tags'): for subdir, dirs, files in os.walk(baseDir + '/tags'):
for f in files: for f in files:
if not f.endswith('.txt'):
continue
tagsFilename = os.path.join(baseDir + '/tags', f) tagsFilename = os.path.join(baseDir + '/tags', f)
if not os.path.isfile(tagsFilename): if not os.path.isfile(tagsFilename):
continue continue

View File

@ -17,12 +17,12 @@ from bookmarks import bookmarkedByPerson
from like import likedByPerson from like import likedByPerson
from like import noOfLikes from like import noOfLikes
from follow import isFollowingActor from follow import isFollowingActor
from posts import isEditor
from posts import postIsMuted from posts import postIsMuted
from posts import getPersonBox from posts import getPersonBox
from posts import isDM from posts import isDM
from posts import downloadAnnounce from posts import downloadAnnounce
from posts import populateRepliesJson from posts import populateRepliesJson
from utils import isEditor
from utils import locatePost from utils import locatePost
from utils import loadJson from utils import loadJson
from utils import getCachedPostDirectory from utils import getCachedPostDirectory

View File

@ -10,6 +10,7 @@ import os
from shutil import copyfile from shutil import copyfile
import urllib.parse import urllib.parse
from datetime import datetime from datetime import datetime
from utils import isEditor
from utils import loadJson from utils import loadJson
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import getNicknameFromActor from utils import getNicknameFromActor
@ -18,6 +19,7 @@ from utils import locatePost
from utils import isPublicPost from utils import isPublicPost
from utils import firstParagraphFromString from utils import firstParagraphFromString
from utils import searchBoxPosts from utils import searchBoxPosts
from utils import getHashtagCategory
from feeds import rss2TagHeader from feeds import rss2TagHeader
from feeds import rss2TagFooter from feeds import rss2TagFooter
from webapp_utils import getAltPath from webapp_utils import getAltPath
@ -663,13 +665,37 @@ def htmlHashtagSearch(cssCache: {},
hashtagSearchForm += '<center>\n' + \ hashtagSearchForm += '<center>\n' + \
'<h1>#' + hashtag + '</h1>\n' + '</center>\n' '<h1>#' + hashtag + '</h1>\n' + '</center>\n'
# edit the category for this hashtag
if isEditor(baseDir, nickname):
category = getHashtagCategory(baseDir, hashtag)
hashtagSearchForm += '<div class="container">\n'
hashtagSearchForm += ' <form method="POST" action="' + \
'/users/' + nickname + '/sethashtagcategory">\n'
hashtagSearchForm += ' <center>\n'
hashtagSearchForm += \
' <input type="hidden" name="hashtagName" value="' + \
hashtag + '">\n'
hashtagSearchForm += \
' <input type="text" name="hashtagCategory" value="' + \
category + '">\n'
hashtagSearchForm += \
' <button type="submit" class="button" name="submitYes">' + \
translate['Submit'] + '</button>\n'
hashtagSearchForm += ' <a href="/tags/rss2/' + hashtag + '">'
hashtagSearchForm += \
'<img style="width:3%;min-width:50px" ' + \
'loading="lazy" alt="RSS 2.0" title="RSS 2.0" src="/' + \
iconsPath + '/logorss.png" /></a>\n'
hashtagSearchForm += ' </center>\n'
hashtagSearchForm += ' </form>\n'
hashtagSearchForm += '</div>\n'
else:
# RSS link for hashtag feed # RSS link for hashtag feed
hashtagSearchForm += '<center><a href="/tags/rss2/' + hashtag + '">' hashtagSearchForm += '<center><a href="/tags/rss2/' + hashtag + '">'
hashtagSearchForm += \ hashtagSearchForm += \
'<img style="width:3%;min-width:50px" ' + \ '<img style="width:3%;min-width:50px" ' + \
'loading="lazy" alt="RSS 2.0" ' + \ 'loading="lazy" alt="RSS 2.0" title="RSS 2.0" src="/' + \
'title="RSS 2.0" src="/' + \ iconsPath + '/logorss.png" /></a></center>\n'
iconsPath + '/logorss.png" /></a></center>'
if startIndex > 0: if startIndex > 0:
# previous page link # previous page link

View File

@ -8,6 +8,7 @@ __status__ = "Production"
import os import os
import time import time
from utils import isEditor
from utils import removeIdEnding from utils import removeIdEnding
from follow import followerApprovalActive from follow import followerApprovalActive
from person import isPersonSnoozed from person import isPersonSnoozed
@ -24,7 +25,6 @@ from webapp_column_left import getLeftColumnContent
from webapp_column_right import getRightColumnContent from webapp_column_right import getRightColumnContent
from webapp_headerbuttons import headerButtonsTimeline from webapp_headerbuttons import headerButtonsTimeline
from posts import isModerator from posts import isModerator
from posts import isEditor
def logTimelineTiming(enableTimingLog: bool, timelineStartTime, def logTimelineTiming(enableTimingLog: bool, timelineStartTime,