Skip to content

Commit

Permalink
Merge pull request #513 from chris-allan/settings-util
Browse files Browse the repository at this point in the history
Allow plugins to use settings utilities
  • Loading branch information
knabar authored Dec 12, 2023
2 parents 368808f + 526f884 commit 8bcbf20
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 45 deletions.
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

0 comments on commit 8bcbf20

Please sign in to comment.