-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log record many residents: Backend (#192)
* Create & migrate log_record_residents table * changed add record function * change delete and update * modify update logic * change get function * changed filtering by residents * modify comments * change filter logic again * initial frontend changes * fix count function * changing create and edit * Enable multiselect for residents * small fixes * Enable resident multiselect when creating log * small changes * Fix residents array for API request * Multiselect residents for edit log * testing some stuff * fix edit log * change migration files * send empty tags array * change filter query to filter by initial + room num * Pass resident labels * Revert "change filter query to filter by initial + room num" This reverts commit 173d504. * Revert "Pass resident labels" This reverts commit 3b03c7f. * resolve pr comments * run lint function * run linter * resolve PR comments * Style residents dropdown * Minor style fixes --------- Co-authored-by: Carolyn Zhang <[email protected]>
- Loading branch information
1 parent
f912d50
commit 90a181e
Showing
24 changed files
with
227 additions
and
123 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from sqlalchemy import inspect | ||
from sqlalchemy.orm.properties import ColumnProperty | ||
|
||
from . import db | ||
|
||
|
||
class LogRecordResidents(db.Model): | ||
__tablename__ = "log_record_residents" | ||
|
||
id = db.Column(db.Integer, primary_key=True, nullable=False) | ||
log_record_id = db.Column( | ||
db.Integer, db.ForeignKey("log_records.log_id"), nullable=False | ||
) | ||
resident_id = db.Column(db.Integer, db.ForeignKey("residents.id"), nullable=False) | ||
|
||
def to_dict(self, include_relationships=False): | ||
# define the entities table | ||
cls = type(self) | ||
|
||
mapper = inspect(cls) | ||
formatted = {} | ||
for column in mapper.attrs: | ||
field = column.key | ||
attr = getattr(self, field) | ||
# if it's a regular column, extract the value | ||
if isinstance(column, ColumnProperty): | ||
formatted[field] = attr | ||
# otherwise, it's a relationship field | ||
# (currently not applicable, but may be useful for entity groups) | ||
elif include_relationships: | ||
# recursively format the relationship | ||
# don't format the relationship's relationships | ||
formatted[field] = [obj.to_dict() for obj in attr] | ||
return formatted |
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
54 changes: 54 additions & 0 deletions
54
backend/migrations/versions/0c76a8fe211d_add_log_record_residents.py
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,54 @@ | ||
"""add log_record_residents | ||
Revision ID: 0c76a8fe211d | ||
Revises: 24fad25f60e3 | ||
Create Date: 2023-10-19 00:02:43.259307 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "0c76a8fe211d" | ||
down_revision = "24fad25f60e3" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"log_record_residents", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("log_record_id", sa.Integer(), nullable=False), | ||
sa.Column("resident_id", sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["log_record_id"], | ||
["log_records.log_id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["resident_id"], | ||
["residents.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
with op.batch_alter_table("log_records", schema=None) as batch_op: | ||
batch_op.drop_constraint("log_records_resident_id_fkey", type_="foreignkey") | ||
batch_op.drop_column("resident_id") | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("log_records", schema=None) as batch_op: | ||
batch_op.add_column( | ||
sa.Column("resident_id", sa.INTEGER(), autoincrement=False, nullable=False) | ||
) | ||
batch_op.create_foreign_key( | ||
"log_records_resident_id_fkey", "residents", ["resident_id"], ["id"] | ||
) | ||
|
||
op.drop_table("log_record_residents") | ||
# ### end Alembic commands ### |
This file was deleted.
Oops, something went wrong.
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.