Make scripts/objects lists use EvMore. Change EvMore to not justify by default.

This commit is contained in:
Griatch 2020-01-11 15:49:12 +01:00
parent b5aee2c41e
commit 69d85bd184
221 changed files with 2190 additions and 6810 deletions

View file

@ -70,10 +70,7 @@ class Attribute(SharedMemoryModel):
"cannot be edited through the admin interface.",
)
db_strvalue = models.TextField(
"strvalue",
null=True,
blank=True,
help_text="String-specific storage for quick look-up",
"strvalue", null=True, blank=True, help_text="String-specific storage for quick look-up"
)
db_category = models.CharField(
"category",
@ -107,9 +104,7 @@ class Attribute(SharedMemoryModel):
help_text="Subclass of Attribute (None or nick)",
)
# time stamp
db_date_created = models.DateTimeField(
"date_created", editable=False, auto_now_add=True
)
db_date_created = models.DateTimeField("date_created", editable=False, auto_now_add=True)
# Database manager
# objects = managers.AttributeManager()
@ -209,9 +204,7 @@ class Attribute(SharedMemoryModel):
result (bool): If the lock was passed or not.
"""
result = self.locks.check(
accessing_obj, access_type=access_type, default=default
)
result = self.locks.check(accessing_obj, access_type=access_type, default=default)
return result
@ -253,9 +246,7 @@ class AttributeHandler(object):
}
attrs = [
conn.attribute
for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(
**query
)
for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
]
self._cache = dict(
(
@ -320,15 +311,11 @@ class AttributeHandler(object):
"attribute__db_model__iexact": self._model,
"attribute__db_attrtype": self._attrtype,
"attribute__db_key__iexact": key.lower(),
"attribute__db_category__iexact": category.lower()
if category
else None,
"attribute__db_category__iexact": category.lower() if category else None,
}
if not self.obj.pk:
return []
conn = getattr(self.obj, self._m2m_fieldname).through.objects.filter(
**query
)
conn = getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query)
if conn:
attr = conn[0].attribute
if _TYPECLASS_AGGRESSIVE_CACHE:
@ -347,26 +334,20 @@ class AttributeHandler(object):
# for this category before
catkey = "-%s" % category
if _TYPECLASS_AGGRESSIVE_CACHE and catkey in self._catcache:
return [
attr
for key, attr in self._cache.items()
if key.endswith(catkey) and attr
]
return [attr for key, attr in self._cache.items() if key.endswith(catkey) and attr]
else:
# we have to query to make this category up-date in the cache
query = {
"%s__id" % self._model: self._objid,
"attribute__db_model__iexact": self._model,
"attribute__db_attrtype": self._attrtype,
"attribute__db_category__iexact": category.lower()
if category
else None,
"attribute__db_category__iexact": category.lower() if category else None,
}
attrs = [
conn.attribute
for conn in getattr(
self.obj, self._m2m_fieldname
).through.objects.filter(**query)
for conn in getattr(self.obj, self._m2m_fieldname).through.objects.filter(
**query
)
]
if _TYPECLASS_AGGRESSIVE_CACHE:
for attr in attrs:
@ -637,15 +618,11 @@ class AttributeHandler(object):
strattr = kwargs.get("strattr", False)
for tup in args:
if not is_iter(tup) or len(tup) < 2:
raise RuntimeError(
"batch_add requires iterables as arguments (got %r)." % tup
)
raise RuntimeError("batch_add requires iterables as arguments (got %r)." % tup)
ntup = len(tup)
keystr = str(tup[0]).strip().lower()
new_value = tup[1]
category = (
str(tup[2]).strip().lower() if ntup > 2 and tup[2] is not None else None
)
category = str(tup[2]).strip().lower() if ntup > 2 and tup[2] is not None else None
lockstring = tup[3] if ntup > 3 else ""
attr_objs = self._getcache(keystr, category)
@ -720,9 +697,7 @@ class AttributeHandler(object):
if key is None:
self.clear(
category=category,
accessing_obj=accessing_obj,
default_access=default_access,
category=category, accessing_obj=accessing_obj, default_access=default_access
)
return
@ -735,9 +710,7 @@ class AttributeHandler(object):
for attr_obj in attr_objs:
if not (
accessing_obj
and not attr_obj.access(
accessing_obj, self._attredit, default=default_access
)
and not attr_obj.access(accessing_obj, self._attredit, default=default_access)
):
try:
attr_obj.delete()
@ -778,8 +751,7 @@ class AttributeHandler(object):
[
attr.delete()
for attr in attrs
if attr
and attr.access(accessing_obj, self._attredit, default=default_access)
if attr and attr.access(accessing_obj, self._attredit, default=default_access)
]
else:
[attr.delete() for attr in attrs if attr and attr.pk]
@ -806,9 +778,7 @@ class AttributeHandler(object):
"""
if not self._cache_complete:
self._fullcache()
attrs = sorted(
[attr for attr in self._cache.values() if attr], key=lambda o: o.id
)
attrs = sorted([attr for attr in self._cache.values() if attr], key=lambda o: o.id)
if accessing_obj:
return [
attr
@ -887,20 +857,14 @@ def initialize_nick_templates(in_template, out_template):
# validate the templates
regex_args = [match.group(2) for match in _RE_NICK_ARG.finditer(regex_string)]
temp_args = [
match.group(2) for match in _RE_NICK_TEMPLATE_ARG.finditer(out_template)
]
temp_args = [match.group(2) for match in _RE_NICK_TEMPLATE_ARG.finditer(out_template)]
if set(regex_args) != set(temp_args):
# We don't have the same $-tags in input/output.
raise NickTemplateInvalid
regex_string = _RE_NICK_SPACE.sub(r"\\s+", regex_string)
regex_string = _RE_NICK_ARG.sub(
lambda m: "(?P<arg%s>.+?)" % m.group(2), regex_string
)
template_string = _RE_NICK_TEMPLATE_ARG.sub(
lambda m: "{arg%s}" % m.group(2), out_template
)
regex_string = _RE_NICK_ARG.sub(lambda m: "(?P<arg%s>.+?)" % m.group(2), regex_string)
template_string = _RE_NICK_TEMPLATE_ARG.sub(lambda m: "{arg%s}" % m.group(2), out_template)
return regex_string, template_string
@ -996,17 +960,10 @@ class NickHandler(AttributeHandler):
"""
if category == "channel":
nick_regex, nick_template = initialize_nick_templates(
key + " $1", replacement + " $1"
)
nick_regex, nick_template = initialize_nick_templates(key + " $1", replacement + " $1")
else:
nick_regex, nick_template = initialize_nick_templates(key, replacement)
super().add(
key,
(nick_regex, nick_template, key, replacement),
category=category,
**kwargs
)
super().add(key, (nick_regex, nick_template, key, replacement), category=category, **kwargs)
def remove(self, key, category="inputline", **kwargs):
"""
@ -1022,9 +979,7 @@ class NickHandler(AttributeHandler):
"""
super().remove(key, category=category, **kwargs)
def nickreplace(
self, raw_string, categories=("inputline", "channel"), include_account=True
):
def nickreplace(self, raw_string, categories=("inputline", "channel"), include_account=True):
"""
Apply nick replacement of entries in raw_string with nick replacement.
@ -1058,9 +1013,7 @@ class NickHandler(AttributeHandler):
{
nick.key: nick
for nick in make_iter(
self.obj.account.nicks.get(
category=category, return_obj=True
)
self.obj.account.nicks.get(category=category, return_obj=True)
)
if nick and nick.key
}
@ -1072,9 +1025,7 @@ class NickHandler(AttributeHandler):
regex = re.compile(nick_regex, re.I + re.DOTALL + re.U)
self._regex_cache[nick_regex] = regex
is_match, raw_string = parse_nick_template(
raw_string.strip(), regex, template
)
is_match, raw_string = parse_nick_template(raw_string.strip(), regex, template)
if is_match:
break
return raw_string
@ -1165,9 +1116,5 @@ class NAttributeHandler(object):
"""
if return_tuples:
return [
(key, value)
for (key, value) in self._store.items()
if not key.startswith("_")
]
return [(key, value) for (key, value) in self._store.items() if not key.startswith("_")]
return [key for key in self._store if not key.startswith("_")]