<commit_before>"""
The custom manager for Scripts.
"""

from django.db.models import Q
from src.typeclasses.managers import TypedObjectManager
from src.typeclasses.managers import returns_typeclass_list
from src.utils.utils import make_iter
__all__ = ("ScriptManager",)

VALIDATE_ITERATION = 0

class ScriptManager(TypedObjectManager):
    """
    This Scriptmanager implements methods for searching
    and manipulating Scripts directly from the database.

    Evennia-specific search methods (will return Typeclasses or
    lists of Typeclasses, whereas Django-general methods will return
    Querysets or database objects).

    dbref (converter)
    get_id  (or dbref_search)
    get_dbref_range
    object_totals
    typeclass_search
    get_all_scripts_on_obj
    get_all_scripts
    delete_script
    remove_non_persistent
    validate
    script_search (equivalent to ev.search_script)
    copy_script

    """
    @returns_typeclass_list
    def get_all_scripts_on_obj(self, obj, key=None):
        """
        Returns as result all the Scripts related to a particular object.
        key can be given as a dbref or name string. If given, only scripts
        matching the key on the object will be returned.
        """
        if not obj:
            return []
        if key:
            dbref = self.dbref(key)
            if dbref or dbref == 0:
                script = self.filter(db_obj=obj, id=dbref)
                if script:
                    return script
            return self.filter(db_obj=obj, db_key=key)
        return self.filter(db_obj=obj)

    @returns_typeclass_list
    def get_all_scripts(self, key=None):
        """<commit_msg>Fixed bug where user scripts filter on login uses typeclass instead of dbobj and crashes.<commit_after>"""
The custom manager for Scripts.
"""

from django.db.models import Q
from src.typeclasses.managers import TypedObjectManager
from src.typeclasses.managers import returns_typeclass_list
from src.utils.utils import make_iter
__all__ = ("ScriptManager",)

VALIDATE_ITERATION = 0

class ScriptManager(TypedObjectManager):
    """
    This Scriptmanager implements methods for searching
    and manipulating Scripts directly from the database.

    Evennia-specific search methods (will return Typeclasses or
    lists of Typeclasses, whereas Django-general methods will return
    Querysets or database objects).

    dbref (converter)
    get_id  (or dbref_search)
    get_dbref_range
    object_totals
    typeclass_search
    get_all_scripts_on_obj
    get_all_scripts
    delete_script
    remove_non_persistent
    validate
    script_search (equivalent to ev.search_script)
    copy_script

    """
    @returns_typeclass_list
    def get_all_scripts_on_obj(self, obj, key=None):
        """
        Returns as result all the Scripts related to a particular object.
        key can be given as a dbref or name string. If given, only scripts
        matching the key on the object will be returned.
        """
        if not obj:
            return []
        obj = obj.dbobj
        if key:
            dbref = self.dbref(key)
            if dbref or dbref == 0:
                script = self.filter(db_obj=obj, id=dbref)
                if script:
                    return script
            return self.filter(db_obj=obj.dbobj, db_key=key)
        return self.filter(db_obj=obj)

    @returns_typeclass_list
    def get_all_scripts(self, key=None):
        """
{'fraction_non_alphanumeric': 0.061046511627906974, 'fraction_numerical': 0.0011627906976744186, 'mean_word_length': 2.703982777179763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4001494', 'n_tokens_mistral': 977, 'n_tokens_neox': 955, 'n_words': 308}