Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/mypy-1.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchegm authored Jul 3, 2024
2 parents 1d543d4 + 6ac2c62 commit f1817f0
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 185 deletions.
108 changes: 54 additions & 54 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 30 additions & 9 deletions src/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,43 @@ def __init__(
"""
# pylint: disable=too-many-arguments
self.id = id_
self.name = name
self.coordinator = coordinator
self.coordinator_email = coordinator_email
self.name = name if name else ""
self.coordinator = coordinator if coordinator else ""
self.coordinator_email = coordinator_email if coordinator_email else ""
self.status = status
self.type = type_
self.family = family
self.members = members
self.approvers = approvers
self.clinvar_submitter_ids = clinvar_submitter_ids
self.type = type_ if type_ else ""
self.family = family if family else ""
self.members = members if members else []
self.approvers = approvers if approvers else []
self.clinvar_submitter_ids = (
clinvar_submitter_ids if clinvar_submitter_ids else []
)
self.errors: dict = {}

@classmethod
def _row_to_affiliation(cls, row: tuple) -> object:
def _row_to_affiliation(cls, row: tuple) -> "Affiliation":
"""Convert table row to instance of affiliations object."""
return cls(*row)

@classmethod
def get_by_id(cls, id_) -> Optional["Affiliation"]:
"""Return an affiliation matching a given ID."""
con = sqlite3.connect(DB_FILE) # type: ignore
cur = con.cursor()
try:
cur.execute("SELECT * FROM affiliations WHERE id = ?", (id_,))
result = cur.fetchone()
except sqlite3.Error as err:
logger.error("Unable to get affiliation by ID")
logger.error("Error code: %s", err.sqlite_errorcode)
logger.error("Error name: %s", err.sqlite_errorname)
con.rollback()
result = None
con.close()
if result:
return cls._row_to_affiliation(result)
return None

@classmethod
def all(cls) -> Optional[List]:
"""Return all affiliations in the database."""
Expand Down
15 changes: 15 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ def index():
return render_template("index.html", affiliations=affiliations_set, email=email)


@app.route("/edit")
def edit():
"""Edit an existing affiliation."""
logger.info("User accessed edit")
affil_id = request.args.get("affil")
if not affil_id:
return redirect(url_for("index"))
email = session["email"] if "email" in session else None
# TODO(sanchegm): Redirect to main page if user is not logged in.
affiliation = Affiliation.get_by_id(affil_id)
if not affiliation:
return redirect(url_for("index"))
return render_template("edit.html", affiliation=affiliation, email=email)


@app.route("/login", methods=["GET", "POST"])
def login():
"""The login route.
Expand Down
14 changes: 14 additions & 0 deletions src/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ def test_sha_route():
response = CLIENT.get("/sha")
assert response.status_code == 200
assert len(response.text) == 40 # SHA-1 is 40 characters in length.


def test_edit_route():
"""Ensure edit route redirects."""
response = CLIENT.get("/edit?affil=10000")
assert response.status_code == 200
assert "Submit</button>" in response.text
assert "<button>Cancel" in response.text
assert "<label>Name:</label>" in response.text
assert (
'<input type="text" value="Interface Admin" placeholder="Name" />'
in response.text
)
assert "<label>Family:</label>" in response.text
Loading

0 comments on commit f1817f0

Please sign in to comment.