forked from indymedia/epicyon
Editors can set a hashtag category
parent
c4b81eb22d
commit
c715d39b4a
|
@ -65,7 +65,6 @@ from person import canRemovePost
|
|||
from person import personSnooze
|
||||
from person import personUnsnooze
|
||||
from posts import isModerator
|
||||
from posts import isEditor
|
||||
from posts import mutePost
|
||||
from posts import unmutePost
|
||||
from posts import createQuestionPost
|
||||
|
@ -169,6 +168,7 @@ from shares import getSharesFeedForPerson
|
|||
from shares import addShare
|
||||
from shares import removeShare
|
||||
from shares import expireShares
|
||||
from utils import isEditor
|
||||
from utils import getImageExtensions
|
||||
from utils import mediaFileMimeType
|
||||
from utils import getCSS
|
||||
|
|
28
posts.py
28
posts.py
|
@ -92,34 +92,6 @@ def isModerator(baseDir: str, nickname: str) -> bool:
|
|||
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,
|
||||
domain: str, followFile='followers.txt') -> int:
|
||||
"""Returns the number of followers of the given handle from the given domain
|
||||
|
|
54
utils.py
54
utils.py
|
@ -19,6 +19,60 @@ from calendar import monthrange
|
|||
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() -> []:
|
||||
"""Returns a list of the possible image file extensions
|
||||
"""
|
||||
|
|
|
@ -10,7 +10,7 @@ import os
|
|||
from shutil import copyfile
|
||||
from utils import getConfigParam
|
||||
from utils import getNicknameFromActor
|
||||
from posts import isEditor
|
||||
from utils import isEditor
|
||||
from webapp_utils import htmlPostSeparator
|
||||
from webapp_utils import getLeftImageFile
|
||||
from webapp_utils import getImageFile
|
||||
|
|
|
@ -16,7 +16,7 @@ from utils import loadJson
|
|||
from utils import getConfigParam
|
||||
from utils import votesOnNewswireItem
|
||||
from utils import getNicknameFromActor
|
||||
from posts import isEditor
|
||||
from utils import isEditor
|
||||
from posts import isModerator
|
||||
from webapp_utils import getRightImageFile
|
||||
from webapp_utils import getImageFile
|
||||
|
|
|
@ -90,6 +90,8 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str:
|
|||
|
||||
for subdir, dirs, files in os.walk(baseDir + '/tags'):
|
||||
for f in files:
|
||||
if not f.endswith('.txt'):
|
||||
continue
|
||||
tagsFilename = os.path.join(baseDir + '/tags', f)
|
||||
if not os.path.isfile(tagsFilename):
|
||||
continue
|
||||
|
|
|
@ -17,12 +17,12 @@ from bookmarks import bookmarkedByPerson
|
|||
from like import likedByPerson
|
||||
from like import noOfLikes
|
||||
from follow import isFollowingActor
|
||||
from posts import isEditor
|
||||
from posts import postIsMuted
|
||||
from posts import getPersonBox
|
||||
from posts import isDM
|
||||
from posts import downloadAnnounce
|
||||
from posts import populateRepliesJson
|
||||
from utils import isEditor
|
||||
from utils import locatePost
|
||||
from utils import loadJson
|
||||
from utils import getCachedPostDirectory
|
||||
|
|
|
@ -10,6 +10,7 @@ import os
|
|||
from shutil import copyfile
|
||||
import urllib.parse
|
||||
from datetime import datetime
|
||||
from utils import isEditor
|
||||
from utils import loadJson
|
||||
from utils import getDomainFromActor
|
||||
from utils import getNicknameFromActor
|
||||
|
@ -18,6 +19,7 @@ from utils import locatePost
|
|||
from utils import isPublicPost
|
||||
from utils import firstParagraphFromString
|
||||
from utils import searchBoxPosts
|
||||
from utils import getHashtagCategory
|
||||
from feeds import rss2TagHeader
|
||||
from feeds import rss2TagFooter
|
||||
from webapp_utils import getAltPath
|
||||
|
@ -663,13 +665,37 @@ def htmlHashtagSearch(cssCache: {},
|
|||
hashtagSearchForm += '<center>\n' + \
|
||||
'<h1>#' + hashtag + '</h1>\n' + '</center>\n'
|
||||
|
||||
# RSS link for hashtag feed
|
||||
hashtagSearchForm += '<center><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></center>'
|
||||
# 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
|
||||
hashtagSearchForm += '<center><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></center>\n'
|
||||
|
||||
if startIndex > 0:
|
||||
# previous page link
|
||||
|
|
|
@ -8,6 +8,7 @@ __status__ = "Production"
|
|||
|
||||
import os
|
||||
import time
|
||||
from utils import isEditor
|
||||
from utils import removeIdEnding
|
||||
from follow import followerApprovalActive
|
||||
from person import isPersonSnoozed
|
||||
|
@ -24,7 +25,6 @@ from webapp_column_left import getLeftColumnContent
|
|||
from webapp_column_right import getRightColumnContent
|
||||
from webapp_headerbuttons import headerButtonsTimeline
|
||||
from posts import isModerator
|
||||
from posts import isEditor
|
||||
|
||||
|
||||
def logTimelineTiming(enableTimingLog: bool, timelineStartTime,
|
||||
|
|
Loading…
Reference in New Issue