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

As a Gitcoin admin, I want an embedded survey for each Gitcoin hackathon so I know the motivations of each hacker #6128

Merged
merged 17 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
53 changes: 51 additions & 2 deletions app/dashboard/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
from .models import (
Activity, BlockedURLFilter, BlockedUser, Bounty, BountyEvent, BountyFulfillment, BountyInvites, BountySyncRequest,
CoinRedemption, CoinRedemptionRequest, Coupon, Earning, FeedbackEntry, HackathonEvent, HackathonProject,
HackathonRegistration, HackathonSponsor, Interest, LabsResearch, PortfolioItem, Profile, ProfileView, SearchHistory,
Sponsor, Tip, TipPayout, TokenApproval, Tool, ToolVote, TribeMember, UserAction, UserVerificationModel,
HackathonRegistration, HackathonSponsor, Interest, LabsResearch, PortfolioItem, Profile, ProfileView,
SearchHistory, Sponsor, Tip, TipPayout, TokenApproval, Tool, ToolVote, TribeMember, UserAction,
UserVerificationModel, Poll, Question, Option, Answer
)


Expand Down Expand Up @@ -410,6 +411,50 @@ class TribeMemberAdmin(admin.ModelAdmin):
list_display = ['pk', 'profile', 'org', 'leader', 'status']


class QuestionInline(admin.TabularInline):
fields = ['id', 'poll', 'question_type', 'text']
readonly_fields = ['id']
raw_id_fields = ['poll']
show_change_link = True
model = Question
extra = 0


class OptionsInline(admin.TabularInline):
zoek1 marked this conversation as resolved.
Show resolved Hide resolved
fields = ['id', 'question', 'text']
raw_id_fields = ['question']
readonly_fields = ['id']
show_change_link = True
model = Option
extra = 0


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


class QuestionsAdmin(admin.ModelAdmin):
list_display = ['id', 'poll', 'question_type', 'text']
raw_id_fields = ['poll']
search_fields = ['question_type', 'text']
inlines = [OptionsInline]


class OptionsAdmin(admin.ModelAdmin):
list_display = ['id', 'question', 'text']
raw_id_fields = ['question']
search_fields = ['question', 'text']


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


admin.site.register(BountyEvent, BountyEventAdmin)
admin.site.register(SearchHistory, SearchHistoryAdmin)
admin.site.register(Activity, ActivityAdmin)
Expand Down Expand Up @@ -442,3 +487,7 @@ class TribeMemberAdmin(admin.ModelAdmin):
admin.site.register(UserVerificationModel, VerificationAdmin)
admin.site.register(Coupon, CouponAdmin)
admin.site.register(TribeMember, TribeMemberAdmin)
admin.site.register(Poll, PollsAdmin)
admin.site.register(Question, QuestionsAdmin)
admin.site.register(Option, OptionsAdmin)
admin.site.register(Answer, AnswersAdmin)
78 changes: 78 additions & 0 deletions app/dashboard/migrations/0103_auto_20200428_1057.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Generated by Django 2.2.4 on 2020-04-28 10:57

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import economy.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('dashboard', '0102_auto_20200422_1452'),
]

operations = [
migrations.CreateModel(
name='Poll',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('title', models.CharField(blank=True, max_length=350, null=True)),
('active', models.BooleanField(default=False)),
('hackathon', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='dashboard.HackathonEvent')),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='sponsor',
name='tribe',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='dashboard.Profile'),
),
migrations.CreateModel(
name='Question',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('question_type', models.CharField(choices=[('SINGLE_CHOICE', 'Single Choice'), ('MUTIPLE_CHOICE', 'Multiple Choices'), ('OPEN', 'Open')], max_length=50)),
('text', models.CharField(blank=True, max_length=350, null=True)),
('poll', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.Poll')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Option',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('text', models.CharField(blank=True, max_length=350, null=True)),
('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.Question')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Answer',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('open_response', models.CharField(blank=True, max_length=350, null=True)),
('choice', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dashboard.Option')),
('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.Question')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]
36 changes: 36 additions & 0 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4424,6 +4424,7 @@ class Sponsor(SuperModel):
name = models.CharField(max_length=255, help_text='sponsor Name')
logo = models.ImageField(help_text='sponsor logo', blank=True)
logo_svg = models.FileField(help_text='sponsor logo svg', blank=True)
tribe = models.ForeignKey(Profile, null=True, on_delete=models.SET_NULL)

def __str__(self):
return self.name
Expand Down Expand Up @@ -4852,3 +4853,38 @@ class TribeMember(SuperModel):
max_length=20,
blank=True
)


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)


class Question(SuperModel):
TYPE_QUESTIONS = (
('SINGLE_CHOICE', 'Single Choice'),
('MUTIPLE_CHOICE', 'Multiple Choices'),
('OPEN', 'Open'),
)
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)

def __str__(self):
return f'Question.{self.id} {self.text}'


class Option(SuperModel):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
text = models.CharField(max_length=350, blank=True, null=True)

def __str__(self):
return f'Option.{self.id} {self.text}'


class Answer(SuperModel):
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
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)
Loading