Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facility user model modifications #4

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions kolibri/core/auth/constants/demographics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import unicode_literals

MALE = "MALE"
FEMALE = "FEMALE"
NOT_SPECIFIED = "NOT_SPECIFIED"
DEFERRED = "DEFERRED"


choices = (
(MALE, "Male"),
(FEMALE, "Female"),
(NOT_SPECIFIED, "Not specified"),
(DEFERRED, "Defers for later"),
)

DEMO_FIELDS = ("gender", "birth_year", "id_number")
36 changes: 36 additions & 0 deletions kolibri/core/auth/migrations/0016_auto_20220907_1512.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2022-09-07 13:12
from __future__ import unicode_literals

from django.db import migrations, models
import kolibri.core.auth.models


class Migration(migrations.Migration):

dependencies = [
('kolibriauth', '0015_facilityuser_deleted'),
]

operations = [
migrations.AddField(
model_name='facilityuser',
name='birth_year',
field=models.CharField(blank=True, default='', max_length=16, validators=[kolibri.core.auth.models.validate_birth_year]),
),
migrations.AddField(
model_name='facilityuser',
name='exam_number',
field=models.CharField(blank=True, default='', max_length=64),
),
migrations.AddField(
model_name='facilityuser',
name='gender',
field=models.CharField(blank=True, choices=[('MALE', 'Male'), ('FEMALE', 'Female'), ('NOT_SPECIFIED', 'Not specified'), ('DEFERRED', 'Defers for later')], default='', max_length=16),
),
migrations.AddField(
model_name='facilityuser',
name='grade',
field=models.CharField(blank=True, default='', max_length=15),
),
]
41 changes: 41 additions & 0 deletions kolibri/core/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
from .permissions.general import IsFromSameFacility
from .permissions.general import IsOwn
from .permissions.general import IsSelf
from kolibri.core.auth.constants.demographics import choices as GENDER_CHOICES
from kolibri.core.auth.constants.demographics import DEFERRED
from kolibri.core.auth.constants.morango_scope_definitions import FULL_FACILITY
from kolibri.core.auth.constants.morango_scope_definitions import SINGLE_USER
from kolibri.core.errors import KolibriValidationError
Expand Down Expand Up @@ -526,6 +528,33 @@ def create_superuser(self, username, password):
# make the user into a superuser on this device
DevicePermissions.objects.create(user=superuser, is_superuser=True)

def validate_birth_year(value):
error = ""

if value == "NOT_SPECIFIED" or value == "DEFERRED":
return

try:
if int(value) < 1900:
error = (
"Birth year {value} is invalid, as it is prior to the year 1900".format(
value=value
)
)

elif int(value) > 3000:
error = (
"Birth year {value} is invalid, as it is after the year 3000".format(
value=value
)
)

except ValueError:
error = "{value} is not a valid value for birth_year".format(value=value)

if error != "":
raise ValidationError(error)


@python_2_unicode_compatible
class FacilityUser(KolibriAbstractBaseUser, AbstractFacilityDataModel):
Expand Down Expand Up @@ -556,6 +585,18 @@ class FacilityUser(KolibriAbstractBaseUser, AbstractFacilityDataModel):

deleted = models.BooleanField(default=False)

gender = models.CharField(
max_length=16, choices=GENDER_CHOICES, default="", blank=True
)

birth_year = models.CharField(
max_length=16, default="", validators=[validate_birth_year], blank=True
)
exam_number = models.CharField(max_length=64, default="", blank=True)

grade = models.CharField(max_length=15,default="", blank=True)


@property
def is_deleted(self):
return self.deleted
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/edulution/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf.urls import url
from rest_framework import routers

from ..learn.api_urls import urlpatterns as learnurlpatterns
from learn.api_urls import urlpatterns as learnurlpatterns
from .viewsets import KnowledgeMapViewset

router = routers.SimpleRouter()
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/edulution/assets/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import router from 'kolibri.coreVue.router';
import {
setFacilitiesAndConfig,
prepareLearnApp,
} from '../../../learn/assets/src/modules/coreLearn/actions';
} from '../../learn/assets/src/modules/coreLearn/actions';
import RootVue from './views/EdulutionIndex';
import routes from './routes';
import pluginModule from './modules/pluginModule';
Expand Down
50 changes: 24 additions & 26 deletions kolibri/plugins/edulution/assets/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
RecommendedPages as LearnRecommendedPage,
ClassesPageNames as LearnClassesPageNames,
pageNameToModuleMap as learnPageNameToModuleMap,
} from '../../../learn/assets/src/constants';
} from '../../learn/assets/src/constants';

export const PageNames = {
...LearnPageNames,
Expand Down Expand Up @@ -78,32 +78,30 @@ export const prefixToColourMap = {
accent: '#E91E63',*/
},
/*colors for new courses*/
'level 1': {
light: '#D1DDE6',
dark: '#0072CE',
accent: '#6CACE4',
},
'level 2': {
light: '#D4EBBE',
dark: '#509E2F',
accent: '#84BD00',
},
'level 3': {
light: '#E0DBE3',
dark: '#440099',
accent: '#7474C1',

},
'level 1': {
light: '#D1DDE6',
dark: '#0072CE',
accent: '#6CACE4',
},
'level 2': {
light: '#D4EBBE',
dark: '#509E2F',
accent: '#84BD00',
},
'level 3': {
light: '#E0DBE3',
dark: '#440099',
accent: '#7474C1',
},


'level 4': {
light: '#BBDDE6',
dark: '#004B87',
accent: '#005EB8',
'level 4': {
light: '#BBDDE6',
dark: '#004B87',
accent: '#005EB8',
},
'level 5': {
light: '#F9E547',
dark: '#FFA300',
accent: '#FFC72C',
},
light: '#F9E547',
dark: '#FFA300',
accent: '#FFC72C',
},
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PageNames, PageModes } from '../../constants';
import { pageMode as learnPageMode } from '../../../../../learn/assets/src/modules/coreLearn/getters';
import { pageMode as learnPageMode } from '../../../../learn/assets/src/modules/coreLearn/getters';

export function pageMode(state) {
const mode = learnPageMode(state);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pluginModule from '../../../../learn/assets/src/modules/pluginModule';
import pluginModule from '../../../learn/assets/src/modules/pluginModule';
import * as getters from './coreLearn/getters';
import topicsTree from './topicsTree';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
ClassroomResource,
LearnerGroupResource,
} from 'kolibri.resources';
import { LearnerClassroomResource } from '../../../../../learn/assets/src/apiResources';
import { LearnerClassroomResource } from '../../../../learn/assets/src/apiResources';
import { PageNames } from '../../constants';
import { _collectionState } from '../../../../../learn/assets/src/modules/coreLearn/utils';
import { _collectionState } from '../../../../learn/assets/src/modules/coreLearn/utils';

function displaySubscribedChannels(store, channels, channelRootIds, include_fields) {
ContentNodeSlimResource.fetchCollection({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PageNames } from '../../constants';
import {
_collectionState,
normalizeContentNode,
} from '../../../../../learn/assets/src/modules/coreLearn/utils';
} from '../../../../learn/assets/src/modules/coreLearn/utils';
import { KnowledgeMapResource } from '../../apiResources';

export function showKnowledgeMap(store, id) {
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/edulution/assets/src/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import store from 'kolibri.coreVue.vuex.store';
import { showKnowledgeMap } from '../modules/topicsTree/handlers';
import { PageNames } from '../constants';
import routes from '../../../../learn/assets/src/routes';
import routes from '../../../learn/assets/src/routes';
import { showChannels } from '../modules/topicsRoot/handlers';

export default [
Expand Down
2 changes: 1 addition & 1 deletion kolibri/plugins/edulution/assets/src/views/Breadcrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { mapState, mapGetters } from 'vuex';
import KBreadcrumbs from 'kolibri.coreVue.components.KBreadcrumbs';
import { PageNames, PageModes } from '../constants';
import classesBreadcrumbItems from '../../../../learn/assets/src/views/classes/classesBreadcrumbItems';
import classesBreadcrumbItems from '../../../learn/assets/src/views/classes/classesBreadcrumbItems';

export default {
name: 'Breadcrumbs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import { mapState } from 'vuex';
import { PageNames } from '../constants';
import PageHeader from '../../../../learn/assets/src/views/PageHeader';
import PageHeader from '../../../learn/assets/src/views/PageHeader';
import ContentCardGroupGrid from './ContentCardGroupGrid';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import { validateLinkObject } from 'kolibri.utils.validators';
import responsiveWindow from 'kolibri.coreVue.mixins.responsiveWindow';
import CopiesModal from '../../../../learn/assets/src/views/CopiesModal';
import CopiesModal from '../../../learn/assets/src/views/CopiesModal';
import EdulutionContentCard from './EdulutionContentCard';

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import CoachContentLabel from 'kolibri.coreVue.components.CoachContentLabel';
import TextTruncator from 'kolibri.coreVue.components.TextTruncator';
import KButton from 'kolibri.coreVue.components.KButton';
import CardThumbnail from '../../../../learn/assets/src/views/ContentCard/CardThumbnail';
import CardThumbnail from '../../../learn/assets/src/views/ContentCard/CardThumbnail';
import ToggledRouterLink from './ToggledRouterLink';

export default {
Expand Down Expand Up @@ -155,7 +155,7 @@
<style lang="scss" scoped>

@import '~kolibri.styles.definitions';
@import '../../../../learn/assets/src/views/ContentCard/card';
@import '../../../learn/assets/src/views/ContentCard/card';

$margin: 16px;

Expand Down
28 changes: 14 additions & 14 deletions kolibri/plugins/edulution/assets/src/views/EdulutionIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
import responsiveWindow from 'kolibri.coreVue.mixins.responsiveWindow';
import CoreBase from 'kolibri.coreVue.components.CoreBase';
import store from 'kolibri.coreVue.vuex.store';
import ContentPage from '../../../../learn/assets/src/views/ContentPage';
import ContentPage from '../../../learn/assets/src/views/ContentPage';
import { PageNames, RecommendedPages, ClassesPageNames, pageNameToModuleMap } from '../constants';
import LessonResourceViewer from '../../../../learn/assets/src/views/classes/LessonResourceViewer';
import RecommendedPage from '../../../../learn/assets/src/views/RecommendedPage';
import TotalPoints from '../../../../learn/assets/src/views/TotalPoints';
import TopicsPage from '../../../../learn/assets/src/views/TopicsPage';
import SearchPage from '../../../../learn/assets/src/views/SearchPage';
import ActionBarSearchBox from '../../../../learn/assets/src/views/ActionBarSearchBox';
import RecommendedSubpage from '../../../../learn/assets/src/views/RecommendedSubpage';
import ExamReportViewer from '../../../../learn/assets/src/views/LearnExamReportViewer';
import ExamPage from '../../../../learn/assets/src/views/ExamPage';
import AllClassesPage from '../../../../learn/assets/src/views/classes/AllClassesPage';
import ClassAssignmentsPage from '../../../../learn/assets/src/views/classes/ClassAssignmentsPage';
import LessonPlaylistPage from '../../../../learn/assets/src/views/classes/LessonPlaylistPage';
import ContentUnavailablePage from '../../../../learn/assets/src/views/ContentUnavailablePage';
import LessonResourceViewer from '../../../learn/assets/src/views/classes/LessonResourceViewer';
import RecommendedPage from '../../../learn/assets/src/views/RecommendedPage';
import TotalPoints from '../../../learn/assets/src/views/TotalPoints';
import TopicsPage from '../../../learn/assets/src/views/TopicsPage';
import SearchPage from '../../../learn/assets/src/views/SearchPage';
import ActionBarSearchBox from '../../../learn/assets/src/views/ActionBarSearchBox';
import RecommendedSubpage from '../../../learn/assets/src/views/RecommendedSubpage';
import ExamReportViewer from '../../../learn/assets/src/views/LearnExamReportViewer';
import ExamPage from '../../../learn/assets/src/views/ExamPage';
import AllClassesPage from '../../../learn/assets/src/views/classes/AllClassesPage';
import ClassAssignmentsPage from '../../../learn/assets/src/views/classes/ClassAssignmentsPage';
import LessonPlaylistPage from '../../../learn/assets/src/views/classes/LessonPlaylistPage';
import ContentUnavailablePage from '../../../learn/assets/src/views/ContentUnavailablePage';
import { THEME_MODULE_NAMESPACE } from '../../../../../core/assets/src/state/modules/theme';
import ChannelsPage from './ChannelsPage';
import Breadcrumbs from './Breadcrumbs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import ContentIcon from 'kolibri.coreVue.components.ContentIcon';
import UiIconButton from 'kolibri.coreVue.components.UiIconButton';
import { PageNames } from '../constants';
import PageHeader from '../../../../learn/assets/src/views/PageHeader';
import PageHeader from '../../../learn/assets/src/views/PageHeader';
import ContentCardGroupGrid from './ContentCardGroupGrid';

export default {
Expand Down Expand Up @@ -124,7 +124,7 @@

<style lang="scss">

@import '../../../../learn/assets/src/views/ContentCard/card';
@import '../../../learn/assets/src/views/ContentCard/card';

.collapsible-grid {
margin-bottom: 8px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<style lang="scss" scoped>

@import '~kolibri.styles.definitions';
@import '../../../../learn/assets/src/views/ContentCard/card';
@import '../../../learn/assets/src/views/ContentCard/card';

$margin: 16px;

Expand Down
Empty file.
14 changes: 14 additions & 0 deletions kolibri/plugins/edulution/learn/api_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.conf.urls import include
from django.conf.urls import url
from rest_framework import routers

from .viewsets import LearnerClassroomViewset
from .viewsets import LearnerLessonViewset

router = routers.SimpleRouter()
router.register(r'learnerclassroom', LearnerClassroomViewset, base_name='learnerclassroom')
router.register(r'learnerlesson', LearnerLessonViewset, base_name='learnerlesson')

urlpatterns = [
url(r'^', include(router.urls)),
]
22 changes: 22 additions & 0 deletions kolibri/plugins/edulution/learn/assets/src/apiResources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Resource } from 'kolibri.lib.apiResource';

/**
* Gets all of the Classrooms in which a Learner is enrolled
*
* @example To get Classrooms without assignments and progress:
* LearnerClassroomResource.fetchCollection({
* getParams: { no_assignments: true },
* })
*/
export const LearnerClassroomResource = new Resource({
name: 'learnerclassroom',
namespace: 'learnplugin',
});

/**
* Gets Lesson(s) that are assigned to the Learner
*/
export const LearnerLessonResource = new Resource({
name: 'learnerlesson',
namespace: 'learnplugin',
});
Loading