Ejemplo n.º 1
0
class MigrateVerifiedTrackCohortsSetting(ConfigurationModel):
    """
    Configuration for the swap_from_auto_track_cohorts management command.
    """
    class Meta(object):
        app_label = "verified_track_content"

    old_course_key = CourseKeyField(
        max_length=255,
        blank=False,
        help_text="Course key for which to migrate verified track cohorts from"
    )
    rerun_course_key = CourseKeyField(
        max_length=255,
        blank=False,
        help_text="Course key for which to migrate verified track cohorts to enrollment tracks to"
    )
    audit_cohort_names = models.TextField(
        help_text="Comma-separated list of audit cohort names"
    )

    @classmethod
    def get_audit_cohort_names(cls):
        """Get the list of audit cohort names for the course"""
        return [cohort_name for cohort_name in cls.current().audit_cohort_names.split(",") if cohort_name]
Ejemplo n.º 2
0
class CourseCohortsSettings(models.Model):
    """
    This model represents cohort settings for courses.
    """
    is_cohorted = models.BooleanField(default=False)

    course_id = CourseKeyField(
        unique=True,
        max_length=255,
        db_index=True,
        help_text="Which course are these settings associated with?",
    )

    _cohorted_discussions = models.TextField(db_column='cohorted_discussions',
                                             null=True,
                                             blank=True)  # JSON list

    # pylint: disable=invalid-name
    always_cohort_inline_discussions = models.BooleanField(default=True)

    @property
    def cohorted_discussions(self):
        """Jsonify the cohorted_discussions"""
        return json.loads(self._cohorted_discussions)

    @cohorted_discussions.setter
    def cohorted_discussions(self, value):
        """Un-Jsonify the cohorted_discussions"""
        self._cohorted_discussions = json.dumps(value)
Ejemplo n.º 3
0
class CourseModesArchive(models.Model):
    """
    Store the past values of course_mode that a course had in the past. We decided on having
    separate model, because there is a uniqueness contraint on (course_mode, course_id)
    field pair in CourseModes. Having a separate table allows us to have an audit trail of any changes
    such as course price changes
    """
    class Meta(object):
        app_label = "course_modes"

    # the course that this mode is attached to
    course_id = CourseKeyField(max_length=255, db_index=True)

    # the reference to this mode that can be used by Enrollments to generate
    # similar behavior for the same slug across courses
    mode_slug = models.CharField(max_length=100)

    # The 'pretty' name that can be translated and displayed
    mode_display_name = models.CharField(max_length=255)

    # minimum price in USD that we would like to charge for this mode of the course
    min_price = models.IntegerField(default=0)

    # the suggested prices for this mode
    suggested_prices = models.CommaSeparatedIntegerField(max_length=255, blank=True, default='')

    # the currency these prices are in, using lower case ISO currency codes
    currency = models.CharField(default="usd", max_length=8)

    # turn this mode off after the given expiration date
    expiration_date = models.DateField(default=None, null=True, blank=True)

    expiration_datetime = models.DateTimeField(default=None, null=True, blank=True)
Ejemplo n.º 4
0
class ContractItem(models.Model):
    """
    D:\PycharmProject\NativestackEdxDoc\app\edxapp\edx-platform\common\djangoapps\student\models.py +990
    """
    course_id = CourseKeyField(max_length=255, db_index=True)
    start_date = models.DateField(blank=True, null=True, verbose_name=u"开始日期")
    end_date = models.DateField(blank=True, null=True, verbose_name=u"结束日期")
    contract = models.ForeignKey(MosoContract,
                                 blank=True,
                                 null=True,
                                 related_name='in_contract',
                                 verbose_name=u"隶属合同")
    students = models.ManyToManyField(User,
                                      blank=True,
                                      null=True,
                                      verbose_name=u"包含学员",
                                      related_name="student_contractitem")

    def __unicode__(self):
        """
          File "/edx/app/edxapp/edx-platform/lms/djangoapps/mosoadmin/models.py", line 92, in __unicode__
                return "  {}   " % self.contract.code
            TypeError: not all arguments converted during string formatting
        字符串格式化处理中文时,优选 % 且加 u''
        """
        return u"隶属于 %s 合同" % self.contract.code
Ejemplo n.º 5
0
class CourseDiscussionSettings(models.Model):
    course_id = CourseKeyField(
        unique=True,
        max_length=255,
        db_index=True,
        help_text="Which course are these settings associated with?",
    )
    always_divide_inline_discussions = models.BooleanField(default=False)
    _divided_discussions = models.TextField(db_column='divided_discussions',
                                            null=True,
                                            blank=True)  # JSON list

    COHORT = 'cohort'
    ENROLLMENT_TRACK = 'enrollment_track'
    NONE = 'none'
    ASSIGNMENT_TYPE_CHOICES = ((NONE, 'None'), (COHORT, 'Cohort'),
                               (ENROLLMENT_TRACK, 'Enrollment Track'))
    division_scheme = models.CharField(max_length=20,
                                       choices=ASSIGNMENT_TYPE_CHOICES,
                                       default=NONE)

    @property
    def divided_discussions(self):
        """Jsonify the divided_discussions"""
        return json.loads(self._divided_discussions)

    @divided_discussions.setter
    def divided_discussions(self, value):
        """Un-Jsonify the divided_discussions"""
        self._divided_discussions = json.dumps(value)
Ejemplo n.º 6
0
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='InstructorTask',
            fields=[
                ('id',
                 models.AutoField(verbose_name='ID',
                                  serialize=False,
                                  auto_created=True,
                                  primary_key=True)),
                ('task_type', models.CharField(max_length=50, db_index=True)),
                ('course_id', CourseKeyField(max_length=255, db_index=True)),
                ('task_key', models.CharField(max_length=255, db_index=True)),
                ('task_input', models.CharField(max_length=255)),
                ('task_id', models.CharField(max_length=255, db_index=True)),
                ('task_state',
                 models.CharField(max_length=50, null=True, db_index=True)),
                ('task_output', models.CharField(max_length=1024, null=True)),
                ('created', models.DateTimeField(auto_now_add=True,
                                                 null=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('subtasks', models.TextField(blank=True)),
                ('requester', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
Ejemplo n.º 7
0
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Note',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('course_id', CourseKeyField(max_length=255, db_index=True)),
                ('uri', models.CharField(max_length=255, db_index=True)),
                ('text', models.TextField(default=b'')),
                ('quote', models.TextField(default=b'')),
                ('range_start', models.CharField(max_length=2048)),
                ('range_start_offset', models.IntegerField()),
                ('range_end', models.CharField(max_length=2048)),
                ('range_end_offset', models.IntegerField()),
                ('tags', models.TextField(default=b'')),
                ('created', models.DateTimeField(db_index=True, auto_now_add=True, null=True)),
                ('updated', models.DateTimeField(auto_now=True, db_index=True)),
                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
Ejemplo n.º 8
0
class CourseAuthorization(models.Model):
    """
    Enable the course email feature on a course-by-course basis.
    """
    class Meta(object):
        app_label = "bulk_email"

    # The course that these features are attached to.
    course_id = CourseKeyField(max_length=255, db_index=True, unique=True)

    # Whether or not to enable instructor email
    email_enabled = models.BooleanField(default=False)

    @classmethod
    def instructor_email_enabled(cls, course_id):
        """
        Returns whether or not email is enabled for the given course id.
        """
        try:
            record = cls.objects.get(course_id=course_id)
            return record.email_enabled
        except cls.DoesNotExist:
            return False

    def __unicode__(self):
        not_en = "Not "
        if self.email_enabled:
            not_en = ""
        # pylint: disable=no-member
        return u"Course '{}': Instructor Email {}Enabled".format(
            text_type(self.course_id), not_en)
Ejemplo n.º 9
0
class UnregisteredLearnerCohortAssignments(models.Model):
    class Meta(object):
        unique_together = (('course_id', 'email'), )

    course_user_group = models.ForeignKey(CourseUserGroup)
    email = models.CharField(blank=True, max_length=255, db_index=True)
    course_id = CourseKeyField(max_length=255)
Ejemplo n.º 10
0
class CoursePreference(models.Model):
    """
    This is a place to keep course preferences that are not inherent to the course.  Those should be attributes
    of the course xmodule (advanced settings).
    A good example is whether this course allows nonregistered users to access it.
    """
    course_id = CourseKeyField(max_length=255, db_index=True)
    pref_key = models.CharField(max_length=255)
    pref_value = models.CharField(max_length=255, null=True)

    class Meta:
        app_label = 'courseware'
        unique_together = (('course_id', 'pref_key'))

    @classmethod
    def get_pref_value(cls, course_id, pref_key):
        try:
            return cls.objects.get(course_id=course_id,
                                   pref_key=pref_key).pref_value
        except cls.DoesNotExist:
            return None

    @classmethod
    def course_allows_nonregistered_access(cls, course_id):
        return bool(cls.get_pref_value(course_id,
                                       'allow_nonregistered_access'))

    def __unicode__(self):
        return u"{} : {} : {}".format(self.course_id, self.pref_key,
                                      self.pref_value)
Ejemplo n.º 11
0
class CertificateGenerationHistory(TimeStampedModel):
    """
    Model for storing Certificate Generation History.
    """

    course_id = CourseKeyField(max_length=255)
    generated_by = models.ForeignKey(User)
    instructor_task = models.ForeignKey(InstructorTask)
    is_regeneration = models.BooleanField(default=False)

    def get_task_name(self):
        """
        Return "regenerated" if record corresponds to Certificate Regeneration task, otherwise returns 'generated'
        """
        # Translators: This is a past-tense verb that is used for task action messages.
        return _("regenerated") if self.is_regeneration else _("generated")

    def get_certificate_generation_candidates(self):
        """
        Return the candidates for certificate generation task. It could either be students or certificate statuses
        depending upon the nature of certificate generation task. Returned value could be one of the following,

        1. "All learners" Certificate Generation task was initiated for all learners of the given course.
        2. Comma separated list of certificate statuses, This usually happens when instructor regenerates certificates.
        3. "for exceptions", This is the case when instructor generates certificates for white-listed
            students.
        """
        task_input = self.instructor_task.task_input
        if not task_input.strip():
            # if task input is empty, it means certificates were generated for all learners
            # Translators: This string represents task was executed for all learners.
            return _("All learners")

        task_input_json = json.loads(task_input)

        # get statuses_to_regenerate from task_input convert statuses to human readable strings and return
        statuses = task_input_json.get('statuses_to_regenerate', None)
        if statuses:
            readable_statuses = [
                CertificateStatuses.readable_statuses.get(status) for status in statuses
                if CertificateStatuses.readable_statuses.get(status) is not None
            ]
            return ", ".join(readable_statuses)

        # If "student_set" is present in task_input, then this task only
        # generates certificates for white listed students. Note that
        # this key used to be "students", so we include that in this conditional
        # for backwards compatibility.
        if 'student_set' in task_input_json or 'students' in task_input_json:
            # Translators: This string represents task was executed for students having exceptions.
            return _("For exceptions")
        else:
            return _("All learners")

    class Meta(object):
        app_label = "certificates"

    def __unicode__(self):
        return u"certificates %s by %s on %s for %s" % \
               ("regenerated" if self.is_regeneration else "generated", self.generated_by, self.created, self.course_id)
Ejemplo n.º 12
0
class Courses(TimeStampedModel):
    """
    Model for storing course id and name.
    """
    course_key = CourseKeyField(db_index=True, max_length=255)
    name = models.CharField(max_length=200)

    class Meta:
        app_label = 'micro_masters'
        verbose_name = 'Course'
        verbose_name_plural = 'Courses'
        unique_together = (('course_key', 'name'), )

    @classmethod
    def create_or_update_from_course_overview(cls, course_overview):
        title = course_overview.display_name
        course_key = course_overview.id
        try:
            course = cls.objects.get(course_key=course_key)
            course.name = title
            course.save()
        except cls.DoesNotExist:
            cls.objects.create(course_key=course_key, name=title)

    def __unicode__(self):
        return self.name

    def __repr__(self):
        return self.__unicode__()
Ejemplo n.º 13
0
class Migration(migrations.Migration):

    dependencies = [
        ('grades', '0004_visibleblocks_course_id'),
    ]

    operations = [
        migrations.AlterField(
            model_name='coursepersistentgradesflag',
            name='course_id',
            field=CourseKeyField(max_length=255, db_index=True),
        ),
    ]

    def unapply(self, project_state, schema_editor, collect_sql=False):
        """
        This is a bit of a hack. This migration is removing a unique index that was erroneously included in the initial
        migrations for this app, so it's very likely that IntegrityErrors would result if we did roll this particular
        migration back. To avoid this, we override the default unapply method and skip the addition of a unique index
        that was never intended to exist.

        The assumption here is that you are never going to be specifically targeting a migration < 0005 for grades,
        and will only ever be migrating backwards if you intend to go all the way back to zero and drop the tables.

        If this is not the case and you are reading this comment, please file a PR to help us with your intended usage.
        """
        pass
Ejemplo n.º 14
0
class CourseEnrollment(models.Model):
    '''
    The production model is student.models.CourseEnrollment

    The purpose of this mock is to provide the model needed to
    retrieve:
    * The learners enrolled in a course
    * When a learner enrolled
    * If the learner is active
    '''

    user = models.ForeignKey(User)
    course_id = CourseKeyField(max_length=255, db_index=True)
    created = models.DateTimeField(null=True)

    # If is_active is False, then the student is not considered to be enrolled
    # in the course (is_enrolled() will return False)
    is_active = models.BooleanField(default=True)

    mode = models.CharField(default=CourseMode.DEFAULT_MODE_SLUG,
                            max_length=100)

    objects = CourseEnrollmentManager()

    class Meta(object):
        unique_together = (('user', 'course_id'), )
        ordering = ('user', 'course_id')

    course_overview = models.ForeignKey(CourseOverview)
Ejemplo n.º 15
0
class EmbargoedCourse(models.Model):
    """
    Enable course embargo on a course-by-course basis.

    Deprecated by `RestrictedCourse`
    """
    objects = NoneToEmptyManager()

    # The course to embargo
    course_id = CourseKeyField(max_length=255, db_index=True, unique=True)

    # Whether or not to embargo
    embargoed = models.BooleanField(default=False)

    @classmethod
    def is_embargoed(cls, course_id):
        """
        Returns whether or not the given course id is embargoed.

        If course has not been explicitly embargoed, returns False.
        """
        try:
            record = cls.objects.get(course_id=course_id)
            return record.embargoed
        except cls.DoesNotExist:
            return False

    def __unicode__(self):
        not_em = "Not "
        if self.embargoed:
            not_em = ""
        # pylint: disable=no-member
        return u"Course '{}' is {}Embargoed".format(
            self.course_id.to_deprecated_string(), not_em)
Ejemplo n.º 16
0
class CourseCohortsSettings(models.Model):
    """
    This model represents cohort settings for courses.
    """
    is_cohorted = models.BooleanField(default=False)

    course_id = CourseKeyField(
        unique=True,
        max_length=255,
        db_index=True,
        help_text="Which course are these settings associated with?",
    )

    _cohorted_discussions = models.TextField(db_column='cohorted_discussions',
                                             null=True,
                                             blank=True)  # JSON list

    # Note that although a default value is specified here for always_cohort_inline_discussions (False),
    # in reality the default value at the time that cohorting is enabled for a course comes from
    # course_module.always_cohort_inline_discussions (via `migrate_cohort_settings`).
    # pylint: disable=invalid-name
    always_cohort_inline_discussions = models.BooleanField(default=False)

    @property
    def cohorted_discussions(self):
        """Jsonify the cohorted_discussions"""
        return json.loads(self._cohorted_discussions)

    @cohorted_discussions.setter
    def cohorted_discussions(self, value):
        """Un-Jsonify the cohorted_discussions"""
        self._cohorted_discussions = json.dumps(value)
Ejemplo n.º 17
0
class CohortMembership(models.Model):
    """Used internally to enforce our particular definition of uniqueness"""

    course_user_group = models.ForeignKey(CourseUserGroup)
    user = models.ForeignKey(User)
    course_id = CourseKeyField(max_length=255)

    previous_cohort = None
    previous_cohort_name = None
    previous_cohort_id = None

    class Meta(object):
        unique_together = (('user', 'course_id'), )

    def clean_fields(self, *args, **kwargs):
        if self.course_id is None:
            self.course_id = self.course_user_group.course_id
        super(CohortMembership, self).clean_fields(*args, **kwargs)

    def clean(self):
        if self.course_user_group.group_type != CourseUserGroup.COHORT:
            raise ValidationError(
                "CohortMembership cannot be used with CourseGroup types other than COHORT"
            )
        if self.course_user_group.course_id != self.course_id:
            raise ValidationError("Non-matching course_ids provided")
Ejemplo n.º 18
0
class StudentProgressHistory(TimeStampedModel):
    """
    A running audit trail for the StudentProgress model.  Listens for
    post_save events and creates/stores copies of progress entries.
    """
    user = models.ForeignKey(User, db_index=True)
    course_id = CourseKeyField(db_index=True, max_length=255, blank=True)
    completions = models.IntegerField()
Ejemplo n.º 19
0
class VerifiedTrackCohortedCourse(models.Model):
    """
    Tracks which courses have verified track auto-cohorting enabled.
    """
    course_key = CourseKeyField(
        max_length=255,
        db_index=True,
        unique=True,
        help_text=ugettext_lazy(
            u"The course key for the course we would like to be auto-cohorted."
        ))

    verified_cohort_name = models.CharField(
        max_length=100, default=DEFAULT_VERIFIED_COHORT_NAME)

    enabled = models.BooleanField()

    CACHE_NAMESPACE = u"verified_track_content.VerifiedTrackCohortedCourse.cache."

    def __unicode__(self):
        return u"Course: {}, enabled: {}".format(unicode(self.course_key),
                                                 self.enabled)

    @classmethod
    def verified_cohort_name_for_course(cls, course_key):
        """
        Returns the given cohort name for the specific course.

        Args:
            course_key (CourseKey): a course key representing the course we want the verified cohort name for

        Returns:
            The cohort name if the course key has one associated to it. None otherwise.

        """
        try:
            config = cls.objects.get(course_key=course_key)
            return config.verified_cohort_name
        except cls.DoesNotExist:
            return None

    @classmethod
    @ns_request_cached(CACHE_NAMESPACE)
    def is_verified_track_cohort_enabled(cls, course_key):
        """
        Checks whether or not verified track cohort is enabled for the given course.

        Args:
            course_key (CourseKey): a course key representing the course we want to check

        Returns:
            True if the course has verified track cohorts is enabled
            False if not
        """
        try:
            return cls.objects.get(course_key=course_key).enabled
        except cls.DoesNotExist:
            return False
Ejemplo n.º 20
0
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CourseRerunState',
            fields=[
                ('id',
                 models.AutoField(verbose_name='ID',
                                  serialize=False,
                                  auto_created=True,
                                  primary_key=True)),
                ('created_time', models.DateTimeField(auto_now_add=True)),
                ('updated_time', models.DateTimeField(auto_now=True)),
                ('course_key', CourseKeyField(max_length=255, db_index=True)),
                ('action', models.CharField(max_length=100, db_index=True)),
                ('state', models.CharField(max_length=50)),
                ('should_display', models.BooleanField(default=False)),
                ('message', models.CharField(max_length=1000)),
                ('source_course_key',
                 CourseKeyField(max_length=255, db_index=True)),
                ('display_name',
                 models.CharField(default=b'', max_length=255, blank=True)),
                ('created_user',
                 models.ForeignKey(
                     related_name='created_by_user+',
                     on_delete=django.db.models.deletion.SET_NULL,
                     to=settings.AUTH_USER_MODEL,
                     null=True)),
                ('updated_user',
                 models.ForeignKey(
                     related_name='updated_by_user+',
                     on_delete=django.db.models.deletion.SET_NULL,
                     to=settings.AUTH_USER_MODEL,
                     null=True)),
            ],
        ),
        migrations.AlterUniqueTogether(
            name='coursererunstate',
            unique_together=set([('course_key', 'action')]),
        ),
    ]
Ejemplo n.º 21
0
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='BadgeAssertion',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('data', jsonfield.fields.JSONField()),
                ('backend', models.CharField(max_length=50)),
                ('image_url', models.URLField()),
                ('assertion_url', models.URLField()),
                ('modified', fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
                ('created', fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False, db_index=True)),
            ],
        ),
        migrations.CreateModel(
            name='BadgeClass',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('slug', models.SlugField(max_length=255, validators=[badges.models.validate_lowercase])),
                ('issuing_component', models.SlugField(default=b'', blank=True, validators=[badges.models.validate_lowercase])),
                ('display_name', models.CharField(max_length=255)),
                ('course_id', CourseKeyField(default=None, max_length=255, blank=True)),
                ('description', models.TextField()),
                ('criteria', models.TextField()),
                ('mode', models.CharField(default=b'', max_length=100, blank=True)),
                ('image', models.ImageField(upload_to=b'badge_classes', validators=[badges.models.validate_badge_image])),
            ],
        ),
        migrations.CreateModel(
            name='CourseCompleteImageConfiguration',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('mode', models.CharField(help_text='The course mode for this badge image. For example, "verified" or "honor".', unique=True, max_length=125)),
                ('icon', models.ImageField(help_text='Badge images must be square PNG files. The file size should be under 250KB.', upload_to=b'course_complete_badges', validators=[badges.models.validate_badge_image])),
                ('default', models.BooleanField(default=False, help_text='Set this value to True if you want this image to be the default image for any course modes that do not have a specified badge image. You can have only one default image.')),
            ],
        ),
        migrations.AlterUniqueTogether(
            name='badgeclass',
            unique_together=set([('slug', 'issuing_component', 'course_id')]),
        ),
        migrations.AddField(
            model_name='badgeassertion',
            name='badge_class',
            field=models.ForeignKey(to='badges.BadgeClass'),
        ),
        migrations.AddField(
            model_name='badgeassertion',
            name='user',
            field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
        ),
    ]
Ejemplo n.º 22
0
class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Bookmark',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
                ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
                ('course_key', CourseKeyField(max_length=255, db_index=True)),
                ('usage_key', LocationKeyField(max_length=255, db_index=True)),
                ('_path', jsonfield.fields.JSONField(help_text=b'Path in course tree to the block', db_column=b'path')),
                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='XBlockCache',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
                ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
                ('course_key', CourseKeyField(max_length=255, db_index=True)),
                ('usage_key', LocationKeyField(unique=True, max_length=255, db_index=True)),
                ('display_name', models.CharField(default=b'', max_length=255)),
                ('_paths', jsonfield.fields.JSONField(default=[], help_text=b'All paths in course tree to the corresponding block.', db_column=b'paths')),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.AddField(
            model_name='bookmark',
            name='xblock_cache',
            field=models.ForeignKey(to='bookmarks.XBlockCache'),
        ),
        migrations.AlterUniqueTogether(
            name='bookmark',
            unique_together=set([('user', 'usage_key')]),
        ),
    ]
Ejemplo n.º 23
0
class CustomSettings(models.Model):
    """
    Extra Custom Settings for each course
    """
    id = CourseKeyField(max_length=255, db_index=True, primary_key=True)
    is_featured = models.BooleanField(default=False)
    tags = models.CharField(max_length=255, null=True, blank=True)

    def __unicode__(self):
        return '{} | {}'.format(self.id, self.is_featured)
Ejemplo n.º 24
0
class DiscussionCommunity(TimeStampedModel):
    """
        Model to store each course related communities
    """

    course_id = CourseKeyField(max_length=255, db_index=True)
    community_url = models.CharField(max_length=255, unique=True)

    def __str__(self):
        return "%s" % self.community_url
Ejemplo n.º 25
0
class CourseOverview(models.Model):
    '''
    Provides a mock model for the edx-platform 'CourseOverview' model

    Future Improvements
    -------------------

    We want to provide enhanced live querying like
    - "Which courses are invitation only?"
    - "Which courses have a maximum allowed enrollment above X"
    
    '''

    # Faking id, picking arbitrary length
    # Actual field is of type opaque_keys.edx.keys.CourseKey
    #id = models.CharField(db_index=True, primary_key=True, max_length=255)

    class Meta(object):
        app_label = 'course_overviews'

    # IMPORTANT: Bump this whenever you modify this model and/or add a migration.
    VERSION = 6

    # Cache entry versioning.
    version = models.IntegerField()

    id = CourseKeyField(db_index=True, primary_key=True, max_length=255)
    display_name = models.TextField(null=True)
    org = models.TextField(max_length=255, default='outdated_entry')
    # For the tests, the CourseOverviewFactory does a LazyAttribute on
    # display_org_with_default
    display_org_with_default = models.TextField()
    number = models.TextField()
    created = models.DateTimeField(null=True)  # from TimeStampedModel
    start = models.DateTimeField(null=True)
    end = models.DateTimeField(null=True)
    enrollment_start = models.DateTimeField(null=True)
    enrollment_end = models.DateTimeField(null=True)
    self_paced = models.BooleanField(default=False)

    @property
    def display_name_with_default_escaped(self):
        return self.display_name

    @property
    def display_number_with_default(self):
        return self.number

    @property
    def display_order_with_default(self):
        return self.org

    @classmethod
    def get_from_id(cls, course_id):
        return cls.objects.get(id=as_course_key(course_id))
Ejemplo n.º 26
0
class CertificateTemplate(TimeStampedModel):
    """A set of custom web certificate templates.

    Web certificate templates are Django web templates
    to replace PDF certificate.

    A particular course may have several kinds of certificate templates
    (e.g. honor and verified).

    """
    name = models.CharField(
        max_length=255,
        help_text=_(u'Name of template.'),
    )
    description = models.CharField(
        max_length=255,
        null=True,
        blank=True,
        help_text=_(u'Description and/or admin notes.'),
    )
    template = models.TextField(
        help_text=_(u'Django template HTML.'),
    )
    organization_id = models.IntegerField(
        null=True,
        blank=True,
        db_index=True,
        help_text=_(u'Organization of template.'),
    )
    course_key = CourseKeyField(
        max_length=255,
        null=True,
        blank=True,
        db_index=True,
    )
    mode = models.CharField(
        max_length=125,
        choices=GeneratedCertificate.MODES,
        default=GeneratedCertificate.MODES.honor,
        null=True,
        blank=True,
        help_text=_(u'The course mode for this template.'),
    )
    is_active = models.BooleanField(
        help_text=_(u'On/Off switch.'),
        default=False,
    )

    def __unicode__(self):
        return u'%s' % (self.name, )

    class Meta(object):
        get_latest_by = 'created'
        unique_together = (('organization_id', 'course_key', 'mode'),)
        app_label = "certificates"
Ejemplo n.º 27
0
class WaffleFlagCourseOverrideModel(ConfigurationModel):
    """
    Used to force a waffle flag on or off for a course.
    """
    OVERRIDE_CHOICES = Choices(('on', _('Force On')), ('off', _('Force Off')))
    ALL_CHOICES = OVERRIDE_CHOICES + Choices('unset')

    KEY_FIELDS = ('waffle_flag', 'course_id')

    # The course that these features are attached to.
    waffle_flag = CharField(max_length=255, db_index=True)
    course_id = CourseKeyField(max_length=255, db_index=True)
    override_choice = CharField(choices=OVERRIDE_CHOICES,
                                default=OVERRIDE_CHOICES.on,
                                max_length=3)

    @classmethod
    @request_cached
    def override_value(cls, waffle_flag, course_id):
        """
        Returns whether the waffle flag was overridden (on or off) for the
        course, or is unset.

        Arguments:
            waffle_flag (String): The name of the flag.
            course_id (CourseKey): The course id for which the flag may have
                been overridden.

        If the current config is not set or disabled for this waffle flag and
            course id, returns ALL_CHOICES.unset.
        Otherwise, returns ALL_CHOICES.on or ALL_CHOICES.off as configured for
            the override_choice.

        """
        if not course_id or not waffle_flag:
            return cls.ALL_CHOICES.unset

        effective = cls.objects.filter(
            waffle_flag=waffle_flag,
            course_id=course_id).order_by('-change_date').first()
        if effective and effective.enabled:
            return effective.override_choice
        return cls.ALL_CHOICES.unset

    class Meta(object):
        app_label = "waffle_utils"
        verbose_name = 'Waffle flag course override'
        verbose_name_plural = 'Waffle flag course overrides'

    def __unicode__(self):
        enabled_label = "Enabled" if self.enabled else "Not Enabled"
        # pylint: disable=no-member
        return u"Course '{}': Persistent Grades {}".format(
            text_type(self.course_id), enabled_label)
Ejemplo n.º 28
0
class VerificationCheckpoint(DeprecatedModelMixin, models.Model):  # pylint: disable=model-missing-unicode
    """
    DEPRECATED - do not use. To be removed in a future Open edX release (Hawthorn).
    """
    course_id = CourseKeyField(max_length=255, db_index=True)
    checkpoint_location = models.CharField(max_length=255)
    photo_verification = models.ManyToManyField(SoftwareSecurePhotoVerification)

    class Meta(object):
        app_label = "verify_student"
        unique_together = ('course_id', 'checkpoint_location')
Ejemplo n.º 29
0
class UserCourseTag(models.Model):
    """
    Per-course user tags, to be used by various things that want to store tags about
    the user.  Added initially to store assignment to experimental groups.
    """
    user = models.ForeignKey(User, db_index=True, related_name="+")
    key = models.CharField(max_length=255, db_index=True)
    course_id = CourseKeyField(max_length=255, db_index=True)
    value = models.TextField()

    class Meta(object):
        unique_together = ("user", "course_id", "key")
Ejemplo n.º 30
0
class SkippedReverification(DeprecatedModelMixin, models.Model):  # pylint: disable=model-missing-unicode
    """
    DEPRECATED - do not use. To be removed in a future Open edX release (Hawthorn).
    """
    user = models.ForeignKey(User)
    course_id = CourseKeyField(max_length=255, db_index=True)
    checkpoint = models.ForeignKey(VerificationCheckpoint, related_name="skipped_checkpoint")
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta(object):
        app_label = "verify_student"
        unique_together = (('user', 'course_id'),)