blob: 5260e8554b07998b73bde7c14ce3cd4ba710904c [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 %}
7from core.models.{{ 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 Bhatiac4f803f2017-04-21 11:50:39 +020011{% for b in m.bases %}
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020012{% if b.name!='XOSBase' and 'Mixin' not in b.name %}
13from core.models.{{b.name | lower}} import {{ b.name }}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020014{% endif %}
15{% endfor %}
16
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040017{% for policy,error in xproto_validations(m.options) %}
18{{ xproto_fol_to_python_validator(policy, proto.policies[policy], m, error) }}
19{% endfor %}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070020
Sapan Bhatia4e80a262017-05-19 23:10:51 +020021class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}:
Sapan Bhatia2941a052017-07-10 15:10:03 -040022 plural_name = "{{ xproto_pluralize(m) }}"
23
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070024 # Primitive Fields (Not Relations)
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020025 {% for f in m.fields %}
26 {%- if not f.link -%}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070027 {{ f.name }} = {{ xproto_django_type(f.type, f.options) }}( {{ xproto_django_options_str(f) }} )
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020028 {% endif %}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070029 {%- endfor %}
30
31 # Relations
Sapan Bhatia3cfdf632017-06-08 05:14:03 +020032 {% for l in m.links %}{% set peer_name=l.peer.name %}
33 {{ 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 -070034 {%- endfor %}
35
Sapan Bhatiaf7934b52017-06-12 05:04:23 -070036 # Meta
37 {%- set uniques = xproto_field_graph_components(m.fields) %}
38 {%- if uniques %}
39 class Meta:
40 unique_together = {{ xproto_tuplify(uniques) }}
41 {%- endif %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020042 {% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %}
Sapan Bhatiaff1b8fa2017-04-10 19:44:38 -070043
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040044 {% if m.name!='XOSBase' and 'Mixin' not in m.name %}
45
46 # Generated methods
47 def save(self, *args, **kwds):
Sapan Bhatia113c2b92017-07-25 08:41:58 -040048 if not self.leaf_model_name:
49 self.leaf_model_name = "{{ m.name }}"
50
Sapan Bhatia9227b4d2017-07-25 23:14:48 -040051 try:
52 self.__xos_save_base(*args, **kwds)
53 except AttributeError:
54 pass
55
56 {% for policy,error in xproto_validations(m.options) %}
57 policy_{{policy}}_validator(self, None)
58 {% endfor %}
59 super({{ m.name }}, self).save(*args, **kwds)
60
61 {% endif %}
Sapan Bhatiac4f803f2017-04-21 11:50:39 +020062{% if file_exists(xproto_base_name(m.name)|lower+'_bottom.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_bottom.py') }}{% endif %}
63+++ {{m.name|lower}}.py
Sapan Bhatia2941a052017-07-10 15:10:03 -040064{% endif %}{% endfor %}