Browse Source

small tweaks

pull/10/head
crunch 4 months ago
parent
commit
782d9365b2
5 changed files with 31 additions and 67 deletions
  1. +0
    -1
      Consulta_project/landing/static/js/script.min.js
  2. +2
    -13
      Consulta_project/landing/templates/landing/index_base.html
  3. +10
    -2
      Consulta_project/polls/models.py
  4. +5
    -5
      Consulta_project/polls/serializers.py
  5. +14
    -46
      Consulta_project/polls/templates/polls/stats.html

+ 0
- 1
Consulta_project/landing/static/js/script.min.js View File

@@ -1 +0,0 @@
$(document).ready(function(){$("[data-bs-tooltip]").tooltip(),$("[data-bs-chart]").each(function(t,a){this.chart=new Chart($(a),$(a).data("bs-chart"))})});

+ 2
- 13
Consulta_project/landing/templates/landing/index_base.html View File

@@ -11,6 +11,8 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Bitter:400,700">
<link href="https://fonts.googleapis.com/css?family=Inter&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{% static "css/styles.min.css" %}">
{% block misc_scripts %}
{% endblock misc_scripts %}
</head>

<body style="font-family: Inter;">
@@ -60,20 +62,7 @@
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
<script src="/static/js/script.min.js"></script>

<!-- Optional JavaScript
jQuery first, then Popper.js, then Bootstrap JS
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script> -->
</body>

</html>

+ 10
- 2
Consulta_project/polls/models.py View File

@@ -2,6 +2,7 @@ from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User
from django.core.serializers import json
import json

# Create your models here.

@@ -57,8 +58,12 @@ class Question(models.Model):
answers.append(answer.id)
return answers

def __str__(self):
return self.question_string
def answer_strings(self):
answer_strings = []

for answer in self.get_answers():
answer_strings.append(answer.answer_string)
return answer_strings

def get_owner(self):
return self.user
@@ -66,6 +71,9 @@ class Question(models.Model):
def get_absolute_url(self):
return reverse('question-detail', args=[self.poll.slug, self.pk, ])

def __str__(self):
return self.question_string

def get_answers(self):
return Answer.objects.filter(question=self)



+ 5
- 5
Consulta_project/polls/serializers.py View File

@@ -7,12 +7,12 @@ class PollSerializer(serializers.HyperlinkedModelSerializer):
model = Poll
fields = ['id', 'name', 'semester', 'topic', 'lecture', 'url', 'questions']

class QuestionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Question
fields = ['id', 'question_string', 'poll', 'answers']

class AnswerSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Answer
fields = ['id', 'answer_string', 'count', 'question',]

class QuestionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Question
fields = ['id', 'question_string', 'poll', 'answers']

+ 14
- 46
Consulta_project/polls/templates/polls/stats.html View File

@@ -1,7 +1,14 @@
{% extends "landing/index_base.html" %}
{% block content %}
{% load static %}

{% block misc_scripts %}
<link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
<script type="text/javascript" src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
{% endblock misc_scripts %}

{% block content %}


<div class="d-flex justify-content-center align-items-center" style="background-color: rgba(0,0,0,0.1);margin-top: 30px;font-family: Inter;min-height: 75vh;">
<div class="container justify-content-center" style="padding-bottom: 30px;padding-top: 30px;">
<div class="row d-flex justify-content-center align-items-center">
@@ -22,10 +29,13 @@
</div>
<div class="row d-flex justify-content-center align-items-center">
<div class="col-auto" style="margin-top: 15px;margin-bottom: 15px;">
<div style="padding-top: 20px;padding-bottom: 10px;"><canvas data-bs-chart="{&quot;type&quot;:&quot;bar&quot;,&quot;data&quot;:{&quot;labels&quot;:[&quot;Yes&quot;,&quot;No&quot;,&quot;I don't know&quot;],&quot;datasets&quot;:[{&quot;label&quot;:&quot;Vote Count&quot;,&quot;backgroundColor&quot;:&quot;#282d32&quot;,&quot;borderColor&quot;:&quot;rgb(0,188,140)&quot;,&quot;borderWidth&quot;:&quot;1&quot;,&quot;data&quot;:[&quot;6&quot;,&quot;5&quot;,&quot;4&quot;]}]},&quot;options&quot;:{&quot;maintainAspectRatio&quot;:true,&quot;legend&quot;:{&quot;display&quot;:false},&quot;title&quot;:{&quot;display&quot;:false,&quot;text&quot;:&quot;&quot;,&quot;position&quot;:&quot;top&quot;},&quot;scales&quot;:{&quot;xAxes&quot;:[{&quot;gridLines&quot;:{&quot;color&quot;:&quot;rgb(0,188,140)&quot;,&quot;zeroLineColor&quot;:&quot;rgb(0,188,140)&quot;,&quot;drawBorder&quot;:true,&quot;drawTicks&quot;:true,&quot;borderDash&quot;:[&quot;3&quot;],&quot;zeroLineBorderDash&quot;:[&quot;3&quot;],&quot;drawOnChartArea&quot;:true},&quot;ticks&quot;:{&quot;fontColor&quot;:&quot;#dfe7f1&quot;,&quot;beginAtZero&quot;:true,&quot;padding&quot;:0}}],&quot;yAxes&quot;:[{&quot;gridLines&quot;:{&quot;color&quot;:&quot;rgb(0,188,140)&quot;,&quot;zeroLineColor&quot;:&quot;rgb(0,188,140)&quot;,&quot;drawBorder&quot;:true,&quot;drawTicks&quot;:true,&quot;borderDash&quot;:[&quot;3&quot;],&quot;zeroLineBorderDash&quot;:[&quot;3&quot;],&quot;drawOnChartArea&quot;:false},&quot;ticks&quot;:{&quot;fontColor&quot;:&quot;#dfe7f1&quot;,&quot;beginAtZero&quot;:true,&quot;padding&quot;:0}}]}}}"></canvas></div>
<div class="ct-chart-{{ question.id }} ct-perfect-fourth" style="padding-top: 20px;padding-bottom: 10px;" data-id={{ question.id }}>
</div>
</div>
<div class="col-auto" style="margin-top: 15px;margin-bottom: 15px;">
<div style="padding-top: 20px;padding-bottom: 10px;"><canvas data-bs-chart="{&quot;type&quot;:&quot;pie&quot;,&quot;data&quot;:{&quot;labels&quot;:[&quot;Yes&quot;,&quot;No&quot;,&quot;I don't know&quot;],&quot;datasets&quot;:[{&quot;label&quot;:&quot;Vote Count&quot;,&quot;backgroundColor&quot;:[&quot;#505e6c&quot;,&quot;#f4476b&quot;,&quot;#282d32&quot;],&quot;borderColor&quot;:[&quot;rgb(0,188,140)&quot;,&quot;rgb(0,188,140)&quot;,&quot;rgb(0,188,140)&quot;],&quot;data&quot;:[&quot;5&quot;,&quot;6&quot;,&quot;4&quot;]}]},&quot;options&quot;:{&quot;maintainAspectRatio&quot;:true,&quot;legend&quot;:{&quot;display&quot;:true,&quot;position&quot;:&quot;left&quot;,&quot;reverse&quot;:false},&quot;title&quot;:{&quot;display&quot;:false,&quot;text&quot;:&quot;&quot;,&quot;position&quot;:&quot;top&quot;}}}"></canvas></div>
<div style="padding-top: 20px;padding-bottom: 10px;">
</div>
</div>
</div>
@@ -55,47 +65,5 @@
{% endfor %}
</div>
</div>

<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
<script src="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>

<div class="container" style="text-align: center; margin-top: 6em;">

<h2>Poll: {{ poll.name }}</h2>

<p id="poll-id" style="display: none;">{{ poll.id }}</p>

<div class="ct-chart"></div>

<hr>

{% for question in poll.get_questions %}


{% if question.get_answers %}
<h3 data-id={{ question.id }}>Question: {{ question.question_string }}</h3>

<div class="ct-chart-{{ question.id }}"></div>

{% else %}

<h3>Question: {{ question.question_string }}</h3>

<p>There are no answers to this question.</p>

{% endif %}

<br>

{% empty %}

<p>There are no questions in this poll.</p>

{% endfor %}

</div>

<script src="{% static 'js/stats.js' %}"></script> -->

<script type="text/javascript" src="{% static 'js/stats.js' %}"></script>
{% endblock content %}

Loading…
Cancel
Save