Skip to content

Commit

Permalink
Merge pull request #123 from iMMAP/refactor/url_names_links
Browse files Browse the repository at this point in the history
Reactor url names, optimize ORM queries and clean up views
  • Loading branch information
shtayeb authored Dec 19, 2023
2 parents 41316c6 + d7b1a74 commit 3704a55
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 618 deletions.
2 changes: 1 addition & 1 deletion src/core/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@
"BUILD_URL_PREFIX": "/" + STATIC_URL + "build",
"DEV_MODE": True,
"STATIC_LOOKUP": False,
"SERVER": {"HOST": "0.0.0.0"},
# "SERVER": {"HOST": "0.0.0.0"},
}
15 changes: 0 additions & 15 deletions src/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""rh URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<div class="holder">
<ul class="breadcrumbs">
<li>
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'landing' %}">Home</a>
</li>
<li>
<a id="return-url" href="{% url parent_page %}">
<a id="return-url" href="{% url 'projects-list' %}?state={{project.state}}">
{% if project.state == 'in-progress' %}
Active Projects
{% elif project.state == 'draft' %}
Expand All @@ -21,7 +21,7 @@
</a>
</li>
<li>
<a href="{% url 'view_project' project.id %}">{{ project.code }}</a>
<a href="{% url 'projects-detail' project.id %}">{{ project.code }}</a>
</li>
<li>
<a href="{% url 'project_reports_home' project=project.id %}">Progress Reports</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<div class="holder">
<ul class="breadcrumbs">
<li>
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'landing' %}">Home</a>
</li>
<li>
<a id="return-url" href="{% url parent_page %}">
<a id="return-url" href="{% url 'projects-list' %}?state={{project.state}}">
{% if project.state == 'in-progress' %}
Active Projects
{% elif project.state == 'draft' %}
Expand All @@ -28,7 +28,7 @@
</a>
</li>
<li>
<a href="{% url 'view_project' project.id %}">{{ project.code }}</a>
<a href="{% url 'projects-detail' project.id %}">{{ project.code }}</a>
</li>
<li class="current">
Progress Reports
Expand Down
41 changes: 3 additions & 38 deletions src/project_reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,9 @@ def index_project_report_view(request, project):
project_report_archive = project_reports.filter(active=False)
project_reports_todo = active_project_reports.filter(state__in=["todo", "pending", "submit", "reject"])
project_report_complete = active_project_reports.filter(state="complete")
project_state = project.state
parent_page = {
"in-progress": "active_projects",
"draft": "draft_projects",
"done": "completed_projects",
"archive": "archived_projects",
}.get(project_state, None)

context = {
"project": project,
"parent_page": parent_page,
"project_reports": active_project_reports,
"project_reports_todo": project_reports_todo,
"project_report_complete": project_report_complete,
Expand Down Expand Up @@ -76,13 +69,7 @@ def create_project_monthly_report_view(request, project):
initial={"report_due_date": end_of_month, "project": project},
)

project_state = project.state
parent_page = {
"in-progress": "active_projects",
"draft": "draft_projects",
"done": "completed_projects",
"archive": "archived_projects",
}.get(project_state, None)


if request.method == "POST":
if form.is_valid():
Expand All @@ -100,7 +87,6 @@ def create_project_monthly_report_view(request, project):
context = {
"project": project,
"report_form": form,
"parent_page": parent_page,
"project_view": False,
"financial_view": False,
"reports_view": True,
Expand Down Expand Up @@ -305,18 +291,10 @@ def details_monthly_progress_view(request, project, report):
monthly_report = get_object_or_404(ProjectMonthlyReport, pk=report)
activity_reports = monthly_report.activityplanreport_set.select_related("activity_plan", "indicator")

project_state = project.state
parent_page = {
"in-progress": "active_projects",
"draft": "draft_projects",
"done": "completed_projects",
"archive": "archived_projects",
}.get(project_state, None)
context = {
"project": project,
"monthly_report": monthly_report,
"activity_reports": activity_reports,
"parent_page": parent_page,
"project_view": False,
"financial_view": False,
"reports_view": True,
Expand Down Expand Up @@ -500,12 +478,6 @@ def create_project_monthly_report_progress_view(request, project, report):
# Add error handling code here
pass

parent_page = {
"in-progress": "active_projects",
"draft": "draft_projects",
"done": "completed_projects",
"archive": "archived_projects",
}.get(project_state, None)

combined_formset = zip(activity_report_formset.forms, location_report_formsets)

Expand All @@ -517,7 +489,6 @@ def create_project_monthly_report_progress_view(request, project, report):
"activity_report_formset": activity_report_formset,
# 'location_report_formset': location_report_formset,
"combined_formset": combined_formset,
"parent_page": parent_page,
"project_view": False,
"financial_view": False,
"reports_view": True,
Expand Down Expand Up @@ -671,12 +642,7 @@ def update_project_monthly_report_progress_view(request, project, report):
# Add error handling code here
pass

parent_page = {
"in-progress": "active_projects",
"draft": "draft_projects",
"done": "completed_projects",
"archive": "archived_projects",
}.get(project_state, None)

combined_formset = zip(activity_report_formset.forms, location_report_formsets)

context = {
Expand All @@ -686,7 +652,6 @@ def update_project_monthly_report_progress_view(request, project, report):
"report_form": monthly_report_instance,
"activity_report_formset": activity_report_formset,
"combined_formset": combined_formset,
"parent_page": parent_page,
"project_view": False,
"financial_view": False,
"reports_view": True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<div class="holder">
<ul class="breadcrumbs">
<li>
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'landing' %}">Home</a>
</li>
<li>
<a id="return-url" href="{% url parent_page %}">
<a id="return-url" href="{% url 'projects-list' %}?state={{project.state}}">
{% if project.state == 'in-progress' %}
Active Projects
{% elif project.state == 'draft' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h2 class="plan-title">{{ project.title }}</h2>
{% endfor %}
</div>
<div class="plan-submit-holder">
<a href="{% url 'update_project' project.pk %}"
<a href="{% url 'projects-update' project.pk %}"
class="btn btn-gray-outline">Back</a>
<button type="submit"
class="btn btn-red"
Expand Down
13 changes: 6 additions & 7 deletions src/rh/templates/rh/projects/forms/project_form_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
<div class="holder">
<ul class="breadcrumbs">
<li>
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'landing' %}">Home</a>
</li>
{% if parent_page %}
<li>
<a id="return-url" href="{% url parent_page %}">
<a id="return-url" href="{% url 'projects-list' %}?state={{project.state}}">
{% if project.state == 'in-progress' %}
Active Projects
{% elif project.state == 'draft' %}
Expand All @@ -23,7 +22,6 @@
{% endif %}
</a>
</li>
{% endif %}
{% if project %}
<li class="current">{{ project.code }}</li>
{% else %}
Expand All @@ -36,7 +34,7 @@
<div class="sidebar-nav-holder">
<ul class="sidebar-nav">
<li class="{% if project_planning %}current{% endif %}">
<a href="{% if project %}{% url 'update_project' project.pk %}{% else %}{% url 'create_project' %}{% endif %}">
<a href="{% if project %}{% url 'projects-update' project.pk %}{% else %}{% url 'projects-create' %}{% endif %}">
Project Planning
</a>
</li>
Expand All @@ -46,8 +44,9 @@
Planning</a>
</li>
<li class="{% if project_review %}current{% endif %}">
<a class="{% if not plans %}disabled-link{% endif %}"
href="{% if project and plans %}{% url 'project_plan_review' project.pk %}{% else %}#{% endif %}">Review</a>

<a class="disabled-link"
href="{% if project %} {% url 'project_plan_review' project.pk %} {% else %}#{% endif %}">Review</a>
</li>
</ul>
</div>
Expand Down
8 changes: 2 additions & 6 deletions src/rh/templates/rh/projects/projects_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
<div class="page-navigation-panel">
<div class="holder">
<div class="link-holder">
{% if parent_page %}
<a href="{% url parent_page %}" class="btn-back">Back to All Projects</a>
{% else %}
<a href="{% url 'active_projects' %}" class="btn-back">Back to Active Projects</a>
{% endif %}
<a href="{% url 'projects-list' %}?state=in-progress" class="btn-back">Back to Active Projects</a>
</div>

<div class="tabs-nav-holder">
<ul class="tabs-nav">
<li class="{% if project_view %}active{% endif %}">
<a href="{% if project %}{% url 'view_project' project.pk %}{% else %}{% url 'create_project' %}{% endif %}">Project
<a href="{% if project %}{% url 'projects-detail' project.pk %}{% else %}{% url 'projects-create' %}{% endif %}">Project
planning</a>
</li>
<li class="{% if financial_view %}active{% endif %}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr data-url="{% url 'view_project' project.id %}">
<tr data-url="{% url 'projects-detail' project.id %}">
<td class="cluster-col">
<div class="table-flex-holder">
<div class="input-check-holder">
Expand Down Expand Up @@ -99,7 +99,7 @@
<li>
<button>
<a href="#"
data-url="{% url 'delete_project' project.pk %}"
data-url="{% url 'projects-delete' project.pk %}"
data-type="delete"
data-verify="{{project.state}}"
data-name="project"
Expand Down
12 changes: 0 additions & 12 deletions src/rh/templates/rh/projects/views/archived_projects.html

This file was deleted.

12 changes: 0 additions & 12 deletions src/rh/templates/rh/projects/views/completed_projects.html

This file was deleted.

12 changes: 0 additions & 12 deletions src/rh/templates/rh/projects/views/draft_projects.html

This file was deleted.

10 changes: 5 additions & 5 deletions src/rh/templates/rh/projects/views/project_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<div class="holder">
<ul class="breadcrumbs">
<li>
<a href="{% url 'home' %}">Home</a>
<a href="{% url 'landing' %}">Home</a>
</li>
<li>
<a id="return-url" href="{% url parent_page %}">
<a id="return-url" href="{% url 'projects-list' %}?state={{project.state}}">
{% if project.state == 'in-progress' %}
Active Projects
{% elif project.state == 'draft' %}
Expand Down Expand Up @@ -42,7 +42,7 @@
{% endfor %}
</li>
</ul>
<a href="{% url 'update_project' project.pk %}" class="btn btn-red">Edit</a>
<a href="{% url 'projects-update' project.pk %}" class="btn btn-red">Edit</a>

</div>
<div class="bottom-block">
Expand Down Expand Up @@ -517,7 +517,7 @@
</a>
{% endif %}
<a href="#"
data-url="{% url 'delete_project' project.pk %}"
data-url="{% url 'projects-delete' project.pk %}"
data-type="delete"
data-name="project"
data-verify="{{project.state}}"
Expand Down Expand Up @@ -697,7 +697,7 @@
</div>
</div>

{% for activity_plan in activity_plans %}
{% for activity_plan in project.activityplan_set.all %}
<div class="activity-planning read-only">
<div class="activity-acc-block activity-acc-accordion">
<div class="inner-holder">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<tbody>
<!--Include The Active Projects Details Here -->
{% for project in projects %}
{% include "rh/projects/views/projects_details.html" %}
{% include "rh/projects/views/_projects_details.html" %}
{% endfor %}
</tbody>
{% endblock table_body %}
Expand Down
Loading

0 comments on commit 3704a55

Please sign in to comment.