-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from lucyparsons/multi-department-support
Initial multi department support
- Loading branch information
Showing
12 changed files
with
225 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from sqlalchemy import * | ||
from migrate import * | ||
|
||
|
||
from migrate.changeset import schema | ||
pre_meta = MetaData() | ||
post_meta = MetaData() | ||
departments = Table('departments', post_meta, | ||
Column('id', Integer, primary_key=True, nullable=False), | ||
Column('name', String(length=255), index=True, nullable=False), | ||
Column('short_name', String(length=100), nullable=False), | ||
) | ||
|
||
|
||
def upgrade(migrate_engine): | ||
# Upgrade operations go here. Don't create your own engine; bind | ||
# migrate_engine to your metadata | ||
pre_meta.bind = migrate_engine | ||
post_meta.bind = migrate_engine | ||
post_meta.tables['departments'].create() | ||
|
||
|
||
def downgrade(migrate_engine): | ||
# Operations to reverse the above upgrade go here. | ||
pre_meta.bind = migrate_engine | ||
post_meta.bind = migrate_engine | ||
post_meta.tables['departments'].drop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends "base.html" %} | ||
{% import "bootstrap/wtf.html" as wtf %} | ||
{% block title %}OpenOversight Admin - Add Department{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container theme-showcase" role="main"> | ||
|
||
<div class="page-header"> | ||
<h1>Add Department</h1> | ||
</div> | ||
<div class="col-md-6"> | ||
<form class="form" method="post" role="form"> | ||
{{ form.hidden_tag() }} | ||
{{ wtf.form_errors(form, hiddens="only") }} | ||
|
||
{{ wtf.form_field(form.name, autofocus="autofocus") }} | ||
{{ wtf.form_field(form.short_name) }} | ||
{{ wtf.form_field(form.submit, id="submit", button_map={'submit':'primary'}) }} | ||
</form> | ||
<br> | ||
</div> | ||
|
||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
|
||
<div class="container" role="main"> | ||
|
||
<div class="text-center"> | ||
<h1><small>Departments</small></h1> | ||
</div> | ||
|
||
<div class="text-center frontpage-leads"> | ||
|
||
{% for department in departments %} | ||
|
||
<h4><small>{{ department.name }} ({{department.short_name}})</small></h4> | ||
|
||
{% endfor %} | ||
|
||
{% if current_user.is_administrator %} | ||
<a href="{{ url_for('main.add_department') }}" | ||
class="btn btn-primary" role="button"> | ||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> | ||
Add New Department | ||
</a> | ||
{% endif %} | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,11 @@ def mockdata(session, request): | |
session.add_all(assignments) | ||
session.add_all(faces) | ||
|
||
department = models.Department(name='Springfield Police Department', | ||
short_name='SPD') | ||
session.add(department) | ||
session.commit() | ||
|
||
test_user = models.User(email='[email protected]', | ||
username='test_user', | ||
password='dog', | ||
|
@@ -196,6 +201,7 @@ def teardown(): | |
models.Image.query.delete() | ||
models.Face.query.delete() | ||
models.Unit.query.delete() | ||
models.Department.query.delete() | ||
session.commit() | ||
session.flush() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,11 @@ def populate(): | |
db.session.add_all(test_images) | ||
db.session.commit() | ||
|
||
department = models.Department(name='Springfield Police Department', | ||
short_name='SPD') | ||
db.session.add(department) | ||
db.session.commit() | ||
|
||
officers = [generate_officer() for o in range(NUM_OFFICERS)] | ||
db.session.add_all(officers) | ||
db.session.commit() | ||
|
@@ -120,6 +125,7 @@ def populate(): | |
test_user = models.User(email='[email protected]', | ||
username='test_user', | ||
password='testtest', | ||
is_administrator=True, | ||
confirmed=True) | ||
db.session.add(test_user) | ||
db.session.commit() | ||
|
@@ -137,6 +143,10 @@ def cleanup(): | |
for face in faces: | ||
db.session.delete(face) | ||
|
||
departments = models.Department.query.all() | ||
for dept in departments: | ||
db.session.delete(dept) | ||
|
||
officers = models.Officer.query.all() | ||
for po in officers: | ||
db.session.delete(po) | ||
|