Skip to content

Commit 2ddcea7

Browse files
author
ksamuel
committed
More calculated indicators and no more unexpected recursion on non recursive calculation.
0 parents  commit 2ddcea7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4707
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.pyc
2+
*.db
3+
*.sqlite*
4+
~*
5+
*.orig
6+
private
7+
*.log
8+
*.log.*
9+
*.mo
10+
local_settings.py
11+
doc
12+
/virtualenv

django_mangrove/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
VERSION = (0, 0, 1)
2+
3+
def get_version():
4+
version = "%s.%s" % (VERSION[0], VERSION[1])
5+
if VERSION[2] != 0:
6+
version = "%s.%s" % (version, VERSION[2])
7+
return version
8+
9+
__version__ = get_version()

django_mangrove/generic_report/__init__.py

Whitespace-only changes.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# vim: ai ts=4 sts=4 et sw=4
4+
5+
from django.contrib import admin
6+
from .models import *
7+
import eav
8+
9+
admin.site.register(Report)
10+
admin.site.register(Record)
11+
admin.site.register(Indicator)
12+
13+
eav.register(Record)

django_mangrove/generic_report/fixtures/dev.json

+1
Large diffs are not rendered by default.
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# vim: ai ts=4 sts=4 et sw=4
4+
5+
from django import forms
6+
7+
from .models import Campaign
8+
from django.forms import ValidationError
9+
from django.utils.translation import ugettext as _
10+
11+
from simple_locations.models import Area
12+
13+
from report_parts.models import Report, ReportType
14+
15+
from .models import Results
16+
17+
# if we change the distributor, it should be set for all the active campagn
18+
19+
class CampaignForm(forms.ModelForm):
20+
21+
class Meta:
22+
model = Campaign
23+
24+
25+
def clean(self, *args, **kwargs):
26+
27+
if 'locations' not in self.data:
28+
raise ValidationError(_(u'You must select at least one location'))
29+
return forms.ModelForm.clean(self, *args, **kwargs)
30+
31+
32+
def save(self, *args, **kwargs):
33+
34+
campaign = forms.ModelForm.save(self, *args, **kwargs)
35+
36+
# todo : make add a slug to report type
37+
rt = ReportType.objects.get(name='NTD Mali')
38+
# todo: put more validation here
39+
# create or enable checked location
40+
locations = set(self.data.getlist('locations'))
41+
for location in locations:
42+
area = Area.objects.get(pk=location)
43+
44+
try:
45+
result = Results.objects.get(campaign=campaign, area=area)
46+
if campaign.drugs_pack and not result.drugs_pack :
47+
result.drugs_pack = campaign.drugs_pack
48+
result.save()
49+
except Results.DoesNotExist:
50+
loc = area.as_data_source.data_collection
51+
pack = campaign.drugs_pack
52+
report_mgr = Report.objects.create(type=rt)
53+
result = Results.objects.create(campaign=campaign,
54+
area=area,
55+
data_collection_location=loc,
56+
drugs_pack=pack,
57+
report_manager=report_mgr)
58+
else:
59+
if result.disabled:
60+
result.disabled = False
61+
result.save()
62+
63+
# disable unchecked locations
64+
for result in campaign.results_set.all():
65+
if unicode(result.area.pk) not in locations:
66+
result.disabled = True
67+
result.save()
68+
69+
return campaign
70+

django_mangrove/generic_report/locale/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)