From 55d068583357f091f4d06224bfaa3516252c91e5 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Wed, 26 Aug 2020 23:58:06 -0400 Subject: [PATCH] working --- config/settings.py | 5 +- homepage/forms.py | 21 +++-- homepage/migrations/0008_answer_time.py | 20 +++++ .../migrations/0009_auto_20200826_2331.py | 33 +++++++ .../migrations/0010_answer_question_text.py | 18 ++++ .../migrations/0011_auto_20200826_2014.py | 18 ++++ .../migrations/0012_auto_20200826_2354.py | 48 ++++++++++ homepage/models.py | 83 ++++++++++++++---- homepage/templates/homepage/create.html | 1 + homepage/templates/homepage/finish.html | 5 -- homepage/templates/homepage/index.html | 49 +++++++++-- homepage/templates/homepage/results.html | 48 ++++++++++ homepage/urls.py | 2 +- homepage/views.py | 26 ++++-- static/css/res/FuturaPTMedium.otf | Bin 0 -> 118072 bytes static/css/res/banner-wys.png | Bin 0 -> 715301 bytes static/css/res/banner.png | Bin 715301 -> 230443 bytes static/css/res/hilo-hero.png | Bin 0 -> 26865 bytes static/css/res/poll-mobile.png | Bin 0 -> 168531 bytes static/css/res/poll.png | Bin 0 -> 99355 bytes static/css/res/results-mobile-noinsta.png | Bin 0 -> 81613 bytes static/css/res/results-mobile.png | Bin 0 -> 102433 bytes static/css/res/results-noinsta.png | Bin 0 -> 58257 bytes static/css/res/results.png | Bin 0 -> 66896 bytes static/css/styles.css | 77 +++++++++------- static/css/styles.scss | 74 +++++++++++----- 26 files changed, 426 insertions(+), 102 deletions(-) create mode 100644 homepage/migrations/0008_answer_time.py create mode 100644 homepage/migrations/0009_auto_20200826_2331.py create mode 100644 homepage/migrations/0010_answer_question_text.py create mode 100644 homepage/migrations/0011_auto_20200826_2014.py create mode 100644 homepage/migrations/0012_auto_20200826_2354.py create mode 100644 homepage/templates/homepage/create.html delete mode 100644 homepage/templates/homepage/finish.html create mode 100644 homepage/templates/homepage/results.html create mode 100644 static/css/res/FuturaPTMedium.otf create mode 100644 static/css/res/banner-wys.png create mode 100644 static/css/res/hilo-hero.png create mode 100644 static/css/res/poll-mobile.png create mode 100644 static/css/res/poll.png create mode 100644 static/css/res/results-mobile-noinsta.png create mode 100644 static/css/res/results-mobile.png create mode 100644 static/css/res/results-noinsta.png create mode 100644 static/css/res/results.png diff --git a/config/settings.py b/config/settings.py index df967cb..e8d929b 100755 --- a/config/settings.py +++ b/config/settings.py @@ -39,7 +39,8 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'widget_tweaks', - 'django_cleanup' + 'django_cleanup', + 'profanity' ] MIDDLEWARE = [ @@ -108,7 +109,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'UTC' +TIME_ZONE = 'America/New_York' USE_I18N = True diff --git a/homepage/forms.py b/homepage/forms.py index a55987a..11af0b8 100644 --- a/homepage/forms.py +++ b/homepage/forms.py @@ -1,16 +1,21 @@ from django import forms from django.contrib.auth.models import User -import re +from profanity.validators import validate_is_profane from .models import Answer, EMOTION_CHOICES class PollForm(forms.ModelForm): - hi = forms.CharField(max_length=200, required=True) - lo = forms.CharField(max_length=200, required=True) - emotion = forms.ChoiceField(widget=forms.RadioSelect, choices=EMOTION_CHOICES, required=True) - name = forms.CharField(max_length=100) - place = forms.CharField(max_length=100) - question = forms.CharField(max_length=200) + hi = forms.CharField(max_length=200, validators=[validate_is_profane], required=False) + lo = forms.CharField(max_length=200, validators=[validate_is_profane], required=False) + emotion = forms.ChoiceField(widget=forms.RadioSelect, choices=EMOTION_CHOICES, required=False) + name = forms.CharField(max_length=100, validators=[validate_is_profane], required=False) + place = forms.CharField(max_length=100, validators=[validate_is_profane], required=False) + question = forms.CharField(max_length=200, validators=[validate_is_profane], required=False) + + def __init__(self, *args, **kwargs): + super(PollForm, self).__init__(*args, **kwargs) + self.initial['emotion'] = 'meh' + self.fields['emotion'] = forms.ChoiceField(widget=forms.RadioSelect, choices=EMOTION_CHOICES) class Meta: model = Answer - fields = ['hi', 'lo', 'emotion', 'name', 'place', 'question'] \ No newline at end of file + fields = ['hi', 'lo', 'emotion', 'name', 'place','question'] \ No newline at end of file diff --git a/homepage/migrations/0008_answer_time.py b/homepage/migrations/0008_answer_time.py new file mode 100644 index 0000000..64489cc --- /dev/null +++ b/homepage/migrations/0008_answer_time.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1 on 2020-08-26 20:11 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0007_location_hero_mobile'), + ] + + operations = [ + migrations.AddField( + model_name='answer', + name='time', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='time answered'), + preserve_default=False, + ), + ] diff --git a/homepage/migrations/0009_auto_20200826_2331.py b/homepage/migrations/0009_auto_20200826_2331.py new file mode 100644 index 0000000..fa2565e --- /dev/null +++ b/homepage/migrations/0009_auto_20200826_2331.py @@ -0,0 +1,33 @@ +# Generated by Django 3.1 on 2020-08-26 23:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0008_answer_time'), + ] + + operations = [ + migrations.AddField( + model_name='location', + name='insta', + field=models.CharField(blank=True, max_length=20, null=True), + ), + migrations.AddField( + model_name='location', + name='results', + field=models.ImageField(default='results.png', upload_to='results'), + ), + migrations.AddField( + model_name='location', + name='results_mobile', + field=models.ImageField(default='results-mobile.png', upload_to='results'), + ), + migrations.AlterField( + model_name='answer', + name='time', + field=models.DateTimeField(blank=True, null=True, verbose_name='time answered'), + ), + ] diff --git a/homepage/migrations/0010_answer_question_text.py b/homepage/migrations/0010_answer_question_text.py new file mode 100644 index 0000000..9806a75 --- /dev/null +++ b/homepage/migrations/0010_answer_question_text.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-08-26 23:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0009_auto_20200826_2331'), + ] + + operations = [ + migrations.AddField( + model_name='answer', + name='question_text', + field=models.CharField(blank=True, max_length=50, null=True), + ), + ] diff --git a/homepage/migrations/0011_auto_20200826_2014.py b/homepage/migrations/0011_auto_20200826_2014.py new file mode 100644 index 0000000..f6158f5 --- /dev/null +++ b/homepage/migrations/0011_auto_20200826_2014.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-08-27 00:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0010_answer_question_text'), + ] + + operations = [ + migrations.RenameField( + model_name='answer', + old_name='question_text', + new_name='current_question', + ), + ] diff --git a/homepage/migrations/0012_auto_20200826_2354.py b/homepage/migrations/0012_auto_20200826_2354.py new file mode 100644 index 0000000..7b5fcb7 --- /dev/null +++ b/homepage/migrations/0012_auto_20200826_2354.py @@ -0,0 +1,48 @@ +# Generated by Django 3.1 on 2020-08-27 03:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('homepage', '0011_auto_20200826_2014'), + ] + + operations = [ + migrations.AlterField( + model_name='answer', + name='current_question', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AlterField( + model_name='poll', + name='emotion_text', + field=models.CharField(blank=True, default='how are you feeling today?', max_length=100, null=True), + ), + migrations.AlterField( + model_name='poll', + name='hi_text', + field=models.CharField(blank=True, default='What was the Hi of this we', max_length=100, null=True), + ), + migrations.AlterField( + model_name='poll', + name='lo_text', + field=models.CharField(blank=True, default='What was the Lo of this we', max_length=100, null=True), + ), + migrations.AlterField( + model_name='poll', + name='name_text', + field=models.CharField(blank=True, default="what's your name?", max_length=100, null=True), + ), + migrations.AlterField( + model_name='poll', + name='place_text', + field=models.CharField(blank=True, default='where are you from?', max_length=100, null=True), + ), + migrations.AlterField( + model_name='poll', + name='question_text', + field=models.CharField(blank=True, max_length=100, null=True), + ), + ] diff --git a/homepage/models.py b/homepage/models.py index aeef0a8..e718dfc 100755 --- a/homepage/models.py +++ b/homepage/models.py @@ -1,6 +1,9 @@ from django.db import models import os +from django.utils import timezone +import pytz + from django.core.files import File @@ -8,6 +11,7 @@ from django.conf import settings from django.templatetags.static import static from django.utils.text import slugify + from PIL import Image, ImageDraw, ImageFont # Create your models here. @@ -15,33 +19,53 @@ from PIL import Image, ImageDraw, ImageFont class Location (models.Model): name = models.CharField(max_length=20, blank=True, null=True) slug = models.CharField(max_length=20, blank=True, null=True) + insta = models.CharField(max_length=20, blank=True, null=True) hero = models.ImageField(default="hero.png", upload_to='heros') hero_mobile = models.ImageField(default="hero-mobile.png", upload_to='heros') + results = models.ImageField(default="results.png", upload_to='results') + results_mobile = models.ImageField(default="results-mobile.png", upload_to='results') + def __str__(self): return self.name def save(self, *args, **kwargs): + def drawPic (input, output, font, x, y, text): + img = Image.open(input) + draw = ImageDraw.Draw(img) + draw.text((x,y), text, (255,255,255), font=font) + img.save(output) + self.slug = slugify(self.name) self.hero = f'heros/hero-{self.slug}.png' self.hero_mobile = f'heros/hero-{self.slug}-mobile.png' + if self.insta is not None and self.insta is not '' and self.insta[0] is not '@': + self.insta = '@' + self.insta + + self.results = f'results/results-{self.slug}.png' + self.results_mobile = f'results/results-{self.slug}-mobile.png' super().save(*args, **kwargs) output = f'{settings.PROJECT_PATH}/media/heros/hero-{self.slug}.png' mobile_output = f'{settings.PROJECT_PATH}/media/heros/hero-{self.slug}-mobile.png' - - img = Image.open(settings.PROJECT_PATH + static("css/res/hero.png")) - draw = ImageDraw.Draw(img) font = ImageFont.truetype(settings.PROJECT_PATH + static("css/fonts/Shorelines-Script-Bold.otf"), 80) - draw.text((1050,450), self.slug, (255,255,255), font=font) - img.save(output) - img = Image.open(settings.PROJECT_PATH + static("css/res/hero-mobile.png")) - draw = ImageDraw.Draw(img) - font = ImageFont.truetype(settings.PROJECT_PATH + static("css/fonts/Shorelines-Script-Bold.otf"), 80) - draw.text((420,860), self.slug, (255,255,255), font=font) - img.save(mobile_output) + drawPic (settings.PROJECT_PATH + static("css/res/hero.png"), output, font, 1050, 450, self.slug) + drawPic (settings.PROJECT_PATH + static("css/res/hero-mobile.png"), mobile_output, font, 420, 860, self.slug) + + output = f'{settings.PROJECT_PATH}/media/results/results-{self.slug}.png' + mobile_output = f'{settings.PROJECT_PATH}/media/results/results-{self.slug}-mobile.png' + font = ImageFont.truetype(settings.PROJECT_PATH + static("css/fonts/FuturaPTMedium.otf"), 60) + + if self.insta is not None and self.insta is not '': + drawPic (settings.PROJECT_PATH + static("css/res/results.png"), output, font, 735, 805, self.insta) + drawPic (settings.PROJECT_PATH + static("css/res/results-mobile.png"), mobile_output, font, 360, 1380, self.insta) + else: + img = Image.open(settings.PROJECT_PATH + static("css/res/results-noinsta.png")) + img.save(output) + img = Image.open(settings.PROJECT_PATH + static("css/res/results-mobile-noinsta.png")) + img.save(mobile_output) @@ -49,22 +73,22 @@ class Poll (models.Model): location = models.OneToOneField(Location, on_delete=models.CASCADE) ask_hi = models.BooleanField(default=True) - hi_text = models.CharField(max_length=50, blank=True, null=True, default='What was the Hi of this we') + hi_text = models.CharField(max_length=100, blank=True, null=True, default='What was the Hi of this we') ask_lo = models.BooleanField(default=True) - lo_text = models.CharField(max_length=50, blank=True, null=True, default='What was the Lo of this we') + lo_text = models.CharField(max_length=100, blank=True, null=True, default='What was the Lo of this we') ask_emotion = models.BooleanField(default=True) - emotion_text = models.CharField(max_length=50, blank=True, null=True, default="how are you feeling today?") + emotion_text = models.CharField(max_length=100, blank=True, null=True, default="how are you feeling today?") ask_name = models.BooleanField(default=True) - name_text = models.CharField(max_length=50, blank=True, null=True, default="what's your name?") + name_text = models.CharField(max_length=100, blank=True, null=True, default="what's your name?") ask_place = models.BooleanField(default=True) - place_text = models.CharField(max_length=50, blank=True, null=True, default="where are you from?") + place_text = models.CharField(max_length=100, blank=True, null=True, default="where are you from?") ask_question = models.BooleanField(default=False) - question_text = models.CharField(max_length=50, blank=True, null=True) + question_text = models.CharField(max_length=100, blank=True, null=True) pub_date = models.DateTimeField('date published') @@ -86,7 +110,32 @@ class Answer (models.Model): emotion = models.CharField(max_length=8, default='meh', choices=EMOTION_CHOICES, blank=True, null=True) name = models.CharField(max_length=100, blank=True, null=True) place = models.CharField(max_length=100, blank=True, null=True) + current_question = models.CharField(max_length=100, blank=True, null=True) question = models.CharField(max_length=200, blank=True, null=True) + time = models.DateTimeField('time answered', blank=True, null=True) + + def save(self, *args, **kwargs): + self.time = timezone.now() + if self.hi is '': + self.hi = "Not stated" + + if self.lo is '': + self.lo = "Not stated" + + if self.name is '': + self.name = "Anonymous" + + if self.place is '': + self.place = "Somewhere" + + if self.question is '': + self.question = "Not stated" + + if self.current_question is '': + self.current_question = self.poll.question_text + + super().save(self, *args, **kwargs) + def __str__(self): - return self.name \ No newline at end of file + return f"{self.name}'s response on {self.poll.location.name} at {self.time.strftime('%m/%d/%Y, %H:%M:%S')}" \ No newline at end of file diff --git a/homepage/templates/homepage/create.html b/homepage/templates/homepage/create.html new file mode 100644 index 0000000..a16aec7 --- /dev/null +++ b/homepage/templates/homepage/create.html @@ -0,0 +1 @@ +create.html diff --git a/homepage/templates/homepage/finish.html b/homepage/templates/homepage/finish.html deleted file mode 100644 index e8fc68c..0000000 --- a/homepage/templates/homepage/finish.html +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'homepage/base.html' %} -{% load static %} - -{% block content %} -{% enblock %} \ No newline at end of file diff --git a/homepage/templates/homepage/index.html b/homepage/templates/homepage/index.html index 3d9ddf7..9173ef1 100755 --- a/homepage/templates/homepage/index.html +++ b/homepage/templates/homepage/index.html @@ -4,6 +4,17 @@ {% block content %} +
@@ -52,8 +63,8 @@

-
-
+
+
{% if messages %} {% for message in messages %} @@ -65,31 +76,41 @@
{% endfor %} {% endif %} -
+ + {% csrf_token %} {% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} + + + {{ form.errors }} + {{ form.non_field_errors }} +
-

NOW IS YOUR TIME TO SHINE

+

NOW IS YOUR TIME TO SHINE

{% if hi_text %}
- {{ form.hi|add_class:'w-75 mx-auto rounded' }} + {{ form.hi|add_class:'w-80 mx-auto rounded' }} {% for error in form.hi.errors %} {{ error }} {% endfor %}
+ {% else %} + {{ form.hi|add_class:'hidden' }} {% endif %} {% if lo_text %}
- {{ form.lo|add_class:'w-75 mx-auto rounded' }} + {{ form.lo|add_class:'w-80 mx-auto rounded' }} {% for error in form.lo.errors %} {{ error }} {% endfor %}
+ {% else %} + {{ form.lo|add_class:'hidden' }} {% endif %}

SOME MORE QUESTIONS FOR THE SOUL

@@ -109,33 +130,43 @@
{% endfor %}
+ {% else %} + {% for radio in form.emotion %} + {{ radio.tag|add_class:'hidden' }} + {% endfor %} {% endif %} {% if name_text %}
- {{ form.name|add_class:'w-75 mx-auto rounded' }} + {{ form.name|add_class:'w-80 mx-auto rounded' }} {% for error in form.name.errors %} {{ error }} {% endfor %}
+ {% else %} + {{ form.name|add_class:'hidden' }} {% endif %} {% if place_text %}
- {{ form.place|add_class:'w-75 mx-auto rounded' }} + {{ form.place|add_class:'w-80 mx-auto rounded' }} {% for error in form.place.errors %} {{ error }} {% endfor %}
+ {% else %} + {{ form.place|add_class:'hidden' }} {% endif %} {% if question_text %}
- {{ form.question|add_class:'w-75 mx-auto rounded' }} + {{ form.question|add_class:'w-80 mx-auto rounded' }} {% for error in form.question.errors %} {{ error }} {% endfor %}
+ {% else %} + {{ form.question|add_class:'hidden' }} {% endif %}