diff --git a/app/dashboard/templates/shared/menu.html b/app/dashboard/templates/shared/menu.html index 4266dab737c..fecb7e22cdc 100644 --- a/app/dashboard/templates/shared/menu.html +++ b/app/dashboard/templates/shared/menu.html @@ -139,7 +139,7 @@ - +
@@ -149,8 +149,8 @@
- {% trans "Govern" %} - {% trans "Decide the future of the open web" %} + {% trans "DAO" %} + {% trans "Get involved in the decentralized GitcoinDAO community." %}
diff --git a/app/grants/router.py b/app/grants/router.py index 72b2bb8438d..a3864e29129 100644 --- a/app/grants/router.py +++ b/app/grants/router.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta -from django.core.paginator import Paginator +from django.core.paginator import EmptyPage, Paginator import django_filters.rest_framework from ratelimit.decorators import ratelimit diff --git a/app/grants/urls.py b/app/grants/urls.py index 8f06fd35c85..77b6961912d 100644 --- a/app/grants/urls.py +++ b/app/grants/urls.py @@ -24,11 +24,11 @@ collection_thumbnail, contribute_to_grants_v1, contribution_addr_from_all_as_json, contribution_addr_from_grant_as_json, contribution_addr_from_grant_during_round_as_json, contribution_addr_from_round_as_json, contribution_info_from_grant_during_round_as_json, create_matching_pledge_v1, - flag, get_collection, get_collections_list, get_ethereum_cart_data, get_grant_payload, get_grants, - get_interrupted_contributions, get_replaced_tx, get_trust_bonus, grant_activity, grant_categories, grant_details, - grant_details_api, grant_details_contributions, grant_details_contributors, grant_edit, grant_fund, grant_new, - grants, grants_addr_as_json, grants_bulk_add, grants_by_grant_type, grants_cart_view, grants_info, grants_landing, - grants_type_redirect, ingest_contributions, ingest_contributions_view, invoice, leaderboard, + flag, get_clr_sybil_input, get_collection, get_collections_list, get_ethereum_cart_data, get_grant_payload, + get_grants, get_interrupted_contributions, get_replaced_tx, get_trust_bonus, grant_activity, grant_categories, + grant_details, grant_details_api, grant_details_contributions, grant_details_contributors, grant_edit, grant_fund, + grant_new, grants, grants_addr_as_json, grants_bulk_add, grants_by_grant_type, grants_cart_view, grants_info, + grants_landing, grants_type_redirect, ingest_contributions, ingest_contributions_view, invoice, leaderboard, manage_ethereum_cart_data, new_matching_partner, profile, quickstart, remove_grant_from_collection, save_collection, toggle_grant_favorite, verify_grant, ) @@ -114,5 +114,7 @@ path('v1/api/export_addresses/grant_round.json', contribution_addr_from_grant_during_round_as_json, name='contribution_addr_from_grant_during_round_as_json'), path('v1/api/export_info/grant_round.json', contribution_info_from_grant_during_round_as_json, name='contribution_addr_from_grant_during_round_as_json'), + # custom API + path('v1/api/get-clr-data/', get_clr_sybil_input, name='get_clr_sybil_input') ] diff --git a/app/grants/views.py b/app/grants/views.py index f4bb92c94ee..f6bdef7d5a1 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -23,7 +23,6 @@ import logging import math import re -import time import uuid from datetime import datetime from urllib.parse import urlencode @@ -38,6 +37,7 @@ from django.db import connection, transaction from django.db.models import Q, Subquery from django.http import Http404, HttpResponse, JsonResponse +from django.http.response import HttpResponseBadRequest, HttpResponseServerError from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.templatetags.static import static @@ -67,6 +67,7 @@ from economy.models import Token as FTokens from economy.utils import convert_token_to_usdt from eth_account.messages import defunct_hash_message +from grants.clr import fetch_data from grants.models import ( CartActivity, Contribution, Flag, Grant, GrantAPIKey, GrantBrandingRoutingPolicy, GrantCategory, GrantCLR, GrantCollection, GrantType, MatchPledge, Subscription, @@ -81,7 +82,7 @@ from kudos.models import BulkTransferCoupon, Token from marketing.mails import grant_cancellation, new_grant_flag_admin from marketing.models import Keyword, Stat -from perftools.models import JSONStore +from perftools.models import JSONStore, StaticJsonEnv from ratelimit.decorators import ratelimit from retail.helpers import get_ip from townsquare.models import Announcement, Favorite, PinnedPost @@ -3496,6 +3497,73 @@ def handle_ingestion(profile, network, identifier, do_write): return JsonResponse({ 'success': True, 'ingestion_types': ingestion_types }) + +def get_clr_sybil_input(request, round_id): + ''' + This returns a paginated JSON response to return contributions + which are considered while calculating the QF match for a given CLR + ''' + token = request.headers['token'] + page = request.GET.get('page', 1) + + data = StaticJsonEnv.objects.get(key='BSCI_SYBIL_TOKEN').data + + if not round_id or not token or not data['token']: + return HttpResponseBadRequest("error: missing arguments") + + if token != data['token']: + return HttpResponseBadRequest("error: invalid token") + + clr = GrantCLR.objects.filter(pk=round_id).first() + if not clr: + return HttpResponseBadRequest("error: round not found") + + try: + limit = data['limit'] if data['limit'] else 100 + + # fetch grant contributions needed for round + __, all_clr_contributions = fetch_data(clr) + total_count = all_clr_contributions.count() + + # extract only needed fields + all_clr_contributions = list(all_clr_contributions.values( + 'created_on', 'profile_for_clr__handle', 'profile_for_clr_id', + 'match', 'normalized_data' + )) + + # paginate contributions + contributions = Paginator(all_clr_contributions, limit) + try: + contributions_queryset = contributions.page(page) + except EmptyPage: + response = { + 'metadata': { + 'count': 0, + 'current_page': 0, + 'num_pages': 0, + 'has_next': False + }, + 'contributions': [] + } + return HttpResponse(response) + + response = { + 'metadata': { + 'count': total_count, + 'current_page': page, + 'total_pages': contributions.num_pages, + 'has_next': contributions_queryset.has_next() + }, + 'contributions': contributions_queryset.object_list + } + + except Exception as e: + print(e) + return HttpResponseServerError() + + return JsonResponse(response) + + @csrf_exempt def get_trust_bonus(request): '''