Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nk20-scripts
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
BDE
nk20-scripts
Commits
fa0ac589
Commit
fa0ac589
authored
5 years ago
by
Pierre-antoine Comby
Browse files
Options
Downloads
Patches
Plain Diff
better print
parent
aeb5ac9f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
management/commands/import_nk15.py
+17
-10
17 additions, 10 deletions
management/commands/import_nk15.py
with
17 additions
and
10 deletions
management/commands/import_nk15.py
+
17
−
10
View file @
fa0ac589
...
...
@@ -47,7 +47,7 @@ def update_line(n,N, content):
n
=
str
(
n
)
N
=
str
(
N
)
n
.
rjust
(
len
(
N
))
print
(
f
"
(
{
n
}
/
{
N
}
)
{
content
:
10.10
}
"
,
end
=
"
\r
"
)
print
(
f
"
\r
(
{
n
}
/
{
N
}
)
{
content
:
10.10
}
"
,
end
=
""
)
@transaction.atomic
def
import_comptes
(
cur
):
...
...
@@ -152,15 +152,21 @@ def import_boutons(cur):
@transaction.atomic
def
import_transaction
(
cur
):
cur
.
execute
(
"
SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY transaction.id;
"
)
cur
.
execute
(
"
SELECT * FROM transactions LEFT JOIN adhesions ON transactions.id = adhesions.idtransaction ORDER BY transaction
s
.id;
"
)
N
=
cur
.
rowcount
for
idx
,
row
in
enumerate
(
cur
):
update_line
(
idx
,
N
,
row
[
"
label
"
])
update_line
(
idx
,
N
,
row
[
"
description
"
])
# some date are set to None, use the previous one
date
=
row
[
"
date
"
]
if
date
is
None
:
date
=
old_date
else
:
old_date
=
date
obj_dict
=
{
# "pk": row["id"],
"
destination_id
"
:
MAP_IDBDE
[
row
[
"
destinataire
"
]],
"
source_id
"
:
MAP_IDBDE
[
row
[
"
emetteur
"
]],
"
created_at
"
:
make_aware
(
row
[
"
date
"
]
),
"
created_at
"
:
make_aware
(
date
),
"
amount
"
:
row
[
"
montant
"
],
"
quantity
"
:
row
[
"
quantite
"
],
"
reason
"
:
row
[
"
description
"
],
...
...
@@ -251,24 +257,25 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
kwargs
):
global
MAP_IDBDE
nk15db
,
nk15user
=
kwargs
[
'
nk15db
'
],
kwargs
[
'
nk15user
'
]
#reset database.
call_command
(
"
migrate
"
)
call_command
(
"
loaddata
"
,
"
initial
"
)
self
.
print_success
(
"
reset nk20 database
"
)
# connecting to nk15 database
conn
=
pg
.
connect
(
database
=
nk15db
,
user
=
nk15user
)
cur
=
conn
.
cursor
(
cursor_factory
=
pge
.
DictCursor
)
if
kwargs
[
"
comptes
"
]:
#reset database.
call_command
(
"
migrate
"
)
call_command
(
"
loaddata
"
,
"
initial
"
)
self
.
print_success
(
"
reset nk20 database
"
)
import_comptes
(
cur
)
self
.
print_success
(
"
comptes table imported
"
)
elif
kwargs
[
"
map
"
]:
filename
=
kwargs
[
"
map
"
]
with
open
(
filename
,
'
w
'
)
as
fp
:
with
open
(
filename
,
'
r
'
)
as
fp
:
MAP_IDBDE
=
json
.
load
(
fp
)
MAP_IDBDE
=
{
int
(
k
):
int
(
v
)
for
k
,
v
in
MAP_IDBDE
.
items
()}
if
kwargs
[
"
save
"
]:
filename
=
kwargs
[
"
save
"
]
with
open
(
filename
,
'
r
'
)
as
fp
:
with
open
(
filename
,
'
w
'
)
as
fp
:
json
.
dump
(
MAP_IDBDE
,
fp
,
sort_keys
=
True
,
indent
=
2
)
# /!\ need a prober MAP_IDBDE
...
...
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