Merge branch 'master' into develop

This commit is contained in:
Griatch 2017-12-31 13:42:59 +01:00
commit c18c0fc479
5 changed files with 48 additions and 13 deletions

View file

@ -168,7 +168,7 @@ class CmdTutorialLook(default_cmds.CmdLook):
else: else:
# no detail found, delegate our result to the normal # no detail found, delegate our result to the normal
# error message handler. # error message handler.
_SEARCH_AT_RESULT(None, caller, args, looking_at_obj) _SEARCH_AT_RESULT(looking_at_obj, caller, args)
return return
else: else:
# we found a match, extract it from the list and carry on # we found a match, extract it from the list and carry on

View file

@ -2,7 +2,7 @@ from django.contrib import admin
from evennia.typeclasses.models import Tag from evennia.typeclasses.models import Tag
from django import forms from django import forms
from evennia.utils.picklefield import PickledFormField from evennia.utils.picklefield import PickledFormField
from evennia.utils.dbserialize import from_pickle from evennia.utils.dbserialize import from_pickle, _SaverSet
import traceback import traceback
@ -164,12 +164,12 @@ class AttributeForm(forms.ModelForm):
attr_category = forms.CharField(label="Category", attr_category = forms.CharField(label="Category",
help_text="type of attribute, for sorting", help_text="type of attribute, for sorting",
required=False, required=False,
max_length=4) max_length=128)
attr_value = PickledFormField(label="Value", help_text="Value to pickle/save", required=False) attr_value = PickledFormField(label="Value", help_text="Value to pickle/save", required=False)
attr_type = forms.CharField(label="Type", attr_type = forms.CharField(label="Type",
help_text="Internal use. Either unset (normal Attribute) or \"nick\"", help_text="Internal use. Either unset (normal Attribute) or \"nick\"",
required=False, required=False,
max_length=4) max_length=16)
attr_strvalue = forms.CharField(label="String Value", attr_strvalue = forms.CharField(label="String Value",
help_text="Only set when using the Attribute as a string-only store", help_text="Only set when using the Attribute as a string-only store",
required=False, required=False,
@ -213,6 +213,9 @@ class AttributeForm(forms.ModelForm):
self.instance.attr_key = attr_key self.instance.attr_key = attr_key
self.instance.attr_category = attr_category self.instance.attr_category = attr_category
self.instance.attr_value = attr_value self.instance.attr_value = attr_value
# prevent set from being transformed to unicode
if isinstance(attr_value, set) or isinstance(attr_value, _SaverSet):
self.fields['attr_value'].disabled = True
self.instance.deserialized_value = from_pickle(attr_value) self.instance.deserialized_value = from_pickle(attr_value)
self.instance.attr_strvalue = attr_strvalue self.instance.attr_strvalue = attr_strvalue
self.instance.attr_type = attr_type self.instance.attr_type = attr_type
@ -237,6 +240,17 @@ class AttributeForm(forms.ModelForm):
instance.attr_lockstring = self.cleaned_data['attr_lockstring'] instance.attr_lockstring = self.cleaned_data['attr_lockstring']
return instance return instance
def clean_attr_value(self):
"""
Prevent Sets from being cleaned due to literal_eval failing on them. Otherwise they will be turned into
unicode.
"""
data = self.cleaned_data['attr_value']
initial = self.instance.attr_value
if isinstance(initial, set) or isinstance(initial, _SaverSet):
return initial
return data
class AttributeFormSet(forms.BaseInlineFormSet): class AttributeFormSet(forms.BaseInlineFormSet):
""" """

View file

@ -59,6 +59,22 @@ def timeformat(when=None):
tz_sign, tz_hour, tz_mins) tz_sign, tz_hour, tz_mins)
def log_msg(msg):
"""
Wrapper around log.msg call to catch any exceptions that might
occur in logging. If an exception is raised, we'll print to
stdout instead.
Args:
msg: The message that was passed to log.msg
"""
try:
log.msg(msg)
except Exception:
print("Exception raised while writing message to log. Original message: %s" % msg)
def log_trace(errmsg=None): def log_trace(errmsg=None):
""" """
Log a traceback to the log. This should be called from within an Log a traceback to the log. This should be called from within an
@ -80,9 +96,9 @@ def log_trace(errmsg=None):
except Exception as e: except Exception as e:
errmsg = str(e) errmsg = str(e)
for line in errmsg.splitlines(): for line in errmsg.splitlines():
log.msg('[EE] %s' % line) log_msg('[EE] %s' % line)
except Exception: except Exception:
log.msg('[EE] %s' % errmsg) log_msg('[EE] %s' % errmsg)
log_tracemsg = log_trace log_tracemsg = log_trace
@ -101,7 +117,7 @@ def log_err(errmsg):
except Exception as e: except Exception as e:
errmsg = str(e) errmsg = str(e)
for line in errmsg.splitlines(): for line in errmsg.splitlines():
log.msg('[EE] %s' % line) log_msg('[EE] %s' % line)
# log.err('ERROR: %s' % (errmsg,)) # log.err('ERROR: %s' % (errmsg,))
@ -121,7 +137,7 @@ def log_warn(warnmsg):
except Exception as e: except Exception as e:
warnmsg = str(e) warnmsg = str(e)
for line in warnmsg.splitlines(): for line in warnmsg.splitlines():
log.msg('[WW] %s' % line) log_msg('[WW] %s' % line)
# log.msg('WARNING: %s' % (warnmsg,)) # log.msg('WARNING: %s' % (warnmsg,))
@ -139,7 +155,7 @@ def log_info(infomsg):
except Exception as e: except Exception as e:
infomsg = str(e) infomsg = str(e)
for line in infomsg.splitlines(): for line in infomsg.splitlines():
log.msg('[..] %s' % line) log_msg('[..] %s' % line)
log_infomsg = log_info log_infomsg = log_info
@ -157,7 +173,7 @@ def log_dep(depmsg):
except Exception as e: except Exception as e:
depmsg = str(e) depmsg = str(e)
for line in depmsg.splitlines(): for line in depmsg.splitlines():
log.msg('[DP] %s' % line) log_msg('[DP] %s' % line)
log_depmsg = log_dep log_depmsg = log_dep

View file

@ -120,9 +120,11 @@ def dbsafe_decode(value, compress_object=False):
class PickledWidget(Textarea): class PickledWidget(Textarea):
def render(self, name, value, attrs=None): def render(self, name, value, attrs=None):
"""Display of the PickledField in django admin"""
value = repr(value) value = repr(value)
try: try:
literal_eval(value) # necessary to convert it back after repr(), otherwise validation errors will mutate it
value = literal_eval(value)
except ValueError: except ValueError:
return value return value

View file

@ -175,8 +175,11 @@ function onKeydown (event) {
} }
if (code === 27) { // Escape key if (code === 27) { // Escape key
closePopup("#optionsdialog"); if ($('#helpdialog').is(':visible')) {
closePopup("#helpdialog"); closePopup("#helpdialog");
} else {
closePopup("#optionsdialog");
}
} }
if (history_entry !== null) { if (history_entry !== null) {