Add notes app and a PoC for highlights

This commit is contained in:
Ramon Wenger 2019-10-02 11:38:53 +02:00
parent 90598342b8
commit 584b48a6a6
13 changed files with 98 additions and 1 deletions

View File

@ -6,6 +6,7 @@ fragment ContentBlockParts on ContentBlockNode {
contents contents
userCreated userCreated
mine mine
highlights
hiddenFor { hiddenFor {
edges { edges {
node { node {

View File

@ -0,0 +1,21 @@
# Generated by Django 2.0.6 on 2019-10-01 13:25
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('notes', '0001_initial'),
('books', '0014_auto_20190912_1228'),
]
operations = [
migrations.AddField(
model_name='contentblock',
name='highlights',
field=models.ManyToManyField(related_name='highlighted_content_blocks', through='notes.ContentBlockHighlight', to=settings.AUTH_USER_MODEL),
),
]

View File

@ -10,8 +10,9 @@ from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock,
ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock
from books.utils import get_type_and_value from books.utils import get_type_and_value
from core.wagtail_utils import StrictHierarchyPage from core.wagtail_utils import StrictHierarchyPage
from notes.models import Highlight, ContentBlockHighlight
from surveys.models import Survey from surveys.models import Survey
from users.models import SchoolClass from users.models import SchoolClass, User
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -33,10 +34,14 @@ class ContentBlock(StrictHierarchyPage):
(BASE_SOCIETY, 'Instrument Gesellschaft'), (BASE_SOCIETY, 'Instrument Gesellschaft'),
) )
# blocks without owner are visible by default, need to be hidden for each class
hidden_for = models.ManyToManyField(SchoolClass, related_name='hidden_content_blocks') hidden_for = models.ManyToManyField(SchoolClass, related_name='hidden_content_blocks')
# blocks with owner are hidden by default, need to be shown for each class
visible_for = models.ManyToManyField(SchoolClass, related_name='visible_content_blocks') visible_for = models.ManyToManyField(SchoolClass, related_name='visible_content_blocks')
user_created = models.BooleanField(default=False) user_created = models.BooleanField(default=False)
highlights = models.ManyToManyField(User, through=ContentBlockHighlight, related_name='highlighted_content_blocks')
content_blocks = [ content_blocks = [
('text_block', TextBlock()), ('text_block', TextBlock()),
('basic_knowledge', BasicKnowledgeBlock()), ('basic_knowledge', BasicKnowledgeBlock()),

View File

@ -5,6 +5,7 @@ from graphene_django.filter import DjangoFilterConnectionField
from api.utils import get_object from api.utils import get_object
from books.utils import are_solutions_enabled_for from books.utils import are_solutions_enabled_for
from notes.models import ContentBlockHighlight
from rooms.models import ModuleRoomSlug from rooms.models import ModuleRoomSlug
from ..models import Book, Topic, Module, Chapter, ContentBlock from ..models import Book, Topic, Module, Chapter, ContentBlock
@ -24,6 +25,7 @@ def process_module_room_slug_block(content):
class ContentBlockNode(DjangoObjectType): class ContentBlockNode(DjangoObjectType):
mine = graphene.Boolean() mine = graphene.Boolean()
highlights = graphene.List(graphene.String)
class Meta: class Meta:
model = ContentBlock model = ContentBlock
@ -54,6 +56,12 @@ class ContentBlockNode(DjangoObjectType):
self.contents.stream_data = updated_stream_data self.contents.stream_data = updated_stream_data
return self.contents return self.contents
def resolve_highlights(self, info, **kwargs):
return [highlight.id for highlight in ContentBlockHighlight.objects.filter(
user=info.context.user,
content_block=self
)]
class ChapterNode(DjangoObjectType): class ChapterNode(DjangoObjectType):
content_blocks = DjangoFilterConnectionField(ContentBlockNode) content_blocks = DjangoFilterConnectionField(ContentBlockNode)

View File

@ -54,6 +54,7 @@ INSTALLED_APPS = [
'portfolio', 'portfolio',
'statistics', 'statistics',
'surveys', 'surveys',
'notes',
'wagtail.contrib.forms', 'wagtail.contrib.forms',
'wagtail.contrib.redirects', 'wagtail.contrib.redirects',

0
server/notes/__init__.py Normal file
View File

3
server/notes/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
server/notes/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class NotesConfig(AppConfig):
name = 'notes'

View File

@ -0,0 +1,29 @@
# Generated by Django 2.0.6 on 2019-10-01 13:25
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('books', '0014_auto_20190912_1228'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='ContentBlockHighlight',
fields=[
('id', models.UUIDField(primary_key=True, serialize=False)),
('content_block', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='books.ContentBlock')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]

View File

18
server/notes/models.py Normal file
View File

@ -0,0 +1,18 @@
from django.db import models
# Create your models here.
from core.wagtail_utils import StrictHierarchyPage
from users.models import User
# todo: change from Highlight to Bookmark / Note (tbd)
class Highlight(models.Model):
id = models.UUIDField(primary_key=True)
user = models.ForeignKey(User, on_delete=models.CASCADE)
class Meta:
abstract = True
class ContentBlockHighlight(Highlight):
content_block = models.ForeignKey('books.ContentBlock', on_delete=models.CASCADE)

3
server/notes/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
server/notes/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.