Skip to content

Commit

Permalink
Add draft determinations to todo list (HyphaApp#3846)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepsajan0 authored and wes-otf committed Apr 17, 2024
1 parent 30e77e0 commit d7f8d91
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hypha/apply/dashboard/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ <h2 class="text-center font-light">{% trans "My tasks" %}</h2>
{% for task in my_tasks.data %}
<div class="bg-white p-1 flex mb-1 items-center border border-gray-600">
<svg class="icon icon--dashboard-tasks"><use xlink:href="#{{ task.icon }}"></use></svg>
<div class="flex-1">{{ task.text|markdown|nh3 }}</div>
<div class="flex flex-1 items-center">
{{ task.text|markdown|nh3 }}
{% if task.type == "Draft" %}
<span class="bg-red-200 hover:opacity-70 transition-opacity rounded-full whitespace-nowrap inline-block ms-1 my-2 px-2 pt-0.5 pb-1 text-sm font-medium text-gray-800">{{ task.type }}</span>
{% endif %}
</div>
<a class="button button-primary m-2" href="{{ task.url }}">{% trans "View" %}</a>
</div>
{% endfor %}
Expand Down
21 changes: 21 additions & 0 deletions hypha/apply/determinations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from hypha.apply.funds.workflow import DETERMINATION_OUTCOMES, Concept
from hypha.apply.projects.models import Project
from hypha.apply.stream_forms.models import BaseStreamForm
from hypha.apply.todo.options import DETERMINATION_DRAFT
from hypha.apply.todo.views import (
add_task_to_user,
remove_tasks_for_user,
remove_tasks_of_related_obj_for_specific_code,
)
from hypha.apply.users.decorators import staff_required
from hypha.apply.utils.views import CreateOrUpdateView, ViewDispatcher

Expand Down Expand Up @@ -425,6 +431,11 @@ def form_valid(self, form):

super().form_valid(form)
if self.object.is_draft:
add_task_to_user(
code=DETERMINATION_DRAFT,
user=self.object.author,
related_obj=self.object,
)
return HttpResponseRedirect(self.submission.get_absolute_url())

with transaction.atomic():
Expand Down Expand Up @@ -460,6 +471,16 @@ def form_valid(self, form):
if self.submission.accepted_for_funding and settings.PROJECTS_AUTO_CREATE:
Project.create_from_submission(self.submission)

# remove current users's task for determination
remove_tasks_for_user(
code=DETERMINATION_DRAFT, user=self.object.author, related_obj=self.object
)

# remove all current determination tasks for the submission
remove_tasks_of_related_obj_for_specific_code(
code=DETERMINATION_DRAFT, related_obj=self.object
)

messenger(
MESSAGES.DETERMINATION_OUTCOME,
request=self.request,
Expand Down
41 changes: 41 additions & 0 deletions hypha/apply/todo/migrations/0002_alter_task_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 4.2.11 on 2024-04-03 12:39

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("todo", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="task",
name="code",
field=models.CharField(
choices=[
("determination_draft", "Determination draft"),
("project_waiting_paf", "Project waiting PAF"),
("project_submit_paf", "Project submit PAF"),
("paf_required_changes", "PAF required changes"),
("paf_waiting_assignee", "PAF waiting assignee"),
("paf_waiting_approval", "PAF waiting approval"),
("project_waiting_contract", "Project waiting contract"),
(
"project_waiting_contract_document",
"Project waiting contract document",
),
(
"project_waiting_contract_review",
"Project waiting contract review",
),
("project_waiting_invoice", "Project waiting invoice"),
("invoice_required_changes", "Invoice required changes"),
("invoice_waiting_approval", "Invoice waiting approval"),
("invoice_waiting_paid", "Invoice waiting paid"),
("report_due", "Report due"),
],
max_length=50,
),
),
]
10 changes: 10 additions & 0 deletions hypha/apply/todo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from hypha.apply.activity.adapters.utils import link_to

DETERMINATION_DRAFT = "determination_draft"
PROJECT_WAITING_PAF = "project_waiting_paf"
PROJECT_SUBMIT_PAF = "project_submit_paf"
PAF_REQUIRED_CHANGES = "paf_required_changes"
Expand All @@ -19,6 +20,7 @@
REPORT_DUE = "report_due"

TASKS_CODE_CHOICES = (
(DETERMINATION_DRAFT, "Determination draft"),
(PROJECT_WAITING_PAF, "Project waiting PAF"),
(PROJECT_SUBMIT_PAF, "Project submit PAF"),
(PAF_REQUIRED_CHANGES, "PAF required changes"),
Expand All @@ -38,6 +40,14 @@
template_map = {
# SUBMISSIONS ACTIONS
# :todo: actions for mupltiple stages of submission
DETERMINATION_DRAFT: {
"text": _(
'Determination draft for submission [<span class=" truncate inline-block w-32 align-bottom ">{related.submission.title}</span>]({link} "{related.submission.title}") is waiting to be submitted'
),
"icon": "edit-draft",
"url": "{link}",
"type": _("Draft"),
},
# PROJECT actions
# draft state (staff action)
PROJECT_WAITING_PAF: {
Expand Down
15 changes: 15 additions & 0 deletions hypha/apply/todo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ def remove_tasks_for_user_group(code, user_group, related_obj):
return None


def remove_tasks_of_related_obj_for_specific_code(code, related_obj):
"""
Remove all tasks of a related object with the provide code irrespective to their users
input:
code: TASKS_CODE_CHOICES.keys()
related_obj: Object - Submission, Project, Invoice, Report
"""
Task.objects.filter(
code=code,
related_content_type=ContentType.objects.get_for_model(related_obj).id,
related_object_id=related_obj.id,
).delete()
return None


def remove_tasks_of_related_obj(related_obj):
"""
Remove all tasks of a related object irrespective of their code and users
Expand Down
4 changes: 4 additions & 0 deletions hypha/templates/includes/sprites.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
<path d="M7.54625 9.5375L7.54625 4.11249L8.47594 4.11249L8.47594 9.5375L7.54625 9.5375ZM8.64 11.4937C8.64 11.6354 8.58531 11.7542 8.47594 11.85C8.36135 11.95 8.2051 12 8.00719 12C7.80927 12 7.65302 11.95 7.53844 11.85C7.41865 11.7542 7.35875 11.6354 7.35875 11.4937C7.35875 11.3562 7.41865 11.2375 7.53844 11.1375C7.65302 11.0417 7.80927 10.9937 8.00719 10.9937C8.2051 10.9937 8.36135 11.0417 8.47594 11.1375C8.58531 11.2375 8.64 11.3562 8.64 11.4937Z" fill="#F05E54"/>
</symbol>

<svg id="edit-draft" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path d="M12 20h9"/>
<path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/>
</svg>
</svg>

0 comments on commit d7f8d91

Please sign in to comment.