blob: 1ba3cff2546c7ed847d249f082ef6a874ea3468a [file] [log] [blame]
Sapan Bhatia7148c082017-06-16 15:04:11 -07001{% if options.legacy =='"True"' -%}
2{% set legacy_tag = '_decl' %}
3{% set legacy = True %}
4from core.models.xosbase import *
5{% else %}
6{% set legacy = False %}
7{% set legacy_tag = '' %}
Sapan Bhatia504cc972017-04-27 01:56:28 +02008from header import *
Sapan Bhatia7148c082017-06-16 15:04:11 -07009{% endif %}
Sapan Bhatia504cc972017-04-27 01:56:28 +020010
11{% for m in proto.messages %}
12{% if file_exists(m.name|lower+'_header.py') -%}from {{m.name|lower }}_header import *{% endif %}
13{% if file_exists(m.name|lower+'_top.py') -%}{{ include_file(m.name|lower+'_top.py') }} {% endif %}
14
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020015{%- for l in m.links -%}{% set peer_name=l.peer.name %}
16{% if peer_name not in proto.message_names -%}
17from core.models import {{ peer_name }}
Sapan Bhatia504cc972017-04-27 01:56:28 +020018{%- endif -%}
19{%- endfor -%}
20{%- for b in m.bases -%}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020021{%- if b.name!='XOSBase' and 'Mixin' not in b.name %}
22from core.models import {{ b.name }}
Sapan Bhatia504cc972017-04-27 01:56:28 +020023{%- endif -%}
24{% endfor %}
25
26{% endfor %}
27
28{% for m in proto.messages %}
Sapan Bhatia7148c082017-06-16 15:04:11 -070029class {{ m.name }}{{ legacy_tag }}{{ xproto_base_def(m.name, m.bases) }}:
Sapan Bhatia504cc972017-04-27 01:56:28 +020030
31 KIND = {{ xproto_first_non_empty([m.options.kind, options.kind, options.name, "Set a kind in your xproto!"]) }}
32
33 class Meta:
34 app_label = {{ xproto_first_non_empty([m.options.app_label, options.app_label, options.name, "Set an app label in your xproto!"]) | lower}}
35 # name = {{ xproto_first_non_empty([m.options.name, options.name, "Set a name in your xproto!"]) }}
36 verbose_name = {{ xproto_first_non_empty([m.options.verbose_name, options.verbose_name, "Set a verbose name in your xproto!"]) }}
37
38 # Primitive Fields (Not Relations)
39 {% for f in m.fields %}
40 {%- if not f.link -%}
41 {{ f.name }} = {{ xproto_django_type(f.type, f.options) }}( {{ xproto_django_options_str(f) }} )
42 {% endif %}
43 {%- endfor %}
44
45 # Relations
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020046 {% for l in m.links %}{% set peer_name=l.peer.name %}
Sapan Bhatia7148c082017-06-16 15:04:11 -070047 {% if legacy and peer_name in proto.message_names %}{% set peer_tag = legacy_tag %}{% else %}{% set peer_tag = '' %}{% endif -%}
48 {{ l.src_port }} = {{ xproto_django_link_type(l) }}( {%- if peer_name==m.name -%}'self'{%- else -%}{{ peer_name }}{{ peer_tag }} {%- endif -%}, {{ xproto_django_options_str(l, l.dst_port ) }} )
Sapan Bhatia504cc972017-04-27 01:56:28 +020049 {%- endfor %}
50
51 {% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %}
52 pass
53
Sapan Bhatia7148c082017-06-16 15:04:11 -070054{% if file_exists(m.name|lower+'_bottom.py') -%}{{ include_file(m.name|lower+'_bottom.py') }}{% endif %}
Sapan Bhatia504cc972017-04-27 01:56:28 +020055{% endfor %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -070056+++ models{{ legacy_tag }}.py