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
dcc35581
Commit
dcc35581
authored
9 years ago
by
Martin Burchell
Browse files
Options
Downloads
Patches
Plain Diff
Implemented updating of category on form submit
parent
304addd6
No related branches found
Branches containing commit
No related tags found
1 merge request
!37
Items can be edited when form is submitted
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/hid/tests/add_edit_item_view_tests.py
+48
-4
48 additions, 4 deletions
django/website/hid/tests/add_edit_item_view_tests.py
django/website/hid/views/item.py
+13
-3
13 additions, 3 deletions
django/website/hid/views/item.py
with
61 additions
and
7 deletions
django/website/hid/tests/add_edit_item_view_tests.py
+
48
−
4
View file @
dcc35581
...
...
@@ -31,9 +31,15 @@ def item():
@pytest.fixture
def
view
(
item
):
def
item_type
():
return
{
'
name
'
:
'
question
'
,
'
long_name
'
:
'
Question
'
}
@pytest.fixture
def
view
(
item
,
item_type
):
view
=
AddEditItemView
()
view
.
item
=
item
view
.
item_type
=
item_type
url
=
reverse
(
'
edit-item
'
,
kwargs
=
{
'
item_id
'
:
item
[
'
id
'
]})
...
...
@@ -53,6 +59,7 @@ def form(view, item):
return
form
ReqFactory
=
RequestFactory
()
...
...
@@ -353,8 +360,6 @@ def test_displaying_unknown_item_returns_redirect_response(generic_item):
@pytest.mark.django_db
def
test_item_can_be_updated
(
view
,
form
):
view
.
item_type
=
{
'
long_name
'
:
'
Question
'
}
new_text
=
"
What is the cause of Ebola?
"
form
.
cleaned_data
[
'
body
'
]
=
new_text
,
...
...
@@ -364,9 +369,48 @@ def test_item_can_be_updated(view, form):
assert
item
[
'
body
'
]
==
new_text
@pytest.mark.django_db
def
test_item_category_can_be_updated
(
view
,
form
):
form
.
cleaned_data
[
'
category
'
]
=
'
Ebola updates
'
,
view
.
form_valid
(
form
)
item
=
transport
.
items
.
get
(
view
.
item
[
'
id
'
])
terms
=
{
t
[
'
taxonomy
'
]:
t
[
'
name
'
]
for
t
in
item
[
'
terms
'
]}
assert
terms
[
'
ebola-questions
'
]
==
'
Ebola updates
'
@pytest.mark.django_db
def
test_item_category_can_be_unset
(
view
,
form
):
transport
.
items
.
add_term
(
view
.
item
[
'
id
'
],
'
ebola-questions
'
,
'
Ebola origins
'
)
form
.
cleaned_data
[
'
category
'
]
=
''
view
.
form_valid
(
form
)
item
=
transport
.
items
.
get
(
view
.
item
[
'
id
'
])
terms
=
{
t
[
'
taxonomy
'
]:
t
[
'
name
'
]
for
t
in
item
[
'
terms
'
]}
assert
'
ebola-questions
'
not
in
terms
@pytest.mark.django_db
def
test_item_category_not_required
(
view
,
form
):
form
.
cleaned_data
[
'
category
'
]
=
''
view
.
form_valid
(
form
)
item
=
transport
.
items
.
get
(
view
.
item
[
'
id
'
])
terms
=
{
t
[
'
taxonomy
'
]:
t
[
'
name
'
]
for
t
in
item
[
'
terms
'
]}
assert
'
ebola-questions
'
not
in
terms
@pytest.mark.django_db
def
test_item_update_logs_message_and_redirects
(
view
,
form
):
view
.
item_type
=
{
'
long_name
'
:
'
Question
'
}
view
.
item_type
[
'
long_name
'
]
=
'
Question
'
response
=
view
.
form_valid
(
form
)
assert
response
.
url
==
form
.
cleaned_data
[
'
next
'
]
...
...
This diff is collapsed.
Click to expand it.
django/website/hid/views/item.py
+
13
−
3
View file @
dcc35581
...
...
@@ -154,14 +154,24 @@ class AddEditItemView(FormView):
id
=
int
(
form
.
cleaned_data
[
'
id
'
])
if
self
.
item_type
:
item_type
=
self
.
item_type
[
'
long_name
'
]
item_description
=
self
.
item_type
[
'
long_name
'
]
taxonomy
=
ITEM_TYPE_CATEGORY
.
get
(
self
.
item_type
[
'
name
'
])
else
:
item_type
=
'
Item
'
item_description
=
'
Item
'
taxonomy
=
None
# 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
)
msg
=
_
(
"
%s %d successfully updated.
"
)
%
(
item_
type
,
item_
description
,
id
,
)
...
...
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