Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-CSVImport
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-CSVImport
Commits
6a48e539
Commit
6a48e539
authored
2 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add arg to regex field type to raise an exception if no match was found
parent
610d82bc
No related branches found
No related tags found
1 merge request
!108
Resolve "Reg ex field type should be able to give feedback if there was no match"
Pipeline
#80616
passed
2 years ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Stage: docker
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.rst
+6
-0
6 additions, 0 deletions
CHANGELOG.rst
aleksis/apps/csv_import/field_types.py
+10
-0
10 additions, 0 deletions
aleksis/apps/csv_import/field_types.py
with
16 additions
and
0 deletions
CHANGELOG.rst
+
6
−
0
View file @
6a48e539
...
...
@@ -9,6 +9,12 @@ and this project adheres to `Semantic Versioning`_.
Unreleased
----------
Added
~~~~~
* If activated, imports with regex field types will show error messages
when there is no match.
`2.3`_ - 2022-06-25
-------------------
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/csv_import/field_types.py
+
10
−
0
View file @
6a48e539
...
...
@@ -144,16 +144,26 @@ class RegExFieldType(ProcessFieldType):
data_type
=
str
reg_ex
:
str
=
""
fail_if_no_match
:
bool
=
False
def
get_reg_ex
(
self
):
return
self
.
reg_ex
or
self
.
get_args
().
get
(
"
reg_ex
"
,
""
)
def
get_fail_if_no_match
(
self
):
return
self
.
fail_if_no_match
or
self
.
get_args
().
get
(
"
fail_if_no_match
"
,
False
)
def
process
(
self
,
instance
:
Model
,
value
):
match
=
re
.
fullmatch
(
self
.
get_reg_ex
(),
value
)
if
match
:
for
key
,
item
in
match
.
groupdict
().
items
():
setattr
(
instance
,
key
,
item
)
instance
.
save
()
elif
self
.
get_fail_if_no_match
():
raise
IndexError
(
_
(
"
No match on {} for regular expression {} found.
"
).
format
(
value
,
self
.
get_reg_ex
()
)
)
@field_type_registry.register
...
...
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