diff --git a/DirectReport/__main__.py b/DirectReport/__main__.py index 0bde0532..567a1d2c 100644 --- a/DirectReport/__main__.py +++ b/DirectReport/__main__.py @@ -2,8 +2,10 @@ from DirectReport.commandline import commandline + def main(): commandline.cli() + if __name__ == "__main__": main() diff --git a/DirectReport/browserview/app.py b/DirectReport/browserview/app.py index f4d83134..b761d1eb 100644 --- a/DirectReport/browserview/app.py +++ b/DirectReport/browserview/app.py @@ -26,6 +26,7 @@ login_manager.login_view = "login" user_model = UserModel() + @app.route("/") def home(): """ @@ -34,6 +35,7 @@ def home(): """ return render_template('index.html', title='Home') + @app.errorhandler(404) def page_not_found(e): """ @@ -44,17 +46,20 @@ def page_not_found(e): """ return render_template('404.html', error=e), 404 + @login_manager.user_loader def user_loader(email): user = user_model.get_user_by_email(email) return user + @login_manager.request_loader def request_loader(request): email = request.form.get('email') user = user_model.get_user_by_email(email) return user + @app.route("/new", methods=['GET', 'POST']) @login_required def new(): @@ -64,6 +69,7 @@ def new(): """ return render_template('list.html', title='New Entry', data=[]) + @login_manager.unauthorized_handler def unauthorized_handler(): if request.headers.get("X-Requested-With") == "XMLHttpRequest": @@ -74,12 +80,14 @@ def unauthorized_handler(): else: return redirect(url_for('auth.login')) + @app.route("/team", methods=['GET']) def team(): return render_template('team/team.html', title='Team', data=[]) + @app.route("/generate_email", methods=['POST']) -def generate_email(): +def generateemail(): prompt = "" if request.method == "POST": prompt = json.dumps(request.get_json()["prompt"]) @@ -87,13 +95,14 @@ def generate_email(): elements = {"email": report.choices[0].message.content} return elements, 201 + @app.route("/repo/", methods=['GET']) def repo(reponame=None): - client = GithubClient() repo = client.get_repo_issues("chriswebb09", reponame) print(repo) return render_template('team/team.html', title='Team', data=[]) + if __name__ == "__main__": app.run(debug=True, port=5000) diff --git a/DirectReport/browserview/auth/auth.py b/DirectReport/browserview/auth/auth.py index e071021e..f0e631aa 100644 --- a/DirectReport/browserview/auth/auth.py +++ b/DirectReport/browserview/auth/auth.py @@ -13,6 +13,7 @@ user_model = UserModel() + @auth.route('/signup', methods=['POST', 'GET']) def signup(): if request.method == 'POST': @@ -27,12 +28,14 @@ def signup(): return redirect(url_for('auth.login')) return render_template('auth/signup.html') + @auth.route('/logout') @login_required def logout(): logout_user() return redirect(url_for('reportsbp.team_report')) + @auth.route('/login', methods=['POST', 'GET']) def login(): if request.method == 'POST': @@ -49,11 +52,13 @@ def login(): flash("Please check your login details and try again.") return render_template('auth/login.html') + @auth.route("/account", methods=['GET', 'POST']) @login_required def account(): return render_template('account.html', title='Account', name=current_user.username, userid=current_user.id) + @auth.route("/account_data", methods=['GET']) @login_required def account_data(): @@ -63,22 +68,16 @@ def account_data(): shortlog = client.parse_git_shortlog(logitem) report_results = [] for report in saved_reports: - report_element = { - "report": report - } + report_element = {"report": report} report_results.append(report_element) - user_account = { + user_account = { "name": current_user.firstname + " " + current_user.lastname, "firstname": current_user.firstname, "lastname": current_user.lastname, "userid": current_user.id, "username": current_user.username, - "email": current_user.email - } - user_element = { - "user": user_account, - "reports": report_results, - "shortlog": shortlog + "email": current_user.email, } - return user_element, 201 \ No newline at end of file + user_element = {"user": user_account, "reports": report_results, "shortlog": shortlog} + return user_element, 201 diff --git a/DirectReport/browserview/github.py b/DirectReport/browserview/github.py index 28fc4e7d..eb570417 100644 --- a/DirectReport/browserview/github.py +++ b/DirectReport/browserview/github.py @@ -81,22 +81,21 @@ def get_repo_issues(self, repo_owner, repo_name): response.raise_for_status() return response.json() -class HuggingFaceClient: +class HuggingFaceClient: def query(self, payload): API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf" headers = {"Authorization": "Bearer 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"} response = requests.post(API_URL, headers=headers, json=payload) return response.json() -class GoogleAIClient: - +class GoogleAIClient: def query(self, prompt): API_URL = f"https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key={appsecrets.GOOGLE_AI_TOKEN}" headers = {"Content-Type": "application/json"} prompt_data = prompts.GENERATE_SUMMARY_PROMPT_PREIX + prompt - data = {"prompt": { "text": f"{prompt_data}"}} + data = {"prompt": {"text": f"{prompt_data}"}} response = requests.post(API_URL, data=json.dumps(data), headers=headers) data = json.loads(response.text) return data @@ -105,4 +104,3 @@ def get_data_from(self, prompt): response = self.query(prompt) response_data = response["candidates"][0]["output"] return response_data - diff --git a/DirectReport/browserview/modelclient.py b/DirectReport/browserview/modelclient.py index 078b9c75..c27e88de 100644 --- a/DirectReport/browserview/modelclient.py +++ b/DirectReport/browserview/modelclient.py @@ -11,38 +11,30 @@ { "name": "Adrian Prantl", "accomplishments": "Adrian made significant contributions to the DebugInfo and SILGen, including adding support for debug info for coroutine alloc as,inlined and specialized generic variables.He also worked on the mangling testcase,fixed source locations of variable assignments and function calls, and added build-script support for SwiftLLDB backwards-compatibility tests.", - "commits": "67" + "commits": "67", }, { "name": "Alan Zeino", "accomplishments": "Alan fixed a typo in the code example in libSyntax README.", - "commits": "1" + "commits": "1", }, { "name": "Alejandro", "accomplishments": "Alejandro removed awarning, made some documentation fixes, fixed Binary Floating Point. random(in:) open range returning upperBound, and fixed a minor code typo in SILPro.", - "commits": "3" - }, - { - "name": "Akshay Shrimali", - "accomplishments": "Akshay updated the README.md file.", - "commits": "1" + "commits": "3", }, + {"name": "Akshay Shrimali", "accomplishments": "Akshay updated the README.md file.", "commits": "1"}, { "name": "Ahmad Alhashemi", "accomplishments": "Ahmad worked on the Parser, detecting non breaking space U+00A0 and providing a fix.He also made minor style edits and added more non-breaking space testcases.", - "commits": "5" - }, - { - "name": "Albin Sadowski", - "accomplishments": "Albin fixed syntax highlighting in CHANGELOG.", - "commits": "1" + "commits": "5", }, + {"name": "Albin Sadowski", "accomplishments": "Albin fixed syntax highlighting in CHANGELOG.", "commits": "1"}, { "name": "Alex Blewitt", "accomplishments": "Alex worked on several fixes including compare for lhs and rhs, using || instead of && for kind comparison,removing duplicate conditional check and duplicate if statement.", - "commits": "5" - } + "commits": "5", + }, ], "report": { "summary": "The team made significant progress this week with a total of 83 commits.The main focus was on DebugInfo and SILGen enhancements, Parser improvements, and various fixes.", @@ -51,18 +43,18 @@ "highlights": [ { "title": "DebugInfo and SILGen Enhancements", - "description": "Adrian Prantl made significant contributions to the DebugInfo and SILGen, including adding support for debuginfo for coroutine allocas, inlined and specialized generic variables." + "description": "Adrian Prantl made significant contributions to the DebugInfo and SILGen, including adding support for debuginfo for coroutine allocas, inlined and specialized generic variables.", }, { "title": "Parser Improvements", - "description": "Ahmad Alhashemi worked on the Parser,detecting non breaking space U+00A0 and providing a fix." + "description": "Ahmad Alhashemi worked on the Parser,detecting non breaking space U+00A0 and providing a fix.", }, { "title": "Various Fixes", - "description": "The team worked on several fixes including compare for lhs and rhs, using || instead of && for kind comparison,removing duplicate conditional check and duplicate if statement." - } + "description": "The team worked on several fixes including compare for lhs and rhs, using || instead of && for kind comparison,removing duplicate conditional check and duplicate if statement.", + }, ], - "conclusion": "The team demonstrated good progress this week, with a focus on enhancing DebugInfo and SILGen, improving the Parser, and implementing various fixes. The team should continue to focus on these areas in the coming week." + "conclusion": "The team demonstrated good progress this week, with a focus on enhancing DebugInfo and SILGen, improving the Parser, and implementing various fixes. The team should continue to focus on these areas in the coming week.", }, "broad_categories": { "debug_info": 16, @@ -71,34 +63,83 @@ "test_related": 6, "nonbreaking_space_handling": 5, "readme_update": 1, - "syntax_fix": 1 - } - + "syntax_fix": 1, + }, } -RAW_REPORT_DATA_2 = {"report": { - "broad_categories": {"code_maintenance": 9, "debug_info": 16, "documentation": 7, "nonbreaking_space_handling": 5, "readme_update": 1, "syntax_fix": 1, "test_related": 6}, - +RAW_REPORT_DATA_2 = { + "report": { + "broad_categories": { + "code_maintenance": 9, + "debug_info": 16, + "documentation": 7, + "nonbreaking_space_handling": 5, + "readme_update": 1, + "syntax_fix": 1, + "test_related": 6, + }, "report": { "areas_of_focus": ['DebugInfo and SILGen Enhancements', 'Parser Improvements', 'Various Fixes'], "conclusion": 'The team demonstrated good progress this week, with a focus on enhancing DebugInfo and SILGen, improving the Parser, and implementing various fixes. The team should continue to focus on these areas in the coming week.', "highlights": [ - {"description": 'Adrian Prantl made significant contributions to the DebugInfo and SILGen, including adding support for debuginfo for coroutine allocas, inlined and specialized generic variables.', 'title': 'DebugInfo and SILGen Enhancements'}, - {"description": 'Ahmad Alhashemi worked on the Parser, detecting non-breaking space U+00A0 and providing a fix.', 'title': 'Parser Improvements'}, - {"description": 'The team worked on several fixes including compare for lhs and rhs, using || instead of && for kind comparison, removing duplicate conditional check and duplicate if statement.', 'title': 'Various Fixes'} + { + "description": 'Adrian Prantl made significant contributions to the DebugInfo and SILGen, including adding support for debuginfo for coroutine allocas, inlined and specialized generic variables.', + 'title': 'DebugInfo and SILGen Enhancements', + }, + { + "description": 'Ahmad Alhashemi worked on the Parser, detecting non-breaking space U+00A0 and providing a fix.', + 'title': 'Parser Improvements', + }, + { + "description": 'The team worked on several fixes including compare for lhs and rhs, using || instead of && for kind comparison, removing duplicate conditional check and duplicate if statement.', + 'title': 'Various Fixes', + }, ], 'summary': 'The team made significant progress this week with a total of 83 commits. The main focus was on DebugInfo and SILGen enhancements, Parser improvements, and various fixes.', - 'total_commits': '83' + 'total_commits': '83', + }, + "shortlog": { + 'Adrian Prantl': 67, + 'Ahmad Alhashemi': 5, + 'Akshay Shrimali': 1, + 'Alan Zeino': 1, + 'Albin Sadowski': 1, + 'Alejandro': 3, + 'Alex Blewitt': 5, }, - "shortlog": {'Adrian Prantl': 67, 'Ahmad Alhashemi': 5, 'Akshay Shrimali': 1, 'Alan Zeino': 1, 'Albin Sadowski': 1, 'Alejandro': 3, 'Alex Blewitt': 5}, "team": [ - {'accomplishments': 'Adrian made significant contributions to the DebugInfo and SILGen, including adding support for debug info for coroutine allocas, inlined and specialized generic variables. He also worked on the mangling testcase, fixed source locations of variable assignments and function calls, and added build-script support for Swift LLDB backwards-compatibility tests.', 'commits': '67', 'name': 'Adrian Prantl'}, - {'accomplishments': 'Alan fixed a typo in the code example in libSyntax README.', 'commits': '1', 'name': 'Alan Zeino'}, - {'accomplishments': 'Alejandro removed a warning, made some documentation fixes, fixed Binary Floating Point. random(in:) open range returning upperBound, and fixed a minor code typo in SILPro.', 'commits': '3', 'name': 'Alejandro'}, + { + 'accomplishments': 'Adrian made significant contributions to the DebugInfo and SILGen, including adding support for debug info for coroutine allocas, inlined and specialized generic variables. He also worked on the mangling testcase, fixed source locations of variable assignments and function calls, and added build-script support for Swift LLDB backwards-compatibility tests.', + 'commits': '67', + 'name': 'Adrian Prantl', + }, + { + 'accomplishments': 'Alan fixed a typo in the code example in libSyntax README.', + 'commits': '1', + 'name': 'Alan Zeino', + }, + { + 'accomplishments': 'Alejandro removed a warning, made some documentation fixes, fixed Binary Floating Point. random(in:) open range returning upperBound, and fixed a minor code typo in SILPro.', + 'commits': '3', + 'name': 'Alejandro', + }, {'accomplishments': 'Akshay updated the README.md file.', 'commits': '1', 'name': 'Akshay Shrimali'}, - {'accomplishments': 'Ahmad worked on the Parser, detecting non-breaking space U+00A0 and providing a fix. He also made minor style edits and added more non-breaking space testcases.', 'commits': '5', 'name': 'Ahmad Alhashemi'}, - {'accomplishments': 'Albin fixed syntax highlighting in CHANGELOG.', 'commits': '1', 'name': 'Albin Sadowski'}, - {'accomplishments': 'Alex worked on several fixes including compare for lhs and rhs, using || instead of && for kind comparison, removing duplicate conditional check and duplicate if statement.', 'commits': '5', 'name': 'Alex Blewitt'} - ] + { + 'accomplishments': 'Ahmad worked on the Parser, detecting non-breaking space U+00A0 and providing a fix. He also made minor style edits and added more non-breaking space testcases.', + 'commits': '5', + 'name': 'Ahmad Alhashemi', + }, + { + 'accomplishments': 'Albin fixed syntax highlighting in CHANGELOG.', + 'commits': '1', + 'name': 'Albin Sadowski', + }, + { + 'accomplishments': 'Alex worked on several fixes including compare for lhs and rhs, using || instead of && for kind comparison, removing duplicate conditional check and duplicate if statement.', + 'commits': '5', + 'name': 'Alex Blewitt', + }, + ], }, - 'created_at': '1702314769.558132'} \ No newline at end of file + 'created_at': '1702314769.558132', +} diff --git a/DirectReport/browserview/prompt_logic.py b/DirectReport/browserview/prompt_logic.py index 2894599a..a09e28dc 100644 --- a/DirectReport/browserview/prompt_logic.py +++ b/DirectReport/browserview/prompt_logic.py @@ -6,26 +6,21 @@ from DirectReport.datadependencies import appsecrets, prompts openai.api_key = appsecrets.SECRET_KEY + + def generate_email(data): prompt = prompts.GENERATE_EMAIL_PROMPT_PREFIX + data - message=[{"role": "user", "content": prompt}] + message = [{"role": "user", "content": prompt}] response = openai.ChatCompletion.create( - model="gpt-4", - messages = message, - temperature=0.1, - max_tokens=1000, - frequency_penalty=0.0 + model="gpt-4", messages=message, temperature=0.1, max_tokens=1000, frequency_penalty=0.0 ) return response + def get_team_summarys_from_git_shortlog(data): prompt = prompts.GENERATE_SUMMARY_PROMPT_PREIX + data - message=[{"role": "user", "content": prompt}] + message = [{"role": "user", "content": prompt}] response = openai.ChatCompletion.create( - model="gpt-4", - messages = message, - temperature=0, - max_tokens=1000, - frequency_penalty=0.0 + model="gpt-4", messages=message, temperature=0, max_tokens=1000, frequency_penalty=0.0 ) return response diff --git a/DirectReport/browserview/reportbp.py b/DirectReport/browserview/reportbp.py index 10959e90..41ebfce7 100644 --- a/DirectReport/browserview/reportbp.py +++ b/DirectReport/browserview/reportbp.py @@ -13,6 +13,7 @@ reportsbp = Blueprint('reportsbp', __name__) + @reportsbp.route("/report", methods=['GET', 'POST']) @login_required def report(): @@ -30,20 +31,31 @@ def report(): response_data = googleAi.get_data_from(prompt).replace("\'", "\"") response_data = response_data.replace("\n", " ") data_json = json.loads(response_data) - data_json["broad_categories"] = {"debug_info": 16, "code_maintenance": 9, "documentation": 7, "test_related": 6, "nonbreaking_space_handling": 5, "readme_update": 1, "syntax_fix": 1} + data_json["broad_categories"] = { + "debug_info": 16, + "code_maintenance": 9, + "documentation": 7, + "test_related": 6, + "nonbreaking_space_handling": 5, + "readme_update": 1, + "syntax_fix": 1, + } data_json["shortlog"] = client.parse_git_shortlog(log_item) data_json["repos"] = repodata ReportBuilder.new(data_json, prompt, current_user.id) return data_json, 201 + @reportsbp.route("/teamreport", methods=['GET', 'POST']) @login_required def team_report(): if request.method == "POST": json_data = request.get_json() report_model = ReportModel(json_data["id"], json_data['summary'], json_data['created_at']) + print(report_model) return render_template('team/teamreport.html', title='Team Report', data=[]) + @reportsbp.route('/entry/', methods=['GET', 'POST']) @login_required def detail(uid=None): @@ -63,7 +75,9 @@ def detail(uid=None): json_data["id"], json_data['entry'], json_data['topic'], json_data['created_at'], json_data['week_id'] ) entry = item.get_entry(uid).to_dict() - return render_template('detail.html', title='Detail', data=reportJSON) + print(entry) + return render_template('detail.html', title='Detail', data=entry) + @reportsbp.route("/getreport/", methods=['GET']) @login_required @@ -72,12 +86,14 @@ def get_report(uid=None): report = list(filter(lambda report: report["uuid"] == uid, reports))[0] return report, 201 + @reportsbp.route("/getlist", methods=['GET']) @login_required def get_list(): reports = ReportBuilder.get_reports_for_user_id(current_user.id) return reports, 201 + @reportsbp.route("/list", methods=['GET', 'POST']) @login_required def list_entries(): @@ -88,8 +104,6 @@ def list_entries(): reports = ReportBuilder.get_reports_for_user_id(current_user.id) report_results = [] for report in reports: - report_element = { - "report": report - } + report_element = {"report": report} report_results.append(report_element) return render_template('list.html', title='List', data=report_results) diff --git a/DirectReport/commandline/commandline.py b/DirectReport/commandline/commandline.py index 42711453..04adf04a 100644 --- a/DirectReport/commandline/commandline.py +++ b/DirectReport/commandline/commandline.py @@ -10,22 +10,32 @@ file = Path(__file__).resolve() package_root_directory = file.parents[1] sys.path.append(str(package_root_directory)) + + @click.group() def cli(): """Main Click group for the command line interface.""" pass + + @cli.group() def list_items(): """Click group for list items related commands.""" pass + + @cli.group() def item(): """Click group for item related commands.""" pass + + @cli.group() def web_browser(): """Click group for web browser related commands.""" pass + + @click.command() @click.option('--day', 'transformation', flag_value='day') @click.option('--all', 'transformation', flag_value='all') @@ -43,6 +53,8 @@ def list(transformation): if all_list is not None: for all_item in all_list: print(str(all_item) + "\n") + + @click.command() @click.option('--entry', 'transformation', flag_value='entry', default=True, help="Add new entry to list") def new(transformation): @@ -55,6 +67,8 @@ def new(transformation): entry = click.prompt('Goal', type=str) ListBuilder.new(entry, topic) return + + @click.command() @click.option('--id', help="Delete item with id", prompt='What is the id of the entry you wish to delete?') def delete(uid): @@ -63,6 +77,8 @@ def delete(uid): :param uid: The ID of the item to delete. """ ListBuilder.delete(uid) + + @click.command() @click.option("--url", default="http://127.0.0.1:5000", help="URL to open in the web browser") def launch(url): @@ -74,6 +90,8 @@ def launch(url): # print(ListBuilder.list_all()) click.launch(url) app.run() + + @click.command() def mail(): """ @@ -84,6 +102,7 @@ def mail(): body = "" webbrowser.open('mailto:?to=' + recipient + '&subject=' + subject + '&body=' + body, new=1) + list_items.add_command(list) item.add_command(new) item.add_command(delete) @@ -93,4 +112,4 @@ def mail(): cli = click.CommandCollection(sources=[list_items, item, web_browser]) if __name__ == '__main__': - cli() \ No newline at end of file + cli() diff --git a/DirectReport/datadependencies/appsecrets.py b/DirectReport/datadependencies/appsecrets.py new file mode 100644 index 00000000..86627a65 --- /dev/null +++ b/DirectReport/datadependencies/appsecrets.py @@ -0,0 +1,8 @@ +global SECRET_KEY +SECRET_KEY = "" +global GITHUB_TOKEN +GITHUB_TOKEN = "" +global GOOGLE_AI_TOKEN +GOOGLE_AI_TOKEN = "" +global MISTRAL_API_KEY +MISTRAL_API_KEY = "" diff --git a/DirectReport/datadependencies/prompts.py b/DirectReport/datadependencies/prompts.py index 226ba05d..e5a0d9b4 100644 --- a/DirectReport/datadependencies/prompts.py +++ b/DirectReport/datadependencies/prompts.py @@ -1,7 +1 @@ #!/usr/bin/env python3 - -global GENERATE_EMAIL_PROMPT_PREFIX -global GENERATE_SUMMARY_PROMPT_PREIX - -GENERATE_EMAIL_PROMPT_PREFIX = "can you take this data and summarize in professional manner for an email on the team status for my manager?\n" + "Data: " -GENERATE_SUMMARY_PROMPT_PREIX = "can you provide a short summary of what what was accomplished overall along with the time frame it was accomplished in, please categorize the majors improvements in areas_of__focus and please provide individual breakdown based on the following list of team members, list each contributor as a team member, and work using the following " + "Format: \n" + "{ \n" + "'team'" + ": [{" + "\n 'name'" + ": '', " + "\n 'accomplishments'" + ": '' " + " ," + "\n 'commits'" + ": '' \n" + "}]," + "\n'report'" + ": {" + "\n 'summary'" + ": ''" + ", \n 'highlights'" + ": [{" + "\n 'title'" + ": '' ," + "\n 'description'" + ": '' " + "\n }], \n" + "'areas_of_focus'" + ": [], \n" + " 'conclusion'" + ": ''" + "\n}" + "\n}" + "\n" " under no circumstances show the reponse include triple single quotes or extraneous newline characters the response data must use double quotes not single quote. The highlights section must be included in own element outside of the summary, THE RESPONSE MUST BE PROPERLY FORMATTED JSON " + "Data:" \ No newline at end of file diff --git a/DirectReport/models/daily_builder.py b/DirectReport/models/daily_builder.py index 2ccadba8..6b002631 100644 --- a/DirectReport/models/daily_builder.py +++ b/DirectReport/models/daily_builder.py @@ -4,8 +4,8 @@ from DirectReport.models.daily_storage import DailyUUIDTable import uuid -class DailyBuilder: +class DailyBuilder: def __init__(self): pass diff --git a/DirectReport/models/daily_storage.py b/DirectReport/models/daily_storage.py index 7c8e4c77..b6231c62 100644 --- a/DirectReport/models/daily_storage.py +++ b/DirectReport/models/daily_storage.py @@ -3,6 +3,7 @@ import sqlite3 import uuid + class DailyUUIDTable: """ A class to interact with SQLite database for managing daily date-UUID mappings. diff --git a/DirectReport/models/entry.py b/DirectReport/models/entry.py index 7509a7a2..0b647ef1 100644 --- a/DirectReport/models/entry.py +++ b/DirectReport/models/entry.py @@ -22,8 +22,6 @@ def __init__(self, uuid, topic, message, created_at, modified_on): :type created_at: float :param modified_on: The timestamp when the entry was last modified. :type modified_on: float - :param week_uuid: The unique identifier for the week. - :type week_uuid: str """ self.uuid = uuid self.topic = topic @@ -62,7 +60,7 @@ def to_dict(self): "topic": self.topic, "message": self.message, "created_at": str(self.created_at), - "modified_on": str(self.modified_on) + "modified_on": str(self.modified_on), } @classmethod @@ -79,7 +77,7 @@ def from_dict(cls, data): message = data.get("message") created_at = datetime.datetime.fromisoformat(data.get("created_at")).timestamp() modified_on = datetime.datetime.fromisoformat(data.get("modified_on")).timestamp() - return cls(uuid, topic, message, created_at, modified_on, week_uuid) + return cls(uuid, topic, message, created_at, modified_on) def mark_modified(self): """ diff --git a/DirectReport/models/entry_storage.py b/DirectReport/models/entry_storage.py index 2fe74561..33ca215e 100644 --- a/DirectReport/models/entry_storage.py +++ b/DirectReport/models/entry_storage.py @@ -3,6 +3,7 @@ import sqlite3 from DirectReport.models.entry import Entry + class EntryStorage: """ A class to interact with SQLite database for storing and retrieving `Entry` objects. @@ -38,7 +39,7 @@ def add_entry(self, entry): entry.topic, entry.message, entry.created_at.__str__(), - entry.modified_on.__str__() + entry.modified_on.__str__(), ) self.conn.execute( "INSERT OR IGNORE INTO entries (uuid, topic, message, created_at, modified_on) VALUES (?, ?, ?, ?, ?)", diff --git a/DirectReport/models/list_builder.py b/DirectReport/models/list_builder.py index 8422dfb3..9541c51e 100644 --- a/DirectReport/models/list_builder.py +++ b/DirectReport/models/list_builder.py @@ -5,6 +5,7 @@ from DirectReport.models.entry import Entry from DirectReport.models.entry_storage import EntryStorage + class ListBuilder: """ @@ -26,9 +27,7 @@ def new(entry_text, topic_text=None): storage.create_table() if topic_text is None or topic_text == '': topic_text = "Entry for work on " + str(today) - new_entry = Entry( - str(uuid.uuid1()), topic_text, entry_text, today, datetime.datetime.now().timestamp() - ) + new_entry = Entry(str(uuid.uuid1()), topic_text, entry_text, today, datetime.datetime.now().timestamp()) storage.add_entry(new_entry) @staticmethod @@ -43,9 +42,7 @@ def update(uid, entry_text, topic_text, created_at): """ storage = EntryStorage('EntryStorage.db') storage.create_table() - new_entry = Entry( - str(uuid.UUID(uid)), topic_text, entry_text, created_at, datetime.datetime.now().timestamp() - ) + new_entry = Entry(str(uuid.UUID(uid)), topic_text, entry_text, created_at, datetime.datetime.now().timestamp()) storage.update_entry(new_entry) @staticmethod diff --git a/DirectReport/models/report.py b/DirectReport/models/report.py index 2a3a456e..b51e0733 100644 --- a/DirectReport/models/report.py +++ b/DirectReport/models/report.py @@ -46,7 +46,7 @@ def to_dict(self): "user_id": self.user_id, "raw_input": self.raw_input, "report": self.report, - "created_at": str(self.created_at) + "created_at": str(self.created_at), } @classmethod diff --git a/DirectReport/models/report_builder.py b/DirectReport/models/report_builder.py index 89277c71..bcf2f5a7 100644 --- a/DirectReport/models/report_builder.py +++ b/DirectReport/models/report_builder.py @@ -27,9 +27,7 @@ def new(report, raw_input, user_id): storage.create_table() if report is None or report == '': report = "Entry for work on " + str(today) - new_report = Report( - str(uuid.uuid1()), user_id, raw_input, report, datetime.datetime.now().timestamp() - ) + new_report = Report(str(uuid.uuid1()), user_id, raw_input, report, datetime.datetime.now().timestamp()) storage.add_report(new_report) @staticmethod @@ -69,4 +67,4 @@ def list_all(): """ storage = ReportModel('ReportStorage.db') list_items = storage.list_all_reports_as_dict() - return list_items \ No newline at end of file + return list_items diff --git a/DirectReport/models/report_model.py b/DirectReport/models/report_model.py index 2f0c9d08..40150726 100644 --- a/DirectReport/models/report_model.py +++ b/DirectReport/models/report_model.py @@ -39,7 +39,7 @@ def add_report(self, report): report.user_id.__str__(), report.raw_input.__str__(), report.report.__str__(), - report.created_at.__str__() + report.created_at.__str__(), ) self.conn.execute( "INSERT OR IGNORE INTO reports (uuid, user_id, raw_input, report, created_at) VALUES (?, ?, ?, ?, ?)", diff --git a/DirectReport/models/team.py b/DirectReport/models/team.py index fae4d30b..b7fc7e41 100644 --- a/DirectReport/models/team.py +++ b/DirectReport/models/team.py @@ -5,7 +5,6 @@ class Team: - def __init__(self, team_id, team_name, team_email): self.team_id = team_id self.team_name = team_name diff --git a/DirectReport/models/team_member.py b/DirectReport/models/team_member.py index 131d89ef..fe592d23 100644 --- a/DirectReport/models/team_member.py +++ b/DirectReport/models/team_member.py @@ -5,7 +5,6 @@ class TeamMember: - def __init__(self, id, team_id, username): self.id = id self.team_id = team_id diff --git a/DirectReport/models/team_member_model.py b/DirectReport/models/team_member_model.py index 3cf5d5a2..416f9686 100644 --- a/DirectReport/models/team_member_model.py +++ b/DirectReport/models/team_member_model.py @@ -2,30 +2,34 @@ import sqlite3 import uuid +from .team_member import TeamMember class TeamMemberModel: - def __init__(self, db_name="teammember.db"): self.conn = sqlite3.connect(db_name, check_same_thread=False) self.create_table() def create_table(self): cursor = self.conn.cursor() - cursor.execute(""" + cursor.execute( + """ CREATE TABLE IF NOT EXISTS teammember ( id TEXT UNIQUE NOT NULL PRIMARY KEY, team_id TEXT NOT NULL, username TEXT NOT NULL ) - """) + """ + ) self.conn.commit() def insert_team(self, team_id, username): cursor = self.conn.cursor() uuid_str = str(uuid.uuid4()) try: - cursor.execute("INSERT INTO teammember (id, team_id, username) VALUES (?, ?, ?)", (uuid_str, team_id, username)) + cursor.execute( + "INSERT INTO teammember (id, team_id, username) VALUES (?, ?, ?)", (uuid_str, team_id, username) + ) self.conn.commit() print("User added successfully!") except sqlite3.IntegrityError: @@ -37,5 +41,6 @@ def get_team_by_id(self, team_id): result = cursor.fetchone() if result: return TeamMember(result[0], result[1], result[2]) + def close(self): self.conn.close() diff --git a/DirectReport/models/team_model.py b/DirectReport/models/team_model.py index f0b6696d..b7456c25 100644 --- a/DirectReport/models/team_model.py +++ b/DirectReport/models/team_model.py @@ -2,30 +2,31 @@ import sqlite3 import uuid +from .team import Team class TeamModel: - def __init__(self, db_name="team.db"): self.conn = sqlite3.connect(db_name, check_same_thread=False) self.create_table() def create_table(self): cursor = self.conn.cursor() - cursor.execute(""" - CREATE TABLE IF NOT EXISTS team ( + cursor.execute( + """CREATE TABLE IF NOT EXISTS team ( id TEXT UNIQUE NOT NULL PRIMARY KEY, team_name TEXT NOT NULL, team_email TEXT NOT NULL - ) - """) - + )""" + ) def insert_team(self, team_name, team_email): cursor = self.conn.cursor() uuid_str = str(uuid.uuid4()) try: - cursor.execute("INSERT INTO team (id, team_name, team_email) VALUES (?, ?, ?)", (uuid_str, team_name, team_email)) + cursor.execute( + "INSERT INTO team (id, team_name, team_email) VALUES (?, ?, ?)", (uuid_str, team_name, team_email) + ) self.conn.commit() print("User added successfully!") except sqlite3.IntegrityError: diff --git a/DirectReport/models/user_model.py b/DirectReport/models/user_model.py index 45986fad..5e9b15da 100644 --- a/DirectReport/models/user_model.py +++ b/DirectReport/models/user_model.py @@ -6,9 +6,7 @@ from werkzeug.security import generate_password_hash, check_password_hash - class User(UserMixin): - def __init__(self, id, username, firstname, lastname, email, password): self.id = email self.uid = id @@ -28,14 +26,11 @@ def is_anonymous(self): def is_authenticated(self): return self.authenticated - def is_active(self): - return True - def get_id(self): return self.id def check_password(self, password): - return check_password_hash(self.password, password) + return check_password_hash(self.password, password) # return verify_password(self.password, password) # from Flask-Security # return verify_and_update_password(self.password, password) # from Flask-Security # return check_password(self.password, password) # from werkzeug.security @@ -56,7 +51,8 @@ def __init__(self, db_name="users.db"): def create_table(self): cursor = self.conn.cursor() - cursor.execute(""" + cursor.execute( + """ CREATE TABLE IF NOT EXISTS users ( id TEXT NOT NULL, uid TEXT NOT NULL, @@ -66,14 +62,18 @@ def create_table(self): email TEXT UNIQUE NOT NULL PRIMARY KEY, password TEXT NOT NULL ) - """) + """ + ) self.conn.commit() def insert_user(self, id, username, firstname, lastname, email, password): cursor = self.conn.cursor() uuid_str = str(uuid.uuid4()) try: - cursor.execute("INSERT INTO users (id, uid, username, firstname, lastname, email, password) VALUES (?, ?, ?, ?, ?, ?, ?)", (id, uuid_str, username, firstname, lastname, email, password)) + cursor.execute( + "INSERT INTO users (id, uid, username, firstname, lastname, email, password) VALUES (?, ?, ?, ?, ?, ?, ?)", + (id, uuid_str, username, firstname, lastname, email, password), + ) self.conn.commit() print("User added successfully!") except sqlite3.IntegrityError: @@ -81,7 +81,9 @@ def insert_user(self, id, username, firstname, lastname, email, password): def get_user_by_email(self, email): cursor = self.conn.cursor() - cursor.execute("SELECT id, uid, username, firstname, lastname, email, password FROM users WHERE email=?", (email,)) + cursor.execute( + "SELECT id, uid, username, firstname, lastname, email, password FROM users WHERE email=?", (email,) + ) result = cursor.fetchone() if result: return User(result[0], result[2], result[3], result[4], result[5], result[6]) diff --git a/DirectReport/tests/test_commandline.py b/DirectReport/tests/test_commandline.py index adfb51ad..bfc4e095 100644 --- a/DirectReport/tests/test_commandline.py +++ b/DirectReport/tests/test_commandline.py @@ -41,4 +41,3 @@ def test_cli_list_all(): def test_cli_mail(): result = runner.invoke(mail) assert result.exit_code == 0 - diff --git a/DirectReport/tests/test_db.py b/DirectReport/tests/test_db.py index fe5b8bff..ab2af35f 100644 --- a/DirectReport/tests/test_db.py +++ b/DirectReport/tests/test_db.py @@ -37,7 +37,7 @@ def test_add_get_entry(temp_db): topic="My topic", message="Test message", created_at=datetime.now().timestamp(), - modified_on=datetime.now().timestamp() + modified_on=datetime.now().timestamp(), ) storage.add_entry(entry) @@ -53,7 +53,7 @@ def test_update_entry(temp_db): topic="Test Topic", message="Test message", created_at=datetime.now().timestamp(), - modified_on=datetime.now().timestamp() + modified_on=datetime.now().timestamp(), ) storage.add_entry(entry) entry.message = "Updated message" @@ -70,7 +70,7 @@ def test_delete_entry(temp_db): topic="New Topic", message="Test message", created_at=datetime.now().timestamp(), - modified_on=datetime.now().timestamp() + modified_on=datetime.now().timestamp(), ) storage.add_entry(entry) @@ -87,17 +87,16 @@ def test_get_all_entries(temp_db): topic="New", message="Test message 1", created_at=datetime.now().timestamp(), - modified_on=datetime.now().timestamp() + modified_on=datetime.now().timestamp(), ) entry2 = Entry( uuid=str(uuid.uuid4()), topic="Topic new", message="Test message 2", created_at=datetime.now().timestamp(), - modified_on=datetime.now().timestamp() + modified_on=datetime.now().timestamp(), ) storage.add_entry(entry1) storage.add_entry(entry2) entries = storage.list_all_entries() assert len(entries) == 2 - diff --git a/DirectReport/tests/test_list_builder.py b/DirectReport/tests/test_list_builder.py index 625f9650..1e4e4cf4 100644 --- a/DirectReport/tests/test_list_builder.py +++ b/DirectReport/tests/test_list_builder.py @@ -20,4 +20,3 @@ def temp_db(): yield db_path os.close(db_fd) os.remove(db_path) - diff --git a/DirectReport/tests/test_model.py b/DirectReport/tests/test_model.py index 8884bad9..a3106c94 100644 --- a/DirectReport/tests/test_model.py +++ b/DirectReport/tests/test_model.py @@ -3,4 +3,3 @@ from DirectReport.models.entry import Entry import datetime import uuid -