Add last visited module to user

This commit is contained in:
Ramon Wenger 2019-03-01 11:19:43 +01:00
parent b86b1eea37
commit 10b35a5a3e
7 changed files with 85 additions and 8 deletions

View File

@ -7,6 +7,10 @@ fragment UserParts on UserNode {
firstName
lastName
avatar
lastModule {
id
slug
}
schoolClasses {
edges {
node {

View File

@ -7,8 +7,8 @@
class="start-sections__section"
title="Inhalte"
subtitle="Neues Wissen erwerben"
link-text="Alle Inhalte anzeigen"
route="/book/topic/geld-und-kauf"
:link-text="moduleText"
:route="moduleRoute"
>
<contents-illustration></contents-illustration>
</section-block>
@ -53,6 +53,8 @@
import PortfolioIllustration from '@/components/illustrations/PortfolioIllustration';
import RoomsIllustration from '@/components/illustrations/RoomsIllustration';
import {meQuery} from '@/graphql/queries';
export default {
components: {
SectionBlock,
@ -62,7 +64,24 @@
RoomsIllustration
},
computed: {},
computed: {
moduleRoute() {
if (this.me.lastModule && this.me.lastModule.slug) {
return `/module/${this.me.lastModule.slug}`;
}
return '/book/topic/geld-und-kauf';
},
moduleText() {
if (this.me.lastModule && this.me.lastModule.slug) {
return 'Aktuelles Modul anzeigen';
}
return 'Alle Inhalte anzeigen'
}
},
apollo: {
me: meQuery
}
}
</script>

View File

@ -0,0 +1,23 @@
# Generated by Django 2.0.6 on 2019-03-01 09:54
import assignments.models
from django.db import migrations
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.images.blocks
import wagtail.snippets.blocks
class Migration(migrations.Migration):
dependencies = [
('books', '0007_auto_20190205_1529'),
]
operations = [
migrations.AlterField(
model_name='contentblock',
name='contents',
field=wagtail.core.fields.StreamField([('text_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())])), ('basic_knowledge', wagtail.core.blocks.StructBlock([('description', wagtail.core.blocks.RichTextBlock()), ('basic_knowledge', wagtail.core.blocks.PageChooserBlock(required=True, target_model=['basicknowledge.BasicKnowledge']))])), ('assignment', wagtail.core.blocks.StructBlock([('assignment_id', wagtail.snippets.blocks.SnippetChooserBlock(assignments.models.Assignment))])), ('image_block', wagtail.images.blocks.ImageChooserBlock()), ('image_url_block', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('link_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('solution', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())], icon='tick')), ('video_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('document_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('infogram_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock()), ('title', wagtail.core.blocks.TextBlock())])), ('genially_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())]))], blank=True, null=True),
),
]

View File

@ -199,12 +199,21 @@ class BookQuery(object):
def resolve_module(self, info, **kwargs):
slug = kwargs.get('slug')
id = kwargs.get('id')
# save last visited module in user
user = info.context.user
module = None
if id is not None:
return get_object(Module, id)
if slug is not None:
return Module.objects.get(slug=slug)
return None
module = get_object(Module, id)
elif slug is not None:
module = Module.objects.get(slug=slug)
if module is not None:
user.last_module = module
user.save()
return module
def resolve_topic(self, info, **kwargs):
slug = kwargs.get('slug')

View File

@ -0,0 +1,20 @@
# Generated by Django 2.0.6 on 2019-03-01 09:54
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('books', '0008_auto_20190301_0954'),
('users', '0002_auto_20181017_1340'),
]
operations = [
migrations.AddField(
model_name='user',
name='last_module',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='books.Module'),
),
]

View File

@ -11,6 +11,8 @@ DEFAULT_SCHOOL_ID = 1
class User(AbstractUser):
last_module = models.ForeignKey('books.Module', related_name='+', on_delete=models.SET_NULL, null=True)
def get_role_permissions(self):
perms = set()
for role in Role.objects.get_roles_for_user(self):

View File

@ -14,7 +14,7 @@ class UserNode(DjangoObjectType):
class Meta:
model = User
filter_fields = ['username', 'email']
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', ]
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', 'last_module']
interfaces = (relay.Node,)
def resolve_pk(self, info, **kwargs):