Skip to content

Commit

Permalink
Added project description
Browse files Browse the repository at this point in the history
  • Loading branch information
bgorman87 committed Oct 21, 2023
1 parent 7d82db9 commit 9daf627
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 14 deletions.
15 changes: 9 additions & 6 deletions models/main_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def initialize_database(self):
id INTEGER PRIMARY KEY,
project_number TEXT UNIQUE NOT NULL,
directory TEXT,
description TEXT,
email_to TEXT,
email_cc TEXT,
email_bcc TEXT,
Expand Down Expand Up @@ -552,7 +553,7 @@ def fetch_project_data_table_headers(self) -> list[str]:
headers = None
with self.db_connection(self.database_path) as connection:
# Probably not proper way to mitigate SQL injections but good enough since database_table string is not user supplied
query = f"""SELECT project_number, directory, email_to, email_cc, email_bcc, email_subject, email_profile_name FROM project_data;"""
query = f"""SELECT project_number, directory, description, email_to, email_cc, email_bcc, email_subject, email_profile_name FROM project_data;"""
try:
cursor = connection.cursor()
results = cursor.execute(query).fetchone()
Expand All @@ -572,7 +573,7 @@ def fetch_all_project_data(self) -> list[str]:

with self.db_connection(self.database_path) as connection:
# Probably not proper way to mitigate SQL injections but good enough since database_table string is not user supplied
query = f"""SELECT project_number, directory, email_to, email_cc, email_bcc, email_subject, email_profile_name FROM project_data;"""
query = f"""SELECT project_number, directory, description, email_to, email_cc, email_bcc, email_subject, email_profile_name FROM project_data;"""
try:
database_fetch_results = connection.cursor().execute(query).fetchall()
if not database_fetch_results:
Expand All @@ -587,7 +588,7 @@ def fetch_project_data_by_project_number(self, project_number: str) -> list[str]

with self.db_connection(self.database_path) as connection:

query = f"""SELECT project_number, directory, email_to, email_cc, email_bcc, email_subject, email_profile_name FROM project_data WHERE project_number=?;"""
query = f"""SELECT project_number, directory, description, email_to, email_cc, email_bcc, email_subject, email_profile_name FROM project_data WHERE project_number=?;"""
try:
database_fetch_results = connection.cursor().execute(query, (project_number,)).fetchone()
if not database_fetch_results:
Expand Down Expand Up @@ -669,12 +670,13 @@ def update_project_data_entry(self, old_data, new_data):
msg = None
with self.db_connection(self.database_path) as connection:
try:
update_statement = """UPDATE project_data SET project_number=?, directory=?, email_to=?, email_cc=?, email_bcc=?, email_subject=?, email_profile_name=? WHERE project_number=?;"""
update_statement = """UPDATE project_data SET project_number=?, directory=?, description=?, email_to=?, email_cc=?, email_bcc=?, email_subject=?, email_profile_name=? WHERE project_number=?;"""
data = [
new_data[key]
for key in [
"project_number",
"directory",
"description",
"email_to",
"email_cc",
"email_bcc",
Expand All @@ -695,12 +697,13 @@ def add_new_project_data(self, new_data: dict) -> str:
msg = None
with self.db_connection(self.database_path) as connection:
try:
new_data_query = """INSERT INTO project_data (project_number,directory,email_to,email_cc,email_bcc,email_subject,email_profile_name) VALUES(?,?,?,?,?,?,?);"""
new_data_query = """INSERT INTO project_data (project_number,directory,description,email_to,email_cc,email_bcc,email_subject,email_profile_name) VALUES(?,?,?,?,?,?,?,?);"""
data = [
new_data[key]
for key in [
"project_number",
"directory",
"description",
"email_to",
"email_cc",
"email_bcc",
Expand Down Expand Up @@ -868,7 +871,7 @@ def run(self):
self.import_project_data = temp_project_data
with self.db_connection(self.database_path) as connection:
msg = connection.cursor().executemany(
"""INSERT INTO project_data (project_number,directory,email_to,email_cc,email_bcc,email_subject,email_profile_name) VALUES(?,?,?,?,?,?,?);""",
"""INSERT INTO project_data (project_number,directory,description,email_to,email_cc,email_bcc,email_subject,email_profile_name) VALUES(?,?,?,?,?,?,?,?);""",
self.import_project_data,
)
connection.commit()
Expand Down
53 changes: 45 additions & 8 deletions views/data_viewer_view.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from PySide6 import QtCore, QtGui, QtWidgets

from view_models import data_viewer_view_model
Expand Down Expand Up @@ -182,6 +184,29 @@ def __init__(self, view_model: data_viewer_view_model.DataViewerViewModel):
self.project_data_directory_layout.setStretch(2, 2)
self.main_layout.addLayout(self.project_data_directory_layout)

self.project_data_description_layout = QtWidgets.QHBoxLayout()
self.project_data_description_label = QtWidgets.QLabel()
self.project_data_description_label.setObjectName(
"project_data_description_label"
)
self.project_data_description_layout.addWidget(
self.project_data_description_label
)
self.project_data_description_line_edit = QtWidgets.QLineEdit()
self.project_data_description_line_edit.setObjectName(
"project_data_description_line_edit"
)
self.project_data_description_line_edit.editingFinished.connect(
lambda: self.project_data_change_check(
self.project_data_description_line_edit, "description"
)
)
self.project_data_description_layout.addWidget(
self.project_data_description_line_edit
)

self.main_layout.addLayout(self.project_data_description_layout)

self.project_data_email_subject_layout = QtWidgets.QHBoxLayout()

# Label for email subject line edit
Expand Down Expand Up @@ -242,7 +267,7 @@ def __init__(self, view_model: data_viewer_view_model.DataViewerViewModel):
"profile_email_combo_box_helper"
)
self.profile_email_combo_box_helper.setToolTip(
"Tip: Defined project specific email template will take precedence over profile email template."
"Tip: Project specific email template will take precedence over profile email template."
)
self.profile_email_combo_box_helper.clicked.connect(
self.display_tooltip
Expand Down Expand Up @@ -416,6 +441,9 @@ def translate_ui(self):
self.database_project_number_label.setText(
_translate("MainWindow", "Project Number:")
)
self.project_data_description_label.setText(
_translate("MainWindow", "Project Description:")
)
self.database_directory_label.setText(_translate("MainWindow", "Directory:"))
self.database_email_subject_label.setText(
_translate("MainWindow", "Email Subject:")
Expand All @@ -433,7 +461,6 @@ def translate_ui(self):
self.delete_all_project_data_button.setText(
_translate("MainWindow", "Delete ALL Project Data")
)

self.database_discard_edited_project_data_button.setText(
_translate("MainWindow", "Discard Changes")
)
Expand Down Expand Up @@ -547,6 +574,7 @@ def set_data_viewer_index(self, index: int):
def clear_project_data_fields(self):
self.database_project_number_line_edit.setText("")
self.database_project_directory_line_edit.setText("")
self.project_data_description_line_edit.setText("")
self.database_project_email_subject_line_edit.setText("")
self.database_email_to_list_widget.clear()
self.database_email_cc_list_widget.clear()
Expand Down Expand Up @@ -576,6 +604,7 @@ def project_data_discard_check(self):
has_non_empty_fields = any(widget.text() != "" for widget in [
self.database_project_number_line_edit,
self.database_project_directory_line_edit,
self.project_data_description_line_edit,
self.database_project_email_subject_line_edit,
])
if not has_non_empty_fields:
Expand Down Expand Up @@ -659,11 +688,12 @@ def handle_project_data_update(self):
self._project_data_loaded_data = {
"project_number": self.database_viewer_table.item(current_row, 0).text(),
"directory": self.database_viewer_table.item(current_row, 1).text(),
"email_to": self.database_viewer_table.item(current_row, 2).text(),
"email_cc": self.database_viewer_table.item(current_row, 3).text(),
"email_bcc": self.database_viewer_table.item(current_row, 4).text(),
"email_subject": self.database_viewer_table.item(current_row, 5).text(),
"email_profile_name": self.database_viewer_table.item(current_row, 6).text(),
"description": self.database_viewer_table.item(current_row, 2).text(),
"email_to": self.database_viewer_table.item(current_row, 3).text(),
"email_cc": self.database_viewer_table.item(current_row, 4).text(),
"email_bcc": self.database_viewer_table.item(current_row, 5).text(),
"email_subject": self.database_viewer_table.item(current_row, 6).text(),
"email_profile_name": self.database_viewer_table.item(current_row, 7).text(),
}
self.database_populate_project_edit_fields()
self.database_viewer_table.currentItemChanged.connect(
Expand All @@ -680,6 +710,9 @@ def database_populate_project_edit_fields(self):
self.database_project_directory_line_edit.setText(
self._project_data_loaded_data["directory"]
)
self.project_data_description_line_edit.setText(
self._project_data_loaded_data["description"]
)
self.database_project_email_subject_line_edit.setText(
self._project_data_loaded_data["email_subject"]
)
Expand Down Expand Up @@ -795,7 +828,10 @@ def get_new_project_data(self):
] = self.database_project_number_line_edit.text()
new_project_data[
"directory"
] = self.database_project_directory_line_edit.text().replace("\\", "/")
] = os.path.abspath(self.database_project_directory_line_edit.text())
new_project_data[
"description"
] = self.project_data_description_line_edit.text()
new_project_data[
"email_subject"
] = self.database_project_email_subject_line_edit.text()
Expand Down Expand Up @@ -823,6 +859,7 @@ def project_data_add_new(self) -> None:
self._project_data_loaded_data = {
"project_number": None,
"directory": None,
"description": None,
"email_to": None,
"email_cc": None,
"email_bcc": None,
Expand Down

0 comments on commit 9daf627

Please sign in to comment.