-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make url_for work with all endpoints #1070
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
20249f1
Move logic out of templates
abandoned-prototype 79a4b26
Fix url_for usage
abandoned-prototype 312ab90
More template changes
abandoned-prototype c5aca0f
Fix tests
abandoned-prototype 6dc32e9
Clean up commented out code
abandoned-prototype File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import operator | ||
import re | ||
import time | ||
import uuid | ||
from datetime import date, datetime | ||
from typing import List | ||
from typing import List, Optional | ||
|
||
from authlib.jose import JoseError, JsonWebToken | ||
from cachetools import cached | ||
|
@@ -294,21 +295,27 @@ def gender_label(self): | |
def job_title(self): | ||
if self.assignments: | ||
return max( | ||
self.assignments, key=lambda x: x.start_date or date.min | ||
self.assignments, key=operator.attrgetter("start_date_or_min") | ||
).job.job_title | ||
|
||
def unit_description(self): | ||
if self.assignments: | ||
unit = max(self.assignments, key=lambda x: x.start_date or date.min).unit | ||
unit = max( | ||
self.assignments, key=operator.attrgetter("start_date_or_min") | ||
).unit | ||
return unit.description if unit else None | ||
|
||
def badge_number(self): | ||
if self.assignments: | ||
return max(self.assignments, key=lambda x: x.start_date or date.min).star_no | ||
return max( | ||
self.assignments, key=operator.attrgetter("start_date_or_min") | ||
).star_no | ||
|
||
def currently_on_force(self): | ||
if self.assignments: | ||
most_recent = max(self.assignments, key=lambda x: x.start_date or date.min) | ||
most_recent = max( | ||
self.assignments, key=operator.attrgetter("start_date_or_min") | ||
) | ||
return "Yes" if most_recent.resign_date is None else "No" | ||
return "Uncertain" | ||
|
||
|
@@ -340,6 +347,16 @@ class Salary(BaseModel, TrackUpdates): | |
def __repr__(self): | ||
return f"<Salary: ID {self.officer_id} : {self.salary}" | ||
|
||
@property | ||
def total_pay(self) -> float: | ||
return self.salary + self.overtime_pay | ||
|
||
@property | ||
def year_repr(self) -> str: | ||
if self.is_fiscal_year: | ||
return f"FY{self.year}" | ||
return str(self.year) | ||
Comment on lines
+350
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever. |
||
|
||
|
||
class Assignment(BaseModel, TrackUpdates): | ||
__tablename__ = "assignments" | ||
|
@@ -371,6 +388,14 @@ class Assignment(BaseModel, TrackUpdates): | |
def __repr__(self): | ||
return f"<Assignment: ID {self.officer_id} : {self.star_no}>" | ||
|
||
@property | ||
def start_date_or_min(self): | ||
return self.start_date or date.min | ||
|
||
@property | ||
def start_date_or_max(self): | ||
return self.start_date or date.max | ||
|
||
|
||
class Unit(BaseModel, TrackUpdates): | ||
__tablename__ = "unit_types" | ||
|
@@ -702,6 +727,12 @@ class User(UserMixin, BaseModel): | |
unique=False, | ||
) | ||
|
||
def is_admin_or_coordinator(self, department: Optional[Department]) -> bool: | ||
return self.is_administrator or ( | ||
department is not None | ||
and (self.is_area_coordinator and self.ac_department_id == department.id) | ||
) | ||
|
||
def _jwt_encode(self, payload, expiration): | ||
secret = current_app.config["SECRET_KEY"] | ||
header = {"alg": SIGNATURE_ALGORITHM} | ||
|
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,8 @@ | ||
from flask_login import AnonymousUserMixin | ||
|
||
from OpenOversight.app.models.database import Department | ||
|
||
|
||
class AnonymousUser(AnonymousUserMixin): | ||
def is_admin_or_coordinator(self, department: Department) -> bool: | ||
return False |
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 |
---|---|---|
|
@@ -35,7 +35,7 @@ <h5>Enter ranks in hierarchical order, from lowest to highest rank:</h5> | |
</div> | ||
<div class="text-danger">{{ wtf.form_errors(form.jobs, hiddens="only") }}</div> | ||
{% if form.jobs|length > 1 %} | ||
{% for subfield in (form.jobs|rejectattr('data.is_sworn_officer','eq',False)|sort(attribute='data.order')|list) %} | ||
{% for subfield in (form.jobs|sort(attribute='data.order')|list) %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't we talk about having the sorts be in the view previously? |
||
<fieldset> | ||
<div class="input-group {% if subfield.errors %} has-error{% endif -%} {%- if subfield.flags.required %} required{% endif -%}"> | ||
<div class="input-group-addon"> | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmmm, good call!