Add UserGroup and test data generation for it
This commit is contained in:
parent
e92927132c
commit
34220d7262
|
|
@ -20,7 +20,7 @@
|
||||||
import RoomEntryCountWidget from '@/components/rooms/RoomEntryCountWidget';
|
import RoomEntryCountWidget from '@/components/rooms/RoomEntryCountWidget';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['title', 'type', 'entries', 'group'],
|
props: ['title', 'appearance', 'entries', 'group'],
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
RoomEntryCountWidget,
|
RoomEntryCountWidget,
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
return this.entries.length
|
return this.entries.length
|
||||||
},
|
},
|
||||||
roomClass() {
|
roomClass() {
|
||||||
return `room-widget--${this.type}`
|
return `room-widget--${this.appearance}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,21 +19,21 @@
|
||||||
return {
|
return {
|
||||||
rooms: [
|
rooms: [
|
||||||
{
|
{
|
||||||
title: 'Ein historische Festival',
|
title: 'Ein historisches Festival',
|
||||||
type: 'red',
|
group: 'Klasse 3b',
|
||||||
group: 'Klasse 3b - 2018/2019',
|
appearance: 'red',
|
||||||
entries: [1, 1, 1, 1, 1, 1]
|
entries: [1, 1, 1, 1, 1, 1]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Erfahrungen Lehrbeginn',
|
title: 'Erfahrungen Lehrbeginn',
|
||||||
type: 'green',
|
group: 'Klasse 3b',
|
||||||
group: 'Klasse 3b - 2018/2019',
|
appearance: 'green',
|
||||||
entries: [1]
|
entries: [1]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Interview «Mein neues Umfeld»',
|
title: 'Interview «Mein neues Umfeld»',
|
||||||
type: 'brown',
|
|
||||||
group: 'Hans Muster und 12 weitere Personen',
|
group: 'Hans Muster und 12 weitere Personen',
|
||||||
|
appearance: 'brown',
|
||||||
entries: [1, 1, 1, 1, 1, 1]
|
entries: [1, 1, 1, 1, 1, 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from wagtail.core.rich_text import RichText
|
||||||
|
|
||||||
from book.blocks import ModalTextBlock, StudentEntryBlock
|
from book.blocks import ModalTextBlock, StudentEntryBlock
|
||||||
from book.models import Book, Topic, Module, Chapter, ContentBlock, TextBlock
|
from book.models import Book, Topic, Module, Chapter, ContentBlock, TextBlock
|
||||||
from core.factories import BasePageFactory, fake, DummyImageFactory, fake_title, fake_title_noparam, fake_paragraph
|
from core.factories import BasePageFactory, fake, DummyImageFactory, fake_paragraph
|
||||||
|
|
||||||
|
|
||||||
class BookFactory(BasePageFactory):
|
class BookFactory(BasePageFactory):
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,12 @@ from wagtail.images import get_image_model
|
||||||
fake = Faker('de_DE')
|
fake = Faker('de_DE')
|
||||||
|
|
||||||
|
|
||||||
def fake_title(x):
|
def fake_title(x=None):
|
||||||
return fake.sentence(nb_words=random.randint(2, 4)).replace('.', '')
|
return fake.sentence(nb_words=random.randint(2, 4)).replace('.', '')
|
||||||
|
|
||||||
|
|
||||||
def fake_title_noparam():
|
|
||||||
return fake_title(None)
|
|
||||||
|
|
||||||
def fake_paragraph(x=None):
|
def fake_paragraph(x=None):
|
||||||
return '<p>{}</p>'.format(fake_title_noparam())
|
return '<p>{}</p>'.format(fake_title())
|
||||||
|
|
||||||
|
|
||||||
class BasePageFactory(wagtail_factories.PageFactory):
|
class BasePageFactory(wagtail_factories.PageFactory):
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
from user.factories import UserGroupFactory
|
||||||
|
|
||||||
|
# room_data = [{
|
||||||
|
# {
|
||||||
|
# 'title': 'Ein historisches Festival',
|
||||||
|
# 'type': 'red',
|
||||||
|
# 'group': 'Klasse 3b - 2018/2019'
|
||||||
|
# # 'entries': [1, 1, 1, 1, 1, 1]
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# 'title': 'Erfahrungen Lehrbeginn',
|
||||||
|
# 'type': 'green',
|
||||||
|
# 'group': 'Klasse 3b - 2018/2019'
|
||||||
|
# # 'entries': [1]
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# 'title': 'Interview «Mein neues Umfeld»',
|
||||||
|
# 'type': 'brown',
|
||||||
|
# 'group': 'Hans Muster und 12 weitere Personen'
|
||||||
|
# # 'entries': [1, 1, 1, 1, 1, 1]
|
||||||
|
# }
|
||||||
|
# }]
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
|
||||||
|
def ensure_clean_dir(self, folder):
|
||||||
|
path = os.path.join(settings.MEDIA_ROOT, folder)
|
||||||
|
if os.path.exists(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.makedirs(path)
|
||||||
|
|
||||||
|
def filter_data(self, input_data, 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):
|
||||||
|
# self.ensure_clean_dir('images')
|
||||||
|
# self.ensure_clean_dir('original_images')
|
||||||
|
# self.ensure_clean_dir('documents')
|
||||||
|
#
|
||||||
|
# site = wagtail_factories.SiteFactory.create(is_default_site=True)
|
||||||
|
# Page.objects.filter(title='Root').delete()
|
||||||
|
#
|
||||||
|
# u = UserFactory(
|
||||||
|
# username='test',
|
||||||
|
# is_staff=True,
|
||||||
|
# is_superuser=True
|
||||||
|
# )
|
||||||
|
|
||||||
|
for i in range(0, 6):
|
||||||
|
UserGroupFactory(users=(random.choices(get_user_model().objects.all(), k=3)))
|
||||||
|
|
||||||
|
# for book_idx, book_data in enumerate(data):
|
||||||
|
# book = BookFactory.create(parent=site.root_page, **self.filter_data(book_data, 'topics'))
|
||||||
|
#
|
||||||
|
# default_topics = [{} for i in range(0, random.randint(5, 8))]
|
||||||
|
# topics_data = book_data.get('topics', default_topics)
|
||||||
|
#
|
||||||
|
# for topic_idx, topic_data in enumerate(topics_data):
|
||||||
|
# topic = TopicFactory.create(parent=book, **self.filter_data(topic_data, 'modules'))
|
||||||
|
#
|
||||||
|
# default_modules = [{} for i in range(0, random.randint(3, 6))]
|
||||||
|
# modules_data = topic_data.get('modules', default_modules)
|
||||||
|
#
|
||||||
|
# for module_idx, module_data in enumerate(modules_data):
|
||||||
|
# module = ModuleFactory.create(parent=topic, **self.filter_data(module_data, ['objective_groups', 'chapters']))
|
||||||
|
#
|
||||||
|
# default_objective_groups = [{} for i in range(0, 2)]
|
||||||
|
# objective_group_data = module_data.get('objective_groups', default_objective_groups)
|
||||||
|
#
|
||||||
|
# for objective_group_idx, objective_group_entry in enumerate(objective_group_data):
|
||||||
|
# factory_params = self.filter_data(objective_group_entry, 'objectives')
|
||||||
|
# objective_group = ObjectiveGroupFactory.create(module=module,
|
||||||
|
# user=None,
|
||||||
|
# **factory_params)
|
||||||
|
#
|
||||||
|
# default_objectives = [{} for i in range(0, 4)]
|
||||||
|
# objectives_data = objective_group_entry.get('objectives', default_objectives)
|
||||||
|
#
|
||||||
|
# for objective_idx, objective_data in enumerate(objectives_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, 'contents'))
|
||||||
|
# ContentBlockFactory.create(parent=chapter, **content_block_data)
|
||||||
|
|
@ -48,7 +48,7 @@ INSTALLED_APPS = [
|
||||||
'user',
|
'user',
|
||||||
'book',
|
'book',
|
||||||
'objectives',
|
'objectives',
|
||||||
'news',
|
'rooms',
|
||||||
|
|
||||||
'wagtail.contrib.forms',
|
'wagtail.contrib.forms',
|
||||||
'wagtail.contrib.redirects',
|
'wagtail.contrib.redirects',
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
# Register your models here.
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -11,12 +11,11 @@ class ObjectiveGroup(models.Model):
|
||||||
verbose_name_plural = 'Lernziel Gruppen'
|
verbose_name_plural = 'Lernziel Gruppen'
|
||||||
|
|
||||||
title = models.CharField('title', blank=True, null=False, max_length=255)
|
title = models.CharField('title', blank=True, null=False, max_length=255)
|
||||||
|
|
||||||
module = models.ForeignKey(Module, blank=False, null=False, on_delete=models.CASCADE)
|
module = models.ForeignKey(Module, blank=False, null=False, on_delete=models.CASCADE)
|
||||||
# a user can define her own objectives, hence this optional param
|
# a user can define her own objectives, hence this optional param
|
||||||
user = models.ForeignKey(get_user_model(), blank=True, null=True, on_delete=models.CASCADE)
|
user = models.ForeignKey(get_user_model(), blank=True, null=True, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __unicode__(self):
|
||||||
return 'ObjectiveGroup {}-{}-{}'.format(self.id, self.module, self.title)
|
return 'ObjectiveGroup {}-{}-{}'.format(self.id, self.module, self.title)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -26,10 +25,9 @@ class Objective(models.Model):
|
||||||
verbose_name_plural = 'Lernziele'
|
verbose_name_plural = 'Lernziele'
|
||||||
|
|
||||||
text = models.CharField('text', blank=True, null=False, max_length=255)
|
text = models.CharField('text', blank=True, null=False, max_length=255)
|
||||||
|
|
||||||
group = models.ForeignKey(ObjectiveGroup, blank=False, null=False, on_delete=models.CASCADE)
|
group = models.ForeignKey(ObjectiveGroup, blank=False, null=False, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __unicode__(self):
|
||||||
return 'Objective {}-{}'.format(self.id, self.text)
|
return 'Objective {}-{}'.format(self.id, self.text)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,9 +37,8 @@ class ObjectiveProgressStatus(models.Model):
|
||||||
verbose_name_plural = 'Lernzielstatus'
|
verbose_name_plural = 'Lernzielstatus'
|
||||||
|
|
||||||
done = models.BooleanField('Lernziel erledigt?', default=False)
|
done = models.BooleanField('Lernziel erledigt?', default=False)
|
||||||
|
|
||||||
objective = models.ForeignKey(Objective, blank=False, null=False, on_delete=models.CASCADE)
|
objective = models.ForeignKey(Objective, blank=False, null=False, on_delete=models.CASCADE)
|
||||||
user = models.ForeignKey(get_user_model(), blank=True, null=True, on_delete=models.CASCADE)
|
user = models.ForeignKey(get_user_model(), blank=True, null=True, on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __unicode__(self):
|
||||||
return 'Lernzielstatus {}-{}'.format(self.objective, self.done)
|
return 'Lernzielstatus {}-{}'.format(self.objective, self.done)
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class NewsConfig(AppConfig):
|
class NewsConfig(AppConfig):
|
||||||
name = 'news'
|
name = 'rooms'
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
import factory
|
||||||
|
|
||||||
|
from core.factories import fake
|
||||||
|
from rooms.models import Room
|
||||||
|
from user.factories import UserGroupFactory
|
||||||
|
|
||||||
|
|
||||||
|
class RoomFactory(factory.django.DjangoModelFactory):
|
||||||
|
class Meta:
|
||||||
|
model = Room
|
||||||
|
|
||||||
|
title = factory.LazyAttribute(lambda x: fake.sentence(nb_words=random.randint(4, 8)))
|
||||||
|
user_group = factory.SubFactory(UserGroupFactory)
|
||||||
|
appearance = factory.LazyAttribute(lambda x: random.choice(['red', 'green', 'brown']))
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Generated by Django 2.0.6 on 2018-08-23 10:14
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('user', '0002_usergroup'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Room',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('title', models.CharField(blank=True, max_length=255)),
|
||||||
|
('appearance', models.CharField(blank=True, max_length=255)),
|
||||||
|
('user_group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='user.UserGroup')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Raum',
|
||||||
|
'verbose_name_plural': 'Räume',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
from django.db import models
|
||||||
|
from django_extensions.db.models import TitleDescriptionModel
|
||||||
|
|
||||||
|
from user.models import UserGroup
|
||||||
|
|
||||||
|
|
||||||
|
class Room(models.Model):
|
||||||
|
class Meta:
|
||||||
|
verbose_name = 'Raum'
|
||||||
|
verbose_name_plural = 'Räume'
|
||||||
|
|
||||||
|
title = models.CharField(blank=True, null=False, max_length=255)
|
||||||
|
user_group = models.ForeignKey(UserGroup, blank=False, null=False, on_delete=models.CASCADE)
|
||||||
|
appearance = models.CharField(blank=True, null=False, max_length=255)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return 'Room {}-{}-{}'.format(self.id, self.title, self.user_group)
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.admin import UserAdmin
|
from django.contrib.auth.admin import UserAdmin
|
||||||
|
|
||||||
from .models import User
|
from .models import User, UserGroup
|
||||||
|
|
||||||
admin.site.register(User, UserAdmin)
|
admin.site.register(User, UserAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(UserGroup)
|
||||||
|
class UserGroupAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('id', 'name', 'year')
|
||||||
|
list_filter = ('year',)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
import factory
|
||||||
|
|
||||||
|
from user.models import UserGroup
|
||||||
|
|
||||||
|
|
||||||
|
class UserGroupFactory(factory.django.DjangoModelFactory):
|
||||||
|
class Meta:
|
||||||
|
model = UserGroup
|
||||||
|
|
||||||
|
name = factory.Sequence(lambda n: 'Klasse {}{}'.format(n+1, random.choice(['a', 'b', 'c'])))
|
||||||
|
year = factory.LazyAttribute(lambda x: random.choice([2017, 2018, 2019]))
|
||||||
|
is_deleted = False
|
||||||
|
|
||||||
|
@factory.post_generation
|
||||||
|
def users(self, create, extracted, **kwargs):
|
||||||
|
if not create:
|
||||||
|
# Simple build, do nothing.
|
||||||
|
return
|
||||||
|
|
||||||
|
if extracted:
|
||||||
|
# A list of groups were passed in, use them
|
||||||
|
for user in extracted:
|
||||||
|
self.users.add(user)
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 2.0.6 on 2018-08-23 10:14
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('user', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UserGroup',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=100)),
|
||||||
|
('year', models.PositiveIntegerField(validators=[django.core.validators.MinValueValidator(1900), django.core.validators.MaxValueValidator(2200)])),
|
||||||
|
('is_deleted', models.BooleanField(default=False)),
|
||||||
|
('users', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,5 +1,18 @@
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class UserGroup(models.Model):
|
||||||
|
name = models.CharField(max_length=100, blank=False, null=False)
|
||||||
|
year = models.PositiveIntegerField(blank=False, null=False, validators=[MinValueValidator(1900), MaxValueValidator(2200)])
|
||||||
|
is_deleted = models.BooleanField(blank=False, null=False, default=False)
|
||||||
|
users = models.ManyToManyField(get_user_model())
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return 'ObjectiveGroup {}-{}-{}'.format(self.id, self.module, self.title)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue