Skip to content

Commit

Permalink
Convert to Grant (#8154)
Browse files Browse the repository at this point in the history
* Include description in URL params

* Add URL params to prefill grant

* Add created to hackathon project when convert2grant button used.

* Add related hackathon project to URL get params when using convert to grant

* Prevent unauthorized convert2grant

* Hide convert grant button if already created.

* Ignore dist folder

* Make grant creation work on matic page
  • Loading branch information
amustapha authored Dec 22, 2020
1 parent 3a240b6 commit 0cc7ce5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ app/cache/
# Autogenerated Documentation
_build/
**/.vs
**/dist
8 changes: 6 additions & 2 deletions app/assets/v2/js/grants/_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ Vue.mixin({
'X-CSRFToken': $("input[name='csrfmiddlewaretoken']").val()
};

const apiUrlGrant = '/grants/new';

let apiUrlGrant = '/grants/new';
if (vm.queryParams.get('related_hackathon_project_id')) {
apiUrlGrant += `?related_hackathon_project_id=${vm.queryParams.get('related_hackathon_project_id')}`
}
$.ajax({
type: 'post',
url: apiUrlGrant,
Expand Down Expand Up @@ -375,12 +377,14 @@ if (document.getElementById('gc-new-grant')) {
const writeToRoot = ['chainId'];
const writeToBody = [
'title',
'description_rich',
'reference_url',
'twitter_handle_1',
'twitter_handle_2',
'github_project_url',
'eth_payout_address',
'grant_type',
'team_members',
'grant_categories'
];

Expand Down
7 changes: 6 additions & 1 deletion app/assets/v2/js/grants/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,15 @@ function saveGrant(grantData, isFinal) {
let csrftoken = $("#create-grant input[name='csrfmiddlewaretoken']").val();

$('#new_button').attr('disabled', 'disabled');
let newGrantURL = '/grants/new';
const queryParams = new URLSearchParams(window.location.search)
if (queryParams.get('related_hackathon_project_id')) {
newGrantURL += `?related_hackathon_project_id=${queryParams.get('related_hackathon_project_id')}`
}

$.ajax({
type: 'post',
url: '/grants/new',
url: newGrantURL,
processData: false,
contentType: false,
data: grantData,
Expand Down
3 changes: 3 additions & 0 deletions app/dashboard/templates/project/detail/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
{% endif %}

{% if is_member %}
{% if not project_obj.grant_url %}
<a :href="`/grants/new?title=${project.name}&description_rich=${project.summary}&reference_url=${project.work_url}&github_project_url=${project.work_url}&related_hackathon_project_id=${project.id}`" target="_blank" class="project__action--admin btn button-white btn-block font-subheader btn-lg m-2"><i class="fa fa-plus mr-2"></i>CONVERT TO GRANT</a>
{% endif %}
<button @click="$emit('project:edit')" class="project__action--admin btn button-white btn-block font-subheader btn-lg m-2"><i class="fa fa-pencil mr-2"></i> EDIT PROJECT</button>
{% endif %}
</div>
Expand Down
10 changes: 9 additions & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.humanize.templatetags.humanize import intword, naturaltime
from django.core.paginator import EmptyPage, Paginator
from django.db import connection
from django.db import connection, transaction
from django.db.models import Avg, Count, Max, Q, Subquery
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect
Expand Down Expand Up @@ -1657,6 +1657,7 @@ def grant_new_whitelabel(request):


@login_required
@transaction.atomic
def grant_new(request):
"""Handle new grant."""

Expand Down Expand Up @@ -1762,6 +1763,13 @@ def grant_new(request):

grant = Grant.objects.create(**grant_kwargs)

hackathon_project_id = request.GET.get('related_hackathon_project_id')
if hackathon_project_id:
hackathon_project = HackathonProject.objects.filter(id=hackathon_project_id).first()
if hackathon_project and hackathon_project.profiles.filter(pk=profile.id).exists():
hackathon_project.grant_obj = grant
hackathon_project.save()

team_members = (team_members[0].split(','))
team_members.append(profile.id)
team_members = list(set(team_members))
Expand Down

0 comments on commit 0cc7ce5

Please sign in to comment.