-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
594 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,90 @@ | ||
"""Main module.""" | ||
"""App module.""" | ||
from __future__ import annotations | ||
|
||
from typing import Union | ||
|
||
from flask import Flask, flash, redirect, render_template, url_for | ||
from werkzeug.wrappers.response import Response | ||
|
||
from feedback_linker.forms import ( | ||
FeedbackForm, | ||
LinkForm, | ||
LoginForm, | ||
PersonForm, | ||
ProjectForm, | ||
) | ||
from feedback_linker.models import ( | ||
Feedback, | ||
Link, | ||
Person, | ||
Project, | ||
db, | ||
init_app, | ||
) | ||
|
||
app = Flask(__name__) | ||
app.config['SECRET_KEY'] = 'your_secret_key' | ||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///feedback_linker.db' | ||
init_app(app) | ||
|
||
|
||
@app.route('/') | ||
def index() -> str: | ||
"""Define the view for the index page.""" | ||
return render_template('index.html') | ||
|
||
|
||
@app.route('/login', methods=['GET', 'POST']) | ||
def login() -> str: | ||
"""Define the view for managing login.""" | ||
form = LoginForm() | ||
# Login logic here | ||
return render_template('login.html', form=form) | ||
|
||
|
||
@app.route('/projects', methods=['GET', 'POST']) | ||
def manage_projects() -> Union[Response, str]: | ||
"""Define the view for managing projects.""" | ||
form = ProjectForm() | ||
if form.validate_on_submit(): | ||
project = Project(name=form.name.data) | ||
db.session.add(project) | ||
db.session.commit() | ||
flash('Project created successfully!') | ||
return redirect(url_for('manage_projects')) | ||
projects = Project.query.all() | ||
return render_template('project_list.html', form=form, projects=projects) | ||
|
||
|
||
@app.route('/people', methods=['GET', 'POST']) | ||
def manage_people() -> str: | ||
"""Define the view for managing people.""" | ||
form = PersonForm() | ||
# Person creation logic here | ||
people = Person.query.all() | ||
return render_template('people_list.html', form=form, people=people) | ||
|
||
|
||
@app.route('/links', methods=['GET', 'POST']) | ||
def manage_links() -> str: | ||
"""Define the view for managing links.""" | ||
form = LinkForm() | ||
# Link creation logic here | ||
links = Link.query.all() | ||
return render_template('link_list.html', form=form, links=links) | ||
|
||
|
||
@app.route('/feedback', methods=['GET', 'POST']) | ||
def submit_feedback() -> str: | ||
"""Define the view for submitting feedback.""" | ||
form = FeedbackForm() | ||
# Feedback submission logic here | ||
feedbacks = Feedback.query.all() | ||
return render_template( | ||
'feedback_list.html', form=form, feedbacks=feedbacks | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
db.create_all() | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
"""Forms module.""" | ||
from __future__ import annotations | ||
|
||
from flask_wtf import FlaskForm | ||
from wtforms import ( | ||
IntegerField, | ||
PasswordField, | ||
SelectField, | ||
StringField, | ||
SubmitField, | ||
TextAreaField, | ||
) | ||
from wtforms.ext.sqlalchemy.fields import ( | ||
QuerySelectField, | ||
QuerySelectMultipleField, | ||
) | ||
from wtforms.validators import DataRequired, Email, Length | ||
|
||
from .models import Link, Person, Project | ||
|
||
|
||
def project_choices(): | ||
"""Return the choices for project.""" | ||
return Project.query.all() | ||
|
||
|
||
def person_choices(): | ||
"""Return the choices for person.""" | ||
return Person.query.all() | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
"""The login form.""" | ||
|
||
email = StringField('Email', validators=[DataRequired(), Email()]) | ||
password = PasswordField( | ||
'Password', validators=[DataRequired(), Length(min=6)] | ||
) | ||
submit = SubmitField('Log In') | ||
|
||
|
||
class ProjectForm(FlaskForm): | ||
"""The project form.""" | ||
|
||
name = StringField('Project Name', validators=[DataRequired()]) | ||
people = QuerySelectMultipleField( | ||
'Select People', query_factory=person_choices, get_label='name' | ||
) | ||
submit = SubmitField('Submit') | ||
|
||
|
||
class PersonForm(FlaskForm): | ||
"""The person form.""" | ||
|
||
name = StringField('Name', validators=[DataRequired()]) | ||
email = StringField('Email', validators=[DataRequired(), Email()]) | ||
projects = QuerySelectMultipleField( | ||
'Select Projects', query_factory=project_choices, get_label='name' | ||
) | ||
submit = SubmitField('Submit') | ||
|
||
|
||
class LinkForm(FlaskForm): | ||
"""The link form.""" | ||
|
||
person_one = QuerySelectField( | ||
'Person One', | ||
query_factory=person_choices, | ||
get_label='name', | ||
validators=[DataRequired()], | ||
) | ||
person_two = QuerySelectField( | ||
'Person Two', | ||
query_factory=person_choices, | ||
get_label='name', | ||
validators=[DataRequired()], | ||
) | ||
supervisor = QuerySelectField( | ||
'Supervisor', | ||
query_factory=person_choices, | ||
get_label='name', | ||
validators=[DataRequired()], | ||
) | ||
periodicity = SelectField( | ||
'Periodicity', | ||
choices=[ | ||
('daily', 'Daily'), | ||
('weekly', 'Weekly'), | ||
('monthly', 'Monthly'), | ||
], | ||
validators=[DataRequired()], | ||
) | ||
times = IntegerField('Every X times', validators=[DataRequired()]) | ||
submit = SubmitField('Submit') | ||
|
||
|
||
class FeedbackForm(FlaskForm): | ||
"""The feedback form.""" | ||
|
||
content = TextAreaField('Feedback Content', validators=[DataRequired()]) | ||
link = QuerySelectField( | ||
'Link', | ||
query_factory=lambda: Link.query.all(), | ||
get_label='id', | ||
validators=[DataRequired()], | ||
) | ||
submit = SubmitField('Submit') | ||
|
||
|
||
def init_app(app) -> None: | ||
"""Initialize the app for forms.""" | ||
# This function is here if you need to initialize anything specifically | ||
# for the forms | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
"""Models module.""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
db = SQLAlchemy() | ||
|
||
if TYPE_CHECKING: | ||
from flask_sqlalchemy.model import Model | ||
|
||
BaseModel = db.make_declarative_base(Model) | ||
else: | ||
BaseModel = db.Model | ||
|
||
|
||
class Project(BaseModel): # type: ignore[name-defined] | ||
"""Project model.""" | ||
|
||
__tablename__ = 'project' | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(100), nullable=False) | ||
people = db.relationship( | ||
'Person', secondary='project_person', back_populates='projects' | ||
) | ||
supervisors = db.relationship('Person', secondary='project_supervisor') | ||
|
||
|
||
class Person(BaseModel): # type: ignore[name-defined] | ||
"""Person model.""" | ||
|
||
__tablename__ = 'person' | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(100), nullable=False) | ||
email = db.Column(db.String(100), unique=True, nullable=False) | ||
projects = db.relationship( | ||
'Project', secondary='project_person', back_populates='people' | ||
) | ||
links = db.relationship( | ||
'Link', secondary='person_link', back_populates='people' | ||
) | ||
|
||
|
||
project_person = db.Table( | ||
'project_person', | ||
db.Column( | ||
'person_id', db.Integer, db.ForeignKey('person.id'), primary_key=True | ||
), | ||
db.Column( | ||
'project_id', db.Integer, db.ForeignKey('project.id'), primary_key=True | ||
), | ||
) | ||
|
||
project_supervisor = db.Table( | ||
'project_supervisor', | ||
db.Column( | ||
'person_id', db.Integer, db.ForeignKey('person.id'), primary_key=True | ||
), | ||
db.Column( | ||
'project_id', db.Integer, db.ForeignKey('project.id'), primary_key=True | ||
), | ||
) | ||
|
||
|
||
class Link(BaseModel): # type: ignore[name-defined] | ||
"""Link model.""" | ||
|
||
__tablename__ = 'link' | ||
id = db.Column(db.Integer, primary_key=True) | ||
person_one_id = db.Column(db.Integer, db.ForeignKey('person.id')) | ||
person_two_id = db.Column(db.Integer, db.ForeignKey('person.id')) | ||
supervisor_id = db.Column(db.Integer, db.ForeignKey('person.id')) | ||
periodicity = db.Column(db.String(50)) | ||
times = db.Column(db.Integer) | ||
feedback = db.relationship('Feedback', backref='link', lazy=True) | ||
|
||
|
||
person_link = db.Table( | ||
'person_link', | ||
db.Column( | ||
'link_id', db.Integer, db.ForeignKey('link.id'), primary_key=True | ||
), | ||
db.Column( | ||
'person_id', db.Integer, db.ForeignKey('person.id'), primary_key=True | ||
), | ||
) | ||
|
||
|
||
class Feedback(BaseModel): # type: ignore[name-defined] | ||
"""Feedback model.""" | ||
|
||
__tablename__ = 'feedback' | ||
id = db.Column(db.Integer, primary_key=True) | ||
content = db.Column(db.Text, nullable=False) | ||
link_id = db.Column(db.Integer, db.ForeignKey('link.id')) | ||
timestamp = db.Column(db.DateTime, server_default=db.func.now()) | ||
|
||
|
||
def init_app(app) -> None: | ||
"""Initialize app for the database.""" | ||
db.init_app(app) |
Oops, something went wrong.