Skip to content

Commit

Permalink
Start implementing logic mechanism for action
Browse files Browse the repository at this point in the history
several minor other actions to improve form and display
  • Loading branch information
Stéphane Diacquenod committed Feb 6, 2023
1 parent 5a322f9 commit 9bcea4b
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 63 deletions.
7 changes: 4 additions & 3 deletions conformity/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, *args, **kwargs):
self.fields['create_date'].disabled = True
self.fields['update_date'].disabled = True

# TODO: find a way to check the action status
if self.fields['status'] is Action.Status.CANCELED:
self.fields['title'].disabled = True
if self.get_initial_for_field(self.fields['status'], 'status') is Action.Status.CANCELED.value \
or self.get_initial_for_field(self.fields['status'], 'status') is Action.Status.ENDED.value:
for key, value in self.fields.items():
self.fields[key].disabled = True
18 changes: 18 additions & 0 deletions conformity/migrations/0021_alter_action_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2023-02-06 22:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('conformity', '0020_alter_action_status'),
]

operations = [
migrations.AlterField(
model_name='action',
name='status',
field=models.CharField(choices=[('1', 'Analysing'), ('2', 'Planning'), ('3', 'Implementing'), ('4', 'Controlling'), ('7', 'Frozen'), ('8', 'Closed'), ('9', 'Canceled')], default='1', max_length=5),
),
]
14 changes: 7 additions & 7 deletions conformity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ class Action(models.Model):

class Status(models.TextChoices):
""" List of possible Status for an action """
ANALYSING = 'A', _('Analysing')
PLANNING = 'P', _('Planning')
IMPLEMENTING = 'I', _('Implementing')
CONTROLLING = 'C', _('Controlling')
ENDED = 'E', _('Closed')
FROZEN = 'F', _('Frozen')
CANCELED = 'X', _('Canceled')
ANALYSING = '1', _('Analysing')
PLANNING = '2', _('Planning')
IMPLEMENTING = '3', _('Implementing')
CONTROLLING = '4', _('Controlling')
FROZEN = '7', _('Frozen')
ENDED = '8', _('Closed')
CANCELED = '9', _('Canceled')

' Analyse Phase'
title = models.CharField(max_length=256)
Expand Down
18 changes: 12 additions & 6 deletions conformity/templates/conformity/action_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,26 @@ <h1 class="h1 bi bi-arrow-repeat"> Actions </h1>
{{ action.owner | default_if_none:"" }}
</td>
<td class="col">
{% if action.status == "A" %}
{% if action.status == "1" %}
<i class="bi bi-hexagon-fill text-info"></i>
{% endif %}
{% if action.status == "P" %}
{% if action.status == "2" %}
<i class="bi bi-hexagon-fill text-primary"></i>
{% endif %}
{% if action.status == "I" %}
{% if action.status == "3" %}
<i class="bi bi-hexagon-fill text-warning"></i>
{% endif %}
{% if action.status == "C" %}
{% if action.status == "4" %}
<i class="bi bi-hexagon-fill text-success"></i>
{% endif %}
{% if action.status == "X" %}
<i class="bi bi-hexagon-fill text-dark"></i>
{% if action.status == "7" %}
<i class="bi bi-hexagon"></i>
{% endif %}
{% if action.status == "8" %}
<i class="bi bi-hexagon-fill"></i>
{% endif %}
{% if action.status == "9" %}
<i class="bi bi-hexagon-fill text-danger"></i>
{% endif %}
{{ action.get_status_display }}
</td>
Expand Down
9 changes: 9 additions & 0 deletions conformity/templates/conformity/conformity_orgpol_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h1 class="h1 bi bi-shield-shaded">
<div class="progress">
{% if not con.applicable %}
<div class="progress-bar progress-bar-striped bg-secondary" role="progressbar" style="width: 100%" aria-valuenow="Not applicable" aria-valuemin="0" aria-valuemax="100">Not applicable</div>
{% endif %}
{% if con.status is 100 %}
<div class="progress-bar bg-success" role="progressbar" style="width: {{ con.status }}%" aria-valuenow="{{ con.status }}" aria-valuemin="0" aria-valuemax="100">{{ con.status }}%</div>
{% else %}
<div class="progress-bar" role="progressbar" style="width: {{ con.status }}%" aria-valuenow="{{ con.status }}" aria-valuemin="0" aria-valuemax="100">{{ con.status }}%</div>
{% endif %}
Expand All @@ -52,6 +55,9 @@ <h1 class="h1 bi bi-shield-shaded">
<div class="progress">
{% if not con.applicable %}
<div class="progress-bar progress-bar-striped bg-secondary" role="progressbar" style="width: 100%" aria-valuenow="Not applicable" aria-valuemin="0" aria-valuemax="100">Not applicable</div>
{% endif %}
{% if con.status is 100 %}
<div class="progress-bar bg-success" role="progressbar" style="width: {{ con.status }}%" aria-valuenow="{{ con.status }}" aria-valuemin="0" aria-valuemax="100">{{ con.status }}%</div>
{% else %}
<div class="progress-bar" role="progressbar" style="width: {{ con.status }}%" aria-valuenow="{{ con.status }}" aria-valuemin="0" aria-valuemax="100">{{ con.status }}%</div>
{% endif %}
Expand Down Expand Up @@ -80,6 +86,9 @@ <h1 class="h1 bi bi-shield-shaded">
<div class="progress">
{% if not con.applicable %}
<div class="progress-bar progress-bar-striped bg-secondary" role="progressbar" style="width: 100%" aria-valuenow="Not applicable" aria-valuemin="0" aria-valuemax="100">Not applicable</div>
{% endif %}
{% if con.status is 100 %}
<div class="progress-bar bg-success" role="progressbar" style="width: {{ con.status }}%" aria-valuenow="{{ con.status }}" aria-valuemin="0" aria-valuemax="100">{{ con.status }}%</div>
{% else %}
<div class="progress-bar" role="progressbar" style="width: {{ con.status }}%" aria-valuenow="{{ con.status }}" aria-valuemin="0" aria-valuemax="100">{{ con.status }}%</div>
{% endif %}
Expand Down
77 changes: 51 additions & 26 deletions conformity/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ <h1 class="h2 bi bi-house-door"> Welcome {{request.user.first_name}} !</h1>

{% block content %}
<div class="row d-flex justify-content-evenly">
<div class="col-lg-4 my-3">
<div class="card shadow-sm">
<div class="col-lg-4">
<div class="card shadow-sm my-3">
<div class="card-header d-flex justify-content-between align-items-start bg-gradient">
<h5 class="my-0"><i class="bi bi-card-checklist"></i> Policy</h5>
<a class="btn btn-outline-info btn-sm"
Expand All @@ -20,10 +20,8 @@ <h5 class="my-0"><i class="bi bi-card-checklist"></i> Policy</h5>
{% endfor %}
</ul>
</div>
</div>

<div class="col-lg-4 my-3">
<div class="card shadow-sm">
<div class="card shadow-sm my-3">
<div class="card-header d-flex justify-content-between align-items-start bg-gradient">
<h5 class="my-0"><i class="bi bi-building"></i> Organization</h5>
<a class="btn btn-outline-info btn-sm"
Expand All @@ -36,51 +34,78 @@ <h5 class="my-0"><i class="bi bi-building"></i> Organization</h5>
{% endfor %}
</ul>
</div>
</div>

<div class="col-lg-4 my-3">
<div class="card shadow-sm">
<div class="card shadow-sm my-3">
<div class="card-header d-flex justify-content-between align-items-start bg-gradient">
<h5 class="my-0"><i class="bi bi-shield-shaded"></i> Conformity</h5>
<h5 class="my-0"><i class="bi bi-ui-checks-grid"></i> Audit</h5>
<a class="btn btn-outline-info btn-sm"
href="{%url 'conformity:conformity_index'%}">{{conformity_list|length}} conformities</a>
href="{%url 'conformity:audit_index'%}" >{{audit_list|length}} audits</a>
</div>
<ul class="list-group list-group-flush">
{% for conformity in conformity_list %}
{% for audit in audit_list %}
<a class="list-group-item list-group-item-action"
href="{%url 'conformity:conformity_orgpol_index' conformity.organization.id conformity.measure.policy.id %}"> {{conformity}}</a>
href="{%url 'conformity:audit_detail' audit.id %}"> {{audit}}</a>
{% endfor %}
</ul>
</div>
</div>

<div class="col-lg-4 my-3">
<div class="card shadow-sm">
<div class="col-lg-8">
<div class="card shadow-sm my-3">
<div class="card-header d-flex justify-content-between align-items-start bg-gradient">
<h5 class="my-0"><i class="bi bi-ui-checks-grid"></i> Audit</h5>
<h5 class="my-0"><i class="bi bi-shield-shaded"></i> My Conformities</h5>
<a class="btn btn-outline-info btn-sm"
href="{%url 'conformity:audit_index'%}" >{{audit_list|length}} audits</a>
href="{%url 'conformity:action_index'%}" >{{my_conformity|length}} actions</a>
</div>
<ul class="list-group list-group-flush">
{% for audit in audit_list %}
<a class="list-group-item list-group-item-action"
href="{%url 'conformity:audit_detail' audit.id %}"> {{audit}}</a>
{% for conformity in my_conformity %}
<a class="list-group-item list-group-item-action position-relative" href="{% url 'conformity:conformity_form' conformity.id %}">
{{conformity}}
{% if conformity.status is 100 %}
<span class="badge rounded-pill text-bg-success position-absolute top-50 end-0 translate-middle-y me-3 col-1">
{% else %}
<span class="badge rounded-pill text-bg-warning position-absolute top-50 end-0 translate-middle-y me-3 col-1">
{% endif %}
{{conformity.status}} %
</span>
</a>
{% endfor %}
</ul>
</div>
</div>

<div class="col-lg-8 my-3">
<div class="card shadow-sm">
<div class="card-header d-flex justify-content-between align-items-start bg-gradient">
<h5 class="my-0"><i class="bi bi-arrow-repeat"></i> Actions</h5>
<div class="card shadow-sm my-3">
<div class="card-header d-flex justify-content-between align-items-start bg-gradient">
<h5 class="my-0"><i class="bi bi-arrow-repeat"></i> My Actions</h5>
<a class="btn btn-outline-info btn-sm"
href="{%url 'conformity:action_index'%}" >{{action_list|length}} actions</a>
href="{%url 'conformity:action_index'%}" >{{my_action|length}} actions</a>
</div>
<ul class="list-group list-group-flush">
{% for action in action_list %}
{% for action in my_action %}
<a class="list-group-item list-group-item-action" href="{% url 'conformity:action_form' action.id %}">
{{action}}
{% if action.status == "1" %}
<span class="badge rounded-pill text-bg-info position-absolute top-50 end-0 translate-middle-y me-3 col-2">
{% endif %}
{% if action.status == "2" %}
<span class="badge rounded-pill text-bg-primary position-absolute top-50 end-0 translate-middle-y me-3 col-2">
{% endif %}
{% if action.status == "3" %}
<span class="badge rounded-pill text-bg-warning position-absolute top-50 end-0 translate-middle-y me-3 col-2">
{% endif %}
{% if action.status == "4" %}
<span class="badge rounded-pill text-bg-success position-absolute top-50 end-0 translate-middle-y me-3 col-2">
{% endif %}
{% if action.status == "7" %}
<span class="badge rounded-pill border text-bg-light position-absolute top-50 end-0 translate-middle-y me-3 col-2">
{% endif %}
{% if action.status == "8" %}
<span class="badge rounded-pill text-bg-dark position-absolute top-50 end-0 translate-middle-y me-3 col-2">
{% endif %}
{% if action.status == "9" %}
<span class="badge rounded-pill text-bg-danger position-absolute top-50 end-0 translate-middle-y me-3 col-2">
{% endif %}
{{action.get_status_display}}
</span>
</a>
{% endfor %}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion conformity/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

app_name = 'conformity'
urlpatterns = [
path('', views.home, name='home'),
path('', views.HomeView.as_view(), name='home'),

path('audit/', views.AuditIndexView.as_view(), name='audit_index'),
path('audit/<int:pk>', views.AuditDetailView.as_view(), name='audit_detail'),
Expand Down
49 changes: 29 additions & 20 deletions conformity/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
View of the Conformity Module
"""
from django.views.generic import DetailView, ListView
from django.views.generic import DetailView, ListView, TemplateView
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
Expand All @@ -11,32 +11,40 @@
#
# Home
#
@login_required
def home(request):
"""View function for home page"""
organization_list = Organization.objects.all()
policy_list = Policy.objects.all()
conformity_list = Conformity.objects.filter(measure__level=0)
audit_list = Audit.objects.all()
action_list = Action.objects.all()

context = {
'organization_list': organization_list,
'policy_list': policy_list,
'conformity_list': conformity_list,
'audit_list': audit_list,
'action_list': action_list,
}

return render(request, 'home.html', context=context)
class HomeView(LoginRequiredMixin, TemplateView):
template_name = "home.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
user = self.request.user
organization_list = Organization.objects.all()
policy_list = Policy.objects.all()
conformity_list = Conformity.objects.filter(measure__level=0)
audit_list = Audit.objects.all()
action_list = Action.objects.all()
my_action = Action.objects.filter(owner=user).order_by('status')[:50]
my_conformity = Conformity.objects.filter(responsible=user).order_by('status')[:50]

context = {
'user': user,
'organization_list': organization_list,
'policy_list': policy_list,
'conformity_list': conformity_list,
'audit_list': audit_list,
'action_list': action_list,
'my_action': my_action,
'my_conformity': my_conformity,
}

return context


#
# Audit
#
class AuditIndexView(LoginRequiredMixin, ListView):
model = Audit
ordering = ['start_date']
ordering = ['-start_date']


class AuditDetailView(LoginRequiredMixin, DetailView):
Expand Down Expand Up @@ -154,6 +162,7 @@ class ActionCreateView(LoginRequiredMixin, CreateView):

class ActionIndexView(LoginRequiredMixin, ListView):
model = Action
ordering = ['status','-update_date']


class ActionUpdateView(LoginRequiredMixin, UpdateView):
Expand Down

0 comments on commit 9bcea4b

Please sign in to comment.