Skip to content

Commit

Permalink
minor fixes due to rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
dismantl committed Jul 6, 2020
1 parent e354f3d commit df143b3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
4 changes: 2 additions & 2 deletions OpenOversight/app/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class LinkForm(Form):
choices=LINK_CHOICES,
default='',
validators=[AnyOf(allowed_values(LINK_CHOICES))])
creator_id = HiddenField(validators=[Required(message='Not a valid user ID')])
creator_id = HiddenField(validators=[DataRequired(message='Not a valid user ID')])

def validate(self):
success = super(LinkForm, self).validate()
Expand All @@ -166,7 +166,7 @@ def validate(self):


class OfficerLinkForm(LinkForm):
officer_id = HiddenField(validators=[Required(message='Not a valid officer ID')])
officer_id = HiddenField(validators=[DataRequired(message='Not a valid officer ID')])
submit = SubmitField(label='Submit')


Expand Down
3 changes: 1 addition & 2 deletions OpenOversight/app/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
replace_list, create_note, set_dynamic_default, roster_lookup,
create_description, filter_by_form,
crop_image, create_incident, get_or_create, dept_choices,
upload_image_to_s3_and_store_in_db, get_uploaded_cropped_image,
create_link)
upload_image_to_s3_and_store_in_db, create_link)

from .forms import (FindOfficerForm, FindOfficerIDForm, AddUnitForm,
FaceTag, AssignmentForm, DepartmentForm, AddOfficerForm,
Expand Down
26 changes: 11 additions & 15 deletions OpenOversight/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,21 +464,6 @@ def crop_image(image, crop_data=None, department_id=None):
image_type = imghdr.what(image_buf)
pimage = Pimage.open(image_buf)

def create_link(self, form):
link = Link(
title=form.title.data,
url=form.url.data,
link_type=form.link_type.data,
description=form.description.data,
author=form.author.data,
creator_id=form.creator_id.data)
if hasattr(form, 'officer_id'):
link.officer_id = form.officer_id.data
return link

def get_uploaded_cropped_image(original_image, crop_data):
""" Takes an Image object and a cropping tuple (left, upper, right, lower), and returns a new Image object"""

SIZE = 300, 300
if not crop_data and pimage.size[0] < SIZE[0] and pimage.size[1] < SIZE[1]:
return image
Expand All @@ -494,6 +479,17 @@ def get_uploaded_cropped_image(original_image, crop_data):

return upload_image_to_s3_and_store_in_db(cropped_image_buf, current_user.get_id(), department_id)

def create_link(self, form):
link = Link(
title=form.title.data,
url=form.url.data,
link_type=form.link_type.data,
description=form.description.data,
author=form.author.data,
creator_id=form.creator_id.data)
if hasattr(form, 'officer_id'):
link.officer_id = form.officer_id.data
return link

def upload_image_to_s3_and_store_in_db(image_buf, user_id, department_id=None):
image_buf.seek(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Refactor links
Revision ID: 86eb228e4bc0
Revises: 3015d1dd9eb4
Revises: 562bd5f1bc1f
Create Date: 2019-03-15 22:40:10.473917
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = '86eb228e4bc0'
down_revision = '3015d1dd9eb4'
down_revision = '562bd5f1bc1f'
branch_labels = None
depends_on = None

Expand Down
6 changes: 3 additions & 3 deletions OpenOversight/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ def add_mockdata(session):
session.commit()

test_incident_links = [
models.Link(url='https://stackoverflow.com/', link_type='link', user=test_admin, user_id=test_admin.id),
models.Link(url='http://www.youtube.com/?v=help', link_type='video', user=test_admin, user_id=test_admin.id)
models.Link(url='https://stackoverflow.com/', link_type='link', creator=test_admin, creator_id=test_admin.id),
models.Link(url='http://www.youtube.com/?v=help', link_type='video', creator=test_admin, creator_id=test_admin.id)
]

session.add_all(test_incident_links)
Expand Down Expand Up @@ -403,7 +403,7 @@ def add_mockdata(session):
department_id=2,
address=test_addresses[1],
license_plates=[test_license_plates[0]],
links=test_links,
links=test_incident_links,
officers=[all_officers[o] for o in range(1)],
creator_id=2,
last_updated_id=1
Expand Down

0 comments on commit df143b3

Please sign in to comment.