Add ContentBlock factory, add apollo-link first steps
This commit is contained in:
parent
ca6c5742b4
commit
640af9b047
|
|
@ -13,6 +13,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"apollo-cache-inmemory": "^1.2.2",
|
"apollo-cache-inmemory": "^1.2.2",
|
||||||
"apollo-client": "^2.3.2",
|
"apollo-client": "^2.3.2",
|
||||||
|
"apollo-link": "^1.2.2",
|
||||||
"apollo-link-http": "^1.5.4",
|
"apollo-link-http": "^1.5.4",
|
||||||
"appolo": "^6.0.19",
|
"appolo": "^6.0.19",
|
||||||
"autoprefixer": "^7.1.2",
|
"autoprefixer": "^7.1.2",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {InMemoryCache} from 'apollo-cache-inmemory/lib/index'
|
import {InMemoryCache} from 'apollo-cache-inmemory/lib/index'
|
||||||
import {HttpLink} from 'apollo-link-http/lib/index'
|
import {HttpLink} from 'apollo-link-http/lib/index'
|
||||||
import {ApolloClient} from 'apollo-client/index'
|
import {ApolloClient} from 'apollo-client/index'
|
||||||
|
import {ApolloLink} from 'apollo-link'
|
||||||
import fetch from 'unfetch'
|
import fetch from 'unfetch'
|
||||||
|
|
||||||
const httpLink = new HttpLink({
|
const httpLink = new HttpLink({
|
||||||
|
|
@ -12,9 +13,19 @@ const httpLink = new HttpLink({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const consoleLink = new ApolloLink((operation, forward) => {
|
||||||
|
console.log(`starting request for ${operation.operationName}`);
|
||||||
|
return forward(operation).map((data) => {
|
||||||
|
console.log(`ending request for ${operation.operationName}`);
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const composedLink = ApolloLink.from([consoleLink, httpLink]);
|
||||||
|
|
||||||
// Create the apollo client
|
// Create the apollo client
|
||||||
export default new ApolloClient({
|
export default new ApolloClient({
|
||||||
link: httpLink,
|
link: composedLink,
|
||||||
cache: new InMemoryCache(),
|
cache: new InMemoryCache(),
|
||||||
connectToDevTools: true
|
connectToDevTools: true
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import random
|
||||||
|
|
||||||
import factory
|
import factory
|
||||||
|
|
||||||
from book.models import Book, Topic, Module
|
from book.models import Book, Topic, Module, Chapter, ContentBlock
|
||||||
from core.factories import BasePageFactory, fake, DummyImageFactory
|
from core.factories import BasePageFactory, fake, DummyImageFactory
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -30,3 +30,15 @@ class ModuleFactory(BasePageFactory):
|
||||||
intro = factory.LazyAttribute(lambda x: fake.text(max_nb_chars=200))
|
intro = factory.LazyAttribute(lambda x: fake.text(max_nb_chars=200))
|
||||||
|
|
||||||
hero_image = factory.SubFactory(DummyImageFactory)
|
hero_image = factory.SubFactory(DummyImageFactory)
|
||||||
|
|
||||||
|
|
||||||
|
class ChapterFactory(BasePageFactory):
|
||||||
|
class Meta:
|
||||||
|
model = Chapter
|
||||||
|
|
||||||
|
|
||||||
|
class ContentBlockFactory(BasePageFactory):
|
||||||
|
class Meta:
|
||||||
|
model = ContentBlock
|
||||||
|
|
||||||
|
type = factory.LazyAttribute(lambda x: random.choice(['plain', 'yellow', 'green', 'blue']))
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from django.core.management import BaseCommand
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from wagtail.core.models import Page
|
from wagtail.core.models import Page
|
||||||
|
|
||||||
from book.factories import BookFactory, TopicFactory, ModuleFactory
|
from book.factories import BookFactory, TopicFactory, ModuleFactory, ChapterFactory, ContentBlockFactory
|
||||||
from core.factories import UserFactory
|
from core.factories import UserFactory
|
||||||
from objectives.factories import ObjectiveGroupFactory, ObjectiveFactory
|
from objectives.factories import ObjectiveGroupFactory, ObjectiveFactory
|
||||||
|
|
||||||
|
|
@ -29,7 +29,6 @@ data = [
|
||||||
'teaser': 'Die Berufsbildung ist ein neuer Lebensabschnit',
|
'teaser': 'Die Berufsbildung ist ein neuer Lebensabschnit',
|
||||||
'intro': """
|
'intro': """
|
||||||
<p>Sie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung übernommen.</p>
|
<p>Sie stehen am Anfang eines neuen Lebensabschnitts. In Ihrer Rolle als Berufslernende oder Berufslernender haben Sie Verantwortung übernommen.</p>
|
||||||
|
|
||||||
<p>Wie erging es Ihnen am ersten Arbeits- und Schultag?</p>
|
<p>Wie erging es Ihnen am ersten Arbeits- und Schultag?</p>
|
||||||
""",
|
""",
|
||||||
'objective_groups': [
|
'objective_groups': [
|
||||||
|
|
@ -52,6 +51,24 @@ data = [
|
||||||
{'text': 'Ich kann mein Arbeitsplatz genau beschreiben.'}
|
{'text': 'Ich kann mein Arbeitsplatz genau beschreiben.'}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
'chapters': [
|
||||||
|
{
|
||||||
|
'title': '1.1 Lehrbeginn',
|
||||||
|
'content_blocks': [
|
||||||
|
{'type': 'plain', 'title': 'Auftrag 1', 'content': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?'},
|
||||||
|
{'type': 'yellow', 'title': 'Auftrag 2', 'content': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?'},
|
||||||
|
{'type': 'plain', 'title': 'Auftrag 3', 'content': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?'}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'title': '1.2 Die drei Lernorte',
|
||||||
|
'content_blocks': [
|
||||||
|
{'type': 'plain', 'title': 'Auftrag 1', 'content': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?'},
|
||||||
|
{'type': 'yellow', 'title': 'Auftrag 2', 'content': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?'},
|
||||||
|
{'type': 'blue', 'title': 'Auftrag 3', 'content': 'Sie haben diesen Sommer ihre Lehre begonnen. Was bedeutet dieser neue Abschnitt für Sie?'}
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -135,7 +152,8 @@ class Command(BaseCommand):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
|
||||||
def filter_data(self, input_data, filter_keyword):
|
def filter_data(self, input_data, filter_keyword):
|
||||||
return {k: v for (k, v) in input_data.items() if not (k == filter_keyword)}
|
filters = [filter_keyword] if not isinstance(filter_keyword, list) else filter_keyword
|
||||||
|
return {k: v for (k, v) in input_data.items() if not (k in filters)}
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
|
|
@ -174,7 +192,7 @@ class Command(BaseCommand):
|
||||||
modules_data = topic_data.get('modules', default_modules)
|
modules_data = topic_data.get('modules', default_modules)
|
||||||
|
|
||||||
for module_idx, module_data in enumerate(modules_data):
|
for module_idx, module_data in enumerate(modules_data):
|
||||||
module = ModuleFactory.create(parent=topic, **self.filter_data(module_data, 'objective_groups'))
|
module = ModuleFactory.create(parent=topic, **self.filter_data(module_data, ['objective_groups', 'chapters']))
|
||||||
|
|
||||||
default_objective_groups = [{} for i in range(0, 2)]
|
default_objective_groups = [{} for i in range(0, 2)]
|
||||||
objective_group_data = module_data.get('objective_groups', default_objective_groups)
|
objective_group_data = module_data.get('objective_groups', default_objective_groups)
|
||||||
|
|
@ -190,3 +208,15 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
for objective_idx, objective_data in enumerate(objectives_data):
|
for objective_idx, objective_data in enumerate(objectives_data):
|
||||||
objective = ObjectiveFactory.create(group=objective_group, **objective_data)
|
objective = ObjectiveFactory.create(group=objective_group, **objective_data)
|
||||||
|
|
||||||
|
default_chapters = [{} for i in range(0, 2)]
|
||||||
|
chapters_data = module_data.get('chapters', default_chapters)
|
||||||
|
|
||||||
|
for chapter_idx, chapter_data in enumerate(chapters_data):
|
||||||
|
chapter = ChapterFactory.create(parent=module, **self.filter_data(chapter_data, 'content_blocks'))
|
||||||
|
|
||||||
|
default_content_blocks = [{} for i in range(0, 4)]
|
||||||
|
content_blocks_data = chapter_data.get('content_blocks', default_content_blocks)
|
||||||
|
|
||||||
|
for content_block_idx, content_block_data in enumerate(content_blocks_data):
|
||||||
|
ContentBlockFactory.create(parent=chapter, **self.filter_data(content_block_data, 'content'))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue