-
Notifications
You must be signed in to change notification settings - Fork 6
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
Don't use QSqlDatabase #61
base: develop
Are you sure you want to change the base?
Conversation
This is a proof of concept approach to Table view of team members. We also need rethink how to approach that table business-wise (e.g. I don't know if we allow to delete team members, that are listed in documents?)
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.
Nicely done!
Only couple of comments to improve readability
def rowCount(self, parent=QModelIndex()): | ||
return len(get_team_members()) + (1 if self.insert_row is not None else 0) | ||
|
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.
Just suggestion to place columnCount
and rowCount
next to each other.
if self.insert_row is not None and index.row() + 1 == self.rowCount(): | ||
return self.insert_row.get(TeamMember.__table__.columns.keys()[index.column()], "") |
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.
Can you split this line to make it more readable?
if self.insert_row is not None and index.row() + 1 == self.rowCount(): | |
return self.insert_row.get(TeamMember.__table__.columns.keys()[index.column()], "") | |
if self.insert_row is not None and index.row() + 1 == self.rowCount(): | |
new_value_column_name = TeamMember.__table__.columns.keys()[index.column()] | |
return self.insert_row.get(new_value_column_name, "") |
return getattr( | ||
get_team_members()[index.row()], | ||
TeamMember.__table__.columns.keys()[index.column()], | ||
) | ||
return None |
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.
Can you splilt it?
return getattr( | |
get_team_members()[index.row()], | |
TeamMember.__table__.columns.keys()[index.column()], | |
) | |
return None | |
new_member = get_team_members()[index.row()] | |
return getattr(new_member, new_value_column_name) | |
return None |
def setData(self, index, value, role=Qt.EditRole): | ||
if not index.isValid(): | ||
return False | ||
if self.insert_row is not None and index.row() + 1 == self.rowCount(): |
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.
WDYT to split it into more meaningful lines?
if self.insert_row is not None and index.row() + 1 == self.rowCount(): | |
new_team_member_added = bool(self.insert_row is not None and index.row() + 1 == self.rowCount()) | |
if new_team_member_added: |
with db_session() as db: | ||
tm = TeamMember(**tm_dict) | ||
db.add(tm) | ||
db.commit() |
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.
pls write dedicated query in queries.py
to add team member.
if not index.isValid(): | ||
return False | ||
if self.insert_row is not None and index.row() + 1 == self.rowCount(): | ||
self.insert_row[TeamMember.__table__.columns.keys()[index.column()]] = value |
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.
You call for this TeamMember.__table__.columns.keys()[
mutliple times. Maybe we can move this calculation to __init__
or even class attribute? WDYT?
with db_session() as db: | ||
stmt = delete(TeamMember).where(TeamMember.id == db_id) | ||
db.execute(stmt) | ||
db.commit() |
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.
ditto. Can you implement it in queries.py
self.dataChanged.emit(index, index) | ||
return True | ||
|
||
def removeRow(self, row): |
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.
I'd suggest to add typing for all methods.
if not index.isValid(): | ||
return None | ||
if role == Qt.DisplayRole: | ||
if self.insert_row is not None and index.row() + 1 == self.rowCount(): |
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.
You perform this check self.insert_row is not None
4 times in this class. Maybe you can write wrapper with meaningful name:
@property
def is_new_row_to_save(self):
self.insert_row is not None
and this second check:
def is_last_row(self, index: QModelIndex) -> bool:
return index.row() + 1 == self.rowCount()
This is a proof of concept approach to Table view of team members. We also need rethink how to approach that table business-wise (e.g. I don't know if we allow to delete team members, that are listed in documents?)
Closes #40
Closes #34 (as we don't use QSqlDatabase anymore)