Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
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
Code review analytics
Issue 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
Anders Harrisson
csentry
Commits
909dd31e
Commit
909dd31e
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Clean create_host view
Use the session instead of URL parameters to store the last network chosen.
parent
febf5fa9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/main/views.py
+8
-6
8 additions, 6 deletions
app/main/views.py
with
8 additions
and
6 deletions
app/main/views.py
+
8
−
6
View file @
909dd31e
...
...
@@ -10,7 +10,7 @@ This module implements the main blueprint.
"""
import
sqlalchemy
as
sa
from
flask
import
(
Blueprint
,
render_template
,
jsonify
,
from
flask
import
(
Blueprint
,
render_template
,
jsonify
,
session
,
redirect
,
url_for
,
request
,
flash
,
current_app
)
from
flask_login
import
login_required
from
.forms
import
AttributeForm
,
HostForm
,
ItemForm
...
...
@@ -156,17 +156,17 @@ def list_hosts():
@bp.route
(
'
/hosts/create
'
,
methods
=
(
'
GET
'
,
'
POST
'
))
@login_groups_accepted
(
'
admin
'
,
'
create
'
)
def
create_host
():
# Try to get the network_id from the URL parameters
# to display the form with the same selected network
# when reloading the page (redirect after submit)
# Try to get the network_id from the session
# to pre-fill the form with the same network
try
:
network_id
=
request
.
args
[
'
network_id
'
]
network_id
=
session
[
'
network_id
'
]
except
KeyError
:
# No need to pass request.form when no extra keywords are given
form
=
HostForm
()
else
:
form
=
HostForm
(
request
.
form
,
network_id
=
network_id
)
if
form
.
validate_on_submit
():
network_id
=
form
.
network_id
.
data
host
=
models
.
Host
(
ip
=
form
.
ip
.
data
,
network_id
=
form
.
network_id
.
data
,
name
=
form
.
name
.
data
,
...
...
@@ -182,7 +182,9 @@ def create_host():
flash
(
f
'
{
e
}
'
,
'
error
'
)
else
:
flash
(
f
'
Host
{
host
}
created!
'
,
'
success
'
)
return
redirect
(
url_for
(
'
main.create_host
'
,
network_id
=
host
.
network_id
))
# Save network_id to the session to retrieve it after the redirect
session
[
'
network_id
'
]
=
host
.
network_id
return
redirect
(
url_for
(
'
main.create_host
'
))
return
render_template
(
'
create_host.html
'
,
form
=
form
)
...
...
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