Skip to content
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

Determine standard model scheme #1012

Open
michplunkett opened this issue Aug 6, 2023 · 0 comments
Open

Determine standard model scheme #1012

michplunkett opened this issue Aug 6, 2023 · 0 comments

Comments

@michplunkett
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant