blob: 631e8cd10a905e03ee7f6305ffab8f6841a3c8f1 [file] [log] [blame]
{%- if options.legacy =='"True"' -%}
{%- set legacy_tag = '_decl' -%}
{%- set legacy = True -%}
{%- else -%}
{%- set legacy_tag = '' -%}
{%- set legacy = False -%}
{%- endif -%}
{% for m in proto.messages %}{% if not m.options.skip_django -%}
{% if legacy %}
{# handle models that use custom headers rather than deriving from xosbase #}
{% if m.options.custom_header %}
from {{ m.options.custom_header|replace('"','') }} import *
{% else %}
from core.models.xosbase import *
{% endif %}
{% else %}
{% if file_exists(xproto_base_name(m.name)|lower+'_header.py') -%}from {{xproto_base_name(m.name)|lower }}_header import *{%- else -%}from header import *{% endif %}
{% if file_exists(xproto_base_name(m.name)|lower+'_top.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_top.py') }} {% endif %}
{% endif %}
{%- for l in m.links %}
{% if l.peer.name != m.name %}
from {{ l.peer.name | lower }} import {{ l.peer.name }}
{% endif %}
{%- endfor %}
{% if m.name!='XOSBase' and 'Mixin' not in m.name %}
import security
{% if m.name!='Privilege' %}
from privilege import Privilege
{% endif %}
{% endif %}
{% for b in m.bases %}
{% if b.name!='XOSBase' and 'Mixin' not in b.name %}
from {{b.name | lower}} import {{ b.name }}
{% endif %}
{% endfor %}
{% for policy,error in xproto_validations(m.options) %}
{{ xproto_fol_to_python_validator(policy, proto.policies[policy], m, error) }}
{% endfor %}
class {{ m.name }}{{ legacy_tag }}{{ xproto_base_def(m.name, m.bases) }}:
plural_name = "{{ xproto_pluralize(m) }}"
{%- set feedback_state_fields = xproto_optioned_fields_to_list(xproto_base_fields(m, proto.message_table) + m.fields, 'feedback_state', 'True') %}
{%- if feedback_state_fields|length > 0 %}
feedback_state_fields = {{ feedback_state_fields }}
{%- endif %}
{# {% if m.options.no_sync or m.options.no_policy %}#}
{# {% if m.options.no_sync -%}#}
{# # Removing synchronizer feedback state from model#}
{# backend_status = None#}
{# backend_code = None#}
{# {%- endif %}#}
{# {% if m.options.no_policy -%}#}
{# # Removing model policy feedback state from model#}
{# policy_code = None#}
{# policy_status = None#}
{# {%- endif %}#}
{# {% endif %}#}
# Primitive Fields (Not Relations)
{% for f in m.fields %}
{%- if not f.link -%}
{{ f.name }} = {{ xproto_django_type(f.type, f.options) }}( {{ xproto_django_options_str(f) }} )
{% endif %}
{%- endfor %}
# Relations
{% for l in m.links %}{% set peer_name=l.peer.name %}
{{ l.src_port }} = {{ xproto_django_link_type(l) }}( {%- if peer_name==m.name -%}'self'{%- else -%}{{ peer_name }} {%- endif -%}, {{ xproto_django_link_options_str(l, l.dst_port ) }} )
{%- endfor %}
# Meta
class Meta:
{%- set uniques = xproto_field_graph_components(m.fields, m) %}
{%- if uniques %}
unique_together = {{ xproto_tuplify(uniques) }}
{%- endif %}
{%- if xproto_is_true(m.options.abstract) %}
abstract=True
{%- endif %}
pass
{% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %}
pass
{% if m.name!='XOSBase' and 'Mixin' not in m.name %}
# Generated methods
def save(self, *args, **kwds):
if not self.leaf_model_name:
self.leaf_model_name = "{{ m.name }}"
try:
self.__xos_save_base(*args, **kwds)
except AttributeError:
pass
{% for policy,error in xproto_validations(m.options) %}
policy_{{policy}}_validator(self, None)
{% endfor %}
super({{ m.name }}{{ legacy_tag }}, self).save(*args, **kwds)
def can_access(self, ctx):
{% if m.policy %}
verdict = security.{{m.policy}}_security_check(self, ctx)
return verdict,"{{ m.policy }}"
{% else %}
verdict = XOS_GLOBAL_DEFAULT_SECURITY_POLICY
return verdict,"xos_default_policy"
{% endif %}
{% endif %}
{% if file_exists(xproto_base_name(m.name)|lower+'_bottom.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_bottom.py') }}{% endif %}
{% endif %}{% endfor %}