BO 1.13 tutorials steps condition as JSON

This commit is contained in:
Bossanyi Tibor 2021-04-30 23:01:49 +02:00
parent 311fa6071c
commit 7459dfdc2d
5 changed files with 68 additions and 17 deletions

View File

@ -1,5 +1,8 @@
from django.contrib import admin
from django.db import models
from django_admin_json_editor import JSONEditorWidget
from ..models.tutorial import TutorialTranslation, Tutorial, TutorialSteps
@ -9,13 +12,66 @@ class TranslationTutorialInline(admin.TabularInline):
extra = 0
DATA_SCHEMA = {
'type': 'object',
'title': 'Control for TutorialStep',
'properties': {
'direction': {
'title': 'direction',
'type': 'string',
'enum': ['up', 'down', 'left', 'right']
},
'top': {
'title': 'Top',
'type': 'integer',
},
'left': {
'title': 'Left',
'type': 'integer',
},
'show_bubble': {
'title': 'Show Bubble',
'type': 'boolean',
},
'bubble_x': {
'title': 'Bubble X',
'type': 'integer',
},
'bubble_y': {
'title': 'Bubble Y',
'type': 'integer',
},
'bubble_width': {
'title': 'Bubble Width',
'type': 'integer',
},
'bubble_height': {
'title': 'Bubble Height',
'type': 'integer',
},
'show_check_text': {
'title': 'Show Check Text',
'type': 'boolean',
},
'parent': {
'title': 'parent',
'type': 'integer',
},
},
}
class TutorialStepsAdmin(admin.ModelAdmin):
list_display = ('tutorial_step_id', 'tutorial', 'check_text', 'step', 'direction', 'parent_id', 'branch')
list_display = ('tutorial_step_id', 'tutorial', 'check_text', 'step')
list_filter = ('tutorial__name',)
fields = ('tutorial', 'step', "tutorial_text", "check_text", "direction", "condition", 'parent_id', 'branch'
, "action")
list_editable = ('step','direction', 'parent_id','branch')
fields = ('tutorial', 'step', "tutorial_text", "check_text", "condition")
list_editable = ('step',)
ordering = ('tutorial_step_id',)
formfield_overrides = {
models.TextField: {
'widget': JSONEditorWidget(DATA_SCHEMA, collapsed=False)
},
}
def copy_attributes(self, request, queryset):
for objectAttr in reversed(queryset):

View File

@ -1,4 +1,5 @@
from django.db import models
from django.forms import JSONField, fields
from django.utils.translation import ugettext_lazy as _
from ckeditor.fields import RichTextField
@ -24,18 +25,9 @@ class TutorialSteps(models.Model):
tutorial = models.ForeignKey(Tutorial, on_delete=models.CASCADE)
step = models.IntegerField(help_text="Tutorial Step")
tutorial_text = RichTextField()
direction = models.CharField(max_length=100, blank=True, null=True, help_text="Only for programmers!")
check_text = models.CharField(max_length=50, blank=True, null=True, help_text="Only for programmers!")
condition = models.CharField(max_length=50, blank=True, null=True, help_text="Only for programmers!")
branch = models.CharField(max_length=50, blank=True, null=True, help_text="Only for programmers!")
parent_id = models.IntegerField(help_text="Tutorial Step Parent.")
#parent = models.ForeignKey('self', blank=True, null=True, related_name='parents', on_delete=models.CASCADE)
action = models.BooleanField(default=0, blank=True, null=True, help_text="Tap, select menu, etc")
def get_parent_step(self):
return self.parent.step
get_parent_step.admin_order_field = 'self__step'
get_parent_step.short_description = "parent_step"
check_text = models.CharField(max_length=50, blank=True, null=True, help_text="Only for programmers!")
condition = models.TextField(blank=True, null=True, help_text="Only for programmers!")
class Meta:
db_table = 'tutorial_steps'

View File

@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
import os
BACKOFFICE_VERSION = 1.12
BACKOFFICE_VERSION = 1.13
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -46,6 +46,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'ckeditor',
'ckeditor_uploader',
'django_admin_json_editor',
]
MIDDLEWARE = [

View File

@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
import os
BACKOFFICE_VERSION = 1.12
BACKOFFICE_VERSION = 1.13
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -42,6 +42,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'ckeditor',
'ckeditor_uploader',
'django_admin_json_editor',
]
MIDDLEWARE = [

View File

@ -1,5 +1,6 @@
django==3.2
django-ckeditor==6.0.0
django_admin_json_editor=0.2.3
asgiref==3.3.4
certifi==2020.6.20
chardet==3.0.4