Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/kartoza/prj.app into 137…
Browse files Browse the repository at this point in the history
…1_certification_type
  • Loading branch information
sumandari committed Feb 12, 2022
2 parents 6560b4c + b2895c7 commit 4398bef
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 31 deletions.
5 changes: 4 additions & 1 deletion django_project/certification/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class Meta:
'user',
'degree',
'signature',
'is_active',
)

def __init__(self, *args, **kwargs):
Expand All @@ -172,6 +173,7 @@ def __init__(self, *args, **kwargs):
Field('user', css_class='form-control chosen-select'),
Field('degree', css_class='form-control'),
Field('signature', css_class='form-control'),
Field('is_active', css_class='checkbox-primary'),
)
)
self.helper.layout = layout
Expand Down Expand Up @@ -332,7 +334,8 @@ def __init__(self, *args, **kwargs):
super(CourseForm, self).__init__(*args, **kwargs)
self.fields['course_convener'].queryset = \
CourseConvener.objects.filter(
certifying_organisation=self.certifying_organisation)
certifying_organisation=self.certifying_organisation,
is_active=True)
self.fields['course_convener'].label_from_instance = \
lambda obj: "%s <%s>" % (obj.user.get_full_name(), obj)
self.fields['course_type'].queryset = \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.18 on 2021-11-26 04:51

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('certification', '0006_auto_20210730_0615'),
]

operations = [
migrations.AddField(
model_name='courseconvener',
name='is_active',
field=models.BooleanField(default=True, help_text='Inactive Convener will not be available in your organisation list.'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.18 on 2022-02-12 02:17

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('certification', '0007_courseconvener_is_active'),
('certification', '0009_course_certificate_type'),
]

operations = [
]
6 changes: 6 additions & 0 deletions django_project/certification/models/course_convener.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class CourseConvener(models.Model):
null=True
)

is_active = models.BooleanField(
help_text=_('Inactive Convener will not be available in your '
'organisation list.'),
default=True
)

class Meta:
ordering = ['user']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ <h1>Certifying Organisation (all)</h1>
color: darkblue !important;
text-decoration: none !important;
}
.btn-disabled, .btn-disabled:hover {
color: #d3d3d3
}
</style>

{% if messages %}
Expand Down Expand Up @@ -536,34 +539,7 @@ <h5>No course convener are defined, but you can <a
</td></tr>

{% for courseconvener in courseconveners %}
<tr style="border-bottom: 1px solid #e9e9e9;">
<td class="list">
<div class="col-lg-10">
{% if courseconvener.user.first_name %}
{{ courseconvener.user.first_name }} {{ courseconvener.user.last_name }}
{% else %}
{{ courseconvener.user }}
{% endif %}
</div>
</td>

{% if user_can_delete %}
<td>
<div class="btn-group pull-right button-action">
<a class="btn btn-default btn-xs btn-delete tooltip-toggle"
href='{% url "courseconvener-delete" project_slug=certifyingorganisation.project.slug organisation_slug=certifyingorganisation.slug slug=courseconvener.slug %}'
data-title="Delete {{ courseconvener.user.first_name }} {{ courseconvener.user.last_name }} <{{ courseconvener.user }}>">
<span class="glyphicon glyphicon-minus"></span>
</a>
<a class="btn btn-default btn-xs tooltip-toggle"
href='{% url "courseconvener-update" project_slug=certifyingorganisation.project.slug organisation_slug=certifyingorganisation.slug slug=courseconvener.slug %}'
data-title="Edit {{ courseconvener.user.first_name }} {{ courseconvener.user.last_name }} <{{ courseconvener.user }}>">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</div>
</td>
{% endif %}
</tr>
{% include 'certifying_organisation/includes/convenor_list.html' %}
{% endfor %}
</table>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<tr style="border-bottom: 1px solid #e9e9e9;">
<td class="list">
<div class="col-lg-10">
{% if courseconvener.is_active %}
{% if courseconvener.user.first_name %}
{{ courseconvener.user.first_name }} {{ courseconvener.user.last_name }}
{% else %}
{{ courseconvener.user }}
{% endif %}
{% elif user_can_delete %}
<span style="font-style: italic; font-size: 0.8em; color: #777">
{% if courseconvener.user.first_name %}
{{ courseconvener.user.first_name }} {{ courseconvener.user.last_name }}
{% else %}
{{ courseconvener.user }}
{% endif %}
</span>
<span style="font-size: 0.7em; color: #777"> [inactive]</span>
{% endif %}
</div>
</td>
{% if user_can_delete %}
<td>
<div class="btn-group pull-right button-action">
{% if courseconvener.course_set.exists %}
<a class="btn btn-default btn-xs btn-disabled tooltip-toggle"
{% if courseconvener.is_active %}
data-title="Cannot delete this Convener. Please deactivate the Convener in Edit menu."
{% else %}
data-title="Cannot delete this Convener. You can reactivate the Convener in Edit menu."
{% endif %}
>
<span class="glyphicon glyphicon-minus"></span>
</a>
{% else %}
<a class="btn btn-default btn-xs btn-delete tooltip-toggle"
href='{% url "courseconvener-delete" project_slug=certifyingorganisation.project.slug organisation_slug=certifyingorganisation.slug slug=courseconvener.slug %}'
data-title="Delete {{ courseconvener.user.first_name }} {{ courseconvener.user.last_name }} <{{ courseconvener.user }}>">
<span class="glyphicon glyphicon-minus"></span>
</a>
{% endif %}
<a class="btn btn-default btn-xs tooltip-toggle"
href='{% url "courseconvener-update" project_slug=certifyingorganisation.project.slug organisation_slug=certifyingorganisation.slug slug=courseconvener.slug %}'
data-title="Edit {{ courseconvener.user.first_name }} {{ courseconvener.user.last_name }} <{{ courseconvener.user }}>">
<span class="glyphicon glyphicon-pencil"></span>
</a>
</div>
</td>
{% endif %}
</tr>
1 change: 1 addition & 0 deletions django_project/certification/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def test_Course_Convener_create(self):
self.assertEqual(model.__dict__.get(key), val)
self.assertTrue(model.title == 'new Course Convener Title')
self.assertTrue(model.degree == 'new Course Convener Degree')
self.assertTrue(model.is_active)

# check if PK exists.
self.assertTrue(model.pk is not None)
Expand Down
108 changes: 107 additions & 1 deletion django_project/certification/tests/views/test_course_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
CertifyingOrganisationF,
CertificateTypeF,
ProjectCertificateTypeF,
CourseF
CourseF,
CourseConvenerF
)


Expand Down Expand Up @@ -189,3 +190,108 @@ def test_delete_with_duplicates(self):
'slug': self.certifying_organisation.slug,
})
self.assertRedirects(response, expected_url)

@override_settings(VALID_DOMAIN=['testserver', ])
def test_inactive_convener_should_not_be_in_the_course_convener_list(self):
convener = UserF.create(**{
'username': 'convener',
'password': 'password',
'first_name': 'Pretty',
'last_name': 'Smart',
'is_staff': True
})
convener_inactive = UserF.create(**{
'username': 'inactive_convener',
'password': 'password',
'first_name': 'Wonder',
'last_name': 'Woman',
'is_staff': True
})
CourseConvenerF.create(
user=convener,
certifying_organisation=self.certifying_organisation
)
CourseConvenerF.create(
user=convener_inactive,
certifying_organisation=self.certifying_organisation,
is_active=False
)
self.client.login(username='anita', password='password')
response = self.client.get(reverse('course-create', kwargs={
'project_slug': self.project.slug,
'organisation_slug': self.certifying_organisation.slug,
}))
self.assertContains(response, 'Pretty Smart')
self.assertNotContains(response, 'Wonder Woman')
self.assertNotContains(response, 'inactive_convener')

@override_settings(VALID_DOMAIN=['testserver', ])
def test_inactive_convener_should_not_be_in_normal_user_detail_page(self):
convener = UserF.create(**{
'username': 'convener',
'password': 'password',
'first_name': 'Pretty',
'last_name': 'Smart',
'is_staff': True
})
convener_inactive = UserF.create(**{
'username': 'inactive_convener',
'password': 'password',
'first_name': 'Wonder',
'last_name': 'Woman',
'is_staff': True
})
CourseConvenerF.create(
user=convener,
certifying_organisation=self.certifying_organisation
)
CourseConvenerF.create(
user=convener_inactive,
certifying_organisation=self.certifying_organisation,
is_active=False
)
response = self.client.get(
reverse('certifyingorganisation-detail', kwargs={
'project_slug': self.project.slug,
'slug': self.certifying_organisation.slug,
})
)
self.assertContains(response, 'Pretty Smart')
self.assertNotContains(response, 'Wonder Woman')
self.assertNotContains(response, '[inactive]')

@override_settings(VALID_DOMAIN=['testserver', ])
def test_inactive_convener_should_be_in_normal_user_detail_page(self):
convener = UserF.create(**{
'username': 'convener',
'password': 'password',
'first_name': 'Pretty',
'last_name': 'Smart',
'is_staff': True
})
convener_inactive = UserF.create(**{
'username': 'inactive_convener',
'password': 'password',
'first_name': 'Wonder',
'last_name': 'Woman',
'is_staff': True
})
CourseConvenerF.create(
user=convener,
certifying_organisation=self.certifying_organisation
)
CourseConvenerF.create(
user=convener_inactive,
certifying_organisation=self.certifying_organisation,
is_active=False
)
self.client.login(username='anita', password='password')
response = self.client.get(
reverse('certifyingorganisation-detail', kwargs={
'project_slug': self.project.slug,
'slug': self.certifying_organisation.slug,
})
)
self.assertContains(response, 'Pretty Smart')
self.assertContains(response, 'Wonder Woman')
self.assertContains(response, '[inactive]')
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def get_context_data(self, **kwargs):
certifying_organisation=certifying_organisation)
context['num_coursetype'] = context['coursetypes'].count()
context['courseconveners'] = CourseConvener.objects.filter(
certifying_organisation=certifying_organisation)
certifying_organisation=certifying_organisation
).prefetch_related('course_set')
context['num_courseconvener'] = context['courseconveners'].count()
context['courses'] = Course.objects.filter(
certifying_organisation=certifying_organisation).order_by(
Expand Down

0 comments on commit 4398bef

Please sign in to comment.