Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACT-688 Renamed beneficiary model to Individual #330

Merged
merged 11 commits into from
Apr 9, 2020
2 changes: 1 addition & 1 deletion activity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def admin_configurations(request):
'form_label': data.get('form_label'),
'stakeholder_label': data.get('stakeholder_label'),
'date_format': data.get('date_format'),
'beneficiary_label': data.get('beneficiary_label'),
'individual_label': data.get('individual_label'),
'training_label': data.get('training_label'),
'distribution_label': data.get('distribution_label'),
# 'default_currency': data.get('default_currency')
Expand Down
242 changes: 121 additions & 121 deletions assets/rrima.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions customdashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from workflow.models import ProjectAgreement, ProjectComplete, Program, \
SiteProfile, Country, ActivitySites
from .models import ProgramNarratives, JupyterNotebooks
from formlibrary.models import TrainingAttendance, Distribution, Beneficiary
from formlibrary.models import TrainingAttendance, Distribution, Individual
from indicators.models import CollectedData, Indicator, ActivityTable

from django.db.models import Sum
Expand Down Expand Up @@ -315,7 +315,7 @@ def public_dashboard(request, id=0, public=0):
for t in get_trainings:
training_id_list.append(t.id)

get_beneficiaries = Beneficiary.objects.all().filter(
get_individuals = Individual.objects.all().filter(
training__in=training_id_list)

get_project_completed = []
Expand Down Expand Up @@ -356,7 +356,7 @@ def public_dashboard(request, id=0, public=0):
'get_locations': get_locations,
'get_site_profile_indicator': get_site_profile_indicator,
'get_site_profile_indicator_count': get_site_profile_indicator.count(),
'get_beneficiaries': get_beneficiaries,
'get_individuals': get_individuals,
'get_distributions': get_distributions, 'get_trainings': get_trainings,
'get_project_completed': get_project_completed,
'get_all_projects': get_all_projects,
Expand Down
2 changes: 1 addition & 1 deletion fixtures/formguidance.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"model": "workflow.formguidance", "pk": 2, "fields": {"form": "Agreement", "guidance_link": "https://drive.google.com/open?id=111BzD3uHlJpaj4MSk7l8XApvrpu69QgimWPnfXbBUT4", "guidance": "", "create_date": "2016-05-22T09:07:13Z"}}, {"model": "workflow.formguidance", "pk": 3, "fields": {"form": "Complete", "guidance_link": "https://docs.google.com/document/d/1tDwo3m1ychefNiAMr-8hCZnhEugQlt36AOyUYHlPbVo/edit?usp=sharing", "guidance": "", "create_date": "2016-05-22T09:48:38.546Z"}}, {"model": "workflow.formguidance", "pk": 4, "fields": {"form": "SiteProfile", "guidance_link": "https://drive.google.com/open?id=18nGr_uk1VSzitwjkstxvjGWxtINzlITUgBGFP_s-b9o", "guidance": "", "create_date": "2016-05-22T09:51:00.534Z"}}, {"model": "workflow.formguidance", "pk": 5, "fields": {"form": "Beneficiary", "guidance_link": "", "guidance": "The Beneficiary form has no guidance at this time.", "create_date": "2016-05-22T09:58:02Z"}}, {"model": "workflow.formguidance", "pk": 6, "fields": {"form": "Training", "guidance_link": "", "guidance": "The Training form has no guidance at this time.", "create_date": "2016-05-22T09:58:13Z"}}, {"model": "workflow.formguidance", "pk": 7, "fields": {"form": "ChecklistItem", "guidance_link": "", "guidance": "The Checklist form has no guidance at this time.", "create_date": "2016-05-22T09:58:28Z"}}, {"model": "workflow.formguidance", "pk": 8, "fields": {"form": "Stakeholder", "guidance_link": "", "guidance": "The Stakeholder form has no guidance at this time.", "create_date": "2016-05-22T09:58:55Z"}}, {"model": "workflow.formguidance", "pk": 9, "fields": {"form": "Contact", "guidance_link": "", "guidance": "The Contact form has no guidance at this time.", "create_date": "2016-05-22T09:59:02Z"}}, {"model": "workflow.formguidance", "pk": 10, "fields": {"form": "Documentation", "guidance_link": "", "guidance": "The Documentation form has no guidance at this time.", "create_date": "2016-05-22T09:59:21Z"}}, {"model": "workflow.formguidance", "pk": 11, "fields": {"form": "Indicator", "guidance_link": "https://docs.google.com/document/d/18QN7U6-b3AXmjL9fcHfFaxo1yisxuvpefGmsJTslJY4/", "guidance": "", "create_date": "2016-05-22T09:59:31Z"}}, {"model": "workflow.formguidance", "pk": 12, "fields": {"form": "CollectedData", "guidance_link": "https://docs.google.com/document/d/1sTBwo-oueQeH9NTGDXpbYZdlBTpRXBBK14IZUS0wN08/", "guidance": "", "create_date": "2016-05-22T09:59:41Z"}}]
[{"model": "workflow.formguidance", "pk": 2, "fields": {"form": "Agreement", "guidance_link": "https://drive.google.com/open?id=111BzD3uHlJpaj4MSk7l8XApvrpu69QgimWPnfXbBUT4", "guidance": "", "create_date": "2016-05-22T09:07:13Z"}}, {"model": "workflow.formguidance", "pk": 3, "fields": {"form": "Complete", "guidance_link": "https://docs.google.com/document/d/1tDwo3m1ychefNiAMr-8hCZnhEugQlt36AOyUYHlPbVo/edit?usp=sharing", "guidance": "", "create_date": "2016-05-22T09:48:38.546Z"}}, {"model": "workflow.formguidance", "pk": 4, "fields": {"form": "SiteProfile", "guidance_link": "https://drive.google.com/open?id=18nGr_uk1VSzitwjkstxvjGWxtINzlITUgBGFP_s-b9o", "guidance": "", "create_date": "2016-05-22T09:51:00.534Z"}}, {"model": "workflow.formguidance", "pk": 5, "fields": {"form": "Individual", "guidance_link": "", "guidance": "The Individual form has no guidance at this time.", "create_date": "2016-05-22T09:58:02Z"}}, {"model": "workflow.formguidance", "pk": 6, "fields": {"form": "Training", "guidance_link": "", "guidance": "The Training form has no guidance at this time.", "create_date": "2016-05-22T09:58:13Z"}}, {"model": "workflow.formguidance", "pk": 7, "fields": {"form": "ChecklistItem", "guidance_link": "", "guidance": "The Checklist form has no guidance at this time.", "create_date": "2016-05-22T09:58:28Z"}}, {"model": "workflow.formguidance", "pk": 8, "fields": {"form": "Stakeholder", "guidance_link": "", "guidance": "The Stakeholder form has no guidance at this time.", "create_date": "2016-05-22T09:58:55Z"}}, {"model": "workflow.formguidance", "pk": 9, "fields": {"form": "Contact", "guidance_link": "", "guidance": "The Contact form has no guidance at this time.", "create_date": "2016-05-22T09:59:02Z"}}, {"model": "workflow.formguidance", "pk": 10, "fields": {"form": "Documentation", "guidance_link": "", "guidance": "The Documentation form has no guidance at this time.", "create_date": "2016-05-22T09:59:21Z"}}, {"model": "workflow.formguidance", "pk": 11, "fields": {"form": "Indicator", "guidance_link": "https://docs.google.com/document/d/18QN7U6-b3AXmjL9fcHfFaxo1yisxuvpefGmsJTslJY4/", "guidance": "", "create_date": "2016-05-22T09:59:31Z"}}, {"model": "workflow.formguidance", "pk": 12, "fields": {"form": "CollectedData", "guidance_link": "https://docs.google.com/document/d/1sTBwo-oueQeH9NTGDXpbYZdlBTpRXBBK14IZUS0wN08/", "guidance": "", "create_date": "2016-05-22T09:59:41Z"}}]
12 changes: 6 additions & 6 deletions formlibrary/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from django.contrib import admin

from .models import (
TrainingAttendance, Distribution, Beneficiary
TrainingAttendance, Distribution, Individual
)


@admin.register(Beneficiary)
class BeneficiaryAdmin(admin.ModelAdmin):
list_display = ('site', 'beneficiary_name',)
display = 'Beneficiary'
list_filter = ('site', 'beneficiary_name')
@admin.register(Individual)
class IndividualAdmin(admin.ModelAdmin):
list_display = ('site', 'first_name',)
display = 'Individual'
list_filter = ('site', 'first_name')


@admin.register(Distribution)
Expand Down
6 changes: 3 additions & 3 deletions formlibrary/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from import_export import resources
from .models import TrainingAttendance, Distribution, Beneficiary
from .models import TrainingAttendance, Distribution, Individual


class TrainingAttendanceResource(resources.ModelResource):
Expand All @@ -17,7 +17,7 @@ class Meta:
model = Distribution


class BeneficiaryResource(resources.ModelResource):
class IndividualResource(resources.ModelResource):

class Meta:
model = Beneficiary
model = Individual
18 changes: 9 additions & 9 deletions formlibrary/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from crispy_forms.helper import FormHelper
from django import forms
from .models import TrainingAttendance, Distribution, Beneficiary
from .models import TrainingAttendance, Distribution, Individual
from workflow.models import Program, ProjectAgreement, Office, Province, SiteProfile
from functools import partial

Expand Down Expand Up @@ -42,8 +42,8 @@ def __init__(self, *args, **kwargs):
self.fields['program'].queryset = Program.objects.filter(
organization=self.request.user.activity_user.organization)

self.fields['training_name'].label = '{} name'.format(self.organization.training_label)
self.fields['training_duration'].label = '{} duration'.format(self.organization.training_label)
self.fields['training_name'].label = '{} name'.format(self.organization.training_label)
self.fields['training_duration'].label = '{} duration'.format(self.organization.training_label)


class DistributionForm(forms.ModelForm):
Expand Down Expand Up @@ -80,12 +80,12 @@ def __init__(self, *args, **kwargs):
self.fields['distribution_implementer'].label = '{} implementer'.format(self.organization.distribution_label)
self.fields['distribution_location'].label = '{} location'.format(self.organization.distribution_label)
self.fields['distribution_indicator'].label = '{} indicator'.format(self.organization.distribution_label)


class BeneficiaryForm(forms.ModelForm):

class IndividualForm(forms.ModelForm):

class Meta:
model = Beneficiary
model = Individual
exclude = ['create_date', 'edit_date']

def __init__(self, *args, **kwargs):
Expand All @@ -97,7 +97,7 @@ def __init__(self, *args, **kwargs):
self.helper.help_text_inline = True
self.helper.html5_required = True

super(BeneficiaryForm, self).__init__(*args, **kwargs)
super(IndividualForm, self).__init__(*args, **kwargs)

organization = self.request.user.activity_user.organization
self.fields['training'].queryset = TrainingAttendance.objects.filter(
Expand All @@ -108,5 +108,5 @@ def __init__(self, *args, **kwargs):
program__organization=organization)
self.fields['site'].queryset = SiteProfile.objects.filter(
organizations__id__contains=self.request.user.activity_user.organization.id)
self.fields['beneficiary_name'].label = '{} name'.format(self.organization.beneficiary_label)

self.fields['first_name'].label = '{} name'.format(self.organization.individual_label)
60 changes: 60 additions & 0 deletions formlibrary/migrations/0003_auto_20200409_0727.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 2.2.10 on 2020-04-09 14:27

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('workflow', '0020_auto_20200409_0727'),
('formlibrary', '0002_auto_20200215_0114'),
]

operations = [
migrations.CreateModel(
name='Individual',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(blank=True, max_length=255, null=True)),
('father_name', models.CharField(blank=True, max_length=255, null=True)),
('age', models.IntegerField(blank=True, null=True)),
('gender', models.CharField(blank=True, max_length=255, null=True)),
('signature', models.BooleanField(default=True)),
('remarks', models.TextField(blank=True, max_length=550, null=True)),
('create_date', models.DateTimeField(blank=True, null=True)),
('edit_date', models.DateTimeField(blank=True, null=True)),
],
options={
'ordering': ('first_name',),
},
),
migrations.RenameField(
model_name='distribution',
old_name='total_beneficiaries_received_input',
new_name='total_individuals_received_input',
),
migrations.DeleteModel(
name='Beneficiary',
),
migrations.AddField(
model_name='individual',
name='distribution',
field=models.ManyToManyField(blank=True, to='formlibrary.Distribution'),
),
migrations.AddField(
model_name='individual',
name='program',
field=models.ManyToManyField(blank=True, to='workflow.Program'),
),
migrations.AddField(
model_name='individual',
name='site',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='workflow.SiteProfile'),
),
migrations.AddField(
model_name='individual',
name='training',
field=models.ManyToManyField(blank=True, to='formlibrary.TrainingAttendance'),
),
]
14 changes: 7 additions & 7 deletions formlibrary/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Distribution(models.Model):
reporting_period = models.CharField(max_length=255, null=True, blank=True)
province = models.ForeignKey(
Province, null=True, blank=True, on_delete=models.SET_NULL)
total_beneficiaries_received_input = models.IntegerField(
total_individuals_received_input = models.IntegerField(
null=True, blank=True)
distribution_location = models.CharField(
max_length=255, null=True, blank=True)
Expand Down Expand Up @@ -126,8 +126,8 @@ def __str__(self):
return self.distribution_name


class Beneficiary(models.Model):
beneficiary_name = models.CharField(max_length=255, null=True, blank=True)
class Individual(models.Model):
first_name = models.CharField(max_length=255, null=True, blank=True)
training = models.ManyToManyField(TrainingAttendance, blank=True)
distribution = models.ManyToManyField(Distribution, blank=True)
father_name = models.CharField(max_length=255, null=True, blank=True)
Expand All @@ -142,17 +142,17 @@ class Beneficiary(models.Model):
edit_date = models.DateTimeField(null=True, blank=True)

class Meta:
ordering = ('beneficiary_name',)
ordering = ('first_name',)

# on save add create date or update edit date
def save(self, *args, **kwargs):
if self.create_date is None:
self.create_date = datetime.now()
self.edit_date = datetime.now()
super(Beneficiary, self).save()
super(Individual, self).save()

# displayed in admin templates
def __str__(self):
if self.beneficiary_name is None:
if self.first_name is None:
return "NULL"
return self.beneficiary_name
return self.first_name
8 changes: 4 additions & 4 deletions formlibrary/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from formlibrary.models import Beneficiary, TrainingAttendance
from formlibrary.models import Individual, TrainingAttendance


class TrainingSerializer(serializers.ModelSerializer):
Expand All @@ -9,9 +9,9 @@ class Meta:
fields = ['training_duration']


class BeneficiarySerializer(serializers.ModelSerializer):
class IndividualSerializer(serializers.ModelSerializer):
training = TrainingSerializer(many=True, read_only=True)

class Meta:
model = Beneficiary
fields = ['id', 'beneficiary_name', 'age', 'training']
model = Individual
fields = ['id', 'first_name', 'age', 'training']
16 changes: 8 additions & 8 deletions formlibrary/tests/test_training_attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Program, Country, Province, ProjectAgreement, Sector,
ProjectType, SiteProfile, Office
)
from formlibrary.models import TrainingAttendance, Distribution, Beneficiary
from formlibrary.models import TrainingAttendance, Distribution, Individual
from datetime import datetime


Expand Down Expand Up @@ -92,7 +92,7 @@ def setUp(self):
distribution_implementer="34",
reporting_period="34",
province=get_province,
total_beneficiaries_received_input="34",
total_individuals_received_input="34",
distribution_location="testlocation",
input_type_distributed="testinputtype",
distributor_name_and_affiliation="testdistributorperson",
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_distribution_exists(self):
id=get_distribution.id).count(), 1)


class BeneficiaryTestCase(TestCase):
class IndividualTestCase(TestCase):

def setUp(self):
new_program = Program.objects.create(name="testprogram")
Expand All @@ -142,14 +142,14 @@ def setUp(self):
new_training.save()
# get_training = TrainingAttendance.objects.get(
# training_name="testtraining")
new_benny = Beneficiary.objects.create(
beneficiary_name="Joe Test", father_name="Mr Test", age="42",
new_benny = Individual.objects.create(
first_name="Joe Test", father_name="Mr Test", age="42",
gender="male", signature=False, remarks="life")
new_benny.training.add(new_training)
new_benny.save()

def test_beneficiary_exists(self):
def test_individual_exists(self):
"""Check for Benny object"""
get_benny = Beneficiary.objects.get(beneficiary_name="Joe Test")
self.assertEqual(Beneficiary.objects.filter(
get_benny = Individual.objects.get(first_name="Joe Test")
self.assertEqual(Individual.objects.filter(
id=get_benny.id).count(), 1)
24 changes: 12 additions & 12 deletions formlibrary/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from .views import (
TrainingList, add_training, add_distribution, TrainingListObjects,
BeneficiaryList, BeneficiaryCreate, BeneficiaryListObjects,
BeneficiaryUpdate, TrainingUpdate, delete_training, delete_beneficiary,
IndividualList, IndividualCreate, IndividualListObjects,
IndividualUpdate, TrainingUpdate, delete_training, delete_individual,
TrainingCreate, DistributionList, DistributionCreate, DistributionListObjects,
DistributionUpdate, delete_distribution, GetAgreements,
TrainingParticipantListObjects)
Expand All @@ -28,16 +28,16 @@
path('training_participants/<int:pk>', TrainingParticipantListObjects.as_view(),
name='training_participants'),

path('beneficiary_list/<slug:program>/<slug:training>/<slug:distribution>/',
BeneficiaryList.as_view(), name='beneficiary_list'),
path('beneficiary_objects/<slug:program>/<slug:project>/',
BeneficiaryListObjects.as_view(), name='beneficiary_objects'),
path('beneficiary_add/<slug:id>/',
BeneficiaryCreate.as_view(), name='beneficiary_add'),
path('beneficiary_update/<slug:pk>/',
BeneficiaryUpdate.as_view(), name='beneficiary_update'),
path('beneficiary_delete/<slug:pk>/',
delete_beneficiary, name='beneficiary_delete'),
path('individual_list/<slug:program>/<slug:training>/<slug:distribution>/',
IndividualList.as_view(), name='individual_list'),
path('individual_objects/<slug:program>/<slug:project>/',
IndividualListObjects.as_view(), name='individual_objects'),
path('individual_add/<slug:id>/',
IndividualCreate.as_view(), name='individual_add'),
path('individual_update/<slug:pk>/',
IndividualUpdate.as_view(), name='individual_update'),
path('individual_delete/<slug:pk>/',
delete_individual, name='individual_delete'),

path('distribution_list/<slug:program>/<slug:project>/',
DistributionList.as_view(), name='distribution_list'),
Expand Down
Loading