Skip to content

Commit

Permalink
Finish 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLion9 committed Nov 23, 2016
2 parents c30a410 + 45a7f9e commit 3850aee
Show file tree
Hide file tree
Showing 63 changed files with 5,380 additions and 436 deletions.
101 changes: 97 additions & 4 deletions business_logic/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
# -*- coding: utf-8 -*-
from django.contrib import admin
from django import forms
from django.conf import settings
from django.contrib import admin
from django.contrib.admin import TabularInline

from nested_inline.admin import NestedModelAdmin, NestedStackedInline, NestedTabularInline

from polymorphic.admin import PolymorphicChildModelAdmin
from polymorphic.admin import PolymorphicParentModelAdmin

from adminsortable2.admin import SortableInlineAdminMixin

from nested_inline.admin import NestedStackedInline, NestedModelAdmin
from ace_overlay.widgets import AceOverlayWidget


from .models import (
ProgramInterface,
ProgramArgument,
ProgramArgumentField,
Program,
ReferenceDescriptor,
ProgramVersion,
FunctionDefinition,
PythonCodeFunctionDefinition,
PythonModuleFunctionDefinition,
FunctionLibrary,
FunctionArgument,
FunctionArgumentChoice,
ExecutionEnvironment,
)

from .models import ProgramInterface, ProgramArgument, ProgramArgumentField, Program, ReferenceDescriptor, \
ProgramVersion
from .utils import get_customer_available_content_types


Expand Down Expand Up @@ -76,11 +100,80 @@ class ReferenceDescriptorAdmin(admin.ModelAdmin):
form = ContentTypeHolderForm


class FunctionArgumentChoiceAdmin(SortableInlineAdminMixin, admin.TabularInline):
model = FunctionArgumentChoice
extra = 1


class FunctionArgumentAdmin(admin.ModelAdmin):
model = FunctionArgument
inlines = (FunctionArgumentChoiceAdmin, )
readonly_fields = ('function', 'order')

list_filter = (
'function',
)

def has_add_permission(self, request):
return False


class FunctionArgumentInline(SortableInlineAdminMixin, admin.StackedInline):
model = FunctionArgument
extra = 1
show_change_link = True


class FunctionDefinitionAdmin(PolymorphicChildModelAdmin):
inlines = (FunctionArgumentInline, )


class PythonModuleFunctionDefinitionAdmin(FunctionDefinitionAdmin):
base_model = PythonModuleFunctionDefinition


class PythonCodeFunctionDefinitionAdminForm(forms.ModelForm):
if 'ace_overlay' in settings.INSTALLED_APPS:
code = forms.CharField(
widget=AceOverlayWidget(
mode='python',
wordwrap=False,
theme='solarized_light',
width="850px",
height="800px",
showprintmargin=True
), required=True)

class Meta:
model = PythonCodeFunctionDefinition
fields = ('title', 'description', 'is_returns_value', 'is_context_required', 'code')


class PythonCodeFunctionDefinitionAdmin(FunctionDefinitionAdmin):
base_model = PythonCodeFunctionDefinition
form = PythonCodeFunctionDefinitionAdminForm


class FunctionDefinitionAdmin(PolymorphicParentModelAdmin):
base_model = FunctionDefinition
child_models = (
PythonCodeFunctionDefinition,
PythonModuleFunctionDefinition
)

admin.site.register(ExecutionEnvironment)
admin.site.register(ProgramInterface, ProgramInterfaceAdmin)
admin.site.register(Program, ProgramAdmin)
admin.site.register(ProgramVersion, ProgramVersionAdmin)

admin.site.register(ReferenceDescriptor, ReferenceDescriptorAdmin)

admin.site.register(FunctionArgument, FunctionArgumentAdmin)
admin.site.register(FunctionDefinition, FunctionDefinitionAdmin)
admin.site.register(PythonModuleFunctionDefinition, PythonModuleFunctionDefinitionAdmin)
admin.site.register(PythonCodeFunctionDefinition, PythonCodeFunctionDefinitionAdmin)
admin.site.register(FunctionLibrary)

# register all app models for debug purposes
# from django.apps import apps
# for model in apps.get_app_config('business_logic').get_models():
Expand Down
19 changes: 15 additions & 4 deletions business_logic/blockly/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def visit(self, node, parent_xml):
for child in self.get_children(node):
self.visit(child, parent_xml)

node_xml.set('id', str(node.id))
return node_xml

if content_object.__class__ not in (VariableDefinition, ):
Expand Down Expand Up @@ -189,10 +190,20 @@ def visit_if_statement(self, node, parent_xml):

visit_if_statement.process_children = True

def visit_function(self, node, parent_xml):
function = node.content_object
function_definition = function.definition
children = self.get_children(node)

block = etree.SubElement(parent_xml, 'block', type='business_logic_function')
etree.SubElement(block, 'mutation', args='true')
field = etree.SubElement(block, 'field', name='FUNC')
field.text = function_definition.title

def tree_to_blockly_xml(tree_root):
return BlocklyXmlBuilder().build(tree_root)
for i, child_node in enumerate(children):
value = etree.SubElement(block, 'value', name='ARG{}'.format(i))
self.visit(child_node, value)

return block

def blockly_xml_to_tree(xml):
pass
visit_function.process_children = True
14 changes: 14 additions & 0 deletions business_logic/blockly/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,17 @@ def visit_block_business_logic_argument_field_set(self, node):

def visit_block_business_logic_argument_field_get(self, node):
return self.visit_block_variables_get(node)

def visit_block_business_logic_function(self, node):
children = node.getchildren()

data = {
'data': {
'content_type': get_content_type_id(Function),
'definition_id': FunctionDefinition.objects.get(title=children[1].text).id
}
}

self._visit_children(node, data, children=children[2:])

return data
1 change: 1 addition & 0 deletions business_logic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class ExceptionHandlingPolicy:
IGNORE = 'IGNORE'
INTERRUPT = 'INTERRUPT'
RAISE = 'RAISE'


class ContextConfig(object):
Expand Down
112 changes: 106 additions & 6 deletions business_logic/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ class Migration(migrations.Migration):
('execution', models.ForeignKey(related_name='arguments', to='business_logic.Execution')),
],
),
migrations.CreateModel(
name='ExecutionEnvironment',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(unique=True, max_length=255, verbose_name='Title')),
('description', models.TextField(null=True, verbose_name='Description', blank=True)),
('debug', models.BooleanField(default=False)),
('log', models.BooleanField(default=False)),
('cache', models.BooleanField(default=True)),
('exception_handling_policy', models.CharField(default=b'INTERRUPT', max_length=15, verbose_name='Exception handling policy', choices=[(b'IGNORE', 'Ignore'), (b'INTERRUPT', 'Interrupt'), (b'RAISE', 'Raise')])),
],
),
migrations.CreateModel(
name='ForeachStatement',
fields=[
Expand All @@ -112,18 +124,57 @@ class Migration(migrations.Migration):
'verbose_name_plural': 'Functions',
},
),
migrations.CreateModel(
name='FunctionArgument',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=255, null=True, blank=True)),
('description', models.TextField(null=True, verbose_name='Description', blank=True)),
('order', models.PositiveIntegerField(default=0, db_index=True)),
],
options={
'ordering': ('order',),
'verbose_name': 'Function argument',
'verbose_name_plural': 'Function arguments',
},
),
migrations.CreateModel(
name='FunctionArgumentChoice',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('value', models.CharField(max_length=255)),
('title', models.CharField(max_length=255)),
('order', models.PositiveIntegerField(default=0, db_index=True)),
('argument', models.ForeignKey(related_name='choices', to='business_logic.FunctionArgument')),
],
options={
'ordering': ('order',),
'verbose_name': 'Function argument choice',
'verbose_name_plural': 'Function argument choices',
},
),
migrations.CreateModel(
name='FunctionDefinition',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('module', models.CharField(default=b'__builtins__', max_length=255, verbose_name='Module name')),
('function', models.CharField(max_length=255, verbose_name='Function name')),
('context_required', models.BooleanField(default=False, verbose_name='Context required')),
('title', models.CharField(max_length=255, verbose_name='Function title')),
('title', models.CharField(unique=True, max_length=255, verbose_name='Title')),
('description', models.TextField(null=True, verbose_name='Description', blank=True)),
('is_context_required', models.BooleanField(default=False, verbose_name='Is Context required')),
('is_returns_value', models.BooleanField(default=True, verbose_name='Is returns value')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='FunctionLibrary',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(unique=True, max_length=255, verbose_name='Function library title')),
],
options={
'verbose_name': 'Function definition',
'verbose_name_plural': 'Function definitions',
'verbose_name': 'Function library',
'verbose_name_plural': 'Function libraries',
},
),
migrations.CreateModel(
Expand Down Expand Up @@ -185,6 +236,7 @@ class Migration(migrations.Migration):
('code', models.SlugField(unique=True, max_length=255, verbose_name='Code')),
('creation_time', models.DateTimeField(auto_now_add=True)),
('modification_time', models.DateTimeField(auto_now=True)),
('environment', models.ForeignKey(blank=True, to='business_logic.ExecutionEnvironment', null=True)),
],
options={
'verbose_name': 'Program',
Expand Down Expand Up @@ -225,6 +277,7 @@ class Migration(migrations.Migration):
('code', models.SlugField(null=True, max_length=255, blank=True, unique=True, verbose_name='Code')),
('creation_time', models.DateTimeField(auto_now_add=True)),
('modification_time', models.DateTimeField(auto_now=True)),
('environment', models.ForeignKey(blank=True, to='business_logic.ExecutionEnvironment', null=True)),
],
options={
'verbose_name': 'Program interface',
Expand All @@ -241,6 +294,7 @@ class Migration(migrations.Migration):
('creation_time', models.DateTimeField(auto_now_add=True)),
('modification_time', models.DateTimeField(auto_now=True)),
('entry_point', models.ForeignKey(verbose_name='Entry point', to='business_logic.Node')),
('environment', models.ForeignKey(blank=True, to='business_logic.ExecutionEnvironment', null=True)),
('program', models.ForeignKey(related_name='versions', to='business_logic.Program')),
],
options={
Expand All @@ -262,6 +316,7 @@ class Migration(migrations.Migration):
name='ReferenceDescriptor',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(max_length=255, null=True, blank=True)),
('search_fields', models.TextField(null=True, blank=True)),
('name_field', models.SlugField(max_length=255, null=True, blank=True)),
('content_type', models.OneToOneField(to='contenttypes.ContentType')),
Expand Down Expand Up @@ -334,6 +389,31 @@ class Migration(migrations.Migration):
'verbose_name_plural': 'Variable definitions',
},
),
migrations.CreateModel(
name='PythonCodeFunctionDefinition',
fields=[
('functiondefinition_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='business_logic.FunctionDefinition')),
('code', models.TextField(max_length=255, verbose_name='Code')),
],
options={
'verbose_name': 'Python code function definition',
'verbose_name_plural': 'Python code function definition',
},
bases=('business_logic.functiondefinition',),
),
migrations.CreateModel(
name='PythonModuleFunctionDefinition',
fields=[
('functiondefinition_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='business_logic.FunctionDefinition')),
('module', models.CharField(default=b'__builtins__', max_length=255, verbose_name='Module name')),
('function', models.CharField(max_length=255, verbose_name='Function name')),
],
options={
'verbose_name': 'Python module function definition',
'verbose_name_plural': 'Python module function definition',
},
bases=('business_logic.functiondefinition',),
),
migrations.AddField(
model_name='variable',
name='definition',
Expand Down Expand Up @@ -369,11 +449,31 @@ class Migration(migrations.Migration):
name='parent',
field=models.ForeignKey(related_name='children', blank=True, to='business_logic.LogEntry', null=True),
),
migrations.AddField(
model_name='functionlibrary',
name='functions',
field=models.ManyToManyField(related_name='libraries', to='business_logic.FunctionDefinition'),
),
migrations.AddField(
model_name='functiondefinition',
name='polymorphic_ctype',
field=models.ForeignKey(related_name='polymorphic_business_logic.functiondefinition_set+', editable=False, to='contenttypes.ContentType', null=True),
),
migrations.AddField(
model_name='functionargument',
name='function',
field=models.ForeignKey(related_name='arguments', to='business_logic.FunctionDefinition'),
),
migrations.AddField(
model_name='function',
name='definition',
field=models.ForeignKey(related_name='functions', to='business_logic.FunctionDefinition'),
),
migrations.AddField(
model_name='executionenvironment',
name='libraries',
field=models.ManyToManyField(related_name='environments', to='business_logic.FunctionLibrary', blank=True),
),
migrations.AddField(
model_name='executionargument',
name='program_argument',
Expand Down
19 changes: 0 additions & 19 deletions business_logic/migrations/0002_referencedescriptor_title.py

This file was deleted.

Loading

0 comments on commit 3850aee

Please sign in to comment.