Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
7af7880b
Commit
7af7880b
authored
Apr 04, 2016
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor 'value' models into shared abstract model
parent
3870cec7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
12 deletions
+44
-12
course_discovery/apps/course_metadata/migrations/0002_auto_20160404_1626.py
+22
-0
course_discovery/apps/course_metadata/models.py
+14
-7
course_discovery/apps/course_metadata/tests/test_models.py
+8
-5
No files found.
course_discovery/apps/course_metadata/migrations/0002_auto_20160404_1626.py
0 → 100644
View file @
7af7880b
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'course_metadata'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterModelOptions
(
name
=
'expectedlearningitem'
,
options
=
{},
),
migrations
.
AlterModelOptions
(
name
=
'syllabusitem'
,
options
=
{},
),
]
course_discovery/apps/course_metadata/models.py
View file @
7af7880b
...
...
@@ -23,6 +23,17 @@ class AbstractNamedModel(TimeStampedModel):
abstract
=
True
class
AbstractValueModel
(
TimeStampedModel
):
""" Abstract base class for models with only a value field. """
value
=
models
.
CharField
(
max_length
=
255
)
def
__str__
(
self
):
return
self
.
value
class
Meta
(
object
):
abstract
=
True
class
AbstractMediaModel
(
TimeStampedModel
):
""" Abstract base class for media-related (e.g. image, video) models. """
src
=
models
.
URLField
(
max_length
=
255
,
unique
=
True
)
...
...
@@ -58,18 +69,14 @@ class Prerequisite(AbstractNamedModel):
pass
class
ExpectedLearningItem
(
TimeStamped
Model
):
class
ExpectedLearningItem
(
AbstractValue
Model
):
""" ExpectedLearningItem model. """
value
=
models
.
CharField
(
max_length
=
255
)
def
__str__
(
self
):
return
self
.
value
pass
class
SyllabusItem
(
TimeStamped
Model
):
class
SyllabusItem
(
AbstractValue
Model
):
""" SyllabusItem model. """
parent
=
models
.
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
,
related_name
=
'children'
)
value
=
models
.
CharField
(
max_length
=
255
)
class
Organization
(
TimeStampedModel
):
...
...
course_discovery/apps/course_metadata/tests/test_models.py
View file @
7af7880b
...
...
@@ -2,7 +2,7 @@ import ddt
from
django.test
import
TestCase
from
course_discovery.apps.course_metadata.models
import
(
AbstractNamedModel
,
AbstractMediaModel
,
CourseOrganization
,
ExpectedLearningItem
AbstractNamedModel
,
AbstractMediaModel
,
AbstractValueModel
,
CourseOrganization
)
from
course_discovery.apps.course_metadata.tests
import
factories
...
...
@@ -124,12 +124,15 @@ class AbstractMediaModelTests(TestCase):
self
.
assertEqual
(
str
(
instance
),
src
)
class
ExpectedLearningItem
Tests
(
TestCase
):
""" Tests for
ExpectedLearningItem
. """
class
AbstractValueModel
Tests
(
TestCase
):
""" Tests for
AbstractValueModel
. """
def
test_str
(
self
):
""" Verify casting an instance to a string returns a string containing the value. """
value
=
'Expected learnings'
instance
=
ExpectedLearningItem
(
value
=
value
)
class
TestAbstractValueModel
(
AbstractValueModel
):
pass
value
=
'abc'
instance
=
TestAbstractValueModel
(
value
=
value
)
self
.
assertEqual
(
str
(
instance
),
value
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment