Skip to content
Snippets Groups Projects
Commit 152e8276 authored by Andrea Callia D'Iddio's avatar Andrea Callia D'Iddio
Browse files

Merge branch 'showing-full-names-of-proposers' into 'master'

Feat: Showing full name for proposers of projects, instead of username, where...

See merge request !9
parents a4b095d9 aad9bc8f
No related branches found
No related tags found
1 merge request!9Feat: Showing full name for proposers of projects, instead of username, where...
Pipeline #318823 passed
from ..database import db
class Person(db.Model):
username = db.Column(db.String, primary_key=True)
firstname = db.Column(db.String, nullable=False)
lastname = db.Column(db.String, nullable=False)
@property
def full_name(self) -> str:
return (
f"{self.firstname} {self.lastname}"
if self.firstname and self.lastname
else ""
)
...@@ -22,6 +22,14 @@ ...@@ -22,6 +22,14 @@
<div class="w3-threequarter"> <div class="w3-threequarter">
{{ form.on_behalf(placeholder="Student username", class="w3-input w3-border", id="student-proposer") }} {{ form.on_behalf(placeholder="Student username", class="w3-input w3-border", id="student-proposer") }}
</div> </div>
<div class="w3-quarter {% if not show_box %}w3-hide{% endif %}" style="visibility: hidden">
{{ form.on_behalf(placeholder="Student full name", class="w3-input w3-border", id="format-align") }}
</div>
<div class="w3-threequarter {% if not show_box %}w3-hide{% endif %}">
<div class="w3-input w3-border", id="student-fullname">
{{ person.full_name }}
</div>
</div>
</section> </section>
<button type="submit" class="w3-btn w3-{{ theme_colour }}">Save</button> <button type="submit" class="w3-btn w3-{{ theme_colour }}">Save</button>
</form> </form>
...@@ -48,4 +56,11 @@ ...@@ -48,4 +56,11 @@
toggleStudentProposer(isStudentProposalCheckbox.checked) toggleStudentProposer(isStudentProposalCheckbox.checked)
isStudentProposalCheckbox.addEventListener("change", (event) => toggleStudentProposer(event.target.checked)) isStudentProposalCheckbox.addEventListener("change", (event) => toggleStudentProposer(event.target.checked))
</script> </script>
<script>
// this script makes the student-fullname textbox hidden when the student-proposer textbox is clicked on (presumably with an intention to modify it)
const studentUsernameBox = document.getElementById("student-proposer")
const studentFullnameBox = document.getElementById("student-fullname")
studentUsernameBox.addEventListener("click", async () => {studentFullnameBox.style.visibility = 'hidden';})
</script>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<div class="w3-container"> <div class="w3-container">
<h1 class="w3-center w3-text-blue">Project proposal</h1> <h1 class="w3-center w3-text-blue">Project proposal</h1>
{{ project_details_section('Title', project.title) }} {{ project_details_section('Title', project.title) }}
{{ project_details_section('Proposer', project.on_behalf or project.proposer) }} {{ project_details_section('Proposer', person.full_name if person.full_name else person.username) }}
{{ project_details_section('Description', project.description) }} {{ project_details_section('Description', project.description) }}
</div> </div>
</div> </div>
......
...@@ -7,6 +7,7 @@ from sqlalchemy import and_ ...@@ -7,6 +7,7 @@ from sqlalchemy import and_
from app import messages from app import messages
from app.database import db from app.database import db
from app.forms.project import ProjectForm from app.forms.project import ProjectForm
from app.models.person import Person
from app.models.project import Project from app.models.project import Project
from app.models.shortlist import Shortlisting from app.models.shortlist import Shortlisting
from app.utils.decorators import staff_only from app.utils.decorators import staff_only
...@@ -79,6 +80,9 @@ def delete_project(project_id): ...@@ -79,6 +80,9 @@ def delete_project(project_id):
@login_required @login_required
@staff_only @staff_only
def edit_project(project_id): def edit_project(project_id):
# show_box is a boolean used to decide if we show the text box for student full name. by default this is not shown
show_box = False
person = None
if project := Project.query.get(project_id): if project := Project.query.get(project_id):
form = ProjectForm() form = ProjectForm()
on_behalf_changed = project.on_behalf != form.on_behalf.data on_behalf_changed = project.on_behalf != form.on_behalf.data
...@@ -93,7 +97,19 @@ def edit_project(project_id): ...@@ -93,7 +97,19 @@ def edit_project(project_id):
shortlist_proposer(project) shortlist_proposer(project)
return redirect(url_for("staff.projects")) return redirect(url_for("staff.projects"))
form = ProjectForm(obj=project) form = ProjectForm(obj=project)
return render_template("pages/project-form.html", form=form, project=project)
if project.on_behalf is not None:
person = Person.query.filter(Person.username == project.on_behalf).first()
if person:
show_box = True
return render_template(
"pages/project-form.html",
form=form,
project=project,
show_box=show_box,
person=person,
)
flash(messages.PROJECT_NOT_FOUND) flash(messages.PROJECT_NOT_FOUND)
return redirect(url_for("staff.projects")) return redirect(url_for("staff.projects"))
......
...@@ -4,6 +4,7 @@ from sqlalchemy import or_ ...@@ -4,6 +4,7 @@ from sqlalchemy import or_
from app import messages from app import messages
from app.database import db from app.database import db
from app.models.person import Person
from app.models.project import Project from app.models.project import Project
from app.models.shortlist import Shortlisting from app.models.shortlist import Shortlisting
from app.utils.decorators import only_before_deadline_for_students, students_only from app.utils.decorators import only_before_deadline_for_students, students_only
...@@ -66,7 +67,15 @@ def update_ranking(): ...@@ -66,7 +67,15 @@ def update_ranking():
@students_only @students_only
def view_project(project_id): def view_project(project_id):
if project := Project.query.get(project_id): if project := Project.query.get(project_id):
return render_template("pages/student/project-view.html", project=project) username = project.proposer if project.on_behalf is None else project.on_behalf
person = Person.query.filter(Person.username == username).first() or Person(
username=username, firstname="", lastname=""
)
return render_template(
"pages/student/project-view.html", project=project, person=person
)
flash(messages.PROJECT_NOT_FOUND) flash(messages.PROJECT_NOT_FOUND)
return redirect(url_for("student.projects")) return redirect(url_for("student.projects"))
......
"""add person table
Revision ID: 39059e9c2ab2
Revises: ce0f2fd42857
Create Date: 2022-10-03 17:34:18.028987
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "39059e9c2ab2"
down_revision = "ce0f2fd42857"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"person",
sa.Column("username", sa.String(), nullable=False),
sa.Column("firstname", sa.String(), nullable=False),
sa.Column("lastname", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("username"),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("person")
# ### end Alembic commands ###
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment