8000 refactor of grantclr to make the round_num an actual int + add a subround/customer field by owocki · Pull Request #7685 · gitcoinco/web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor of grantclr to make the round_num an actual int + add a subround/customer field #7685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions app/assets/v2/js/grants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ $(document).ready(() => {
});

Vue.component('grant-sidebar', {
props: [ 'filter_grants', 'grant_types', 'type', 'selected_category', 'keyword', 'following', 'set_type',
'idle_grants', 'show_contributions', 'query_params', 'round_num', 'featured'
props: [
'filter_grants', 'grant_types', 'type', 'selected_category', 'keyword', 'following', 'set_type',
'idle_grants', 'show_contributions', 'query_params', 'round_num', 'sub_round_slug', 'customer_name',
'featured'
],
data: function() {
return {
Expand Down Expand Up @@ -102,10 +104,25 @@ Vue.component('grant-sidebar', {

document.location.href = `/grants/collections?${$.param(collections_query)}`;
} else {
document.location.href = this.round_num ?
`/grants/clr/${this.round_num}?type=${params.type}` :
`/grants/${params.type}`
;
let target = `/grants/${params.type}`;

if (this.round_num) {
target = `/grants/clr/${this.round_num}?type=${params.type}`;

if (this.sub_round_slug && !this.customer_name) {
target = `/grants/clr/${this.round_num}/${this.sub_round_slug}?type=${params.type}`;
}

if (!this.sub_round_slug && this.customer_name) {
target = `/grants/clr/${this.customer_name}/${this.round_num}?type=${params.type}`;
}

if (this.sub_round_slug && this.customer_name) {
target = `/grants/clr/${this.customer_name}/${this.round_num}/${this.sub_round_slug}?type=${params.type}`;
}
}

document.location.href = target;
}
},
searchKeyword: function() {
Expand Down Expand Up @@ -160,6 +177,8 @@ if (document.getElementById('grants-showcase')) {
cart_lock: false,
collection_id: document.collection_id,
round_num: document.round_num,
sub_round_slug: document.sub_round_slug,
customer_name: document.customer_name,
activeCollection: null,
grantsNumPages,
grantsHasNext,
Expand Down Expand Up @@ -187,6 +206,18 @@ if (document.getElementById('grants-showcase')) {
if (vm.round_num) {
let uri = `/grants/clr/${vm.round_num}/`;

if (vm.sub_round_slug && !vm.customer_name) {
uri = `/grants/clr/${vm.round_num}/${vm.sub_round_slug}/`;
}

if (!vm.sub_round_slug && vm.customer_name) {
uri = `/grants/clr/${vm.customer_name}/${vm.round_num}/`;
}

if (vm.sub_round_slug && vm.customer_name) {
uri = `/grants/clr/${vm.customer_name}/${vm.round_num}/${vm.sub_round_slug}/`;
}

if (this.current_type === 'all') {
window.history.pushState('', '', `${uri}?${q || ''}`);
} else {
Expand Down Expand Up @@ -359,6 +390,14 @@ if (document.getElementById('grants-showcase')) {
base_params['round_num'] = vm.round_num;
}

if (vm.sub_round_slug) {
base_params['sub_round_slug'] = vm.sub_round_slug;
}

if (vm.customer_name) {
base_params['customer_name'] = vm.customer_name;
}

const params = new URLSearchParams(base_params).toString();
const getGrants = await fetchData(`/grants/cards_info?${params}`);

Expand Down
3 changes: 1 addition & 2 deletions app/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ class GrantCategoryAdmin(admin.ModelAdmin):


class GrantCLRAdmin(admin.ModelAdmin):
list_display = ['pk', 'round_num', 'start_date', 'end_date','is_active', 'link']

list_display = ['pk', 'customer_name', 'round_num', 'sub_round_slug', 'start_date', 'end_date','is_active']

def link(self, instance):
try:
Expand Down
23 changes: 23 additions & 0 deletions app/grants/migrations/0090_grantclr_sub_round_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.4 on 2020-10-15 19:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grants', '0089_contribution_checkout_type'),
]

operations = [
migrations.AddField(
model_name='grantclr',
name='customer_name',
field=models.CharField(default='all', help_text='Customer Name', max_length=255),
),
migrations.AddField(
model_name='grantclr',
name='sub_round_slug',
field=models.CharField(default='all', help_text='Sub Round Slug', max_length=255),
),
]
28 changes: 28 additions & 0 deletions app/grants/migrations/0091_auto_20201015_1933.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.4 on 2020-10-15 19:33

from django.db import migrations

def forwards(apps, schema_editor):
GrantCLR = apps.get_model('grants', 'GrantCLR')
for gclr in GrantCLR.objects.exclude(round_num__lt=9):
gclr.sub_round_slug = gclr.round_num
gclr.round_num = 7
gclr.save()
for gclr in GrantCLR.objects.all():
gclr.customer_name = "ethereum"
gclr.save()


def backwards(apps, schema_editor):
pass


class Migration(migrations.Migration):

dependencies = [
('grants', '0090_grantclr_sub_round_slug'),
]

operations = [
migrations.RunPython(forwards, backwards),
]
18 changes: 18 additions & 0 deletions app/grants/migrations/0092_auto_20201015_1948.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2020-10-15 19:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grants', '0091_auto_20201015_1933'),
]

operations = [
migrations.AlterField(
model_name='grantclr',
name='round_num',
field=models.PositiveIntegerField(help_text='CLR Round Number'),
),
]
32 changes: 32 additions & 0 deletions app/grants/migrations/0093_auto_20201113_0124.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 2.2.4 on 2020-11-13 01:24

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grants', '0092_auto_20201015_1948'),
]

operations = [
migrations.AlterField(
model_name='grantclr',
name='customer_name',
field=models.CharField(blank=True, default='', help_text='CLR Customer Name', max_length=15),
),
migrations.AlterField(
model_name='grantclr',
name='end_date',
field=models.DateTimeField(help_text='CLR Round End Date'),
),
migrations.AlterField(
model_name='grantclr',
name='sub_round_slug',
field=models.CharField(blank=True, default='', help_text='Sub Round Slug', max_length=25),
),
migrations.AlterUniqueTogether(
name='grantclr',
unique_together={('customer_name', 'round_num', 'sub_round_slug')},
),
]
14 changes: 14 additions & 0 deletions app/grants/migrations/0096_merge_20201119_1921.py
F438
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.4 on 2020-11-19 19:21

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('grants', '0093_auto_20201113_0124'),
('grants', '0095_auto_20201119_1031'),
]

operations = [
]
10 changes: 8 additions & 2 deletions app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ def active_clrs_sum(self):


class GrantCLR(SuperModel):
round_num = models.CharField(max_length=15, help_text="CLR Round Number")

class Meta:
unique_together = ('customer_name', 'round_num', 'sub_round_slug',)

customer_name = models.CharField(max_length=15, default='', blank=True, help_text="CLR Customer Name")
round_num = models.PositiveIntegerField(help_text="CLR Round Number")
sub_round_slug = models.CharField(max_length=25, default='', blank=True, help_text="Sub Round Slug")
is_active = models.BooleanField(default=False, db_index=True, help_text="Is CLR Round currently active")
start_date = models.DateTimeField(help_text="CLR Round Start Date")
end_date = models.DateTimeField(help_text="CLR Round Start Date")
end_date = models.DateTimeField(help_text="CLR Round End Date")
grant_filters = JSONField(
default=dict,
null=True, blank=True,
Expand Down
2 changes: 2 additions & 0 deletions app/grants/templates/grants/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
document.collections = JSON.parse(document.getElementById('collections-object').textContent);
{% if clr_round %}
document.round_num = "{{clr_round.round_num}}";
document.sub_round_slug = "{{clr_round.sub_round_slug}}";
document.customer_name = "{{clr_round.customer_name}}";
{% endif %}
</script>
{% include 'shared/activity_scripts.html' %}
Expand Down
3 changes: 2 additions & 1 deletion app/grants/templates/grants/shared/sidebar_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<grant-sidebar :grant_types="grant_types" :filter_grants="filter_grants" :type="current_type"
:selected_category="category" :keyword="keyword" :following="following"
:set_type="setCurrentType" :idle_grants="idle_grants" :show_contributions="show_contributions"
:query_params="getQueryParams" :round_num="round_num" :featured="featured"
:query_params="getQueryParams" :round_num="round_num" :sub_round_slug="sub_round_slug"
:customer_name="customer_name" :featured="featured"
inline-template>
<div class="sidebar_search font-body pr-0 pl-4 w-100">
<div class="search font-caption mb-4" style="width: 110%;">
Expand Down
6 changes: 4 additions & 2 deletions app/grants/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
app_name = 'grants'
urlpatterns = [
path('', grants, name='grants'),
path('clr/<slug:round_num>', clr_grants, name='clr_grants'),
path('clr/<slug:round_num>/', clr_grants, name='clr_grants'),
path('clr/<int:round_num>', clr_grants, name='clr_grants'),
path('clr/<int:round_num>/<str:sub_round_slug>', clr_grants, name='clr_grants'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would you have round num and slug ?
Is this to group all the clr for round 8 under clr/8/...?

For custom CLR like matic / zcash
I'm not sure if this makes sense

I'd lean towards

  • keeping how it was
  • keeping both

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

round num = 7
slug = community, infra tech, or dapp tech

there can be multiple slugs in the same round.

path('clr/<str:customer_name>/<int:round_num>', clr_grants, name='clr_grants'),
path('clr/<str:customer_name>/<int:round_num>/<str:sub_round_slug>', clr_grants, name='clr_grants'),
path('getstats/', grants_stats_view, name='grants_stats'),
path('grants.json', grants_addr_as_json, name='grants_json'),
path('flag/<int:grant_id>', flag, name='grantflag'),
Expand Down
26 changes: 18 additions & 8 deletions app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,16 @@ def bulk_grants_for_cart(request):
return JsonResponse({'grants': grants})


def clr_grants(request, round_num):
def clr_grants(request, round_num, sub_round_slug='', customer_name=''):
"""CLR grants explorer."""

try:
clr_round = GrantCLR.objects.get(round_num__icontains=round_num)
params = {
'round_num': round_num,
'sub_round_slug': sub_round_slug,
'customer_name': customer_name
}
clr_round = GrantCLR.objects.get(**params)

except GrantCLR.DoesNotExist:
return redirect('/grants')
Expand Down Expand Up @@ -540,11 +545,18 @@ def get_grants(request):
featured = request.GET.get('featured', '') == 'true'
collection_id = request.GET.get('collection_id', '')
round_num = request.GET.get('round_num', None)
sub_round_slug = request.GET.get('sub_round_slug', '')
customer_name = request.GET.get('customer_name', '')

clr_round = None
try:
if round_num:
clr_round = GrantCLR.objects.get(round_num=round_num)
params = {
'round_num': round_num,
'sub_round_slug': sub_round_slug,
'customer_name': customer_name
}
clr_round = GrantCLR.objects.get(**params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chibie love me some **splat!

except GrantCLR.DoesNotExist:
pass

Expand Down Expand Up @@ -2385,6 +2397,7 @@ def record_subscription_activity_helper(activity_type, subscription, profile, an
}
return Activity.objects.create(**kwargs)


def record_grant_activity_helper(activity_type, grant, profile, amount=None, token=None):
"""Registers a new activity concerning a grant

Expand Down Expand Up @@ -2451,7 +2464,6 @@ def new_matching_partner(request):
return TemplateResponse(request, 'grants/new_match.html', params)



def create_matching_pledge_v1(request):

response = {
Expand All @@ -2466,7 +2478,6 @@ def create_matching_pledge_v1(request):

profile = request.user.profile if hasattr(request.user, 'profile') else None


if not profile:
response['message'] = 'error: no matching profile found'
return JsonResponse(response)
Expand All @@ -2475,7 +2486,6 @@ def create_matching_pledge_v1(request):
response['message'] = 'error: pledge creation is a POST operation'
return JsonResponse(response)


grant_types = request.POST.get('grant_types[]', None)
grant_categories = request.POST.get('grant_categories[]', None)
grant_collections = request.POST.get('grant_collections[]', None)
Expand All @@ -2491,7 +2501,6 @@ def create_matching_pledge_v1(request):
response['message'] = 'error: grant_types / grant_collections is parameter'
return JsonResponse(response)


matching_pledge_stage = request.POST.get('matching_pledge_stage', None)
tx_id = request.POST.get('tx_id', None)
if matching_pledge_stage == 'ready' and not tx_id:
Expand All @@ -2518,7 +2527,8 @@ def create_matching_pledge_v1(request):
}

clr_round = GrantCLR.objects.create(
round_num='pledge',
round_num=0,
sub_round_slug='pledge',
start_date=timezone.now(),
end_date=timezone.now(),
total_pot=amount,
Expand Down
0