# 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
        """Completes a task.

        @:return TaskProgress

        """
        # Create progress object to log completion of the task
        task_progress = TaskProgress.objects.create(user=user, task=self)
        # Log the task was completed
        CourseLog.complete_task(user)
        # Calculate course progress to cache in database
        course_progress.calc_progress(user)
        # Check if a lesson is complete, and complete if it is
        self.lesson.check_complete(user)

        return task_progress

    class Meta:
        ordering = ['order']

    def __str__(self):
        return '{}'.format(self.name)


class PassageIndex(models.Model):
    """Describes a passage index.

    This is used to index passages associated with different things for searching.

    """
    start_verse = VerseField()

# 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

        """Completes a task.

        @:return TaskProgress

        """
        # Create progress object to log completion of the task
        task_progress = TaskProgress.objects.create(user=user, task=self)
        # Log the task was completed
        CourseLog.complete_task(user)
        # Calculate course progress to cache in database
        course_progress.calc_progress(user)
        # Check if a lesson is complete, and complete if it is
        self.lesson.check_complete(user)

        return task_progress

    class Meta:
        ordering = ['order']

    def __str__(self):
        return '{}'.format(self.name)


class PassageIndex(models.Model):
    """Describes a passage index.

    This is used to index passages associated with different things for searching.

    """
    start_verse = VerseField()

    end_verse = VerseField()