Sapan Bhatia | 7148c08 | 2017-06-16 15:04:11 -0700 | [diff] [blame] | 1 | {% if options.legacy =='"True"' -%} |
| 2 | {% set legacy_tag = '_decl' %} |
| 3 | {% set legacy = True %} |
| 4 | from core.models.xosbase import * |
| 5 | {% else %} |
| 6 | {% set legacy = False %} |
| 7 | {% set legacy_tag = '' %} |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 8 | from header import * |
Sapan Bhatia | 7148c08 | 2017-06-16 15:04:11 -0700 | [diff] [blame] | 9 | {% endif %} |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 10 | |
| 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 Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 15 | {%- for l in m.links -%}{% set peer_name=l.peer.name %} |
| 16 | {% if peer_name not in proto.message_names -%} |
| 17 | from core.models import {{ peer_name }} |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 18 | {%- endif -%} |
| 19 | {%- endfor -%} |
| 20 | {%- for b in m.bases -%} |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 21 | {%- if b.name!='XOSBase' and 'Mixin' not in b.name %} |
| 22 | from core.models import {{ b.name }} |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 23 | {%- endif -%} |
| 24 | {% endfor %} |
| 25 | |
| 26 | {% endfor %} |
| 27 | |
| 28 | {% for m in proto.messages %} |
Sapan Bhatia | 7148c08 | 2017-06-16 15:04:11 -0700 | [diff] [blame] | 29 | class {{ m.name }}{{ legacy_tag }}{{ xproto_base_def(m.name, m.bases) }}: |
Sapan Bhatia | 2941a05 | 2017-07-10 15:10:03 -0400 | [diff] [blame] | 30 | plural_name = "{{ xproto_pluralize(m) }}" |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 31 | |
| 32 | KIND = {{ xproto_first_non_empty([m.options.kind, options.kind, options.name, "Set a kind in your xproto!"]) }} |
| 33 | |
| 34 | class Meta: |
| 35 | app_label = {{ xproto_first_non_empty([m.options.app_label, options.app_label, options.name, "Set an app label in your xproto!"]) | lower}} |
| 36 | # name = {{ xproto_first_non_empty([m.options.name, options.name, "Set a name in your xproto!"]) }} |
| 37 | verbose_name = {{ xproto_first_non_empty([m.options.verbose_name, options.verbose_name, "Set a verbose name in your xproto!"]) }} |
| 38 | |
| 39 | # Primitive Fields (Not Relations) |
| 40 | {% for f in m.fields %} |
| 41 | {%- if not f.link -%} |
| 42 | {{ f.name }} = {{ xproto_django_type(f.type, f.options) }}( {{ xproto_django_options_str(f) }} ) |
| 43 | {% endif %} |
| 44 | {%- endfor %} |
| 45 | |
| 46 | # Relations |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 47 | {% for l in m.links %}{% set peer_name=l.peer.name %} |
Sapan Bhatia | 7148c08 | 2017-06-16 15:04:11 -0700 | [diff] [blame] | 48 | {% if legacy and peer_name in proto.message_names %}{% set peer_tag = legacy_tag %}{% else %}{% set peer_tag = '' %}{% endif -%} |
| 49 | {{ 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 Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 50 | {%- endfor %} |
| 51 | |
| 52 | {% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %} |
| 53 | pass |
| 54 | |
Sapan Bhatia | 7148c08 | 2017-06-16 15:04:11 -0700 | [diff] [blame] | 55 | {% if file_exists(m.name|lower+'_bottom.py') -%}{{ include_file(m.name|lower+'_bottom.py') }}{% endif %} |
Sapan Bhatia | 504cc97 | 2017-04-27 01:56:28 +0200 | [diff] [blame] | 56 | {% endfor %} |
Sapan Bhatia | 2941a05 | 2017-07-10 15:10:03 -0400 | [diff] [blame] | 57 | +++ models{{ legacy_tag }}.py |