blob: 60cf9ded24ab8f8d1cec6139caf7f0746804a8f9 [file] [log] [blame]
Sapan Bhatiad022aeb2017-06-07 15:49:55 +02001{% for m in proto.messages %}{% if not m.options.skip_django -%}
Sapan Bhatia4e80a262017-05-19 23:10:51 +02002{% 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 %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +02003{% if file_exists(xproto_base_name(m.name)|lower+'_top.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_top.py') }} {% endif %}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -07004{%- for l in m.links %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +02005
Sapan Bhatia3cfdf632017-06-08 05:14:03 +02006{% if l.peer.name != m.name %}
Sapan Bhatiab5ce1862017-07-31 15:48:19 -04007from {{ l.peer.name | lower }} import {{ l.peer.name }}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +02008{% endif %}
9
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070010{%- endfor %}
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040011{% if m.name!='XOSBase' and 'Mixin' not in m.name %}
12import security
13from privilege import Privilege
14{% endif %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020015{% for b in m.bases %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020016{% if b.name!='XOSBase' and 'Mixin' not in b.name %}
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040017from {{b.name | lower}} import {{ b.name }}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020018{% endif %}
19{% endfor %}
20
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040021{% for policy,error in xproto_validations(m.options) %}
22{{ xproto_fol_to_python_validator(policy, proto.policies[policy], m, error) }}
23{% endfor %}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070024
Sapan Bhatia4e80a262017-05-19 23:10:51 +020025class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}:
Sapan Bhatia2941a052017-07-10 15:10:03 -040026 plural_name = "{{ xproto_pluralize(m) }}"
27
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070028 # Primitive Fields (Not Relations)
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020029 {% for f in m.fields %}
30 {%- if not f.link -%}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070031 {{ f.name }} = {{ xproto_django_type(f.type, f.options) }}( {{ xproto_django_options_str(f) }} )
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020032 {% endif %}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070033 {%- endfor %}
34
35 # Relations
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020036 {% for l in m.links %}{% set peer_name=l.peer.name %}
37 {{ 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 ) }} )
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070038 {%- endfor %}
39
Sapan Bhatiaf7934b52017-06-12 05:04:23 -070040 # Meta
41 {%- set uniques = xproto_field_graph_components(m.fields) %}
42 {%- if uniques %}
43 class Meta:
44 unique_together = {{ xproto_tuplify(uniques) }}
45 {%- endif %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020046 {% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %}
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040047 pass
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070048
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040049 {% if m.name!='XOSBase' and 'Mixin' not in m.name %}
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040050 # Generated methods
51 def save(self, *args, **kwds):
Sapan Bhatia113c2b92017-07-25 08:41:58 -040052 if not self.leaf_model_name:
53 self.leaf_model_name = "{{ m.name }}"
54
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040055 try:
56 self.__xos_save_base(*args, **kwds)
57 except AttributeError:
58 pass
59
60 {% for policy,error in xproto_validations(m.options) %}
61 policy_{{policy}}_validator(self, None)
62 {% endfor %}
63 super({{ m.name }}, self).save(*args, **kwds)
64
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040065 def can_access(self, ctx):
66 {% if m.policy %}
67 verdict = security.{{m.policy}}_security_check(self, ctx)
68 return verdict,"{{ m.policy }}"
69 {% else %}
70 verdict = XOS_GLOBAL_DEFAULT_SECURITY_POLICY
71 return verdict,"xos_default_policy"
72 {% endif %}
73
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040074 {% endif %}
Sapan Bhatiab5ce1862017-07-31 15:48:19 -040075
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020076{% if file_exists(xproto_base_name(m.name)|lower+'_bottom.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_bottom.py') }}{% endif %}
77+++ {{m.name|lower}}.py
Sapan Bhatia2941a052017-07-10 15:10:03 -040078{% endif %}{% endfor %}