Sapan Bhatia | d022aeb | 2017-06-07 15:49:55 +0200 | [diff] [blame] | 1 | {% for m in proto.messages %}{% if not m.options.skip_django -%} |
Sapan Bhatia | 4e80a26 | 2017-05-19 23:10:51 +0200 | [diff] [blame] | 2 | {% 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 Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 3 | {% if file_exists(xproto_base_name(m.name)|lower+'_top.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_top.py') }} {% endif %} |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 4 | {%- for l in m.links %} |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 5 | |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 6 | {% if l.peer.name != m.name %} |
Sapan Bhatia | b5ce186 | 2017-07-31 15:48:19 -0400 | [diff] [blame] | 7 | from {{ l.peer.name | lower }} import {{ l.peer.name }} |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 8 | {% endif %} |
| 9 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 10 | {%- endfor %} |
Sapan Bhatia | b5ce186 | 2017-07-31 15:48:19 -0400 | [diff] [blame] | 11 | {% if m.name!='XOSBase' and 'Mixin' not in m.name %} |
| 12 | import security |
| 13 | {% if m.name!='Privilege' %} |
| 14 | from privilege import Privilege |
| 15 | {% endif %} |
| 16 | {% endif %} |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 17 | {% for b in m.bases %} |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 18 | {% if b.name!='XOSBase' and 'Mixin' not in b.name %} |
Sapan Bhatia | b5ce186 | 2017-07-31 15:48:19 -0400 | [diff] [blame] | 19 | from {{b.name | lower}} import {{ b.name }} |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 20 | {% endif %} |
| 21 | {% endfor %} |
| 22 | |
Sapan Bhatia | 9227b4d | 2017-07-25 23:14:48 -0400 | [diff] [blame] | 23 | {% for policy,error in xproto_validations(m.options) %} |
| 24 | {{ xproto_fol_to_python_validator(policy, proto.policies[policy], m, error) }} |
| 25 | {% endfor %} |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 26 | |
Sapan Bhatia | 4e80a26 | 2017-05-19 23:10:51 +0200 | [diff] [blame] | 27 | class {{ m.name }}{{ xproto_base_def(m.name, m.bases) }}: |
Sapan Bhatia | 2941a05 | 2017-07-10 15:10:03 -0400 | [diff] [blame] | 28 | plural_name = "{{ xproto_pluralize(m) }}" |
| 29 | |
Matteo Scandolo | 39b4a27 | 2017-11-17 11:09:21 -0800 | [diff] [blame] | 30 | {# {% if m.options.no_sync or m.options.no_policy %}#} |
| 31 | {# {% if m.options.no_sync -%}#} |
| 32 | {# # Removing synchronizer feedback state from model#} |
| 33 | {# backend_status = None#} |
| 34 | {# backend_code = None#} |
| 35 | {# {%- endif %}#} |
| 36 | {# {% if m.options.no_policy -%}#} |
| 37 | {# # Removing model policy feedback state from model#} |
| 38 | {# policy_code = None#} |
| 39 | {# policy_status = None#} |
| 40 | {# {%- endif %}#} |
| 41 | {# {% endif %}#} |
| 42 | |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 43 | # Primitive Fields (Not Relations) |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 44 | {% for f in m.fields %} |
| 45 | {%- if not f.link -%} |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 46 | {{ f.name }} = {{ xproto_django_type(f.type, f.options) }}( {{ xproto_django_options_str(f) }} ) |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 47 | {% endif %} |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 48 | {%- endfor %} |
| 49 | |
| 50 | # Relations |
Sapan Bhatia | 3cfdf63 | 2017-06-08 05:14:03 +0200 | [diff] [blame] | 51 | {% for l in m.links %}{% set peer_name=l.peer.name %} |
| 52 | {{ 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 Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 53 | {%- endfor %} |
| 54 | |
Sapan Bhatia | f7934b5 | 2017-06-12 05:04:23 -0700 | [diff] [blame] | 55 | # Meta |
| 56 | {%- set uniques = xproto_field_graph_components(m.fields) %} |
| 57 | {%- if uniques %} |
| 58 | class Meta: |
| 59 | unique_together = {{ xproto_tuplify(uniques) }} |
| 60 | {%- endif %} |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 61 | {% if file_exists(m.name|lower + '_model.py') -%}{{ include_file(m.name|lower + '_model.py') | indent(width=2)}}{%- endif %} |
| 62 | pass |
Sapan Bhatia | ff1b8fa | 2017-04-10 19:44:38 -0700 | [diff] [blame] | 63 | |
Sapan Bhatia | 9227b4d | 2017-07-25 23:14:48 -0400 | [diff] [blame] | 64 | {% if m.name!='XOSBase' and 'Mixin' not in m.name %} |
| 65 | # Generated methods |
| 66 | def save(self, *args, **kwds): |
Sapan Bhatia | 113c2b9 | 2017-07-25 08:41:58 -0400 | [diff] [blame] | 67 | if not self.leaf_model_name: |
| 68 | self.leaf_model_name = "{{ m.name }}" |
| 69 | |
Sapan Bhatia | 9227b4d | 2017-07-25 23:14:48 -0400 | [diff] [blame] | 70 | try: |
| 71 | self.__xos_save_base(*args, **kwds) |
| 72 | except AttributeError: |
| 73 | pass |
| 74 | |
| 75 | {% for policy,error in xproto_validations(m.options) %} |
| 76 | policy_{{policy}}_validator(self, None) |
| 77 | {% endfor %} |
| 78 | super({{ m.name }}, self).save(*args, **kwds) |
Sapan Bhatia | b5ce186 | 2017-07-31 15:48:19 -0400 | [diff] [blame] | 79 | |
| 80 | def can_access(self, ctx): |
| 81 | {% if m.policy %} |
| 82 | verdict = security.{{m.policy}}_security_check(self, ctx) |
| 83 | return verdict,"{{ m.policy }}" |
| 84 | {% else %} |
| 85 | verdict = XOS_GLOBAL_DEFAULT_SECURITY_POLICY |
| 86 | return verdict,"xos_default_policy" |
| 87 | {% endif %} |
| 88 | |
Sapan Bhatia | 9227b4d | 2017-07-25 23:14:48 -0400 | [diff] [blame] | 89 | {% endif %} |
| 90 | |
Sapan Bhatia | c4f803f | 2017-04-21 11:50:39 +0200 | [diff] [blame] | 91 | {% if file_exists(xproto_base_name(m.name)|lower+'_bottom.py') -%}{{ include_file(xproto_base_name(m.name)|lower+'_bottom.py') }}{% endif %} |
Sapan Bhatia | 2941a05 | 2017-07-10 15:10:03 -0400 | [diff] [blame] | 92 | {% endif %}{% endfor %} |