Skip to content

Commit

Permalink
Merge branch 'master' into hotfix/impact-type-api
Browse files Browse the repository at this point in the history
  • Loading branch information
gannetson committed Sep 1, 2022
2 parents d5b3bfe + 9266141 commit 5fcd4f9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
1 change: 0 additions & 1 deletion bluebottle/initiatives/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ class InitiativePlatformSettings(BasePlatformSettings):
('team_activity', _('Team activities')),
('theme', _('Theme')),
('category', _('Category')),
('status', _('Status')),
('segments', _('Segments')),
)
INITIATIVE_SEARCH_FILTERS = (
Expand Down
64 changes: 64 additions & 0 deletions scripts/tne_campaign_ranking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from datetime import date
import xlsxwriter

from bluebottle.clients.models import Client
from bluebottle.clients.utils import LocalTenant

from bluebottle.funding.models import Funding, Donor
from bluebottle.geo.models import Location


OFFICE_NAME = 'Mogadishu'
TARGET = 500
DEADLINES = [date(2022, 8, 20), date(2022, 8, 21)]


def run(*args):
tne = Client.objects.get(client_name='nexteconomy')

with LocalTenant(tne, clear_tenant=True):
result = []

location = Location.objects.get(name=OFFICE_NAME)

campaigns = Funding.objects.filter(
initiative__location__name=OFFICE_NAME,
deadline__date__in=DEADLINES,
status__in=('succeeded', 'partially_funded')
)
print(len(campaigns))

for activity in campaigns:
print(activity.title, activity.amount_raised, activity.status)

for campaign in campaigns:
donors = campaign.contributors.instance_of(
Donor
).filter(
status='succeeded'
).order_by(
'created'
)

total = 0
for donor in donors:
total += donor.amount.amount

if total >= TARGET:
result.append({
'id': campaign.id,
'title': campaign.title,
'status': campaign.status,
'target reached': str(donor.created),
})
break

workbook = xlsxwriter.Workbook(f'TNE-{location.name}-{DEADLINES[0]}.xlsx', {'remove_timezone': True})
worksheet = workbook.add_worksheet()

worksheet.write_row(0, 0, result[0].keys())

for (index, row) in enumerate(result):
worksheet.write_row(index + 1, 0, row.values())

workbook.close()

0 comments on commit 5fcd4f9

Please sign in to comment.