Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
d04964e7
Kaydet (Commit)
d04964e7
authored
Mar 08, 2013
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Used commit_on_success_unless_managed in loaddata.
üst
4dbd1b2d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
48 deletions
+21
-48
loaddata.py
django/core/management/commands/loaddata.py
+21
-48
No files found.
django/core/management/commands/loaddata.py
Dosyayı görüntüle @
d04964e7
...
@@ -41,8 +41,6 @@ class Command(BaseCommand):
...
@@ -41,8 +41,6 @@ class Command(BaseCommand):
self
.
ignore
=
options
.
get
(
'ignore'
)
self
.
ignore
=
options
.
get
(
'ignore'
)
self
.
using
=
options
.
get
(
'database'
)
self
.
using
=
options
.
get
(
'database'
)
connection
=
connections
[
self
.
using
]
if
not
len
(
fixture_labels
):
if
not
len
(
fixture_labels
):
raise
CommandError
(
raise
CommandError
(
"No database fixture specified. Please provide the path of at "
"No database fixture specified. Please provide the path of at "
...
@@ -51,13 +49,18 @@ class Command(BaseCommand):
...
@@ -51,13 +49,18 @@ class Command(BaseCommand):
self
.
verbosity
=
int
(
options
.
get
(
'verbosity'
))
self
.
verbosity
=
int
(
options
.
get
(
'verbosity'
))
# commit is a stealth option - it isn't really useful as
with
transaction
.
commit_on_success_unless_managed
(
using
=
self
.
using
):
# a command line option, but it can be useful when invoking
self
.
loaddata
(
fixture_labels
)
# loaddata from within another script.
# If commit=True, loaddata will use its own transaction;
# Close the DB connection -- unless we're still in a transaction. This
# if commit=False, the data load SQL will become part of
# is required as a workaround for an edge case in MySQL: if the same
# the transaction in place when loaddata was invoked.
# connection is used to create tables, load data, and query, the query
commit
=
options
.
get
(
'commit'
,
True
)
# can return incorrect results. See Django #7572, MySQL #37735.
if
transaction
.
get_autocommit
(
self
.
using
):
connections
[
self
.
using
]
.
close
()
def
loaddata
(
self
,
fixture_labels
):
connection
=
connections
[
self
.
using
]
# Keep a count of the installed objects and fixtures
# Keep a count of the installed objects and fixtures
self
.
fixture_count
=
0
self
.
fixture_count
=
0
...
@@ -65,16 +68,6 @@ class Command(BaseCommand):
...
@@ -65,16 +68,6 @@ class Command(BaseCommand):
self
.
fixture_object_count
=
0
self
.
fixture_object_count
=
0
self
.
models
=
set
()
self
.
models
=
set
()
# Get a cursor (even though we don't need one yet). This has
# the side effect of initializing the test database (if
# it isn't already initialized).
cursor
=
connection
.
cursor
()
# Start transaction management. All fixtures are installed in a
# single transaction to ensure that all references are resolved.
if
commit
:
transaction
.
enter_transaction_management
(
using
=
self
.
using
)
class
SingleZipReader
(
zipfile
.
ZipFile
):
class
SingleZipReader
(
zipfile
.
ZipFile
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
zipfile
.
ZipFile
.
__init__
(
self
,
*
args
,
**
kwargs
)
zipfile
.
ZipFile
.
__init__
(
self
,
*
args
,
**
kwargs
)
...
@@ -103,26 +96,17 @@ class Command(BaseCommand):
...
@@ -103,26 +96,17 @@ class Command(BaseCommand):
app_fixtures
=
[
os
.
path
.
join
(
os
.
path
.
dirname
(
path
),
'fixtures'
)
for
path
in
app_module_paths
]
app_fixtures
=
[
os
.
path
.
join
(
os
.
path
.
dirname
(
path
),
'fixtures'
)
for
path
in
app_module_paths
]
try
:
with
connection
.
constraint_checks_disabled
():
with
connection
.
constraint_checks_disabled
():
for
fixture_label
in
fixture_labels
:
for
fixture_label
in
fixture_labels
:
self
.
load_label
(
fixture_label
,
app_fixtures
)
self
.
load_label
(
fixture_label
,
app_fixtures
)
# Since we disabled constraint checks, we must manually check for
# any invalid keys that might have been added
table_names
=
[
model
.
_meta
.
db_table
for
model
in
self
.
models
]
try
:
connection
.
check_constraints
(
table_names
=
table_names
)
except
Exception
as
e
:
e
.
args
=
(
"Problem installing fixtures:
%
s"
%
e
,)
raise
except
(
SystemExit
,
KeyboardInterrupt
):
# Since we disabled constraint checks, we must manually check for
raise
# any invalid keys that might have been added
table_names
=
[
model
.
_meta
.
db_table
for
model
in
self
.
models
]
try
:
connection
.
check_constraints
(
table_names
=
table_names
)
except
Exception
as
e
:
except
Exception
as
e
:
if
commit
:
e
.
args
=
(
"Problem installing fixtures:
%
s"
%
e
,)
transaction
.
rollback
(
using
=
self
.
using
)
transaction
.
leave_transaction_management
(
using
=
self
.
using
)
raise
raise
# If we found even one object in a fixture, we need to reset the
# If we found even one object in a fixture, we need to reset the
...
@@ -135,10 +119,6 @@ class Command(BaseCommand):
...
@@ -135,10 +119,6 @@ class Command(BaseCommand):
for
line
in
sequence_sql
:
for
line
in
sequence_sql
:
cursor
.
execute
(
line
)
cursor
.
execute
(
line
)
if
commit
:
transaction
.
commit
(
using
=
self
.
using
)
transaction
.
leave_transaction_management
(
using
=
self
.
using
)
if
self
.
verbosity
>=
1
:
if
self
.
verbosity
>=
1
:
if
self
.
fixture_object_count
==
self
.
loaded_object_count
:
if
self
.
fixture_object_count
==
self
.
loaded_object_count
:
self
.
stdout
.
write
(
"Installed
%
d object(s) from
%
d fixture(s)"
%
(
self
.
stdout
.
write
(
"Installed
%
d object(s) from
%
d fixture(s)"
%
(
...
@@ -147,13 +127,6 @@ class Command(BaseCommand):
...
@@ -147,13 +127,6 @@ class Command(BaseCommand):
self
.
stdout
.
write
(
"Installed
%
d object(s) (of
%
d) from
%
d fixture(s)"
%
(
self
.
stdout
.
write
(
"Installed
%
d object(s) (of
%
d) from
%
d fixture(s)"
%
(
self
.
loaded_object_count
,
self
.
fixture_object_count
,
self
.
fixture_count
))
self
.
loaded_object_count
,
self
.
fixture_object_count
,
self
.
fixture_count
))
# Close the DB connection. This is required as a workaround for an
# edge case in MySQL: if the same connection is used to
# create tables, load data, and query, the query can return
# incorrect results. See Django #7572, MySQL #37735.
if
commit
:
connection
.
close
()
def
load_label
(
self
,
fixture_label
,
app_fixtures
):
def
load_label
(
self
,
fixture_label
,
app_fixtures
):
parts
=
fixture_label
.
split
(
'.'
)
parts
=
fixture_label
.
split
(
'.'
)
...
...
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