creates heros automagically, added loc model, and other things!
|
@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'widget_tweaks',
|
||||
'django_cleanup'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -123,3 +124,10 @@ STATIC_URL = '/static/'
|
|||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, "static"),
|
||||
]
|
||||
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
MEDIA_URL = '/media/'
|
||||
|
||||
PROJECT_PATH = os.path.abspath(os.path.dirname(__name__))
|
|
@ -15,9 +15,13 @@ Including another URLconf
|
|||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from django.conf.urls.static import static
|
||||
from django.conf import settings
|
||||
|
||||
urlpatterns = [
|
||||
path ('admin/', admin.site.urls),
|
||||
path ('', include('homepage.urls')),
|
||||
path ('admin/', include('admin.urls')),
|
||||
path( 'adminpanel/', admin.site.urls),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
|
@ -1,7 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from .models import Poll, Answer
|
||||
from .models import Poll, Answer, Location
|
||||
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(Location)
|
||||
admin.site.register(Poll)
|
||||
admin.site.register(Answer)
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.0.8 on 2020-08-25 21:41
|
||||
# Generated by Django 3.1 on 2020-08-26 17:28
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -12,23 +12,31 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Location',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(blank=True, max_length=20, null=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Poll',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('askHi', models.BooleanField(default=True)),
|
||||
('HiText', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('askLo', models.BooleanField(default=True)),
|
||||
('LoText', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('askEmotion', models.BooleanField(default=True)),
|
||||
('EmotionText', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('askName', models.BooleanField(default=True)),
|
||||
('NameText', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('askPlace', models.BooleanField(default=True)),
|
||||
('PlaceText', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('askQuestion', models.BooleanField(default=True)),
|
||||
('QuestionText', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('ask_hi', models.BooleanField(default=True)),
|
||||
('hi_text', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('ask_lo', models.BooleanField(default=True)),
|
||||
('lo_text', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('ask_emotion', models.BooleanField(default=True)),
|
||||
('emotion_text', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('ask_name', models.BooleanField(default=True)),
|
||||
('name_text', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('ask_place', models.BooleanField(default=True)),
|
||||
('place_text', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('ask_question', models.BooleanField(default=False)),
|
||||
('question_text', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('pub_date', models.DateTimeField(verbose_name='date published')),
|
||||
('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.location')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
|
@ -37,9 +45,11 @@ class Migration(migrations.Migration):
|
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('hi', models.CharField(blank=True, max_length=200, null=True)),
|
||||
('lo', models.CharField(blank=True, max_length=200, null=True)),
|
||||
('name', models.CharField(blank=True, max_length=200, null=True)),
|
||||
('place', models.CharField(blank=True, max_length=200, null=True)),
|
||||
('poll', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.Poll')),
|
||||
('emotion', models.CharField(blank=True, choices=[('happy', 'Happy'), ('meh', 'Meh'), ('sad', 'Sad')], default='meh', max_length=8, null=True)),
|
||||
('name', models.CharField(blank=True, max_length=100, null=True)),
|
||||
('place', models.CharField(blank=True, max_length=100, null=True)),
|
||||
('question', models.CharField(blank=True, max_length=200, null=True)),
|
||||
('poll', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.poll')),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-08-25 21:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='answer',
|
||||
name='emotion',
|
||||
field=models.CharField(blank=True, max_length=200, null=True),
|
||||
),
|
||||
]
|
38
homepage/migrations/0002_auto_20200826_1732.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Generated by Django 3.1 on 2020-08-26 17:32
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='poll',
|
||||
name='emotion_text',
|
||||
field=models.CharField(blank=True, default='how are you feeling today?', max_length=50, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='poll',
|
||||
name='hi_text',
|
||||
field=models.CharField(blank=True, default='What was the <span class="hi">Hi</span> of this we', max_length=50, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='poll',
|
||||
name='lo_text',
|
||||
field=models.CharField(blank=True, default='What was the <span class="lo">Lo</span> of this we', max_length=50, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='poll',
|
||||
name='name_text',
|
||||
field=models.CharField(blank=True, default="what's your name?", max_length=50, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='poll',
|
||||
name='place_text',
|
||||
field=models.CharField(blank=True, default='where are you from?', max_length=50, null=True),
|
||||
),
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-08-25 22:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0002_answer_emotion'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='answer',
|
||||
name='emotion',
|
||||
field=models.CharField(blank=True, choices=[('happy', 'Happy'), ('meh', 'Meh'), ('sad', 'Sad')], default='meh', max_length=8, null=True),
|
||||
),
|
||||
]
|
19
homepage/migrations/0003_auto_20200826_1738.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 3.1 on 2020-08-26 17:38
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0002_auto_20200826_1732'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='poll',
|
||||
name='location',
|
||||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='homepage.location'),
|
||||
),
|
||||
]
|
|
@ -1,73 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-08-25 22:33
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0003_auto_20200825_2220'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='askEmotion',
|
||||
new_name='ask_emotion',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='askHi',
|
||||
new_name='ask_hi',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='askLo',
|
||||
new_name='ask_lo',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='askName',
|
||||
new_name='ask_name',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='askPlace',
|
||||
new_name='ask_place',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='askQuestion',
|
||||
new_name='ask_question',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='EmotionText',
|
||||
new_name='emotion_text',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='HiText',
|
||||
new_name='hi_text',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='LoText',
|
||||
new_name='lo_text',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='NameText',
|
||||
new_name='name_text',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='PlaceText',
|
||||
new_name='place_text',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='poll',
|
||||
old_name='QuestionText',
|
||||
new_name='question_text',
|
||||
),
|
||||
]
|
23
homepage/migrations/0004_auto_20200826_1831.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.1 on 2020-08-26 18:31
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0003_auto_20200826_1738'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='location',
|
||||
name='hero',
|
||||
field=models.ImageField(default='hero.png', upload_to='heros'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='location',
|
||||
name='slug',
|
||||
field=models.CharField(blank=True, max_length=20, null=True),
|
||||
),
|
||||
]
|
18
homepage/migrations/0005_auto_20200826_1843.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1 on 2020-08-26 18:43
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0004_auto_20200826_1831'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='location',
|
||||
name='hero',
|
||||
field=models.ImageField(default='hero.png', upload_to='heros/<django.db.models.fields.CharField>-hero.png'),
|
||||
),
|
||||
]
|
18
homepage/migrations/0006_auto_20200826_1858.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1 on 2020-08-26 18:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0005_auto_20200826_1843'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='location',
|
||||
name='hero',
|
||||
field=models.ImageField(default='hero.png', upload_to='heros'),
|
||||
),
|
||||
]
|
18
homepage/migrations/0007_location_hero_mobile.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1 on 2020-08-26 19:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('homepage', '0006_auto_20200826_1858'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='location',
|
||||
name='hero_mobile',
|
||||
field=models.ImageField(default='hero-mobile.png', upload_to='heros'),
|
||||
),
|
||||
]
|
|
@ -1,22 +1,67 @@
|
|||
from django.db import models
|
||||
|
||||
import os
|
||||
|
||||
from django.core.files import File
|
||||
|
||||
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.
|
||||
|
||||
class Location (models.Model):
|
||||
name = models.CharField(max_length=20, blank=True, null=True)
|
||||
slug = 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')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.slug = slugify(self.name)
|
||||
self.hero = f'heros/hero-{self.slug}.png'
|
||||
self.hero_mobile = f'heros/hero-{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)
|
||||
|
||||
|
||||
|
||||
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)
|
||||
hi_text = models.CharField(max_length=50, blank=True, null=True, default='What was the <span class="hi">Hi</span> of this we')
|
||||
|
||||
ask_lo = models.BooleanField(default=True)
|
||||
lo_text = models.CharField(max_length=50, blank=True, null=True)
|
||||
lo_text = models.CharField(max_length=50, blank=True, null=True, default='What was the <span class="lo">Lo</span> of this we')
|
||||
|
||||
ask_emotion = models.BooleanField(default=True)
|
||||
emotion_text = models.CharField(max_length=50, blank=True, null=True)
|
||||
emotion_text = models.CharField(max_length=50, 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)
|
||||
name_text = models.CharField(max_length=50, 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)
|
||||
place_text = models.CharField(max_length=50, 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)
|
||||
|
@ -24,7 +69,7 @@ class Poll (models.Model):
|
|||
pub_date = models.DateTimeField('date published')
|
||||
|
||||
def __str__(self):
|
||||
return 'Current Poll'
|
||||
return f"{self.location.name}'s Poll"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,5 +3,6 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path ('', views.homepage, name="homepage"),
|
||||
path ('<slug:slug>/', views.homepage),
|
||||
path ('finish/', views.finish, name="finish")
|
||||
]
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.http import HttpResponseNotFound
|
||||
|
||||
from .forms import PollForm
|
||||
from .models import Poll
|
||||
from .models import Poll, Location
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def homepage (request):
|
||||
poll = get_object_or_404(Poll)
|
||||
def homepage (request, slug="arlington"):
|
||||
location = get_object_or_404(Location, slug=slug)
|
||||
|
||||
try:
|
||||
poll = location.poll
|
||||
except:
|
||||
return HttpResponseNotFound(f'404: No poll was found for {location}!')
|
||||
|
||||
if poll.ask_hi:
|
||||
hi_text = poll.hi_text
|
||||
|
@ -70,3 +76,4 @@ def homepage (request):
|
|||
|
||||
def finish (request):
|
||||
pass
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
argparse
|
||||
django
|
||||
django-widget-tweaks
|
||||
pip-chill
|
||||
python
|
||||
wsgiref
|
||||
argparse==1.4.0
|
||||
django==3.1
|
||||
django-cleanup==5.0.0
|
||||
django-widget-tweaks==1.4.8
|
||||
pillow==7.2.0
|
||||
pip-chill==1.0.0
|
||||
|
|
BIN
static/css/fonts/Shorelines-Script-Bold.otf
Normal file
BIN
static/css/res/Shorelines-Script-Bold.otf
Normal file
Before Width: | Height: | Size: 4.1 MiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 26 KiB |
BIN
static/css/res/wys-hero-mobile.png
Normal file
After Width: | Height: | Size: 4.1 MiB |
BIN
static/css/res/wys-hero.png
Normal file
After Width: | Height: | Size: 1.4 MiB |