Skip to content

Commit cc06d42

Browse files
committed
Code Formatting by Docker Black
1 parent cc3d052 commit cc06d42

31 files changed

+827
-590
lines changed

backend/api.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from backend.auth import jwt, refresh_token
1010
from backend.schemas import spec
1111
from backend.routes.sources import bp as sources_bp
12+
1213
# from backend.routes.incidents import bp as incidents_bp
1314
from backend.routes.officers import bp as officers_bp
1415
from backend.routes.agencies import bp as agencies_bp
@@ -48,15 +49,13 @@ def register_extensions(app: Flask):
4849
# Driver setup
4950
db_driver = GraphDatabase.driver(
5051
f'bolt://{app.config["GRAPH_NM_URI"]}',
51-
auth=(
52-
app.config["GRAPH_USER"],
53-
app.config["GRAPH_PASSWORD"]
54-
))
52+
auth=(app.config["GRAPH_USER"], app.config["GRAPH_PASSWORD"]),
53+
)
5554

5655
try:
5756
db_driver.verify_connectivity()
58-
app.config['DB_DRIVER'] = db_driver
59-
neo_config.DRIVER = app.config['DB_DRIVER']
57+
app.config["DB_DRIVER"] = db_driver
58+
neo_config.DRIVER = app.config["DB_DRIVER"]
6059
print("Connected to Neo4j")
6160
except Exception as e:
6261
print(f"Error connecting to Database: {e}")
@@ -66,15 +65,15 @@ def register_extensions(app: Flask):
6665
neo_url = "bolt://{user}:{pw}@{uri}".format(
6766
user=app.config["GRAPH_USER"],
6867
pw=app.config["GRAPH_PASSWORD"],
69-
uri=app.config["GRAPH_NM_URI"]
68+
uri=app.config["GRAPH_NM_URI"],
7069
)
7170
neo_config.DATABASE_URL = neo_url
7271

7372
spec.register(app)
7473

7574
# Authentication
7675
ph = PasswordHasher()
77-
app.config['PASSWORD_HASHER'] = ph
76+
app.config["PASSWORD_HASHER"] = ph
7877
jwt.init_app(app)
7978

8079
Mail(app)

backend/auth/jwt.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ def verify_contributor_has_source_or_abort():
2424
verify_jwt_in_request()
2525
jwt_decoded = get_jwt()
2626
current_user = User.get(jwt_decoded["sub"])
27-
if (
28-
current_user is None
29-
or not current_user.member_of
30-
):
27+
if current_user is None or not current_user.member_of:
3128
abort(403)
3229
return False
3330
return True

backend/config.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from dotenv import load_dotenv
33
from datetime import timedelta
4+
45
if os.environ.get("FLASK_ENV") != "production":
56
load_dotenv()
67

@@ -34,8 +35,7 @@ class Config(object):
3435
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD")
3536
MAIL_DEFAULT_SENDER = os.environ.get(
3637
"MAIL_DEFAULT_SENDER",
37-
"National Police Data Coalition <{email}>".format(
38-
email=MAIL_USERNAME),
38+
"National Police Data Coalition <{email}>".format(email=MAIL_USERNAME),
3939
)
4040

4141
"""
@@ -60,18 +60,15 @@ class Config(object):
6060

6161
FRONTEND_PORT = os.environ.get("NPDI_WEB_PORT", "3000")
6262
FRONTEND_URL = os.environ.get(
63-
"FRONTEND_URL",
64-
"http://localhost:" + FRONTEND_PORT
63+
"FRONTEND_URL", "http://localhost:" + FRONTEND_PORT
6564
)
6665

6766
SCRAPER_SQS_QUEUE_NAME = os.environ.get("SCRAPER_SQS_QUEUE_NAME")
6867

6968
@property
7069
def NEO4J_BOLT_URI(self):
7170
return "bolt://{user}:{pw}@{uri}".format(
72-
user=self.GRAPH_USER,
73-
pw=self.GRAPH_PASSWORD,
74-
uri=self.GRAPH_NM_URI
71+
user=self.GRAPH_USER, pw=self.GRAPH_PASSWORD, uri=self.GRAPH_NM_URI
7572
)
7673

7774
@property

backend/database/core.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Do not import anything directly from `backend.database._core`. Instead, import
55
from `backend.database`.
66
"""
7+
78
import os
89
from typing import Optional
910

@@ -31,11 +32,11 @@ def execute_query(filename: str) -> Optional[List[Dict[str, Any]]]:
3132
"""
3233
# Read the query from the file
3334
query_path = os.path.join(QUERIES_DIR, secure_filename(filename))
34-
with open(query_path, 'r') as f:
35+
with open(query_path, "r") as f:
3536
query = f.read()
3637

3738
# Get the Neo4j driver
38-
neo4j_conn = current_app.config['DB_DRIVER']
39+
neo4j_conn = current_app.config["DB_DRIVER"]
3940

4041
# Execute the query using the existing connection
4142
with neo4j_conn.session() as session:
@@ -76,7 +77,7 @@ def create_database(overwrite: bool):
7677
"""Initialize the Neo4j database by setting up constraints and indexes."""
7778
if overwrite:
7879
# Get the Neo4j driver
79-
neo4j_conn = current_app.config['DB_DRIVER']
80+
neo4j_conn = current_app.config["DB_DRIVER"]
8081

8182
with neo4j_conn.session() as session:
8283
session.run("MATCH (n) DETACH DELETE n")
@@ -121,14 +122,14 @@ def delete_database(test_db: bool):
121122
"""Delete all data from the Neo4j database."""
122123
if test_db:
123124
# If you have a separate test database, drop it
124-
test_neo4j_conn = current_app.config['DB_DRIVER']
125+
test_neo4j_conn = current_app.config["DB_DRIVER"]
125126
test_db_name = current_app.config.get("GRAPH_TEST_DB_NAME", "test")
126127
with test_neo4j_conn.session(database="system") as session:
127128
session.run(f"DROP DATABASE {test_db_name} IF EXISTS")
128129
click.echo(f"Test database {test_db_name!r} was deleted.")
129130
else:
130131
# Delete all data from the default database
131-
neo4j_conn = current_app.config['DB_DRIVER']
132+
neo4j_conn = current_app.config["DB_DRIVER"]
132133
with neo4j_conn.session() as session:
133134
session.run("MATCH (n) DETACH DELETE n")
134135
click.echo("Deleted all data from the Neo4j database.")

backend/database/models/agency.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
RelationshipTo,
1010
DateProperty,
1111
UniqueIdProperty,
12-
One
12+
One,
1313
)
1414

1515

@@ -50,12 +50,17 @@ class Unit(StructuredNode, JsonSerializable):
5050
agency = RelationshipTo("Agency", "ESTABLISHED_BY", cardinality=One)
5151
commander = RelationshipTo(
5252
"backend.database.models.officer.Officer",
53-
"COMMANDED_BY", model=UnitMembership)
53+
"COMMANDED_BY",
54+
model=UnitMembership,
55+
)
5456
officers = RelationshipTo(
5557
"backend.database.models.officer.Officer",
56-
"MEMBER_OF", model=UnitMembership)
58+
"MEMBER_OF",
59+
model=UnitMembership,
60+
)
5761
citations = RelationshipTo(
58-
'backend.database.models.source.Source', "UPDATED_BY", model=Citation)
62+
"backend.database.models.source.Source", "UPDATED_BY", model=Citation
63+
)
5964

6065
def __repr__(self):
6166
return f"<Unit {self.name}>"
@@ -79,7 +84,8 @@ class Agency(StructuredNode, JsonSerializable):
7984
# Relationships
8085
units = RelationshipTo("Unit", "ESTABLISHED")
8186
citations = RelationshipTo(
82-
'backend.database.models.source.Source', "UPDATED_BY", model=Citation)
87+
"backend.database.models.source.Source", "UPDATED_BY", model=Citation
88+
)
8389

8490
def __repr__(self):
8591
return f"<Agency {self.name}>"

backend/database/models/attachment.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
from backend.schemas import JsonSerializable
2-
from neomodel import (
3-
StringProperty,
4-
UniqueIdProperty,
5-
StructuredNode
6-
)
2+
from neomodel import StringProperty, UniqueIdProperty, StructuredNode
73

84

95
class Attachment(JsonSerializable, StructuredNode):

backend/database/models/civilian.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Define the Classes for Civilians."""
2+
23
from neomodel import (
34
StructuredNode,
45
StringProperty,
56
IntegerProperty,
6-
RelationshipTo
7+
RelationshipTo,
78
)
89

910

@@ -14,6 +15,8 @@ class Civilian(StructuredNode):
1415

1516
# Relationships
1617
complaints = RelationshipTo(
17-
"backend.database.models.complaint.Complaint", "COMPLAINED_OF")
18+
"backend.database.models.complaint.Complaint", "COMPLAINED_OF"
19+
)
1820
witnessed_complaints = RelationshipTo(
19-
"backend.database.models.complaint.Complaint", "WITNESSED")
21+
"backend.database.models.complaint.Complaint", "WITNESSED"
22+
)

backend/database/models/complaint.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Define the Classes for Complaints."""
2+
23
from backend.schemas import JsonSerializable, PropertyEnum
34
from neomodel import (
45
StructuredNode,
@@ -7,7 +8,7 @@
78
RelationshipTo,
89
RelationshipFrom,
910
DateProperty,
10-
UniqueIdProperty
11+
UniqueIdProperty,
1112
)
1213

1314

@@ -20,10 +21,7 @@ class RecordType(str, PropertyEnum):
2021

2122
# Neo4j Models
2223
class BaseSourceRel(StructuredRel, JsonSerializable):
23-
record_type = StringProperty(
24-
choices=RecordType.choices(),
25-
required=True
26-
)
24+
record_type = StringProperty(choices=RecordType.choices(), required=True)
2725

2826

2927
class LegalSourceRel(BaseSourceRel):

backend/database/models/litigation.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
StringProperty,
66
RelationshipTo,
77
DateProperty,
8-
UniqueIdProperty
8+
UniqueIdProperty,
99
)
1010

1111

@@ -35,7 +35,8 @@ class Litigation(StructuredNode, JsonSerializable):
3535
dispositions = RelationshipTo("Disposition", "YIELDED")
3636
defendants = RelationshipTo("Officer", "NAMED_IN")
3737
citations = RelationshipTo(
38-
'backend.database.models.source.Source', "UPDATED_BY", model=Citation)
38+
"backend.database.models.source.Source", "UPDATED_BY", model=Citation
39+
)
3940

4041
def __repr__(self):
4142
return f"<Litigation {self.uid}:{self.case_title}>"

backend/database/models/officer.py

+29-15
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
from neomodel import (
66
StructuredNode,
7-
RelationshipTo, RelationshipFrom, Relationship,
8-
StringProperty, DateProperty,
9-
UniqueIdProperty, One
7+
RelationshipTo,
8+
RelationshipFrom,
9+
Relationship,
10+
StringProperty,
11+
DateProperty,
12+
UniqueIdProperty,
13+
One,
1014
)
1115

1216

@@ -16,20 +20,26 @@ class StateID(StructuredNode, JsonSerializable):
1620
law enforcement agencies. For example, in New York, this would be
1721
the Tax ID Number.
1822
"""
23+
1924
id_name = StringProperty() # e.g. "Tax ID Number"
2025
state = StringProperty(choices=State.choices()) # e.g. "NY"
2126
value = StringProperty() # e.g. "958938"
22-
officer = RelationshipFrom('Officer', "HAS_STATE_ID", cardinality=One)
27+
officer = RelationshipFrom("Officer", "HAS_STATE_ID", cardinality=One)
2328

2429
def __repr__(self):
2530
return f"<StateID: Officer {self.officer_id}, {self.state}>"
2631

2732

2833
class Officer(StructuredNode, JsonSerializable):
2934
__property_order__ = [
30-
"uid", "first_name", "middle_name",
31-
"last_name", "suffix", "ethnicity",
32-
"gender", "date_of_birth"
35+
"uid",
36+
"first_name",
37+
"middle_name",
38+
"last_name",
39+
"suffix",
40+
"ethnicity",
41+
"gender",
42+
"date_of_birth",
3343
]
3444
__hidden_properties__ = ["citations"]
3545

@@ -43,19 +53,23 @@ class Officer(StructuredNode, JsonSerializable):
4353
date_of_birth = DateProperty()
4454

4555
# Relationships
46-
state_ids = RelationshipTo('StateID', "HAS_STATE_ID")
56+
state_ids = RelationshipTo("StateID", "HAS_STATE_ID")
4757
units = Relationship(
48-
'backend.database.models.agency.Unit', "MEMBER_OF_UNIT")
58+
"backend.database.models.agency.Unit", "MEMBER_OF_UNIT"
59+
)
4960
litigation = Relationship(
50-
'backend.database.models.litigation.Litigation', "NAMED_IN")
61+
"backend.database.models.litigation.Litigation", "NAMED_IN"
62+
)
5163
allegations = Relationship(
52-
'backend.database.models.complaint.Allegation', "ACCUSED_OF")
64+
"backend.database.models.complaint.Allegation", "ACCUSED_OF"
65+
)
5366
investigations = Relationship(
54-
'backend.database.models.complaint.Investigation', "LEAD_BY")
55-
commands = Relationship(
56-
'backend.database.models.agency.Unit', "COMMANDS")
67+
"backend.database.models.complaint.Investigation", "LEAD_BY"
68+
)
69+
commands = Relationship("backend.database.models.agency.Unit", "COMMANDS")
5770
citations = RelationshipTo(
58-
'backend.database.models.source.Source', "UPDATED_BY", model=Citation)
71+
"backend.database.models.source.Source", "UPDATED_BY", model=Citation
72+
)
5973

6074
def __repr__(self):
6175
return f"<Officer {self.element_id}>"

0 commit comments

Comments
 (0)