Skip to content
Snippets Groups Projects
Commit 0689c213 authored by Ivan Procaccini's avatar Ivan Procaccini
Browse files

Feat: Create shortlisting model

parent d7c3297f
No related branches found
No related tags found
No related merge requests found
Pipeline #307590 passed
from .administration import *
from .project import *
from .shortlist import *
from sqlalchemy import Sequence
from ..database import db
RANKING_SEQUENCE = Sequence("shortlisting_ranking_seq")
class Shortlisting(db.Model):
id = db.Column(db.Integer, primary_key=True)
project_id = db.Column(db.Integer, db.ForeignKey("project.id"), nullable=False)
student = db.Column(db.String)
ranking = db.Column(
db.Integer,
RANKING_SEQUENCE,
server_default=RANKING_SEQUENCE.next_value(),
nullable=False,
)
......@@ -10,7 +10,7 @@
<div class="w3-display-right">
<a href="{{ url_for("student.view_project", project_id=project.id) }}"
class="w3-button w3-hover-blue">View</a>
<a href=""
<a href="{{ url_for("student.shortlist_project", project_id=project.id) }}"
class="w3-button w3-hover-blue">Shortlist</a>
</div>
</li>
......
from flask import render_template, Blueprint, redirect, url_for, flash
from flask_login import login_required
from flask_login import login_required, current_user
from app import Project, messages
from app import Project, messages, Shortlisting, db
bp = Blueprint("student", __name__, url_prefix="/student")
......@@ -22,3 +22,17 @@ def view_project(project_id):
return render_template("pages/student/project-view.html", project=project)
flash(messages.PROJECT_NOT_FOUND)
return redirect(url_for("student.projects"))
@bp.route("/projects/<project_id>/shortlist")
@login_required
def shortlist_project(project_id):
if Project.query.get(project_id):
shortlisting = Shortlisting(
student=current_user.username, project_id=project_id
)
db.session.add(shortlisting)
db.session.commit()
else:
flash(messages.PROJECT_NOT_FOUND)
return redirect(url_for("student.projects"))
"""Add shortlisting table
Revision ID: d009c2b07eed
Revises: 6dea3a5014b0
Create Date: 2022-08-23 15:08:42.796055
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
from sqlalchemy import Sequence
from sqlalchemy.sql.ddl import CreateSequence, DropSequence
revision = "d009c2b07eed"
down_revision = "6dea3a5014b0"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.execute(CreateSequence(Sequence("shortlisting_ranking_seq")))
op.create_table(
"shortlisting",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("project_id", sa.Integer(), nullable=False),
sa.Column("student", sa.String(), nullable=True),
sa.Column(
"ranking",
sa.Integer(),
server_default=sa.text("nextval('shortlisting_ranking_seq')"),
nullable=False,
),
sa.ForeignKeyConstraint(
["project_id"],
["project.id"],
),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("shortlisting")
op.execute(DropSequence(Sequence("shortlisting_ranking_seq")))
# ### 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