Skip to content

Commit

Permalink
version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
umjennifer committed Oct 18, 2022
1 parent 264660a commit 794d514
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
20 changes: 15 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import date


new_feature = True
new_feature = False
show_tips = False

app = Flask(__name__)
Expand Down Expand Up @@ -37,6 +37,7 @@ class Task(db.Model):

class Deleted_Objective(db.Model):
id = db.Column(db.Integer, primary_key=True)
id_of_deleted_objective = db.Column(db.Integer)
content = db.Column(db.String(200), nullable=False)
key_results = db.relationship('Deleted_Key_Result', backref='objective', cascade="all, delete-orphan")

Expand All @@ -45,13 +46,15 @@ def __repr__(self):

class Deleted_Key_Result(db.Model):
id = db.Column(db.Integer, primary_key=True)
id_of_deleted_key_result = db.Column(db.Integer)
content = db.Column(db.String(200), nullable=False)
objective_id = db.Column(db.Integer, db.ForeignKey('deleted__objective.id')) # TODO: set as can't be null
tasks = db.relationship('Deleted_Task', backref='key_result', cascade="all, delete-orphan")
# TODO: cascade this delete

class Deleted_Task(db.Model):
id = db.Column(db.Integer, primary_key=True)
id_of_deleted_task = db.Column(db.Integer)
content = db.Column(db.String(200), nullable=False)
key_result_id = db.Column(db.Integer, db.ForeignKey('deleted__key__result.id')) # TODO: set as can't be null
# TODO: cascade delete
Expand Down Expand Up @@ -138,12 +141,12 @@ def tips_hide():
@app.route('/delete/objective/<int:id>')
def delete_objective(id):
objective_to_delete = Objective.query.get_or_404(id)
new_deleted_objective = Deleted_Objective(content=objective_to_delete.content, id_of_deleted_objective=id)
try:
db.session.delete(objective_to_delete)
print("objective_to_delete=", objective_to_delete)

# add the item to the recently deleted

# add the item to the recently deleted
db.session.add(new_deleted_objective)

db.session.commit()
return redirect('/')
Expand All @@ -153,8 +156,10 @@ def delete_objective(id):
@app.route('/delete/key_result/<int:id>')
def delete_key_result(id):
key_result_to_delete = Key_Result.query.get_or_404(id)
new_deleted_key_result = Deleted_Key_Result(content=key_result_to_delete.content, id_of_deleted_key_result=id, objective_id=key_result_to_delete.objective_id)
try:
db.session.delete(key_result_to_delete)
db.session.add(new_deleted_key_result)
db.session.commit()
return redirect('/')
except:
Expand All @@ -163,8 +168,10 @@ def delete_key_result(id):
@app.route('/delete/task/<int:id>')
def delete_task(id):
task_to_delete = Task.query.get_or_404(id)
new_deleted_task = Deleted_Task(content=task_to_delete.content, id_of_deleted_task=id, key_result_id=task_to_delete.key_result_id)
try:
db.session.delete(task_to_delete)
db.session.add(new_deleted_task)
db.session.commit()
return redirect('/')
except:
Expand Down Expand Up @@ -198,7 +205,10 @@ def instructions():

@app.route('/recently-deleted', methods=['GET'])
def recently_deleted():
return render_template('recently-deleted.html')
deleted_objectives = Deleted_Objective.query.order_by(Deleted_Objective.id).all()
deleted_key_results = Deleted_Key_Result.query.order_by(Deleted_Key_Result.id).all()
deleted_tasks = Deleted_Task.query.order_by(Deleted_Task.id).all()
return render_template('recently-deleted.html', deleted_objectives=deleted_objectives, deleted_key_results=deleted_key_results, deleted_tasks=deleted_tasks)

# @app.teardown_request
# def teardown_request(exception=None):
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</div>
</nav>

<title>OKR tracker</title>
<title>Goal Tracker</title>
{% block head %}{% endblock %}

</head>
Expand Down
54 changes: 54 additions & 0 deletions templates/recently-deleted.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,64 @@ <h1 style="text-align: center;">Recently Deleted</h1>

<h2>Deleted Objectives</h2>

<table>
<tr>
<th>Objective</th>
<th>Key Results</th>
<th>Actions</th>
</tr>

{% for deleted_objective in deleted_objectives %}
<tr>
<td>{{ deleted_objective.content }}</td>
<td>{{ deleted_objectives.key_results }}</td>

<td>
<a href="/recover/objective/{{deleted_objective.id}}">Recover</a>
</td>
</tr>
{% endfor %}
</table>

<h2>Deleted Key Results</h2>
<table>
<tr>
<th>Key Result</th>
<th>Tasks</th>
<th>Actions</th>
</tr>

{% for deleted_key_result in deleted_key_results %}
<tr>
<td>{{ deleted_key_result.content }}</td>
<td>{{ deleted_key_result.tasks }}</td>

<td>
<a href="/recover/key_result/{{deleted_key_result.id}}">Recover</a>
</td>
</tr>
{% endfor %}
</table>

<h2>Deleted Tasks</h2>
<table>
<tr>
<th>Task</th>
<th>Key Result ID</th>
<th>Actions</th>
</tr>

{% for deleted_task in deleted_tasks %}
<tr>
<td>{{ deleted_task.content }}</td>
<td>{{ deleted_task.key_result_id }}</td>

<td>
<a href="/recover/task/{{deleted_task.id}}">Recover</a>
</td>
</tr>
{% endfor %}
</table>



Expand Down

0 comments on commit 794d514

Please sign in to comment.