Skip to content
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

Add hooks and add new question type #6778

Merged
merged 21 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 3 additions & 0 deletions app/assets/v2/css/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ html {
--gc-purple-hover: #0b0d9d;
--gc-green: #0FCE7C;
--gc-green-hover: #25E899;
--gc-light-green: rgb(211, 250, 235);
--gc-pink: #f9006c;
--gc-pink-hover: #f167a3;
--gc-yellow: #F5A623;
Expand Down Expand Up @@ -52,6 +53,8 @@ html.dark-mode {
--gc-purple-hover: #0b0d9d;
--gc-green: #0FCE7C;
--gc-green-hover: #25E899;
--gc-light-green: transparent;

--gc-pink: #f9006c;
--gc-pink-hover: #f167a3;
--gc-yellow: #F5A623;
Expand Down
66 changes: 66 additions & 0 deletions app/assets/v2/css/town_square.css
Original file line number Diff line number Diff line change
Expand Up @@ -1216,10 +1216,65 @@ body.green.offer_view .announce {
border-top: 6px solid rgba(62, 0, 255, 0.4);
}

.activity.hackathon_new_hacker {
position: relative;
box-sizing: border-box;
z-index: 2;
}

.activity.hackathon_new_hacker:before {
content: '';
position: absolute;
top: -6px;
left: 0;
height: 6px;
width: 100%;
display: block;
background: linear-gradient(to right, #B572D4 0%, #F9DD5B 37%, #75EDB5 100%);
}

.activity.hackathon_new_hacker:after {
content: '';
position: absolute;
top: 58px;
left: 3%;
height: 143px;
width: 94%;
display: block;
background: --var(--gc-light-green);
z-index: -2;
}

.activity.hackathon_new_hacker .activity-avatar::after {
height: 6.1rem;
content: '';
background-image: url(/static/v2/images/townsquare-nh.svg);
width: 6.1rem;
position: absolute;
top: -24px;
left: 8px;
z-index: -1;
}

.activity.hackathon_new_hacker .activity_detail::after {
height: 100%;
content: '';
background: url(/static/v2/images/townsqure-party.png) 0 0 no-repeat;
width: 100%;
position: absolute;
top: 55px;
right: -309px;
z-index: -1;
}

.new_hackathon_project {
border-top: 6px solid rgba(15, 206, 124, 0.25);
}

.activity_main .bg_hackathon_new_hacker {
background-color: #D3FAEB;
}

.bg-gc-blue {
background-color: var(--gc-blue);
}
Expand Down Expand Up @@ -1299,3 +1354,14 @@ body.green.offer_view .announce {
background: var(--gc-dark-violet);
color: white;
}

.tag-list .tag-list__item {
background: #E8F0FA;
padding: 4px;
border-radius: 2px;
font-size: 11px;
color: #6487AE;
display: inline-block;
margin-bottom: 2px;
margin-top: 2px;
}
18 changes: 18 additions & 0 deletions app/assets/v2/images/townsquare-nh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/v2/images/townsqure-party.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/assets/v2/js/vue-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Vue.mixin({
};
},
methods: {
chatWindow: function(handle) {
chatWindow: function(handle, event) {
event.preventDefault();

let vm = this;

const url = handle ? `${vm.chatURL}/hackathons/messages/@${handle}` : `${vm.chatURL}/`;
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class FundRequestAdmin(admin.ModelAdmin):


class QuestionInline(SortableInlineAdminMixin, admin.TabularInline):
fields = ['id', 'poll', 'question_type', 'text']
fields = ['id', 'poll', 'question_type', 'text', 'hook']
readonly_fields = ['id']
raw_id_fields = ['poll']
show_change_link = True
Expand Down
38 changes: 38 additions & 0 deletions app/dashboard/migrations/0119_auto_20200609_1248.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 2.2.4 on 2020-06-09 12:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0118_auto_20200605_1302'),
]

operations = [
migrations.AddField(
model_name='hackathonregistration',
name='looking_project',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='hackathonregistration',
name='looking_team_members',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='question',
name='hook',
field=models.CharField(choices=[('NO_ACTION', 'No trigger any action'), ('TOWNSQUARE_INTRO', 'Create intro on Townsquare'), ('LOOKING_TEAM_PROJECT', 'Looking for team or project')], default='NO_ACTION', max_length=50),
),
migrations.AlterField(
model_name='activity',
name='activity_type',
field=models.CharField(blank=True, choices=[('wall_post', 'Wall Post'), ('status_update', 'Update status'), ('new_bounty', 'New Bounty'), ('start_work', 'Work Started'), ('stop_work', 'Work Stopped'), ('work_submitted', 'Work Submitted'), ('work_done', 'Work Done'), ('worker_approved', 'Worker Approved'), ('worker_rejected', 'Worker Rejected'), ('worker_applied', 'Worker Applied'), ('increased_bounty', 'Increased Funding'), ('killed_bounty', 'Canceled Bounty'), ('new_tip', 'New Tip'), ('receive_tip', 'Tip Received'), ('bounty_abandonment_escalation_to_mods', 'Escalated checkin from @gitcoinbot about bounty status'), ('bounty_abandonment_warning', 'Checkin from @gitcoinbot about bounty status'), ('bounty_removed_slashed_by_staff', 'Dinged and Removed from Bounty by Staff'), ('bounty_removed_by_staff', 'Removed from Bounty by Staff'), ('bounty_removed_by_funder', 'Removed from Bounty by Funder'), ('new_crowdfund', 'New Crowdfund Contribution'), ('new_grant', 'New Grant'), ('update_grant', 'Updated Grant'), ('killed_grant', 'Cancelled Grant'), ('negative_contribution', 'Negative Grant Contribution'), ('new_grant_contribution', 'Contributed to Grant'), ('new_grant_subscription', 'Subscribed to Grant'), ('killed_grant_contribution', 'Cancelled Grant Contribution'), ('new_kudos', 'New Kudos'), ('created_kudos', 'Created Kudos'), ('receive_kudos', 'Receive Kudos'), ('joined', 'Joined Gitcoin'), ('played_quest', 'Played Quest'), ('beat_quest', 'Beat Quest'), ('created_quest', 'Created Quest'), ('updated_avatar', 'Updated Avatar'), ('mini_clr_payout', 'Mini CLR Payout'), ('leaderboard_rank', 'Leaderboard Rank'), ('consolidated_leaderboard_rank', 'Consolidated Leaderboard Rank'), ('consolidated_mini_clr_payout', 'Consolidated CLR Payout'), ('hackathon_registration', 'Hackathon Registration'), ('hackathon_new_hacker', 'Hackathon Registration'), ('new_hackathon_project', 'New Hackathon Project'), ('flagged_grant', 'Flagged Grant')], db_index=True, max_length=50),
),
migrations.AlterField(
model_name='question',
name='question_type',
field=models.CharField(choices=[('SINGLE_OPTION', 'Single option'), ('SINGLE_CHOICE', 'Single Choice'), ('MULTIPLE_CHOICE', 'Multiple Choices'), ('OPEN', 'Open')], max_length=50),
),
]
69 changes: 61 additions & 8 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ class Activity(SuperModel):
('consolidated_leaderboard_rank', 'Consolidated Leaderboard Rank'),
('consolidated_mini_clr_payout', 'Consolidated CLR Payout'),
('hackathon_registration', 'Hackathon Registration'),
('hackathon_new_hacker', 'Hackathon Registration'),
('new_hackathon_project', 'New Hackathon Project'),
('flagged_grant', 'Flagged Grant'),
]
Expand Down Expand Up @@ -2575,6 +2576,8 @@ class HackathonRegistration(SuperModel):
blank=True
)
referer = models.URLField(null=True, blank=True, help_text='Url comes from')
looking_team_members = models.BooleanField(default=False)
looking_project = models.BooleanField(default=False)
registrant = models.ForeignKey(
'dashboard.Profile',
related_name='hackathon_registration',
Expand Down Expand Up @@ -2754,12 +2757,12 @@ def chat_num_unread_msgs(self):
chat_driver = Driver(driver_opts)
chat_driver.login()

response = chat_driver.client.make_request('get',
'/users/me/teams/unread',
options=None,
params=None,
data=None,
files=None,
response = chat_driver.client.make_request('get',
'/users/me/teams/unread',
options=None,
params=None,
data=None,
files=None,
basepath=None)
total_unread = sum(ele.get('msg_count', 0) for ele in response.json())
return total_unread
Expand Down Expand Up @@ -3166,7 +3169,7 @@ def get_desc(self, funded_bounties, fulfilled_bounties):

return f"@{self.handle} is a {role} who has participated in {total_funded_participated} " \
f"transaction{plural} on Gitcoin"


@property
def desc(self):
Expand Down Expand Up @@ -5007,13 +5010,21 @@ class Poll(SuperModel):
hackathon = models.ManyToManyField(HackathonEvent)



class Question(SuperModel):
TYPE_QUESTIONS = (
('SINGLE_OPTION', 'Single option'),
('SINGLE_CHOICE', 'Single Choice'),
('MULTIPLE_CHOICE', 'Multiple Choices'),
('OPEN', 'Open'),
)

TYPE_HOOKS = (
('NO_ACTION', 'No trigger any action'),
('TOWNSQUARE_INTRO', 'Create intro on Townsquare'),
('LOOKING_TEAM_PROJECT', 'Looking for team or project')
)

hook = models.CharField(default='NO_ACTION', choices=TYPE_HOOKS, max_length=50)
poll = models.ForeignKey(Poll, on_delete=models.CASCADE, null=True, blank=True)
question_type = models.CharField(choices=TYPE_QUESTIONS, max_length=50, blank=False, null=False)
text = models.CharField(max_length=350, blank=True, null=True)
Expand Down Expand Up @@ -5043,6 +5054,48 @@ class Answer(SuperModel):
hackathon = models.ForeignKey(HackathonEvent, null=True, on_delete=models.CASCADE)


@receiver(post_save, sender=Answer, dispatch_uid='hooks_on_question_response')
def psave_answer(sender, instance, created, **kwargs):
if created:
if instance.question.hook == 'TOWNSQUARE_INTRO':
registration = HackathonRegistration.objects.filter(hackathon=instance.hackathon,
registrant=instance.user.profile).first()

Activity.objects.create(
profile=instance.user.profile,
hackathonevent=instance.hackathon,
activity_type='hackathon_new_hacker',
metadata={
'answer': instance.id,
'intro_text': f'{instance.open_response or ""} #intro',
'looking_members': registration.looking_team_members if registration else False,
'looking_project': registration.looking_project if registration else False,
'hackathon_registration': registration.id if registration else 0
}
)
elif instance.question.hook == 'LOOKING_TEAM_PROJECT':
registration = HackathonRegistration.objects.filter(hackathon=instance.hackathon,
registrant=instance.user.profile).first()
print(instance)
if registration:
if instance.choice.text.lower().find('team') != -1:
registration.looking_team_members = True

if instance.choice.text.lower().find('project') != -1:
registration.looking_project = True

registration.save()

activity = Activity.objects.filter(
profile=instance.user.profile,
hackathonevent=instance.hackathon,
activity_type='hackathon_new_hacker').last()

if activity:
activity.metadata['looking_team_members'] = registration.looking_team_members
activity.metadata['looking_project'] = registration.looking_project
activity.save()

class Investigation(SuperModel):
profile = models.ForeignKey(
'dashboard.Profile', on_delete=models.CASCADE, related_name='investigations', blank=True
Expand Down
21 changes: 16 additions & 5 deletions app/dashboard/templates/dashboard/hackathon/onboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ <h4 class="text-uppercase font-weight-bolder text-left">How does the Hackathon w
</div>
</div>
<div class="modal" id="questions-form" tabindex="-1" data-backdrop="static" role="dialog" style="height: auto">
<div class="" role="document">
<div role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<a class="close" data-dismiss="modal" aria-label="Close" rel="modal:close">
<span aria-hidden="true">&times;</span>
</button>
</a>
</div>
<div class="px-5">
<form id="hackathon-poll">
Expand All @@ -312,11 +312,23 @@ <h4 class="text-uppercase font-weight-bolder text-left">How does the Hackathon w
{% for question in poll.question_set.all %}
<fieldset style="min-height: 200px" class="carousel-item {% if forloop.first %}active first{% elif forloop.last %}last{% endif %}" data-question="{{ question.id }}" data-step="{{ forloop.counter0 }}" data-rstep="{{ forloop.revcounter0 }}">
<div>
{% if question.question_type == 'SINGLE_CHOICE' %}
{% if question.question_type == 'SINGLE_OPTION' %}
<div class="form__checkbox">
<input type="checkbox" id="single_{{ question.id }}" name="{{ question.id }}">
<label class="form__label" for="single_{{ question.id }}">{{ question.text }}</label>
</div>
{% elif question.question_type == 'SINGLE_CHOICE' %}
<div class="question">
<h4 class="font-header font-weight-bold pt-0 mb-5">{{ forloop.counter }}. {{ question.text }}</h4>
<div class="options">
{% for option in question.option_set.all %}
<div class="px-1">
<input type="radio" id="multiple_{{ option.id }}" name="{{ question.id }}" value="{{ option.id }}">
<label for="multiple_{{ option.id }}">{{ option.text }}</label>
</div>
{% endfor %}
</div>
</div>
{% elif question.question_type == 'MULTIPLE_CHOICE' %}
<div class="question">
<h4 class="font-header font-weight-bold pt-0 mb-5">{{ forloop.counter }}. {{ question.text }}</h4>
Expand Down Expand Up @@ -472,7 +484,6 @@ <h4 class="font-header font-weight-bold pt-0 mb-5">{{ question.text }}</h4>
}
poll_manager.carousel('prev');
})

</script>
<script src="{% static 'v2/js/pages/hackathon-onboard.js' %}"></script>

Expand Down
Loading