Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
8991b161
Commit
8991b161
authored
5 years ago
by
Nimisha Asthagiri
Browse files
Options
Downloads
Patches
Plain Diff
Django2 CSMH Database Router update
parent
8dfcdc32
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
openedx/core/lib/django_courseware_routers.py
+25
-8
25 additions, 8 deletions
openedx/core/lib/django_courseware_routers.py
with
25 additions
and
8 deletions
openedx/core/lib/django_courseware_routers.py
+
25
−
8
View file @
8991b161
...
...
@@ -10,20 +10,32 @@ class StudentModuleHistoryExtendedRouter(object):
DATABASE_NAME
=
'
student_module_history
'
def
_is_csm
h
(
self
,
model
):
def
_is_csm
(
self
,
model
):
"""
Return True if ``model`` is courseware.StudentModuleHistoryExtended.
Return True if ``model`` is courseware.models.StudentModule.
"""
return
(
model
.
_meta
.
app_label
==
'
courseware
'
and
type
(
model
).
__name__
==
'
StudentModule
'
)
def
_is_csm_h
(
self
,
model
):
"""
Return True if ``model`` is coursewarehistoryextended.models.StudentModuleHistoryExtended.
"""
return
(
model
.
_meta
.
app_label
==
'
coursewarehistoryextended
'
and
model
.
__name__
==
'
StudentModuleHistoryExtended
'
(
type
(
model
).
__name__
==
'
StudentModuleHistoryExtended
'
or
getattr
(
model
,
'
__name__
'
,
''
)
==
'
StudentModuleHistoryExtended
'
)
)
def
db_for_read
(
self
,
model
,
**
hints
):
# pylint: disable=unused-argument
"""
Use the StudentModuleHistoryExtendedRouter.DATABASE_NAME if the model is StudentModuleHistoryExtended.
"""
if
self
.
_is_csmh
(
model
):
if
self
.
_is_csm
_
h
(
model
):
return
self
.
DATABASE_NAME
else
:
return
None
...
...
@@ -32,16 +44,21 @@ class StudentModuleHistoryExtendedRouter(object):
"""
Use the StudentModuleHistoryExtendedRouter.DATABASE_NAME if the model is StudentModuleHistoryExtended.
"""
if
self
.
_is_csmh
(
model
):
if
self
.
_is_csm
_
h
(
model
):
return
self
.
DATABASE_NAME
else
:
return
None
def
allow_relation
(
self
,
obj1
,
obj2
,
**
hints
):
# pylint: disable=unused-argument
"""
Disabl
e relations if the model is StudentModuleHistoryExtended.
Manag
e relations if the model is StudentModuleHistoryExtended.
"""
if
self
.
_is_csmh
(
obj1
)
or
self
.
_is_csmh
(
obj2
):
# Allow relation between CSM and CSMH (this cross-database relationship is declared with db_constraint=False).
if
self
.
_is_csm
(
obj1
)
and
self
.
_is_csm_h
(
obj2
):
return
True
# Prevent any other relations with CSMH since CSMH is in its own different database.
elif
self
.
_is_csm_h
(
obj1
)
or
self
.
_is_csm_h
(
obj2
):
return
False
return
None
...
...
@@ -51,7 +68,7 @@ class StudentModuleHistoryExtendedRouter(object):
"""
if
model_name
is
not
None
:
model
=
hints
.
get
(
'
model
'
)
if
model
is
not
None
and
self
.
_is_csmh
(
model
):
if
model
is
not
None
and
self
.
_is_csm
_
h
(
model
):
return
db
==
self
.
DATABASE_NAME
if
db
==
self
.
DATABASE_NAME
:
return
False
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment