Skip to content

Commit

Permalink
Merge branch 'develop' into links-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dismantl authored Sep 27, 2020
2 parents 7f87290 + 327c224 commit 879a850
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ test: start ## Run tests
fi

.PHONY: lint
lint: start
docker-compose run --rm web flake8
lint:
docker-compose run --no-deps --rm web /bin/bash -c 'flake8; mypy app --config="../mypy.ini"'

.PHONY: cleanassets
cleanassets:
Expand Down
19 changes: 10 additions & 9 deletions OpenOversight/app/commands.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from __future__ import print_function
from builtins import input
from getpass import getpass
import sys

import csv
import sys
from builtins import input
from datetime import datetime
from getpass import getpass
from typing import Dict, List

import click
from flask.cli import with_appcontext
from flask import current_app

from .models import db, Assignment, Department, Officer, User, Salary, Job
from .utils import get_officer, str_is_true, prompt_yes_no
from flask.cli import with_appcontext

from .csv_imports import import_csv_files
from .models import Assignment, Department, Job, Officer, Salary, User, db
from .utils import get_officer, prompt_yes_no, str_is_true


@click.command()
Expand Down Expand Up @@ -88,8 +89,8 @@ def link_officers_to_department():


class ImportLog:
updated_officers = {}
created_officers = {}
updated_officers = {} # type: Dict[int, List]
created_officers = {} # type: Dict[int, List]

@classmethod
def log_change(cls, officer, msg):
Expand Down
9 changes: 6 additions & 3 deletions OpenOversight/app/main/model_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import datetime
from flask_sqlalchemy.model import DefaultMeta
from flask_wtf import FlaskForm as Form
from typing import Callable, Union
from flask import render_template, redirect, request, url_for, flash, abort, current_app
from flask.views import MethodView
from flask_login import login_required, current_user
Expand All @@ -8,13 +11,13 @@


class ModelView(MethodView):
model = None
model = None # type: DefaultMeta
model_name = ''
per_page = 20
order_by = '' # this should be a field on the model
descending = False # used for order_by
form = ''
create_function = ''
form = '' # type: Form
create_function = '' # type: Union[str, Callable]
department_check = False

def get(self, obj_id):
Expand Down
2 changes: 1 addition & 1 deletion OpenOversight/app/model_imports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple, Union

import dateutil
import dateutil.parser

from .main import choices
from .models import (
Expand Down
32 changes: 17 additions & 15 deletions OpenOversight/app/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

from flask_sqlalchemy import SQLAlchemy
from flask_sqlalchemy.model import DefaultMeta
from sqlalchemy.orm import validates
from sqlalchemy import UniqueConstraint
from werkzeug.security import generate_password_hash, check_password_hash
Expand All @@ -13,6 +14,7 @@

db = SQLAlchemy()

BaseModel = db.Model # type: DefaultMeta

officer_links = db.Table('officer_links',
db.Column('officer_id', db.Integer, db.ForeignKey('officers.id'), primary_key=True),
Expand All @@ -23,7 +25,7 @@
db.Column('incident_id', db.Integer, db.ForeignKey('incidents.id'), primary_key=True))


class Department(db.Model):
class Department(BaseModel):
__tablename__ = 'departments'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), index=True, unique=True, nullable=False)
Expand All @@ -41,7 +43,7 @@ def toCustomDict(self):
}


class Job(db.Model):
class Job(BaseModel):
__tablename__ = 'jobs'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -61,7 +63,7 @@ def __str__(self):
return self.job_title


class Note(db.Model):
class Note(BaseModel):
__tablename__ = 'notes'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -74,7 +76,7 @@ class Note(db.Model):
date_updated = db.Column(db.DateTime)


class Description(db.Model):
class Description(BaseModel):
__tablename__ = 'descriptions'

creator = db.relationship('User', backref='descriptions')
Expand All @@ -87,7 +89,7 @@ class Description(db.Model):
date_updated = db.Column(db.DateTime)


class Officer(db.Model):
class Officer(BaseModel):
__tablename__ = 'officers'

id = db.Column(db.Integer, primary_key=True)
Expand Down Expand Up @@ -152,7 +154,7 @@ def __repr__(self):
self.suffix)


class Salary(db.Model):
class Salary(BaseModel):
__tablename__ = 'salaries'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -167,7 +169,7 @@ def __repr__(self):
return '<Salary: ID {} : {}'.format(self.officer_id, self.salary)


class Assignment(db.Model):
class Assignment(BaseModel):
__tablename__ = 'assignments'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -186,7 +188,7 @@ def __repr__(self):
self.star_no)


class Unit(db.Model):
class Unit(BaseModel):
__tablename__ = 'unit_types'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -198,7 +200,7 @@ def __repr__(self):
return 'Unit: {}'.format(self.descrip)


class Face(db.Model):
class Face(BaseModel):
__tablename__ = 'faces'

id = db.Column(db.Integer, primary_key=True)
Expand Down Expand Up @@ -238,7 +240,7 @@ def __repr__(self):
return '<Tag ID {}: {} - {}>'.format(self.id, self.officer_id, self.img_id)


class Image(db.Model):
class Image(BaseModel):
__tablename__ = 'raw_images'

id = db.Column(db.Integer, primary_key=True)
Expand Down Expand Up @@ -282,7 +284,7 @@ def __repr__(self):
)


class Location(db.Model):
class Location(BaseModel):
__tablename__ = 'locations'

id = db.Column(db.Integer, primary_key=True)
Expand Down Expand Up @@ -320,7 +322,7 @@ def __repr__(self):
return '{} {}'.format(self.city, self.state)


class LicensePlate(db.Model):
class LicensePlate(BaseModel):
__tablename__ = 'license_plates'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -334,7 +336,7 @@ def validate_state(self, key, state):
return state_validator(state)


class Link(db.Model):
class Link(BaseModel):
__tablename__ = 'links'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -351,7 +353,7 @@ def validate_url(self, key, url):
return url_validator(url)


class Incident(db.Model):
class Incident(BaseModel):
__tablename__ = 'incidents'

id = db.Column(db.Integer, primary_key=True)
Expand All @@ -376,7 +378,7 @@ class Incident(db.Model):
last_updated_by = db.relationship('User', backref='incidents_updated', lazy=True, foreign_keys=[last_updated_id])


class User(UserMixin, db.Model):
class User(UserMixin, BaseModel):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(64), unique=True, index=True)
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pytest-cov==2.4.0
pytest-pep8==1.0.6
xvfbwrapper==0.2.9
mock==2.0.0
mypy==0.782
sphinx==1.7.8
sphinx-autobuild==0.7.1
pandas>=0.23.4
1 change: 1 addition & 0 deletions dockerfiles/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN yarn

COPY create_db.py test_data.py /usr/src/app/
COPY .flake8 /usr/src/app/
COPY mypy.ini /usr/src/app/
EXPOSE 3000

ENV PATH="/usr/src/app/geckodriver:${PATH}"
Expand Down
57 changes: 57 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[mypy]
no_implicit_optional = True


[mypy-boto3]
ignore_missing_imports = True

[mypy-botocore.*]
ignore_missing_imports = True

[mypy-dotenv.*]
ignore_missing_imports = True

[mypy-flickrapi.*]
ignore_missing_imports = True

[mypy-flask_bootstrap.*]
ignore_missing_imports = True

[mypy-flask_limiter.*]
ignore_missing_imports = True

[mypy-flask_login.*]
ignore_missing_imports = True

[mypy-flask_mail.*]
ignore_missing_imports = True

[mypy-flask_migrate.*]
ignore_missing_imports = True

[mypy-flask_sitemap.*]
ignore_missing_imports = True

[mypy-flask_sqlalchemy.*]
ignore_missing_imports = True

[mypy-flask_wtf.*]
ignore_missing_imports = True

[mypy-future.utils.*]
ignore_missing_imports = True

[mypy-PIL.*]
ignore_missing_imports = True

[mypy-sqlalchemy.*]
ignore_missing_imports = True

[mypy-wgetter.*]
ignore_missing_imports = True

[mypy-wtforms.*]
ignore_missing_imports = True

[mypy-us.*]
ignore_missing_imports = True

0 comments on commit 879a850

Please sign in to comment.