blob: 20b4e51ce6cf287d982132df88a4e0cfa7970f50 [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 %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -07004
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -07005{%- for l in m.links %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +02006
Sapan Bhatia3cfdf632017-06-08 05:14:03 +02007{% if l.peer.name != m.name %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -07008from core.models.{{ l.peer.name | lower }} import {{ l.peer.name }}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +02009{% endif %}
10
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070011{%- endfor %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020012{% for b in m.bases %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020013{% if b.name!='XOSBase' and 'Mixin' not in b.name %}
14from core.models.{{b.name | lower}} import {{ b.name }}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020015{% endif %}
16{% endfor %}
17
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070018
Sapan Bhatia4e80a262017-05-19 23:10:51 +020019class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}:
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070020 # Primitive Fields (Not Relations)
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020021 {% for f in m.fields %}
22 {%- if not f.link -%}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070023 {{ f.name }} = {{ xproto_django_type(f.type, f.options) }}( {{ xproto_django_options_str(f) }} )
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020024 {% endif %}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070025 {%- endfor %}
26
27 # Relations
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020028 {% for l in m.links %}{% set peer_name=l.peer.name %}
29 {{ 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 -070030 {%- endfor %}
31
Sapan Bhatiaf7934b52017-06-12 05:04:23 -070032 # Meta
33 {%- set uniques = xproto_field_graph_components(m.fields) %}
34 {%- if uniques %}
35 class Meta:
36 unique_together = {{ xproto_tuplify(uniques) }}
37 {%- endif %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020038 {% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %}
39 pass
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070040
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020041{% if file_exists(xproto_base_name(m.name)|lower+'_bottom.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_bottom.py') }}{% endif %}
Matteo Scandolo67654fa2017-06-09 09:33:17 -070042{% endif %}{% endfor %}