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

Support to Open Response and link single poll to multiple hackathons #6669

Merged
merged 8 commits into from
May 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
7 changes: 3 additions & 4 deletions app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ class OptionsInline(admin.TabularInline):


class PollsAdmin(admin.ModelAdmin):
list_display = ['id', 'title', 'active', 'hackathon', 'created_on']
raw_id_fields = ['hackathon']
list_display = ['id', 'title', 'active']
search_fields = ['title']
inlines = [QuestionInline]

Expand All @@ -501,8 +500,8 @@ class OptionsAdmin(admin.ModelAdmin):


class AnswersAdmin(admin.ModelAdmin):
list_display = ['id', 'user', 'question', 'open_response', 'choice']
raw_id_fields = ['user', 'question', 'choice']
list_display = ['id', 'user', 'question', 'open_response', 'choice', 'checked', 'hackathon']
raw_id_fields = ['user', 'question', 'choice', 'hackathon']
unique_together = ('user', 'question', 'choice')


Expand Down
38 changes: 38 additions & 0 deletions app/dashboard/migrations/0109_auto_20200519_0226.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 2.2.4 on 2020-05-19 02:26

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0108_auto_20200513_0353'),
]

operations = [
migrations.AddField(
model_name='answer',
name='checked',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='answer',
name='hackathon',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.HackathonEvent'),
),
migrations.RemoveField(
model_name='poll',
name='hackathon',
),
migrations.AddField(
model_name='poll',
name='hackathon',
field=models.ManyToManyField(to='dashboard.HackathonEvent'),
),
migrations.AlterField(
model_name='question',
name='question_type',
field=models.CharField(choices=[('SINGLE_CHOICE', 'Single Choice'), ('MULTIPLE_CHOICE', 'Multiple Choices'), ('OPEN', 'Open')], max_length=50),
),
]
11 changes: 7 additions & 4 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4907,7 +4907,7 @@ class TribeMember(SuperModel):
max_length=20,
blank=True
)

@property
def mutual_follow(self):
return TribeMember.objects.filter(profile=self.org, org=self.profile).exists()
Expand All @@ -4922,17 +4922,18 @@ def mutual_following(self):
tribe_following = Subquery(TribeMember.objects.filter(org=self.profile).values_list('profile', flat=True))
return TribeMember.objects.filter(org__in=tribe_following, profile=self.org).exclude(org=self.org)


class Poll(SuperModel):
title = models.CharField(max_length=350, blank=True, null=True)
active = models.BooleanField(default=False)
hackathon = models.ForeignKey(HackathonEvent, on_delete=models.SET_NULL, null=True, blank=True)
hackathon = models.ManyToManyField(HackathonEvent)



class Question(SuperModel):
TYPE_QUESTIONS = (
('SINGLE_CHOICE', 'Single Choice'),
('MUTIPLE_CHOICE', 'Multiple Choices'),
('MULTIPLE_CHOICE', 'Multiple Choices'),
('OPEN', 'Open'),
)
poll = models.ForeignKey(Poll, on_delete=models.CASCADE, null=True, blank=True)
Expand All @@ -4956,3 +4957,5 @@ class Answer(SuperModel):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
open_response = models.CharField(max_length=350, blank=True, null=True)
choice = models.ForeignKey(Option, on_delete=models.CASCADE, null=True, blank=True)
checked = models.BooleanField(default=False)
hackathon = models.ForeignKey(HackathonEvent, null=True, on_delete=models.CASCADE)
94 changes: 72 additions & 22 deletions app/dashboard/templates/dashboard/hackathon/onboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@
.modal-header, .modal-body, .modal-footer {
border: none;
}

@media screen and (min-width: 598px) {
.options {
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body class="interior {{active}} g-font-muli">
Expand Down Expand Up @@ -312,38 +306,54 @@ <h4 class="text-uppercase font-weight-bolder text-left">How does the Hackathon w
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="">
<div class="px-5">
<form id="hackathon-poll">
<div id="poll_container" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
{% 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' %}
<div class="question">
<input type="checkbox" id="{{ question.id }}" name="{{ question.id }}">
<label for="{{ question.id }}">{{ question.text }}</label>
<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 == 'MUTIPLE_CHOICE' %}
{% elif question.question_type == 'MULTIPLE_CHOICE' %}
<div class="question">
<h4 class="font-header text-center font-weight-bold pt-0 mb-5">{{ question.text }}</h4>
<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>
<input type="checkbox" id="{{ option.id }}" name="{{ question.id }}" value="{{ option.id }}">
<label for="{{ option.id }}">{{ option.text }}</label>
<div class="px-1">
<input type="checkbox" id="multiple_{{ option.id }}" name="{{ question.id }}" value="{{ option.id }}">
<label for="multiple_{{ option.id }}">{{ option.text }}</label>
</div>
{% endfor %}
</div>
</div>
{% else %}
<div class="question">
<h4 class="font-header text-center">{{ question.text }}</h4>
<input type="text" name="{{ question.id }}">
<h4 class="font-header font-weight-bold pt-0 mb-5">{{ question.text }}</h4>
<textarea class="form-control" style="height: 120px" cols="10" rows="2" name="{{ question.id }}" ></textarea>
</div>
{% endif %}
</div>
</fieldset>
{% endfor %}
</div>
<div class="mt-5 mb-3 d-flex justify-content-between align-items-center">
<a id="poll-prev" class="btn-link gc-text-blue d-none" href="#" role="button" data-slide="prev">
< Previous
</a>
<div id="poll-empty"></div>
<a id="poll-submit" class="btn btn-lg btn-gc-blue {% if poll.question_set.count > 1%} d-none{% endif %}" href="#">Submit</a>
<a id="poll-next" class="btn btn-lg btn-gc-blue {% if poll.question_set.count <= 1%}d-none{% endif %}" href="#" role="button" data-slide="next">
Next >
</a>

</div>
</div>
</form>
</div>
<div class="modal-footer justify-content-center">
<button id="send_poll" class="btn btn-lg font-header btn-gc-blue mt-4 mb-4 px-4 px-md-5">Join Hackathon Now</button>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -373,8 +383,8 @@ <h4 class="font-header text-center">{{ question.text }}</h4>
});
} else {
$('#questions-form').modal('show');
$('#send_poll').unbind('click')
$('#send_poll').on('click', function () {
$('#poll-submit').unbind('click')
$('#poll-submit').on('click', function () {

const poll = $('#hackathon-poll').serializeArray();
const url = '/register_hackathon/';
Expand Down Expand Up @@ -424,6 +434,46 @@ <h4 class="font-header text-center">{{ question.text }}</h4>
}, 1000);
}

const poll_manager = $('#poll_container').carousel({
interval: false
})

$('[data-slide="next"]').click(function (e) {
e.preventDefault();
const fieldset = $('fieldset.active');

if (fieldset.data('rstep') === 1) {
$("#poll-prev").removeClass('d-none')
$("#poll-next").addClass('d-none')
$('#poll-empty').addClass('d-none')
$('#poll-submit').removeClass('d-none')
} else {
$("#poll-prev").removeClass('d-none')
$("#poll-next").removeClass('d-none')
$('#poll-empty').addClass('d-none')
$('#poll-submit').addClass('d-none')
}
poll_manager.carousel('next');
})

$('[data-slide="prev"]').click(function (e) {
e.preventDefault();
const fieldset = $('fieldset.active');

if (fieldset.data('step') === 1) {
$("#poll-prev").addClass('d-none')
$("#poll-next").removeClass('d-none')
$('#poll-empty').removeClass('d-none')
$('#poll-submit').addClass('d-none')
} else {
$("#poll-prev").removeClass('d-none')
$("#poll-next").removeClass('d-none')
$('#poll-empty').addClass('d-none')
$('#poll-submit').addClass('d-none')
}
poll_manager.carousel('prev');
})

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

Expand Down
26 changes: 19 additions & 7 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4017,16 +4017,28 @@ def hackathon_registration(request):
set_questions = {}
for entry in poll:
question = get_object_or_404(Question, id=int(entry['name']))
option = get_object_or_404(Option, id=int(entry['value']))

Answer.objects.get_or_create(user=request.user, question=question, choice=option)

values = set_questions.get(entry['name'], []) or []
values.append(int(entry['value']))
set_questions[entry['name']] = values
if question.question_type == 'SINGLE_CHOICE':
answer, status = Answer.objects.get_or_create(user=request.user, question=question,
hackathon=hackathon_event)
answer.checked = entry['value'] == 'on'
answer.save()
elif question.question_type == 'MULTIPLE_CHOICE':
option = get_object_or_404(Option, id=int(entry['value']))
Answer.objects.get_or_create(user=request.user, question=question, choice=option,
hackathon=hackathon_event)
values = set_questions.get(entry['name'], []) or []
values.append(int(entry['value']))
set_questions[entry['name']] = values
else:
answer, status = Answer.objects.get_or_create(user=request.user, question=question,
hackathon=hackathon_event)
answer.open_response = entry['value']
answer.save()

for (question, choices) in set_questions.items():
Answer.objects.exclude(user=request.user, question__id=int(question), choice__in=choices).delete()
Answer.objects.filter(user=request.user, question__id=int(question),
hackathon=hackathon_event).exclude(choice__in=choices).delete()

except Exception as e:
logger.error('Error while saving registration', e)
Expand Down