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
9970fe92
Commit
9970fe92
authored
Mar 29, 2016
by
Bill DeRusha
Committed by
Clinton Blackburn
Mar 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Currency to core app
parent
a9ffdd1e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
6 deletions
+58
-6
course_discovery/apps/core/admin.py
+9
-5
course_discovery/apps/core/migrations/0004_currency.py
+24
-0
course_discovery/apps/core/models.py
+12
-0
course_discovery/apps/core/tests/test_models.py
+13
-1
No files found.
course_discovery/apps/core/admin.py
View file @
9970fe92
...
...
@@ -5,26 +5,30 @@ from django.contrib.auth.admin import UserAdmin
from
django.utils.translation
import
ugettext_lazy
as
_
from
course_discovery.apps.core.forms
import
UserThrottleRateForm
from
course_discovery.apps.core.models
import
User
,
UserThrottleRate
from
course_discovery.apps.core.models
import
User
,
UserThrottleRate
,
Currency
@admin.register
(
User
)
class
CustomUserAdmin
(
UserAdmin
):
""" Admin configuration for the custom User model. """
list_display
=
(
'username'
,
'email'
,
'full_name'
,
'first_name'
,
'last_name'
,
'is_staff'
)
fieldsets
=
(
(
None
,
{
'fields'
:
(
'username'
,
'password'
)}),
(
_
(
'Personal info'
),
{
'fields'
:
(
'full_name'
,
'first_name'
,
'last_name'
,
'email'
)}),
(
_
(
'Permissions'
),
{
'fields'
:
(
'is_active'
,
'is_staff'
,
'is_superuser'
,
'groups'
,
'user_permissions'
)}),
(
_
(
'Permissions'
),
{
'fields'
:
(
'is_active'
,
'is_staff'
,
'is_superuser'
,
'groups'
,
'user_permissions'
)}),
(
_
(
'Important dates'
),
{
'fields'
:
(
'last_login'
,
'date_joined'
)}),
)
@admin.register
(
UserThrottleRate
)
class
UserThrottleRateAdmin
(
admin
.
ModelAdmin
):
""" Admin configuration for the UserThrottleRate model. """
form
=
UserThrottleRateForm
raw_id_fields
=
(
'user'
,)
admin
.
site
.
register
(
User
,
CustomUserAdmin
)
admin
.
site
.
register
(
UserThrottleRate
,
UserThrottleRateAdmin
)
@admin.register
(
Currency
)
class
CurrencyAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'code'
,
'name'
,)
ordering
=
(
'code'
,
'name'
,)
search_fields
=
(
'code'
,
'name'
,)
course_discovery/apps/core/migrations/0004_currency.py
0 → 100644
View file @
9970fe92
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'core'
,
'0003_auto_20160315_1910'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Currency'
,
fields
=
[
(
'code'
,
models
.
CharField
(
unique
=
True
,
primary_key
=
True
,
serialize
=
False
,
max_length
=
6
)),
(
'name'
,
models
.
CharField
(
max_length
=
255
)),
],
options
=
{
'verbose_name_plural'
:
'Currencies'
,
},
),
]
course_discovery/apps/core/models.py
View file @
9970fe92
...
...
@@ -37,3 +37,15 @@ class UserThrottleRate(models.Model):
'The rate of requests to limit this user to. The format is specified by Django'
' Rest Framework (see http://www.django-rest-framework.org/api-guide/throttling/).'
)
)
class
Currency
(
models
.
Model
):
""" Table of currencies as defined by ISO-4217. """
code
=
models
.
CharField
(
max_length
=
6
,
primary_key
=
True
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
255
)
def
__str__
(
self
):
return
'{code} - {name}'
.
format
(
code
=
self
.
code
,
name
=
self
.
name
)
class
Meta
(
object
):
verbose_name_plural
=
'Currencies'
course_discovery/apps/core/tests/test_models.py
View file @
9970fe92
...
...
@@ -4,7 +4,7 @@ from django.test import TestCase
from
django_dynamic_fixture
import
G
from
social.apps.django_app.default.models
import
UserSocialAuth
from
course_discovery.apps.core.models
import
User
from
course_discovery.apps.core.models
import
User
,
Currency
# pylint: disable=no-member
...
...
@@ -38,3 +38,15 @@ class UserTests(TestCase):
user
=
G
(
User
,
full_name
=
full_name
,
first_name
=
first_name
,
last_name
=
last_name
)
self
.
assertEqual
(
user
.
get_full_name
(),
full_name
)
class
CurrencyTests
(
TestCase
):
""" Tests for the Currency class. """
def
test_str
(
self
):
""" Verify casting an instance to a string returns a string containing the ID and name of the currency. """
code
=
'USD'
,
name
=
'U.S. Dollar'
instance
=
Currency
(
code
=
code
,
name
=
name
)
self
.
assertEqual
(
str
(
instance
),
'{code} - {name}'
.
format
(
code
=
code
,
name
=
name
))
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