From d1426a2afd7707633d57c6e1c0fc482626b3eaa3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 25 Jun 2021 16:41:31 +0100 Subject: [PATCH] Separate module for minimal button --- daemon.py | 4 ++-- webapp_minimalbutton.py | 40 ++++++++++++++++++++++++++++++++++++++++ webapp_utils.py | 30 ------------------------------ 3 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 webapp_minimalbutton.py diff --git a/daemon.py b/daemon.py index b530f9901..ac58b8369 100644 --- a/daemon.py +++ b/daemon.py @@ -139,8 +139,8 @@ from blog import htmlBlogView from blog import htmlBlogPage from blog import htmlBlogPost from blog import htmlEditBlog -from webapp_utils import setMinimal -from webapp_utils import isMinimal +from webapp_minimalbutton import setMinimal +from webapp_minimalbutton import isMinimal from webapp_utils import getAvatarImageUrl from webapp_utils import htmlHashtagBlocked from webapp_utils import htmlFollowingList diff --git a/webapp_minimalbutton.py b/webapp_minimalbutton.py new file mode 100644 index 000000000..3b1815f36 --- /dev/null +++ b/webapp_minimalbutton.py @@ -0,0 +1,40 @@ +__filename__ = "webapp_minimalbutton.py" +__author__ = "Bob Mottram" +__license__ = "AGPL3+" +__version__ = "1.2.0" +__maintainer__ = "Bob Mottram" +__email__ = "bob@freedombone.net" +__status__ = "Production" +__module_group__ = "Web Interface" + +import os + + +def isMinimal(baseDir: str, domain: str, nickname: str) -> bool: + """Returns true if minimal buttons should be shown + for the given account + """ + accountDir = baseDir + '/accounts/' + \ + nickname + '@' + domain + if not os.path.isdir(accountDir): + return True + minimalFilename = accountDir + '/.notminimal' + if os.path.isfile(minimalFilename): + return False + return True + + +def setMinimal(baseDir: str, domain: str, nickname: str, + minimal: bool) -> None: + """Sets whether an account should display minimal buttons + """ + accountDir = baseDir + '/accounts/' + nickname + '@' + domain + if not os.path.isdir(accountDir): + return + minimalFilename = accountDir + '/.notminimal' + minimalFileExists = os.path.isfile(minimalFilename) + if minimal and minimalFileExists: + os.remove(minimalFilename) + elif not minimal and not minimalFileExists: + with open(minimalFilename, 'w+') as fp: + fp.write('\n') diff --git a/webapp_utils.py b/webapp_utils.py index cae6289aa..22d6fb787 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -1171,33 +1171,3 @@ def htmlKeyboardNavigation(banner: str, links: {}, accessKeys: {}, str(title) + '\n' htmlStr += '\n' return htmlStr - - -def isMinimal(baseDir: str, domain: str, nickname: str) -> bool: - """Returns true if minimal buttons should be shown - for the given account - """ - accountDir = baseDir + '/accounts/' + \ - nickname + '@' + domain - if not os.path.isdir(accountDir): - return True - minimalFilename = accountDir + '/.notminimal' - if os.path.isfile(minimalFilename): - return False - return True - - -def setMinimal(baseDir: str, domain: str, nickname: str, - minimal: bool) -> None: - """Sets whether an account should display minimal buttons - """ - accountDir = baseDir + '/accounts/' + nickname + '@' + domain - if not os.path.isdir(accountDir): - return - minimalFilename = accountDir + '/.notminimal' - minimalFileExists = os.path.isfile(minimalFilename) - if minimal and minimalFileExists: - os.remove(minimalFilename) - elif not minimal and not minimalFileExists: - with open(minimalFilename, 'w+') as fp: - fp.write('\n')