-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#813] New take on the validation script
- Loading branch information
Showing
1 changed file
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |