Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
get_start_flask
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
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
Ishan Patel
get_start_flask
Commits
72b68cce
Commit
72b68cce
authored
7 years ago
by
Bo-Chun Chen
Browse files
Options
Downloads
Patches
Plain Diff
Added views for admin employees pages
parent
46ff59c4
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/admin/views.py
+44
-2
44 additions, 2 deletions
app/admin/views.py
with
44 additions
and
2 deletions
app/admin/views.py
+
44
−
2
View file @
72b68cce
...
...
@@ -2,9 +2,9 @@ from flask import abort, flash, redirect, render_template, url_for
from
flask_login
import
current_user
,
login_required
from
.
import
admin
from
forms
import
DepartmentForm
,
RoleForm
from
forms
import
DepartmentForm
,
EmployeeAssignForm
,
RoleForm
from
..
import
db
from
..models
import
Department
,
Role
from
..models
import
Department
,
Employee
,
Role
def
check_admin
():
"""
...
...
@@ -191,3 +191,45 @@ def delete_role(id):
return
redirect
(
url_for
(
'
admin.list_roles
'
))
return
render_template
(
title
=
"
Delete Role
"
)
# Employee Views
@admin.route
(
'
/employees
'
)
@login_required
def
list_employees
():
"""
List all employees
"""
check_admin
()
employees
=
Employee
.
query
.
all
()
return
render_template
(
'
admin/employees/employees.html
'
,
employees
=
employees
,
title
=
'
Employees
'
)
@admin.route
(
'
/employees/assign/<int:id>
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@login_required
def
assign_employee
(
id
):
"""
Assign a department and a role to an employee
"""
check_admin
()
employee
=
Employee
.
query
.
get_or_404
(
id
)
# prevent admin from being assigned a department or role
if
employee
.
is_admin
:
abort
(
403
)
form
=
EmployeeAssignForm
(
obj
=
employee
)
if
form
.
validate_on_submit
():
employee
.
department
=
form
.
department
.
data
employee
.
role
=
form
.
role
.
data
db
.
session
.
add
(
employee
)
db
.
session
.
commit
()
flash
(
'
You have successfully assigned a department and role.
'
)
# redirect to the roles page
return
redirect
(
url_for
(
'
admin.list_employees
'
))
return
render_template
(
'
admin/employees/employee.html
'
,
employee
=
employee
,
form
=
form
,
title
=
'
Assign Employee
'
)
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