Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
a3f6d8ae
Commit
a3f6d8ae
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Added exception handling for item updates
parent
0cdb6afb
No related branches found
Branches containing commit
No related tags found
1 merge request
!38
Submit exceptions
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/hid/tests/add_edit_item_view_tests.py
+44
-0
44 additions, 0 deletions
django/website/hid/tests/add_edit_item_view_tests.py
django/website/hid/views/item.py
+21
-12
21 additions, 12 deletions
django/website/hid/views/item.py
with
65 additions
and
12 deletions
django/website/hid/tests/add_edit_item_view_tests.py
+
44
−
0
View file @
a3f6d8ae
...
...
@@ -437,3 +437,47 @@ def test_no_category_when_item_type_not_set(view):
initial
=
view
.
get_initial
()
assert
'
category
'
not
in
initial
@pytest.mark.django_db
def
test_item_update_transport_exception_logs_message
(
view
,
form
):
# This could happen if someone else deletes the item when the
# form is open
transport
.
items
.
delete
(
view
.
item
[
'
id
'
])
view
.
form_valid
(
form
)
assert_message
(
view
.
request
,
messages
.
ERROR
,
"
Not found.
"
)
@pytest.mark.django_db
def
test_item_term_update_transport_exception_logs_message
(
view
,
form
):
# This shouldn't be possible from the form but we may get other
# TransportException errors
form
.
cleaned_data
[
'
category
'
]
=
"
A category that doesn
'
t exist
"
view
.
form_valid
(
form
)
assert_message
(
view
.
request
,
messages
.
ERROR
,
"
Term matching query does not exist.
"
)
@pytest.mark.django_db
def
test_item_term_delete_transport_exception_logs_message
(
view
,
form
):
# This shouldn't be possible from the form but we may get other
# TransportException errors
form
.
cleaned_data
[
'
category
'
]
=
''
# Not sure if this is good practice
from
..constants
import
ITEM_TYPE_CATEGORY
ITEM_TYPE_CATEGORY
[
'
question
'
]
=
'
unknown-slug
'
view
.
form_valid
(
form
)
ITEM_TYPE_CATEGORY
[
'
question
'
]
=
'
ebola-questions
'
assert_message
(
view
.
request
,
messages
.
ERROR
,
"
Taxonomy with slug
'
unknown-slug
'
does not exist.
"
)
This diff is collapsed.
Click to expand it.
django/website/hid/views/item.py
+
21
−
12
View file @
a3f6d8ae
...
...
@@ -162,23 +162,32 @@ class AddEditItemView(FormView):
# TODO: Combine terms into single transaction
category
=
form
.
cleaned_data
.
pop
(
'
category
'
,
None
)
transport
.
items
.
update
(
id
,
form
.
cleaned_data
)
if
taxonomy
:
if
category
:
transport
.
items
.
add_term
(
id
,
taxonomy
,
category
)
else
:
transport
.
items
.
delete_all_terms
(
id
,
taxonomy
)
try
:
transport
.
items
.
update
(
id
,
form
.
cleaned_data
)
if
taxonomy
:
if
category
:
transport
.
items
.
add_term
(
id
,
taxonomy
,
category
)
else
:
transport
.
items
.
delete_all_terms
(
id
,
taxonomy
)
message
=
_
(
"
%s %d successfully updated.
"
)
%
(
item_description
,
id
,
)
message_code
=
messages
.
SUCCESS
msg
=
_
(
"
%s %d successfully updated.
"
)
%
(
item_description
,
id
,
)
except
transport
.
exceptions
.
TransportException
as
e
:
message
=
e
.
message
.
get
(
'
detail
'
)
if
message
is
None
:
message
=
e
.
message
message_code
=
messages
.
ERROR
return
self
.
_response
(
form
.
cleaned_data
[
'
next
'
],
message
s
.
SUCCESS
,
m
sg
)
message
_code
,
m
essage
)
def
form_invalid
(
self
,
form
):
"""
Form invalid handler
"""
...
...
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