evennia/docs/4.x/api/evennia.contrib.base_systems.components.dbfield.html
2024-03-17 14:15:56 +01:00

294 lines
No EOL
23 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>evennia.contrib.base_systems.components.dbfield &#8212; Evennia latest documentation</title>
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="evennia.contrib.base_systems.components.exceptions" href="evennia.contrib.base_systems.components.exceptions.html" />
<link rel="prev" title="evennia.contrib.base_systems.components.component" href="evennia.contrib.base_systems.components.component.html" />
</head><body>
<div class="admonition important">
<p class="first admonition-title">Note</p>
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="evennia.contrib.base_systems.components.exceptions.html" title="evennia.contrib.base_systems.components.exceptions"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="evennia.contrib.base_systems.components.component.html" title="evennia.contrib.base_systems.components.component"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia latest</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-4"><a href="evennia.contrib.html" >evennia.contrib</a> &#187;</li>
<li class="nav-item nav-item-5"><a href="evennia.contrib.base_systems.html" >evennia.contrib.base_systems</a> &#187;</li>
<li class="nav-item nav-item-6"><a href="evennia.contrib.base_systems.components.html" accesskey="U">evennia.contrib.base_systems.components</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.contrib.base_systems.components.dbfield</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
<h4>Previous topic</h4>
<p class="topless"><a href="evennia.contrib.base_systems.components.component.html"
title="previous chapter">evennia.contrib.base_systems.components.component</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="evennia.contrib.base_systems.components.exceptions.html"
title="next chapter">evennia.contrib.base_systems.components.exceptions</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
<li><a href="../_sources/api/evennia.contrib.base_systems.components.dbfield.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com/docs/latest/index.html">Documentation Top</a> </li>
<li><a href="https://www.evennia.com">Evennia Home</a> </li>
<li><a href="https://github.com/evennia/evennia">Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li>
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-evennia.contrib.base_systems.components.dbfield">
<span id="evennia-contrib-base-systems-components-dbfield"></span><h1>evennia.contrib.base_systems.components.dbfield<a class="headerlink" href="#module-evennia.contrib.base_systems.components.dbfield" title="Permalink to this headline"></a></h1>
<p>Components - ChrisLR 2022</p>
<p>This file contains the Descriptors used to set Fields in Components</p>
<dl class="py class">
<dt id="evennia.contrib.base_systems.components.dbfield.DBField">
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.base_systems.components.dbfield.</code><code class="sig-name descname">DBField</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">autocreate</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#DBField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.DBField" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="evennia.typeclasses.attributes.html#evennia.typeclasses.attributes.AttributeProperty" title="evennia.typeclasses.attributes.AttributeProperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.typeclasses.attributes.AttributeProperty</span></code></a></p>
<p>Component Attribute Descriptor.
Allows you to set attributes related to a component on the class.
It uses AttributeProperty under the hood but prefixes the key with the component name.</p>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.DBField.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">autocreate</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#DBField.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.DBField.__init__" title="Permalink to this definition"></a></dt>
<dd><p>Allows for specifying Attributes as Django-like fields on the class level. Note that while
one can set a lock on the Attribute, there is no way to <em>check</em> said lock when accessing via
the property - use the full <strong>AttributeHandler</strong> if you need to do access checks. Note however
that if you use the full <strong>AttributeHandler</strong> to access this Attribute, the <strong>at_get/at_set</strong>
methods on this class will _not_ fire (because you are bypassing the <strong>AttributeProperty</strong>
entirely in that case).</p>
<p>Initialize an Attribute as a property descriptor.</p>
<dl class="field-list simple">
<dt class="field-odd">Keyword Arguments</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>default</strong> (<em>any</em>) A default value if the attr is not set. If a callable, this will be
run without any arguments and is expected to return the default value.</p></li>
<li><p><strong>category</strong> (<em>str</em>) The attributes category. If unset, use class default.</p></li>
<li><p><strong>strattr</strong> (<em>bool</em>) If set, this Attribute <em>must</em> be a simple string, and will be
stored more efficiently.</p></li>
<li><p><strong>lockstring</strong> (<em>str</em>) This is not itself useful with the property, but only if
using the full AttributeHandler.get(accessing_obj=…) to access the
Attribute.</p></li>
<li><p><strong>autocreate</strong> (<em>bool</em>) True by default; this means Evennia makes sure to create a new
copy of the Attribute (with the default value) whenever a new object with this
property is created. If <strong>False</strong>, no Attribute will be created until the property
is explicitly assigned a value. This makes it more efficient while it retains
its default (theres no db access), but without an actual Attribute generated,
one cannot access it via .db, the AttributeHandler or see it with <strong>examine</strong>.</p></li>
</ul>
</dd>
</dl>
<p>Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Character</span><span class="p">(</span><span class="n">DefaultCharacter</span><span class="p">):</span>
<span class="n">foo</span> <span class="o">=</span> <span class="n">AttributeProperty</span><span class="p">(</span><span class="n">default</span><span class="o">=</span><span class="s2">&quot;Bar&quot;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.DBField.at_added">
<code class="sig-name descname">at_added</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">component</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#DBField.at_added"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.DBField.at_added" title="Permalink to this definition"></a></dt>
<dd><p>Called when the parent component is added to a host.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>component</strong> (<a class="reference internal" href="evennia.contrib.base_systems.components.component.html#evennia.contrib.base_systems.components.component.Component" title="evennia.contrib.base_systems.components.component.Component"><em>Component</em></a>) The component instance being added.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.DBField.at_removed">
<code class="sig-name descname">at_removed</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">component</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#DBField.at_removed"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.DBField.at_removed" title="Permalink to this definition"></a></dt>
<dd><p>Called when the parent component is removed from a host.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>component</strong> (<a class="reference internal" href="evennia.contrib.base_systems.components.component.html#evennia.contrib.base_systems.components.component.Component" title="evennia.contrib.base_systems.components.component.Component"><em>Component</em></a>) The component instance being removed.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="evennia.contrib.base_systems.components.dbfield.NDBField">
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.base_systems.components.dbfield.</code><code class="sig-name descname">NDBField</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">category</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">strattr</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">lockstring</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">autocreate</span><span class="o">=</span><span class="default_value">True</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#NDBField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.NDBField" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="evennia.typeclasses.attributes.html#evennia.typeclasses.attributes.NAttributeProperty" title="evennia.typeclasses.attributes.NAttributeProperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">evennia.typeclasses.attributes.NAttributeProperty</span></code></a></p>
<p>Component In-Memory Attribute Descriptor.
Allows you to set in-memory attributes related to a component on the class.
It uses NAttributeProperty under the hood but prefixes the key with the component name.</p>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.NDBField.at_added">
<code class="sig-name descname">at_added</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">component</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#NDBField.at_added"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.NDBField.at_added" title="Permalink to this definition"></a></dt>
<dd><p>Called when the parent component is added to a host.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>component</strong> (<a class="reference internal" href="evennia.contrib.base_systems.components.component.html#evennia.contrib.base_systems.components.component.Component" title="evennia.contrib.base_systems.components.component.Component"><em>Component</em></a>) The component instance being added.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.NDBField.at_removed">
<code class="sig-name descname">at_removed</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">component</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#NDBField.at_removed"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.NDBField.at_removed" title="Permalink to this definition"></a></dt>
<dd><p>Called when the parent component is removed from a host.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>component</strong> (<a class="reference internal" href="evennia.contrib.base_systems.components.component.html#evennia.contrib.base_systems.components.component.Component" title="evennia.contrib.base_systems.components.component.Component"><em>Component</em></a>) The component instance being removed.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt id="evennia.contrib.base_systems.components.dbfield.TagField">
<em class="property">class </em><code class="sig-prename descclassname">evennia.contrib.base_systems.components.dbfield.</code><code class="sig-name descname">TagField</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">enforce_single</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#TagField"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.TagField" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Component Tags Descriptor.
Allows you to set Tags related to a component on the class.
The tags are set with a prefixed category, so it can support
multiple tags or enforce a single one.</p>
<p>Default value of a tag is added when the component is registered.
Tags are removed if the component itself is removed.</p>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.TagField.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">default</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">enforce_single</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#TagField.__init__"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.TagField.__init__" title="Permalink to this definition"></a></dt>
<dd><p>Initialize self. See help(type(self)) for accurate signature.</p>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.TagField.at_added">
<code class="sig-name descname">at_added</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">component</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#TagField.at_added"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.TagField.at_added" title="Permalink to this definition"></a></dt>
<dd><p>Called when the parent component is added to a host.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>component</strong> (<a class="reference internal" href="evennia.contrib.base_systems.components.component.html#evennia.contrib.base_systems.components.component.Component" title="evennia.contrib.base_systems.components.component.Component"><em>Component</em></a>) The component instance being added.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt id="evennia.contrib.base_systems.components.dbfield.TagField.at_removed">
<code class="sig-name descname">at_removed</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">component</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/contrib/base_systems/components/dbfield.html#TagField.at_removed"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.contrib.base_systems.components.dbfield.TagField.at_removed" title="Permalink to this definition"></a></dt>
<dd><p>Called when the parent component is removed from a host.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>component</strong> (<a class="reference internal" href="evennia.contrib.base_systems.components.component.html#evennia.contrib.base_systems.components.component.Component" title="evennia.contrib.base_systems.components.component.Component"><em>Component</em></a>) The component instance being removed.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
</div>
</div>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="evennia.contrib.base_systems.components.exceptions.html" title="evennia.contrib.base_systems.components.exceptions"
>next</a> |</li>
<li class="right" >
<a href="evennia.contrib.base_systems.components.component.html" title="evennia.contrib.base_systems.components.component"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia latest</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> &#187;</li>
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> &#187;</li>
<li class="nav-item nav-item-4"><a href="evennia.contrib.html" >evennia.contrib</a> &#187;</li>
<li class="nav-item nav-item-5"><a href="evennia.contrib.base_systems.html" >evennia.contrib.base_systems</a> &#187;</li>
<li class="nav-item nav-item-6"><a href="evennia.contrib.base_systems.components.html" >evennia.contrib.base_systems.components</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.contrib.base_systems.components.dbfield</a></li>
</ul>
</div>
<div class="admonition important">
<p class="first admonition-title">Note</p>
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2023, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>