Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Feb 19, 2024
1 parent b882b0c commit 84cfe96
Show file tree
Hide file tree
Showing 11 changed files with 594 additions and 14 deletions.
15 changes: 8 additions & 7 deletions .makim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ version: 1.0
groups:
clean:
targets:
all:
tmp:
help: Clean unnecessary temporary files
shell: bash
run: |
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name
find . -name '__pycache__' -exec rm -fr '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +{} +
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
rm -fr .mypy_cache
rm -fr .ruff_cache
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
find . -name '*~' -exec rm -f {} +
docs:
targets:
Expand Down
219 changes: 218 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ python = ">=3.8.1,<4"
flask = ">=3.0.2"
flask-wtf = ">=1.2.1"
email-validator = ">=2.1.0.post1"
sqlalchemy = ">=2.0.27"
flask-sqlalchemy = ">=3.1.1"
types-wtforms = "^3.1.0.20240205"
sqlalchemy-stubs = "^0.4"

[tool.poetry.dev-dependencies]
pytest = ">=7.3.2"
Expand Down Expand Up @@ -104,6 +108,18 @@ warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true

# [[tool.mypy.overrides]]
# module = [
# "wtforms",
# ]
# ignore_missing_imports = true


[[tool.mypy.overrides]]
# module = []
ignore_missing_imports = true
module = "feedback_linker.models"
ignore_errors = true


[[tool.mypy.overrides]]
module = "feedback_linker.forms"
ignore_errors = true
2 changes: 1 addition & 1 deletion src/feedback_linker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from importlib import metadata as importlib_metadata


def get_version():
def get_version() -> str:
"""Return the program version."""
try:
return importlib_metadata.version(__name__)
Expand Down
91 changes: 90 additions & 1 deletion src/feedback_linker/app.py
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)
114 changes: 114 additions & 0 deletions src/feedback_linker/forms.py
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
102 changes: 102 additions & 0 deletions src/feedback_linker/models.py
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)
Loading

0 comments on commit 84cfe96

Please sign in to comment.