Skip to content

Commit

Permalink
Feat/publish and unpublish a questionnaire
Browse files Browse the repository at this point in the history
  • Loading branch information
kevlanyo committed Aug 1, 2024
1 parent 9e2c6c3 commit 7f32ab0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
8 changes: 4 additions & 4 deletions survey/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from docutils.nodes import status
from rest_framework import status
from rest_framework import generics
import pandas as pd
#import pandas as pd
from tablib import Dataset
from rest_framework.response import Response as Res
from rest_framework.renderers import JSONRenderer, TemplateHTMLRenderer
Expand Down Expand Up @@ -1037,9 +1037,8 @@ def new_questionnaire(request):
elif user.access_level.id == 4:
raise PermissionDenied


@login_required
def publish_questionnaire(request, q_id):
def publish_questionnaire(request, q_id,q_action):
user = request.user
u = user
error_msg = ''
Expand All @@ -1054,7 +1053,7 @@ def publish_questionnaire(request, q_id):
# return error
return HttpResponse("error")
else:
create_quest.is_published = True
create_quest.is_published = True if q_action == 'Publish' else False
create_quest.save()

# # create the responses flat table
Expand Down Expand Up @@ -1084,6 +1083,7 @@ def publish_questionnaire(request, q_id):
'q': question,
'fac_sel': s,
'error_msg': error_msg,
'q_action': q_action,
}
return render(request, 'survey/publish_questionnaire.html', context)

Expand Down
33 changes: 21 additions & 12 deletions templates/survey/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ <h5 class="card-title text-uppercase text-muted mb-0">Number of Facilities Not S
</div>
</div>
</div>

<!-- Page content -->
<div class="container-fluid mt--6">
<div class="row">
Expand All @@ -168,19 +169,27 @@ <h5 class="card-title text-uppercase text-muted mb-0">Number of Facilities Not S
</div>
</div>
</div>



<!-- <div class="col-xl-2 col-2">
<label class="form-control-label" for="activedd">Survey Status</label>
<div>
<select class="form-control" name="activedd" id="activedd" onchange="facChange()" required>
<option value="" selected>Select One</option>
<option value="active">Active</option>
<option value="inactive">Inactive</option>
</select>

</div>
</div>
</div>
</div>
</div>

<div class="row">
<div class="col-xl-3 col-md-6">
<div class="card card-stats">
<div class="card-body">
<div class="row">
<div class="col">
<h5 class="card-title text-uppercase text-muted mb-0">Number of Facilities Not Started Questionnaires</h5>
<span id="notstart" class="h2 font-weight-bold mb-0"></span>
</div>
<div class="col-auto">
<div class="icon icon-shape bg-gradient-info text-white rounded-circle shadow">
<i class="ni ni-button-pause"></i>
</div>
</div> -->
</div>
</div>
</div>
</div>
Expand Down
16 changes: 9 additions & 7 deletions templates/survey/publish_questionnaire.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
{% endblock %}
{% block breadcrumb %}

<h6 class="h4 text-white d-inline-block mb-0">Publish questionnaire</h6>
<h6 class="h4 text-white d-inline-block mb-0">{{ q_action }} questionnaire</h6>

<nav aria-label="breadcrumb" class="d-none d-md-inline-block ml-md-4">
<ol class="breadcrumb breadcrumb-links breadcrumb-dark">
<li class="breadcrumb-item"><a href="{% url 'dashboard' %}"><i class="fas fa-home"></i></a></li>
<li class="breadcrumb-item"><a href="{% url 'questionnaires' %}"><small>Questionnaires</small></a></li>
<li class="breadcrumb-item"><a href="{% url 'new-questionnaires' %}"><small>Publish questionnaire</small></a>
<li class="breadcrumb-item">
<a href="{% url 'new-questionnaires' %}"><small>{{ q_action }} questionnaire</small></a>
</li>
<li class="breadcrumb-item active" aria-current="page"><small>Publish questionnaire</small></li>
<li class="breadcrumb-item active" aria-current="page"><small>{{ q_action }} questionnaire</small></li>
</ol>
</nav>
{% endblock %}
Expand All @@ -35,7 +37,7 @@ <h6 class="h4 text-white d-inline-block mb-0">Publish questionnaire</h6>
<div class="card">
<!-- Card header -->
<div class="card-header border-0">
<h3 class="mb-0">Publish Questionnaire</h3>
<h3 class="mb-0">{{ q_action }} Questionnaire</h3>

{% if error_msg %}
<ul class="messages">
Expand All @@ -47,7 +49,7 @@ <h3 class="mb-0">Publish Questionnaire</h3>
</div>
<div class="card-body">
<form class="form-group" id="questForm" method="post"
action="{% url 'publish-questionnaires' q_id=q.id %}">
action="{% url 'publish-questionnaires' q_id=q.id q_action=q_action %}">
{% csrf_token %}
<h6 class="heading-small text-muted mb-4">Questionnaire Information</h6>
<div class="pl-lg-4">
Expand Down Expand Up @@ -120,7 +122,7 @@ <h6 class="heading-small text-muted mb-4">Questionnaire Information</h6>
</div>
</div>
<hr class="my-4"/>
<button type="submit" class="btn btn-success">Publish</button>
<button type="submit" class="btn btn-success">{{ q_action }}</button>
<a href="{% url 'questionnaires' %}" type="menu" class="btn btn-danger">Cancel</a>


Expand Down Expand Up @@ -184,7 +186,7 @@ <h6 class="heading-small text-muted mb-4">Questionnaire Information</h6>
text: 'Questionnaire Details Saved',
icon: 'success'
});
location.reload();
window.location.replace("{% url 'questionnaires' %}");
}
},
error: function (er) {
Expand Down
16 changes: 8 additions & 8 deletions templates/survey/questionnaires.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ <h3>Questionnaire Description</h3>
Manage external data</a>
<a class="dropdown-item" href="{% url 'q_response_report' q_id=foo.id %}">
Questionnaire Response Summary</a>
{% if not foo.is_published %}
<a class="dropdown-item" href="{% url 'publish-questionnaires' q_id=foo.id q_action='Publish' %}">
Publish Questionnaire</a>
{% else %}
<a class="dropdown-item" href="{% url 'publish-questionnaires' q_id=foo.id q_action='Unpublish' %}">
Unpublish Questionnaire</a>
{% endif %}
{% else %}
<a class="dropdown-item disabled"
href="{% url 'edit-questionnaires' q_id=foo.id %}">Edit
Expand All @@ -321,14 +328,7 @@ <h3>Questionnaire Description</h3>
Manage external data</a>
<a class="dropdown-item" href="{% url 'q_response_report' q_id=foo.id %}">
Questionnaire Response Summary</a>
{% endif %}

{% if not foo.is_published %}
{% if u.access_level.id == 2 or u.access_level.id == 3 %}
<a class="dropdown-item" href="{% url 'publish-questionnaires' q_id=foo.id %}">
Publish Questionnaire</a>
{% endif %}
{% endif %}
{% endif %}

</div>
</div>
Expand Down

0 comments on commit 7f32ab0

Please sign in to comment.