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
f389ef11
Commit
f389ef11
authored
Oct 07, 2016
by
Awais Qureshi
Committed by
GitHub
Oct 07, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #368 from edx/awais786/ECOM-5433-user-attr-model
Adding UserAttribute table
parents
0dca3588
bed830c0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
2 deletions
+73
-2
course_discovery/apps/publisher/admin.py
+2
-1
course_discovery/apps/publisher/migrations/0011_userattributes.py
+30
-0
course_discovery/apps/publisher/models.py
+14
-0
course_discovery/apps/publisher/tests/factories.py
+8
-1
course_discovery/apps/publisher/tests/test_model.py
+19
-0
No files found.
course_discovery/apps/publisher/admin.py
View file @
f389ef11
from
django.contrib
import
admin
from
course_discovery.apps.publisher.models
import
Course
,
CourseRun
,
Seat
,
State
from
course_discovery.apps.publisher.models
import
Course
,
CourseRun
,
Seat
,
State
,
UserAttributes
admin
.
site
.
register
(
Course
)
admin
.
site
.
register
(
CourseRun
)
admin
.
site
.
register
(
Seat
)
admin
.
site
.
register
(
State
)
admin
.
site
.
register
(
UserAttributes
)
course_discovery/apps/publisher/migrations/0011_userattributes.py
0 → 100644
View file @
f389ef11
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
django_extensions.db.fields
from
django.conf
import
settings
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
migrations
.
swappable_dependency
(
settings
.
AUTH_USER_MODEL
),
(
'publisher'
,
'0010_auto_20161006_1151'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'UserAttributes'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
verbose_name
=
'ID'
,
serialize
=
False
)),
(
'created'
,
django_extensions
.
db
.
fields
.
CreationDateTimeField
(
verbose_name
=
'created'
,
auto_now_add
=
True
)),
(
'modified'
,
django_extensions
.
db
.
fields
.
ModificationDateTimeField
(
auto_now
=
True
,
verbose_name
=
'modified'
)),
(
'enable_email_notification'
,
models
.
BooleanField
(
default
=
True
)),
(
'user'
,
models
.
OneToOneField
(
to
=
settings
.
AUTH_USER_MODEL
,
related_name
=
'attributes'
)),
],
options
=
{
'verbose_name_plural'
:
'UserAttributes'
,
},
),
]
course_discovery/apps/publisher/models.py
View file @
f389ef11
...
...
@@ -321,3 +321,17 @@ def create_workflow_state(course_run):
state
=
State
()
state
.
save
()
course_run
.
state
=
state
class
UserAttributes
(
TimeStampedModel
):
""" Record additional metadata about a user. """
user
=
models
.
OneToOneField
(
User
,
related_name
=
'attributes'
)
enable_email_notification
=
models
.
BooleanField
(
default
=
True
)
def
__str__
(
self
):
return
'{user}: {email_notification}'
.
format
(
user
=
self
.
user
,
email_notification
=
self
.
enable_email_notification
)
class
Meta
:
verbose_name_plural
=
'UserAttributes'
course_discovery/apps/publisher/tests/factories.py
View file @
f389ef11
...
...
@@ -11,7 +11,7 @@ from course_discovery.apps.core.tests.factories import UserFactory
from
course_discovery.apps.course_metadata.choices
import
CourseRunPacing
from
course_discovery.apps.course_metadata.tests
import
factories
from
course_discovery.apps.ietf_language_tags.models
import
LanguageTag
from
course_discovery.apps.publisher.models
import
Course
,
CourseRun
,
Seat
,
State
from
course_discovery.apps.publisher.models
import
Course
,
CourseRun
,
Seat
,
State
,
UserAttributes
class
StateFactory
(
factory
.
DjangoModelFactory
):
...
...
@@ -77,3 +77,10 @@ class GroupFactory(factory.DjangoModelFactory):
class
Meta
:
model
=
Group
class
UserAttributeFactory
(
factory
.
DjangoModelFactory
):
user
=
factory
.
SubFactory
(
UserFactory
)
class
Meta
:
model
=
UserAttributes
course_discovery/apps/publisher/tests/test_model.py
View file @
f389ef11
...
...
@@ -129,3 +129,22 @@ class StateTests(TestCase):
str
(
self
.
state
),
self
.
state
.
get_name_display
()
)
class
UserAttributeTests
(
TestCase
):
""" Tests for the publisher `UserAttribute` model. """
def
setUp
(
self
):
super
(
UserAttributeTests
,
self
)
.
setUp
()
self
.
user_attr
=
factories
.
UserAttributeFactory
()
def
test_str
(
self
):
""" Verify casting an instance to a string returns a string containing the user name and
current enable status. """
self
.
assertEqual
(
str
(
self
.
user_attr
),
'{user}: {enable_email_notification}'
.
format
(
user
=
self
.
user_attr
.
user
,
enable_email_notification
=
self
.
user_attr
.
enable_email_notification
)
)
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