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

Don't use QSqlDatabase #61

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

magul
Copy link
Member

@magul magul commented Apr 6, 2025

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)

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?)
Copy link
Contributor

@Rafalkufel Rafalkufel left a 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

Comment on lines +47 to +49
def rowCount(self, parent=QModelIndex()):
return len(get_team_members()) + (1 if self.insert_row is not None else 0)

Copy link
Contributor

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.

Comment on lines +31 to +32
if self.insert_row is not None and index.row() + 1 == self.rowCount():
return self.insert_row.get(TeamMember.__table__.columns.keys()[index.column()], "")
Copy link
Contributor

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?

Suggested change
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, "")

Comment on lines +33 to +37
return getattr(
get_team_members()[index.row()],
TeamMember.__table__.columns.keys()[index.column()],
)
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you splilt it?

Suggested change
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():
Copy link
Contributor

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?

Suggested change
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:

Comment on lines +68 to +71
with db_session() as db:
tm = TeamMember(**tm_dict)
db.add(tm)
db.commit()
Copy link
Contributor

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
Copy link
Contributor

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?

Comment on lines +90 to +93
with db_session() as db:
stmt = delete(TeamMember).where(TeamMember.id == db_id)
db.execute(stmt)
db.commit()
Copy link
Contributor

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):
Copy link
Contributor

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():
Copy link
Contributor

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()

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