# Path: bible/djangoforms.py
# class VerseField(models.Field):
#     description = "A scripture reference to a specific verse"
# 
#     def __init__(self, *args, **kwargs):
#         kwargs['max_length'] = 8
#         super(VerseField, self).__init__(*args, **kwargs)
# 
#     def db_type(self, connection):
#         return 'int(%s)' % self.max_length
# 
#     def get_prep_value(self, value):
#         return hash(value)
# 
#     # def from_db_value(self, value, expression, connection, context):
# 
#     def to_python(self, value):
#         if value is None or type(value) is Verse:
#             return value
# 
#         try:
#             return Verse(value)
#         except (RangeError, Exception) as err:
#             raise forms.ValidationError(err.__str__())
# 
#     def formfield(self, **kwargs):
#         defaults = {'form_class': VerseFormField}
#         defaults.update(kwargs)
#         return super(VerseField, self).formfield(**defaults)
# 
# Path: reformedacademy/utils.py
# def str2bool(v):
# def find_using_property(list, object, property):
# 
# Path: rfmedia/models.py
# class Asset(models.Model):
#     type = models.ForeignKey(Type)
#     tag = models.CharField(max_length=255, blank=True, null=True)
#     url = models.CharField(max_length=255, blank=True, null=True)
#     filesize = models.BigIntegerField(blank=True, null=True)
#     duration = models.CharField(max_length=255, blank=True, null=True)
#     mime_type = models.CharField(max_length=255, blank=True, null=True)
#     thumbnail_url = models.CharField(max_length=255, blank=True, null=True)
#     active = models.IntegerField()
#     created = models.DateTimeField()
#     modified = models.DateTimeField(blank=True, null=True)
# 
#     @property
#     def download_url(self):
#         return self.url
# 
#     class Meta:
#         db_table = 'assets'
# 
#     def __unicode__(self):
#         return self.url


from urllib.parse import urlparse
from bible.djangoforms import VerseField
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from django.utils.crypto import random
from reformedacademy import utils
from rfmedia.models import Asset
import scriptures
                chapter=to_chapter,
                verse=to_verse
            )
            passages.append(PassageIndex(start_verse=start_verse, end_verse=end_verse))

        return passages


class CourseProgress(models.Model):
    """Describes progress for a course."""
    user = models.ForeignKey(User)
    course = models.ForeignKey(Course)
    started = models.DateTimeField(auto_now=True)
    completed = models.DateTimeField(null=True)
    percentage_complete = models.PositiveIntegerField(default=0, help_text="Always a whole number.")

    def calc_progress(self, user):
        """Calculates the percentage complete for a course and saves to percentage_complete."""

        # Get all tasks for a course
        tp_qs = TaskProgress.objects.filter(user=user, task__lesson__course=self.course).all()
        # Convert the queryset to a list so we can do cached operations
        tp_list = list(tp_qs)

        total_tasks = 0
        completed_tasks = 0
        # Loop through all lessons and tasks while keeping track of total_tasks and completed_tasks
        for lesson in self.course.lesson_set.all():
            for task in lesson.task_set.all():
                total_tasks += 1

# Path: bible/djangoforms.py
# class VerseField(models.Field):
#     description = "A scripture reference to a specific verse"
# 
#     def __init__(self, *args, **kwargs):
#         kwargs['max_length'] = 8
#         super(VerseField, self).__init__(*args, **kwargs)
# 
#     def db_type(self, connection):
#         return 'int(%s)' % self.max_length
# 
#     def get_prep_value(self, value):
#         return hash(value)
# 
#     # def from_db_value(self, value, expression, connection, context):
# 
#     def to_python(self, value):
#         if value is None or type(value) is Verse:
#             return value
# 
#         try:
#             return Verse(value)
#         except (RangeError, Exception) as err:
#             raise forms.ValidationError(err.__str__())
# 
#     def formfield(self, **kwargs):
#         defaults = {'form_class': VerseFormField}
#         defaults.update(kwargs)
#         return super(VerseField, self).formfield(**defaults)
# 
# Path: reformedacademy/utils.py
# def str2bool(v):
# def find_using_property(list, object, property):
# 
# Path: rfmedia/models.py
# class Asset(models.Model):
#     type = models.ForeignKey(Type)
#     tag = models.CharField(max_length=255, blank=True, null=True)
#     url = models.CharField(max_length=255, blank=True, null=True)
#     filesize = models.BigIntegerField(blank=True, null=True)
#     duration = models.CharField(max_length=255, blank=True, null=True)
#     mime_type = models.CharField(max_length=255, blank=True, null=True)
#     thumbnail_url = models.CharField(max_length=255, blank=True, null=True)
#     active = models.IntegerField()
#     created = models.DateTimeField()
#     modified = models.DateTimeField(blank=True, null=True)
# 
#     @property
#     def download_url(self):
#         return self.url
# 
#     class Meta:
#         db_table = 'assets'
# 
#     def __unicode__(self):
#         return self.url


# Path: reformedacademy/models.py
from urllib.parse import urlparse
from bible.djangoforms import VerseField
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from django.utils.crypto import random
from reformedacademy import utils
from rfmedia.models import Asset
import scriptures

                chapter=to_chapter,
                verse=to_verse
            )
            passages.append(PassageIndex(start_verse=start_verse, end_verse=end_verse))

        return passages


class CourseProgress(models.Model):
    """Describes progress for a course."""
    user = models.ForeignKey(User)
    course = models.ForeignKey(Course)
    started = models.DateTimeField(auto_now=True)
    completed = models.DateTimeField(null=True)
    percentage_complete = models.PositiveIntegerField(default=0, help_text="Always a whole number.")

    def calc_progress(self, user):
        """Calculates the percentage complete for a course and saves to percentage_complete."""

        # Get all tasks for a course
        tp_qs = TaskProgress.objects.filter(user=user, task__lesson__course=self.course).all()
        # Convert the queryset to a list so we can do cached operations
        tp_list = list(tp_qs)

        total_tasks = 0
        completed_tasks = 0
        # Loop through all lessons and tasks while keeping track of total_tasks and completed_tasks
        for lesson in self.course.lesson_set.all():
            for task in lesson.task_set.all():
                total_tasks += 1

                task_progress = utils.find_using_property(tp_list, task, 'task')