Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/models/extensions/2_admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Some useful configuration options::
@admin(
inline: lala(
type: stacked
extension: 300
extra: 300
fields: *, ^c
)
)
Expand All @@ -170,7 +170,7 @@ Some useful configuration options::
d

Type: stacked (form under another), tabular (as a table), polymorphic (see later)
Extension: amount of empty lines
extra: amount of empty lines
Fields: fields to show (:ref:`FieldList` syntax)

Polymorphic inline
Expand Down Expand Up @@ -412,7 +412,7 @@ Inlines also can be used in tabs::
@admin(
inline: lala(
type: stacked
extension: 300
extra: 300
fields: *, ^c
)
tabs: main(*), other(lala)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/model/test_populate_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def test_admin_inline_simple():
inline = foo[AdminModelExtension].inlines[0]

assert isinstance(inline, AdminInlineConfig)
assert inline.extension_count == 0
assert inline.extra_count == 0
assert inline.model == foo
assert inline.target_model == bar
assert inline.inline_type == 'tabular'
Expand Down Expand Up @@ -575,7 +575,7 @@ def test_admin_inline_details():
@admin(
inline: lala(
type: stacked
extension: 300
extra: 300
fields: *, ^c
)
)
Expand All @@ -595,7 +595,7 @@ def test_admin_inline_details():
inline = foo[AdminModelExtension].inlines[0]

assert isinstance(inline, AdminInlineConfig)
assert inline.extension_count == 300
assert inline.extra_count == 300
assert inline.inline_type == 'stacked'
assert inline.field_names == ['d']

Expand All @@ -612,7 +612,7 @@ def test_admin_inline_tab():
@admin(
inline: lala(
type: stacked
extension: 300
extra: 300
fields: *, ^c
)
tabs: main(*), other(lala)
Expand Down
6 changes: 3 additions & 3 deletions zmei_generator/contrib/admin/extensions/model/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __init__(self, admin, name):
self.model = admin.model
self.inline_name = name
self.fields_expr = ['*']
self.extension_count = 0
self.extra_count = 0
self.inline_type = 'tabular'

self.field = None
Expand Down Expand Up @@ -207,8 +207,8 @@ def post_process(self):
self.field_set = [f for f in field.target_model.filter_fields(self.fields_expr) if
f.name != self.source_field_name]

if self.extension_count:
if self.extension_count > 0 and self.inline_type == 'polymorphic':
if self.extra_count:
if self.extra_count > 0 and self.inline_type == 'polymorphic':
raise ValidationException('{}->{}: When using inline type "polymorphic" extension must be 0'.format(
self.model.name,
self.inline_name
Expand Down
4 changes: 2 additions & 2 deletions zmei_generator/contrib/admin/grammar/ModelExtensionAdmin.g4
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ an_admin_inline:
(BRACE_OPEN
(
inline_type
|inline_extension
|inline_extra
|inline_fields
|NL
|COMA
Expand All @@ -49,7 +49,7 @@ inline_name: id_or_kw;
inline_type: KW_TYPE COLON inline_type_name;

inline_type_name : (KW_INLINE_TYPE_TABULAR | KW_INLINE_TYPE_STACKED | KW_INLINE_TYPE_POLYMORPHIC) ;
inline_extension: KW_EXTENSION COLON DIGIT;
inline_extra: KW_EXTRA COLON DIGIT;
inline_fields: KW_FIELDS COLON field_list_expr;

an_admin_tabs: KW_TABS COLON an_admin_tab (COMA an_admin_tab)*;
Expand Down
4 changes: 2 additions & 2 deletions zmei_generator/contrib/admin/parsers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def enterInline_type(self, ctx: ZmeiLangParser.Inline_typeContext):
def enterInline_fields(self, ctx: ZmeiLangParser.Inline_fieldsContext):
self.inline.fields_expr = self._get_fields(ctx)

def enterInline_extension(self, ctx: ZmeiLangParser.Inline_extensionContext):
self.inline.extension_count = int(ctx.DIGIT().getText())
def enterInline_extra(self, ctx: ZmeiLangParser.Inline_extraContext):
self.inline.extra_count = int(ctx.DIGIT().getText())

def enterAn_admin_css_file_name(self, ctx: ZmeiLangParser.An_admin_css_file_nameContext):
self.model[AdminModelExtension].css.append(ctx.getText().strip('"\''))
Expand Down
2 changes: 1 addition & 1 deletion zmei_generator/contrib/admin/templates/admin.py.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class {{ inline.class_name }}({{ inline.parent_classes|join(', ') }}):
{% endif %}{% if inline.target_model.sortable %}
sortable = {{ inline.target_model.sortable_field.0|repr }}
{% endif %}{% if not inline.inline_type == 'polymorphic' %}
extension = {{ inline.extension_count }}
extra = {{ inline.extra_count }}
fk_name = '{{ inline.source_field_name }}'
fields = [{{ inline.field_set|field_names() }}]
{% else %}{% for model in inline.target_model.child_models %}
Expand Down
2 changes: 1 addition & 1 deletion zmei_generator/contrib/web/grammar/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
KW_AUTH='auth',
KW_COUNT='count',
KW_I18N='i18n',
KW_EXTENSION='extension',
KW_EXTRA='extra',
KW_TABS='tabs',
KW_LIST='list',
KW_READ_ONLY='read_only',
Expand Down
6 changes: 3 additions & 3 deletions zmei_generator/parser/gen/ZmeiLangParser.interp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ null
'auth'
'count'
'i18n'
'extension'
'extra'
'tabs'
'list'
'read_only'
Expand Down Expand Up @@ -267,7 +267,7 @@ KW_QUERY
KW_AUTH
KW_COUNT
KW_I18N
KW_EXTENSION
KW_EXTRA
KW_TABS
KW_LIST
KW_READ_ONLY
Expand Down Expand Up @@ -448,7 +448,7 @@ an_admin_inline
inline_name
inline_type
inline_type_name
inline_extension
inline_extra
inline_fields
an_admin_tabs
an_admin_tab
Expand Down
152 changes: 76 additions & 76 deletions zmei_generator/parser/gen/ZmeiLangParser.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions zmei_generator/parser/gen/ZmeiLangParser.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ KW_QUERY=102
KW_AUTH=103
KW_COUNT=104
KW_I18N=105
KW_EXTENSION=106
KW_EXTRA=106
KW_TABS=107
KW_LIST=108
KW_READ_ONLY=109
Expand Down Expand Up @@ -262,7 +262,7 @@ PYTHON_LINE_NL=159
'auth'=103
'count'=104
'i18n'=105
'extension'=106
'extra'=106
'tabs'=107
'list'=108
'read_only'=109
Expand Down
10 changes: 5 additions & 5 deletions zmei_generator/parser/gen/ZmeiLangParserListener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated from /Users/aleksandrrudakov/dev/zmei/generator/zmei_generator/parser/gen/grammar/ZmeiLangParser.g4 by ANTLR 4.7.2
# Generated from /Users/alexanderbudanov/Sites/negative/generator/zmei_generator/parser/gen/grammar/ZmeiLangParser.g4 by ANTLR 4.7.2
from antlr4 import *
if __name__ is not None and "." in __name__:
from .ZmeiLangParser import ZmeiLangParser
Expand Down Expand Up @@ -1133,12 +1133,12 @@ def exitInline_type_name(self, ctx:ZmeiLangParser.Inline_type_nameContext):
pass


# Enter a parse tree produced by ZmeiLangParser#inline_extension.
def enterInline_extension(self, ctx:ZmeiLangParser.Inline_extensionContext):
# Enter a parse tree produced by ZmeiLangParser#inline_extra.
def enterInline_extra(self, ctx:ZmeiLangParser.Inline_extraContext):
pass

# Exit a parse tree produced by ZmeiLangParser#inline_extension.
def exitInline_extension(self, ctx:ZmeiLangParser.Inline_extensionContext):
# Exit a parse tree produced by ZmeiLangParser#inline_extra.
def exitInline_extra(self, ctx:ZmeiLangParser.Inline_extraContext):
pass


Expand Down
8 changes: 4 additions & 4 deletions zmei_generator/parser/gen/ZmeiLangSimpleLexer.interp

Large diffs are not rendered by default.

Loading