Skip to content

Commit

Permalink
[#813] New take on the validation script
Browse files Browse the repository at this point in the history
  • Loading branch information
kardan committed Oct 23, 2014
1 parent a537222 commit 02d3785
Showing 1 changed file with 158 additions and 0 deletions.
158 changes: 158 additions & 0 deletions val.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the
# Akvo RSR module. For additional details on the GNU license please
# see < http://www.gnu.org/licenses/agpl.html >.

from __future__ import print_function

import os
import sys
import json




def addCounts(models, data):
from akvo.rsr.models import (Benchmark,
Benchmarkname,
BudgetItem,
BudgetItemLabel,
CountryBudgetItem,
Country,
RecipientCountry,
Category,
FocusArea,
Goal,
Indicator,
IndicatorPeriod,
Invoice,
InternalOrganisationID,
Keyword,
LegacyData,
Link,
OrganisationLocation,
ProjectLocation,
ProjectUpdateLocation,
MiniCMS,
Organisation,
OrganisationAccount,
PartnerSite,
PartnerType,
Partnership,
PayPalGateway,
MollieGateway,
PaymentGatewaySelector,
PlannedDisbursement,
PolicyMarker,
Project,
ProjectComment,
ProjectCondition,
ProjectContact,
ProjectUpdate,
PublishingStatus,
RecipientRegion,
Result,
Sector,
Transaction,
UserProfile,)

for model in models:
if model not in data:
data[model] = {}
obj = eval(model)
data[model]['count'] = obj.objects.all().count()
return data

def addProjectBudget(data):
from akvo.rsr.models import Project

projects = Project.objects.published()
data['Project']['items'] = {}

for project in projects:
# Make sure we have the project item
if project.id not in data['Project']['items']:
data['Project']['items'][project.id] = {}

# Add project data
data['Project']['items'][project.id]['budget'] = project.budget
data['Project']['items'][project.id]['funds'] = project.funds
data['Project']['items'][project.id]['keywords'] = project.keywords


return data


def persistData(data):
with open('/tmp/rsr_validation_data.py', 'w') as f:
# print(json.dumps(data), file=f)
print(repr(data), file=f)


def getData(models):
data = {}
data = addCounts(models, data)
data = addProjectBudget(data)
return data


models = ['Benchmark',
'Benchmarkname',
'BudgetItem',
'BudgetItemLabel',
'CountryBudgetItem',
'Country',
'RecipientCountry',
'Category',
'FocusArea',
'Goal',
'Indicator',
'IndicatorPeriod',
'Invoice',
'InternalOrganisationID',
'Keyword',
'LegacyData',
'Link',
'OrganisationLocation',
'ProjectLocation',
'ProjectUpdateLocation',
'MiniCMS',
'Organisation',
'OrganisationAccount',
'PartnerSite',
'PartnerType',
'Partnership',
'PayPalGateway',
'MollieGateway',
'PaymentGatewaySelector',
'PlannedDisbursement',
'PolicyMarker',
'Project',
'ProjectComment',
'ProjectCondition',
'ProjectContact',
'ProjectUpdate',
'PublishingStatus',
'RecipientRegion',
'Result',
'Sector',
'Transaction',
'UserProfile', ]

if __name__ == "__main__":
try:
sys.path.append('/var/akvo/rsr/code/akvo')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.conf import settings
except ImportError as e:
import sys
message = "Error: Can't find the 'settings' module."
sys.stderr.write(message)
sys.stderr.write("\nImportError: " + str(e) + "\n")
sys.exit(1)

persistData(getData(models))
print("Done collecting reference data")

0 comments on commit 02d3785

Please sign in to comment.