Skip to content

Determine standard model scheme  #1012

@michplunkett

Description

@michplunkett

What issue are you seeing?

We are currently split between two model paradigms and it makes things a bit confusing when updating and creating new models.
We have some models (specifically Incidents) that are based off of the ModelView object:

class ModelView(MethodView):
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 = "" # type: Form
create_function = "" # type: Union[str, Callable]
department_check = False

We then have some (Departments, Officers, etc.) that are dealt with through the use of routes:

@main.route("/officer/<int:officer_id>/assignment/new", methods=[HTTPMethod.POST])
@ac_or_admin_required
def add_assignment(officer_id):
form = AssignmentForm()
form.created_by.data = current_user.get_id()
officer = Officer.query.filter_by(id=officer_id).first()
form.job_title.query = (
Job.query.filter_by(department_id=officer.department_id)
.order_by(Job.order.asc())
.all()
)
if not officer:
flash("Officer not found")
abort(HTTPStatus.NOT_FOUND)
if form.validate_on_submit():
if current_user.is_administrator or (
current_user.is_area_coordinator
and officer.department_id == current_user.ac_department_id
):
try:
add_new_assignment(officer_id, form)
flash("Added new assignment!")
except IntegrityError:
flash("Assignment already exists")
return redirect(
url_for("main.officer_profile", officer_id=officer_id),
code=HTTPStatus.FOUND,
)
elif (
current_user.is_area_coordinator
and not officer.department_id == current_user.ac_department_id
):
abort(HTTPStatus.FORBIDDEN)
else:
current_app.logger.info(form.errors)
flash("Error: " + str(form.errors))
return redirect(url_for("main.officer_profile", officer_id=officer_id))

Trying to work in both paradigms is a bit difficult and adds a lot of confusion to the general development process. If we could move to one or the other, that'd be ideal.

cc: @abandoned-prototype @AetherUnbound @sea-kelp @dismantl

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions