Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Public contract registry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Public contract registry
Commits
6b3010b8
Commit
6b3010b8
authored
Apr 24, 2023
by
Tomáš Valenta
Browse files
Options
Downloads
Patches
Plain Diff
finished old contract import
parent
c7d22fbc
No related branches found
No related tags found
1 merge request
!3
Release
Pipeline
#12516
failed
Apr 24, 2023
Stage: build
Stage: test_deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
contracts/management/commands/import_old_contracts.py
+148
-17
148 additions, 17 deletions
contracts/management/commands/import_old_contracts.py
static_src/admin/contract_file_form.js
+1
-0
1 addition, 0 deletions
static_src/admin/contract_file_form.js
with
149 additions
and
17 deletions
contracts/management/commands/import_old_contracts.py
+
148
−
17
View file @
6b3010b8
...
...
@@ -6,6 +6,7 @@ from datetime import date, datetime
import
yaml
from
django.conf
import
settings
from
django.core.files
import
File
from
django.core.management.base
import
BaseCommand
from
django.db
import
models
from
postal.parser
import
parse_address
...
...
@@ -14,6 +15,7 @@ from git import Repo
from
...models
import
(
Contract
,
ContractFile
,
ContractFilingArea
,
ContractType
,
Contractee
,
...
...
@@ -408,6 +410,33 @@ class Command(BaseCommand):
return
area_name
def
normalize_filename
(
self
,
filename
:
str
)
->
str
:
filename
=
string
.
capwords
(
filename
)
patterns
=
(
(
r
"
\s\s+
"
,
"
"
),
(
r
"
^((P|p)odepsaná (V|v)erze|Strojově Čitelná Verze)$
"
,
"
Anonymizovaná verze
"
,
),
(
r
"
^(P|p)odepsaná (V|v)erze 2$
"
,
"
Anonymizovaná verze 2
"
),
(
r
"
^(U|u)pravitelná (V|v)erze$
"
,
"
Upravitelná verze
"
)
)
for
pattern
in
patterns
:
filename
=
re
.
sub
(
pattern
[
0
],
pattern
[
1
],
filename
)
return
filename
def
parse_index
(
self
,
contract_root
:
str
,
...
...
@@ -775,8 +804,37 @@ class Command(BaseCommand):
instance
.
department
=
self
.
normalize_department
(
signing_party_value
)
self
.
normalization_count
+=
1
if
model
is
Signee
:
if
(
"
s.r.o
"
in
instance
.
name
or
"
s. r. o.
"
in
instance
.
name
or
"
a.s.
"
in
instance
.
name
or
"
a. s.
"
in
instance
.
name
or
"
o.s.
"
in
instance
.
name
or
"
o. s.
"
in
instance
.
name
or
"
z.s.
"
in
instance
.
name
or
"
z. s.
"
in
instance
.
name
or
"
1
"
in
instance
.
name
or
"
2
"
in
instance
.
name
or
"
3
"
in
instance
.
name
or
"
4
"
in
instance
.
name
or
"
5
"
in
instance
.
name
or
"
6
"
in
instance
.
name
or
"
7
"
in
instance
.
name
or
"
8
"
in
instance
.
name
or
"
9
"
in
instance
.
name
or
"
0
"
in
instance
.
name
or
len
(
instance
.
name
.
split
(
"
"
))
not
in
(
2
,
3
)
):
instance
.
entity_type
=
instance
.
EntityTypes
.
LEGAL_ENTITY
else
:
if
instance
.
ico_number
is
None
:
instance
.
entity_type
=
instance
.
EntityTypes
.
NATURAL_PERSON
else
:
instance
.
entity_type
=
instance
.
EntityTypes
.
BUSINESS_NATURAL_PERSON
# Do our best to merge signing parties together.
existing_instance
=
model
.
objects
.
filter
(
existing_instance
s
=
model
.
objects
.
filter
(
(
models
.
Q
(
name
=
instance
.
name
)
&
(
...
...
@@ -812,32 +870,37 @@ class Command(BaseCommand):
if
instance
.
ico_number
is
not
None
else
models
.
Value
(
False
)
)
).
first
()
).
all
()
if
existing_instance
is
not
None
:
if
len
(
existing_instances
)
!=
0
:
for
position
,
existing_instance
in
enumerate
(
existing_instances
):
if
existing_instance
.
ico_number
is
None
and
instance
.
ico_number
is
not
None
:
existing_instance
.
ico_number
=
instance
.
ico_number
existing_instance
.
save
()
instance
=
existing_instance
break
elif
existing_instance
.
ico_number
==
instance
.
ico_number
or
instance
.
ico_number
is
None
:
instance
=
existing_instance
else
:
break
elif
position
==
len
(
existing_instances
)
-
1
:
instance
.
save
()
else
:
instance
.
save
()
return
instance
,
representatives
,
is_contractee
,
issue_count
def
assign_contract_
meta
data
(
def
assign_contract_data
(
self
,
contract
:
Contract
,
metadata
:
dict
,
slug
:
str
,
contract_root
:
str
,
)
->
None
:
filing_area
=
None
types
=
[]
signees
=
[]
contractees
=
[]
files
=
[]
is_already_imported
=
False
observed_issues_count
=
0
...
...
@@ -1109,9 +1172,72 @@ class Command(BaseCommand):
continue
for
filename
in
value
:
if
not
isinstance
(
filename
,
str
):
for
file_data
in
value
:
if
not
isinstance
(
file_data
,
dict
):
observed_issues_count
+=
1
contract
.
notes
+=
f
"
Špatně zadané informace o souboru:
{
file_data
}
.
\n
"
if
self
.
verbosity
>=
2
:
self
.
stderr
.
write
(
self
.
style
.
NOTICE
(
f
"
File data in
{
slug
}
is not a dict:
{
file_data
}
.
"
)
)
continue
for
file_key
,
file_value
in
file_data
.
items
():
file_key
=
file_key
.
strip
()
if
file_key
.
lower
()
in
(
"
název
"
,
"
náhled
"
,
"
náhlad
"
):
continue
if
not
isinstance
(
file_value
,
str
):
observed_issues_count
+=
1
contract
.
notes
+=
f
"
Špatně zadaný název souboru
{
file_key
}
:
{
file_value
}
.
\n
"
if
self
.
verbosity
>=
2
:
self
.
stderr
.
write
(
self
.
style
.
NOTICE
(
f
"
Filename in
{
slug
}
for file
{
file_key
}
invalid:
{
file_value
}
.
"
)
)
continue
file_path
=
os
.
path
.
join
(
contract_root
,
file_value
)
if
not
os
.
path
.
isfile
(
file_path
):
observed_issues_count
+=
1
contract
.
notes
+=
f
"
Neexistující soubor:
{
file_value
}
.
\n
"
if
self
.
verbosity
>=
2
:
self
.
stderr
.
write
(
self
.
style
.
NOTICE
(
f
"
Filename in
{
slug
}
does not correspond to a file:
{
file_value
}
.
"
)
)
continue
with
open
(
file_path
,
"
rb
"
)
as
open_file
:
self
.
normalization_count
+=
1
file
=
ContractFile
(
contract
=
contract
,
name
=
self
.
normalize_filename
(
file_key
),
is_public
=
True
)
file
.
file
.
save
(
file_value
,
File
(
open_file
),
save
=
False
,
)
files
.
append
(
file
)
if
not
is_already_imported
:
if
contract
.
name
in
(
None
,
""
)
or
(
...
...
@@ -1173,6 +1299,9 @@ class Command(BaseCommand):
representative
.
signature
=
signature
representative
.
save
()
for
file
in
files
:
file
.
save
()
contract
.
filing_area
=
filing_area
contract
.
types
.
set
(
types
)
contract
.
save
()
...
...
@@ -1209,10 +1338,11 @@ class Command(BaseCommand):
return
self
.
assign_contract_
meta
data
(
self
.
assign_contract_data
(
contract
,
metadata
,
os
.
path
.
basename
(
contract_root
),
contract_root
,
)
elif
file_
.
endswith
(
"
.pdf
"
):
# TODO
...
...
@@ -1332,6 +1462,7 @@ class Command(BaseCommand):
Contract
,
ContractType
,
ContractFilingArea
,
ContractFile
,
Contractee
,
ContracteeSignature
,
Signee
,
...
...
This diff is collapsed.
Click to expand it.
static_src/admin/contract_file_form.js
+
1
−
0
View file @
6b3010b8
...
...
@@ -6,6 +6,7 @@ $(window).ready(
`<datalist id="file-types">
<option value="Původní verze">
<option value="Anonymizovaná verze">
<option value="Upravitelná verze">
</datalist>`
);
}
...
...
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