Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to use settings utilities #513

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 10 additions & 45 deletions omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@
import tempfile
import re
import json
import pytz
import random
import string
from builtins import str as text
import portalocker

from omero.util.concurrency import get_event
from omeroweb.utils import sort_properties_to_tuple
from omeroweb.utils import (
LeaveUnset,
check_timezone,
identity,
parse_boolean,
leave_none_unset,
leave_none_unset_int,
sort_properties_to_tuple,
str_slash,
)
from omeroweb.connector import Server

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -196,13 +204,6 @@
)


def parse_boolean(s):
s = s.strip().lower()
if s in ("true", "1", "t"):
return True
return False


def parse_paths(s):
return [os.path.normpath(path) for path in json.loads(s)]

Expand All @@ -224,42 +225,6 @@ def check_session_engine(s):
return s


def identity(x):
return x


def check_timezone(s):
"""
Checks that string is a valid time-zone. If not, raise Exception
"""
pytz.timezone(s)
return s


def str_slash(s):
if s is not None:
s = str(s)
if s and not s.endswith("/"):
s += "/"
return s


class LeaveUnset(Exception):
pass


def leave_none_unset(s):
if s is None:
raise LeaveUnset()
return s


def leave_none_unset_int(s):
s = leave_none_unset(s)
if s is not None:
return int(s)


CUSTOM_HOST = CUSTOM_SETTINGS.get("Ice.Default.Host", "localhost")
CUSTOM_HOST = CUSTOM_SETTINGS.get("omero.master.host", CUSTOM_HOST)
# DO NOT EDIT!
Expand Down
45 changes: 45 additions & 0 deletions omeroweb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import logging

import pytz

from django.utils.http import urlencode
from django.urls import reverse
from django.urls import NoReverseMatch
Expand All @@ -30,6 +32,49 @@
logger = logging.getLogger(__name__)


def parse_boolean(s):
s = s.strip().lower()
if s in ("true", "1", "t"):
return True
return False


def identity(x):
return x


def check_timezone(s):
"""
Checks that string is a valid time-zone. If not, raise Exception
"""
pytz.timezone(s)
return s


def str_slash(s):
if s is not None:
s = str(s)
if s and not s.endswith("/"):
s += "/"
return s


class LeaveUnset(Exception):
pass


def leave_none_unset(s):
if s is None:
raise LeaveUnset()
return s


def leave_none_unset_int(s):
s = leave_none_unset(s)
if s is not None:
return int(s)


def is_ajax(request):
"""
Replicates the functionality of the Django 3.1 deprecated
Expand Down
Loading