How to use the kolibri.core.fields.DateTimeTzField function in kolibri

To help you get started, we’ve selected a few kolibri examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github learningequality / kolibri / kolibri / core / logger / models.py View on Github external
raise ValidationError("Content summary progress out of range (0-1)")

        super(ContentSummaryLog, self).save(*args, **kwargs)


class UserSessionLog(BaseLogModel):
    """
    This model provides a record of a user session in Kolibri.
    """

    # Morango syncing settings
    morango_model_name = "usersessionlog"

    user = models.ForeignKey(FacilityUser)
    channels = models.TextField(blank=True)
    start_timestamp = DateTimeTzField(default=local_now)
    last_interaction_timestamp = DateTimeTzField(null=True, blank=True)
    pages = models.TextField(blank=True)

    @classmethod
    def update_log(cls, user):
        """
        Update the current UserSessionLog for a particular user.
        """
        if user and isinstance(user, FacilityUser):
            try:
                user_session_log = cls.objects.filter(user=user).latest(
                    "last_interaction_timestamp"
                )
            except ObjectDoesNotExist:
                user_session_log = None
github learningequality / kolibri / kolibri / core / auth / migrations / 0003_auto_20170621_0958.py View on Github external
for model in Model.objects.all():
                model.save()
        except OperationalError:
            pass

class Migration(migrations.Migration):

    dependencies = [
        ('kolibriauth', '0002_auto_20170608_2125'),
    ]

    operations = [
        migrations.AlterField(
            model_name='deviceowner',
            name='date_joined',
            field=kolibri.core.fields.DateTimeTzField(default=kolibri.utils.time_utils.local_now, editable=False, verbose_name='date joined'),
        ),
        migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="DeviceOwner")),
        migrations.AlterField(
            model_name='facilityuser',
            name='date_joined',
            field=kolibri.core.fields.DateTimeTzField(default=kolibri.utils.time_utils.local_now, editable=False, verbose_name='date joined'),
        ),
        migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="FacilityUser")),
    ]
github learningequality / kolibri / kolibri / core / notifications / migrations / 0001_initial.py View on Github external
("user_id", morango.models.UUIDField()),
                ("classroom_id", morango.models.UUIDField()),
                ("contentnode_id", morango.models.UUIDField(null=True)),
                ("lesson_id", morango.models.UUIDField(null=True)),
                ("quiz_id", morango.models.UUIDField(null=True)),
                (
                    "reason",
                    models.CharField(
                        blank=True,
                        choices=[("Multiple", "MultipleUnsuccessfulAttempts")],
                        max_length=200,
                    ),
                ),
                (
                    "timestamp",
                    kolibri.core.fields.DateTimeTzField(
                        default=kolibri.utils.time_utils.local_now
                    ),
github learningequality / kolibri / kolibri / core / content / migrations / 0002_channelmetadatacache_last_updated.py View on Github external
from __future__ import unicode_literals

from django.db import migrations

import kolibri.core.fields


class Migration(migrations.Migration):

    dependencies = [("content", "0001_initial")]

    operations = [
        migrations.AddField(
            model_name="channelmetadatacache",
            name="last_updated",
            field=kolibri.core.fields.DateTimeTzField(null=True),
        )
github learningequality / kolibri / kolibri / core / serializers.py View on Github external
from rest_framework.serializers import set_value
from rest_framework.settings import api_settings

from .fields import DateTimeTzField as DjangoDateTimeTzField


class DateTimeTzField(DateTimeField):
    def to_internal_value(self, data):
        data = super(DateTimeTzField, self).to_internal_value(data)
        tz = timezone.get_current_timezone()
        if not data.tzinfo:
            data = timezone.make_aware(data, pytz.utc)
        return data.astimezone(tz)


serializer_field_mapping = {DjangoDateTimeTzField: DateTimeTzField}

serializer_field_mapping.update(ModelSerializer.serializer_field_mapping)


class KolibriModelSerializer(ModelSerializer):

    serializer_field_mapping = serializer_field_mapping

    def run_validation(self, data=empty):

        """
        We override the default `run_validation`, because the validation
        performed by validators and the `.validate()` method should
        be coerced into an error dictionary with a 'non_fields_error' key.
        """
        (is_empty_value, data) = self.validate_empty_values(data)
github learningequality / kolibri / kolibri / core / notifications / migrations / 0002_notificationslog.py View on Github external
migrations.CreateModel(
            name="NotificationsLog",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("coach_id", morango.models.UUIDField()),
                (
                    "timestamp",
                    kolibri.core.fields.DateTimeTzField(
                        default=kolibri.utils.time_utils.local_now
                    ),
github learningequality / kolibri / kolibri / core / content / migrations / 0004_auto_20170825_1038.py View on Github external
("number_of_assessments", models.IntegerField()),
                ("mastery_model", kolibri.core.fields.JSONField(default={})),
                ("randomize", models.BooleanField(default=False)),
                ("is_manipulable", models.BooleanField(default=False)),
            ],
        ),
        migrations.CreateModel(
            name="ChannelMetadata",
            fields=[
                ("id", morango.models.UUIDField(primary_key=True, serialize=False)),
                ("name", models.CharField(max_length=200)),
                ("description", models.CharField(blank=True, max_length=400)),
                ("author", models.CharField(blank=True, max_length=400)),
                ("version", models.IntegerField(default=0)),
                ("thumbnail", models.TextField(blank=True)),
                ("last_updated", kolibri.core.fields.DateTimeTzField(null=True)),
                ("min_schema_version", models.CharField(max_length=50)),
            ],
        ),
        migrations.CreateModel(
            name="ContentNode",
            fields=[
                ("id", morango.models.UUIDField(primary_key=True, serialize=False)),
                ("title", models.CharField(max_length=200)),
                ("content_id", morango.models.UUIDField(db_index=True)),
                ("channel_id", morango.models.UUIDField(db_index=True)),
                (
                    "description",
                    models.CharField(blank=True, max_length=400, null=True),
                ),
                ("sort_order", models.FloatField(blank=True, null=True)),
                ("license_owner", models.CharField(blank=True, max_length=200)),
github learningequality / kolibri / kolibri / core / logger / migrations / 0002_auto_20170518_1031.py View on Github external
),
        migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="ExamLog")),
        migrations.AlterField(
            model_name='masterylog',
            name='completion_timestamp',
            field=kolibri.core.fields.DateTimeTzField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='masterylog',
            name='end_timestamp',
            field=kolibri.core.fields.DateTimeTzField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='masterylog',
            name='start_timestamp',
            field=kolibri.core.fields.DateTimeTzField(),
        ),
        migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="MasteryLog")),
        migrations.AlterField(
            model_name='usersessionlog',
            name='last_interaction_timestamp',
            field=kolibri.core.fields.DateTimeTzField(null=True),
        ),
        migrations.AlterField(
            model_name='usersessionlog',
            name='start_timestamp',
            field=kolibri.core.fields.DateTimeTzField(default=kolibri.utils.time_utils.local_now),
        ),
        migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="UserSessionLog")),
    ]
github learningequality / kolibri / kolibri / core / logger / migrations / 0002_auto_20170518_1031.py View on Github external
migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="AttemptLog")),
        migrations.AlterField(
            model_name='contentsessionlog',
            name='end_timestamp',
            field=kolibri.core.fields.DateTimeTzField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='contentsessionlog',
            name='start_timestamp',
            field=kolibri.core.fields.DateTimeTzField(),
        ),
        migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="ContentSessionLog")),
        migrations.AlterField(
            model_name='contentsummarylog',
            name='completion_timestamp',
            field=kolibri.core.fields.DateTimeTzField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='contentsummarylog',
            name='end_timestamp',
            field=kolibri.core.fields.DateTimeTzField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='contentsummarylog',
            name='start_timestamp',
            field=kolibri.core.fields.DateTimeTzField(),
        ),
        migrations.RunPython(partial(convert_datetime_to_datetimetz, model_name="ContentSummaryLog")),
        migrations.AlterField(
            model_name='examattemptlog',
            name='completion_timestamp',
            field=kolibri.core.fields.DateTimeTzField(blank=True, null=True),