Merge pull request #2050 from trhr/django3

Django3
This commit is contained in:
Griatch 2020-02-12 23:01:27 +01:00 committed by GitHub
commit 5e18dcc562
26 changed files with 56 additions and 44 deletions

View file

@ -40,7 +40,7 @@ SERVERNAME = "testing_mygame"
DATABASES = { DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.postgresql_psycopg2", "ENGINE": "django.db.backends.postgresql",
"NAME": "evennia", "NAME": "evennia",
"USER": "evennia", "USER": "evennia",
"PASSWORD": "password", "PASSWORD": "password",

View file

@ -37,7 +37,7 @@ from evennia.scripts.scripthandler import ScriptHandler
from evennia.commands.cmdsethandler import CmdSetHandler from evennia.commands.cmdsethandler import CmdSetHandler
from evennia.utils.optionhandler import OptionHandler from evennia.utils.optionhandler import OptionHandler
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
from random import getrandbits from random import getrandbits
__all__ = ("DefaultAccount",) __all__ = ("DefaultAccount",)

View file

@ -48,7 +48,7 @@ from evennia.comms.channelhandler import CHANNELHANDLER
from evennia.utils import logger, utils from evennia.utils import logger, utils
from evennia.utils.utils import string_suggestions from evennia.utils.utils import string_suggestions
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
_IN_GAME_ERRORS = settings.IN_GAME_ERRORS _IN_GAME_ERRORS = settings.IN_GAME_ERRORS

View file

@ -27,7 +27,7 @@ Set theory.
""" """
from weakref import WeakKeyDictionary from weakref import WeakKeyDictionary
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
from evennia.utils.utils import inherits_from, is_iter from evennia.utils.utils import inherits_from, is_iter
__all__ = ("CmdSet",) __all__ = ("CmdSet",)

View file

@ -72,7 +72,7 @@ from evennia.utils import logger, utils
from evennia.commands.cmdset import CmdSet from evennia.commands.cmdset import CmdSet
from evennia.server.models import ServerConfig from evennia.server.models import ServerConfig
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
__all__ = ("import_cmdset", "CmdSetHandler") __all__ = ("import_cmdset", "CmdSetHandler")

View file

@ -27,7 +27,7 @@ from django.conf import settings
from evennia.commands import cmdset, command from evennia.commands import cmdset, command
from evennia.utils.logger import tail_log_file from evennia.utils.logger import tail_log_file
from evennia.utils.utils import class_from_module from evennia.utils.utils import class_from_module
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
# we must late-import these since any overloads are likely to # we must late-import these since any overloads are likely to
# themselves be using these classes leading to a circular import. # themselves be using these classes leading to a circular import.

View file

@ -107,7 +107,7 @@ to any other identifier you can use.
import re import re
from django.conf import settings from django.conf import settings
from evennia.utils import logger, utils from evennia.utils import logger, utils
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
__all__ = ("LockHandler", "LockException") __all__ = ("LockHandler", "LockException")

View file

@ -31,7 +31,7 @@ from evennia.utils.utils import (
list_to_string, list_to_string,
to_str, to_str,
) )
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
_INFLECT = inflect.engine() _INFLECT = inflect.engine()
_MULTISESSION_MODE = settings.MULTISESSION_MODE _MULTISESSION_MODE = settings.MULTISESSION_MODE

View file

@ -9,7 +9,7 @@ from evennia.scripts.models import ScriptDB
from evennia.utils import create from evennia.utils import create
from evennia.utils import logger from evennia.utils import logger
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
class ScriptHandler(object): class ScriptHandler(object):

View file

@ -8,7 +8,7 @@ ability to run timers.
from twisted.internet.defer import Deferred, maybeDeferred from twisted.internet.defer import Deferred, maybeDeferred
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
from evennia.typeclasses.models import TypeclassBase from evennia.typeclasses.models import TypeclassBase
from evennia.scripts.models import ScriptDB from evennia.scripts.models import ScriptDB
from evennia.scripts.manager import ScriptManager from evennia.scripts.manager import ScriptManager

View file

@ -115,3 +115,7 @@ def check_warnings(settings):
print(" [Devel: settings.IN_GAME_ERRORS is True. Turn off in production.]") print(" [Devel: settings.IN_GAME_ERRORS is True. Turn off in production.]")
if settings.ALLOWED_HOSTS == ["*"]: if settings.ALLOWED_HOSTS == ["*"]:
print(" [Devel: settings.ALLOWED_HOSTS set to '*' (all). Limit in production.]") print(" [Devel: settings.ALLOWED_HOSTS set to '*' (all). Limit in production.]")
for k,v in settings.DATABASES.items():
if "psycopg" in v.get("ENGINE",None):
print(" [Devel: postgresql_psycopg2 backend is deprecated. This module is now called postgresql")
print(" Switch settings.DATABASES to use \"ENGINE\": \"django.db.backends.postgresql\"")

View file

@ -9,7 +9,7 @@ Everything starts at handle_setup()
import time import time
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
from evennia.accounts.models import AccountDB from evennia.accounts.models import AccountDB
from evennia.server.models import ServerConfig from evennia.server.models import ServerConfig
from evennia.utils import create, logger from evennia.utils import create, logger

View file

@ -38,7 +38,7 @@ from evennia.utils import logger
from evennia.comms import channelhandler from evennia.comms import channelhandler
from evennia.server.sessionhandler import SESSIONS from evennia.server.sessionhandler import SESSIONS
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
_SA = object.__setattr__ _SA = object.__setattr__

View file

@ -23,7 +23,7 @@ _ObjectDB = None
_ANSI = None _ANSI = None
# i18n # i18n
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
# Handlers for Session.db/ndb operation # Handlers for Session.db/ndb operation

View file

@ -67,7 +67,7 @@ PSTATUS = chr(18) # ping server or portal status
SRESET = chr(19) # server shutdown in reset mode SRESET = chr(19) # server shutdown in reset mode
# i18n # i18n
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
_SERVERNAME = settings.SERVERNAME _SERVERNAME = settings.SERVERNAME
_MULTISESSION_MODE = settings.MULTISESSION_MODE _MULTISESSION_MODE = settings.MULTISESSION_MODE

View file

@ -245,7 +245,7 @@ IN_GAME_ERRORS = True
# ENGINE - path to the the database backend. Possible choices are: # ENGINE - path to the the database backend. Possible choices are:
# 'django.db.backends.sqlite3', (default) # 'django.db.backends.sqlite3', (default)
# 'django.db.backends.mysql', # 'django.db.backends.mysql',
# 'django.db.backends.postgresql_psycopg2', # 'django.db.backends.postgresql',
# 'django.db.backends.oracle' (untested). # 'django.db.backends.oracle' (untested).
# NAME - database name, or path to the db file for sqlite3 # NAME - database name, or path to the db file for sqlite3
# USER - db admin (unused in sqlite3) # USER - db admin (unused in sqlite3)

View file

@ -27,7 +27,7 @@ def _drop_table(db_cursor, table_name):
db_cursor.execute("SET FOREIGN_KEY_CHECKS=0;") db_cursor.execute("SET FOREIGN_KEY_CHECKS=0;")
db_cursor.execute("DROP TABLE {table};".format(table=table_name)) db_cursor.execute("DROP TABLE {table};".format(table=table_name))
db_cursor.execute("SET FOREIGN_KEY_CHECKS=1;") db_cursor.execute("SET FOREIGN_KEY_CHECKS=1;")
elif _ENGINE == "postgresql_psycopg2": elif _ENGINE == "postgresql":
db_cursor.execute("ALTER TABLE {table} DISABLE TRIGGER ALL;".format(table=table_name)) db_cursor.execute("ALTER TABLE {table} DISABLE TRIGGER ALL;".format(table=table_name))
db_cursor.execute("DROP TABLE {table};".format(table=table_name)) db_cursor.execute("DROP TABLE {table};".format(table=table_name))
db_cursor.execute("ALTER TABLE {table} ENABLE TRIGGER ALL;".format(table=table_name)) db_cursor.execute("ALTER TABLE {table} ENABLE TRIGGER ALL;".format(table=table_name))

View file

@ -28,11 +28,12 @@ except ImportError:
from pickle import dumps, loads from pickle import dumps, loads
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.utils.safestring import SafeString, SafeBytes from django.utils.safestring import SafeString
from evennia.utils.utils import uses_database, is_iter, to_str, to_bytes from evennia.utils.utils import uses_database, is_iter, to_str, to_bytes
from evennia.utils import logger from evennia.utils import logger
__all__ = ("to_pickle", "from_pickle", "do_pickle", "do_unpickle", "dbserialize", "dbunserialize") __all__ = ("to_pickle", "from_pickle", "do_pickle",
"do_unpickle", "dbserialize", "dbunserialize")
PICKLE_PROTOCOL = 2 PICKLE_PROTOCOL = 2
@ -116,13 +117,15 @@ def _init_globals():
global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER, _IGNORE_DATETIME_MODELS global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER, _IGNORE_DATETIME_MODELS
if not _FROM_MODEL_MAP: if not _FROM_MODEL_MAP:
_FROM_MODEL_MAP = defaultdict(str) _FROM_MODEL_MAP = defaultdict(str)
_FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) for c in ContentType.objects.all())) _FROM_MODEL_MAP.update(dict((c.model, c.natural_key())
for c in ContentType.objects.all()))
if not _TO_MODEL_MAP: if not _TO_MODEL_MAP:
from django.conf import settings from django.conf import settings
_TO_MODEL_MAP = defaultdict(str) _TO_MODEL_MAP = defaultdict(str)
_TO_MODEL_MAP.update( _TO_MODEL_MAP.update(
dict((c.natural_key(), c.model_class()) for c in ContentType.objects.all()) dict((c.natural_key(), c.model_class())
for c in ContentType.objects.all())
) )
_IGNORE_DATETIME_MODELS = [] _IGNORE_DATETIME_MODELS = []
for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME: for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME:
@ -185,7 +188,8 @@ class _SaverMutable(object):
) )
self._db_obj.value = self self._db_obj.value = self
else: else:
logger.log_err("_SaverMutable %s has no root Attribute to save to." % self) logger.log_err(
"_SaverMutable %s has no root Attribute to save to." % self)
def _convert_mutables(self, data): def _convert_mutables(self, data):
"""converts mutables to Saver* variants and assigns ._parent property""" """converts mutables to Saver* variants and assigns ._parent property"""
@ -201,7 +205,8 @@ class _SaverMutable(object):
return dat return dat
elif dtype == dict: elif dtype == dict:
dat = _SaverDict(_parent=parent) dat = _SaverDict(_parent=parent)
dat._data.update((key, process_tree(val, dat)) for key, val in item.items()) dat._data.update((key, process_tree(val, dat))
for key, val in item.items())
return dat return dat
elif dtype == set: elif dtype == set:
dat = _SaverSet(_parent=parent) dat = _SaverSet(_parent=parent)
@ -549,7 +554,7 @@ def to_pickle(data):
def process_item(item): def process_item(item):
"""Recursive processor and identification of data""" """Recursive processor and identification of data"""
dtype = type(item) dtype = type(item)
if dtype in (str, int, float, bool, bytes, SafeString, SafeBytes): if dtype in (str, int, float, bool, bytes, SafeString):
return item return item
elif dtype == tuple: elif dtype == tuple:
return tuple(process_item(val) for val in item) return tuple(process_item(val) for val in item)
@ -577,7 +582,8 @@ def to_pickle(data):
except TypeError: except TypeError:
return item return item
except Exception: except Exception:
logger.log_error(f"The object {item} of type {type(item)} could not be stored.") logger.log_error(
f"The object {item} of type {type(item)} could not be stored.")
raise raise
return process_item(data) return process_item(data)
@ -609,7 +615,7 @@ def from_pickle(data, db_obj=None):
def process_item(item): def process_item(item):
"""Recursive processor and identification of data""" """Recursive processor and identification of data"""
dtype = type(item) dtype = type(item)
if dtype in (str, int, float, bool, bytes, SafeString, SafeBytes): if dtype in (str, int, float, bool, bytes, SafeString):
return item return item
elif _IS_PACKED_DBOBJ(item): elif _IS_PACKED_DBOBJ(item):
# this must be checked before tuple # this must be checked before tuple
@ -638,7 +644,7 @@ def from_pickle(data, db_obj=None):
def process_tree(item, parent): def process_tree(item, parent):
"""Recursive processor, building a parent-tree from iterable data""" """Recursive processor, building a parent-tree from iterable data"""
dtype = type(item) dtype = type(item)
if dtype in (str, int, float, bool, bytes, SafeString, SafeBytes): if dtype in (str, int, float, bool, bytes, SafeString):
return item return item
elif _IS_PACKED_DBOBJ(item): elif _IS_PACKED_DBOBJ(item):
# this must be checked before tuple # this must be checked before tuple

View file

@ -187,7 +187,7 @@ _CMD_NOINPUT = cmdhandler.CMD_NOINPUT
# Return messages # Return messages
# i18n # i18n
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
_ERR_NOT_IMPLEMENTED = _( _ERR_NOT_IMPLEMENTED = _(
"Menu node '{nodename}' is either not implemented or " "caused an error. Make another choice." "Menu node '{nodename}' is either not implemented or " "caused an error. Make another choice."

View file

@ -43,7 +43,7 @@ from django.forms.fields import CharField
from django.forms.widgets import Textarea from django.forms.widgets import Textarea
from pickle import loads, dumps from pickle import loads, dumps
from django.utils.encoding import force_text from django.utils.encoding import force_str
DEFAULT_PROTOCOL = 4 DEFAULT_PROTOCOL = 4
@ -210,10 +210,10 @@ class PickledObjectField(models.Field):
""" """
Returns the default value for this field. Returns the default value for this field.
The default implementation on models.Field calls force_text The default implementation on models.Field calls force_str
on the default, which means you can't set arbitrary Python on the default, which means you can't set arbitrary Python
objects as the default. To fix this, we just return the value objects as the default. To fix this, we just return the value
without calling force_text on it. Note that if you set a without calling force_str on it. Note that if you set a
callable as a default, the field will still call it. It will callable as a default, the field will still call it. It will
*not* try to pickle and encode it. *not* try to pickle and encode it.
@ -267,13 +267,13 @@ class PickledObjectField(models.Field):
""" """
if value is not None and not isinstance(value, PickledObject): if value is not None and not isinstance(value, PickledObject):
# We call force_text here explicitly, so that the encoded string # We call force_str here explicitly, so that the encoded string
# isn't rejected by the postgresql_psycopg2 backend. Alternatively, # isn't rejected by the postgresql backend. Alternatively,
# we could have just registered PickledObject with the psycopg # we could have just registered PickledObject with the psycopg
# marshaller (telling it to store it like it would a string), but # marshaller (telling it to store it like it would a string), but
# since both of these methods result in the same value being stored, # since both of these methods result in the same value being stored,
# doing things this way is much easier. # doing things this way is much easier.
value = force_text(dbsafe_encode(value, self.compress, self.protocol)) value = force_str(dbsafe_encode(value, self.compress, self.protocol))
return value return value
def value_to_string(self, obj): def value_to_string(self, obj):

View file

@ -27,7 +27,7 @@ from collections import defaultdict, OrderedDict
from twisted.internet import threads, reactor from twisted.internet import threads, reactor
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext as _ from django.utils.translation import gettext as _
from django.apps import apps from django.apps import apps
from evennia.utils import logger from evennia.utils import logger
@ -1036,7 +1036,7 @@ def uses_database(name="sqlite3"):
shortcut to having to use the full backend name. shortcut to having to use the full backend name.
Args: Args:
name (str): One of 'sqlite3', 'mysql', 'postgresql_psycopg2' name (str): One of 'sqlite3', 'mysql', 'postgresql'
or 'oracle'. or 'oracle'.
Returns: Returns:

View file

@ -6,7 +6,7 @@
# http://diveintopython.org/regular_expressions/street_addresses.html#re.matching.2.3 # http://diveintopython.org/regular_expressions/street_addresses.html#re.matching.2.3
# #
from django.conf.urls import url, include from django.urls import path, include
from django.views.generic import RedirectView from django.views.generic import RedirectView
# Setup the root url tree from / # Setup the root url tree from /
@ -14,9 +14,10 @@ from django.views.generic import RedirectView
urlpatterns = [ urlpatterns = [
# Front page (note that we shouldn't specify namespace here since we will # Front page (note that we shouldn't specify namespace here since we will
# not be able to load django-auth/admin stuff (will probably work in Django>1.9) # not be able to load django-auth/admin stuff (will probably work in Django>1.9)
url(r"^", include("evennia.web.website.urls")), # , namespace='website', app_name='website')), path("", include("evennia.web.website.urls")),
# webclient # webclient
url(r"^webclient/", include("evennia.web.webclient.urls", namespace="webclient")), path("webclient/", include("evennia.web.webclient.urls")),
# favicon # favicon
url(r"^favicon\.ico$", RedirectView.as_view(url="/media/images/favicon.ico", permanent=False)), path("favicon.ico", RedirectView.as_view(
url="/media/images/favicon.ico", permanent=False))
] ]

View file

@ -6,7 +6,7 @@ with evennia set up automatically and get the Evennia JS lib and
JQuery available. JQuery available.
--> -->
{% load staticfiles %} {% load static %}
<html dir="ltr" lang="en"> <html dir="ltr" lang="en">
<head> <head>
<title> {{game_name}} </title> <title> {{game_name}} </title>

View file

@ -2,8 +2,9 @@
This structures the (simple) structure of the This structures the (simple) structure of the
webpage 'application'. webpage 'application'.
""" """
from django.conf.urls import * from django.urls import path
from evennia.web.webclient import views as webclient_views from evennia.web.webclient import views as webclient_views
app_name = "webclient" app_name = "webclient"
urlpatterns = [url(r"^$", webclient_views.webclient, name="index")]
urlpatterns = [path("", webclient_views.webclient, name="index")]

View file

@ -3,7 +3,7 @@ Allow to customize the menu that appears at the top of every Evennia
webpage. Copy this file to your game dir's web/template_overrides/website webpage. Copy this file to your game dir's web/template_overrides/website
folder and edit it to add/remove links to the menu. folder and edit it to add/remove links to the menu.
{% endcomment %} {% endcomment %}
{% load staticfiles %} {% load static %}
<nav class="navbar navbar-dark font-weight-bold navbar-expand-md"> <nav class="navbar navbar-dark font-weight-bold navbar-expand-md">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#menu-content" aria-controls="menu-content" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#menu-content" aria-controls="menu-content" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>

View file

@ -1,4 +1,4 @@
{% load staticfiles sekizai_tags %} {% load static sekizai_tags %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>