mirror of
https://github.com/Rushilwiz/HiLo.git
synced 2025-04-17 18:30:18 -04:00
finished?
This commit is contained in:
parent
55d0685833
commit
925eadaf54
|
@ -40,6 +40,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'widget_tweaks',
|
'widget_tweaks',
|
||||||
'django_cleanup',
|
'django_cleanup',
|
||||||
|
'crispy_forms',
|
||||||
'profanity'
|
'profanity'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from profanity.validators import validate_is_profane
|
from profanity.validators import validate_is_profane
|
||||||
from .models import Answer, EMOTION_CHOICES
|
from .models import Answer, Location, Poll, EMOTION_CHOICES
|
||||||
|
|
||||||
class PollForm(forms.ModelForm):
|
class PollForm(forms.ModelForm):
|
||||||
hi = forms.CharField(max_length=200, validators=[validate_is_profane], required=False)
|
hi = forms.CharField(max_length=200, validators=[validate_is_profane], required=False)
|
||||||
|
@ -18,4 +18,18 @@ class PollForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Answer
|
model = Answer
|
||||||
fields = ['hi', 'lo', 'emotion', 'name', 'place','question']
|
fields = ['hi', 'lo', 'emotion', 'name', 'place','question']
|
||||||
|
|
||||||
|
class LocationForm (forms.ModelForm):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Location
|
||||||
|
fields = ['name', 'insta']
|
||||||
|
|
||||||
|
class CreatePollForm (forms.ModelForm):
|
||||||
|
ask_question = forms.BooleanField(label="Ask extra question", required=False)
|
||||||
|
question_text = forms.CharField(label="Extra question text (leave blank if no extra question)", max_length=100, required=False)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Poll
|
||||||
|
fields = ['ask_hi','hi_text','ask_lo','lo_text','ask_emotion','emotion_text','ask_name','name_text','ask_place','place_text','ask_question','question_text']
|
28
homepage/migrations/0013_auto_20200827_0028.py
Normal file
28
homepage/migrations/0013_auto_20200827_0028.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# Generated by Django 3.1 on 2020-08-27 04:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('homepage', '0012_auto_20200826_2354'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='poll',
|
||||||
|
name='hi_text',
|
||||||
|
field=models.CharField(blank=True, default='What was the <span class="hi">Hi</span> of this week?', max_length=100, 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 week?', max_length=100, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='poll',
|
||||||
|
name='pub_date',
|
||||||
|
field=models.DateTimeField(blank=True, null=True, verbose_name='date published'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -18,9 +18,10 @@ from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
class Location (models.Model):
|
class Location (models.Model):
|
||||||
name = models.CharField(max_length=20, blank=True, null=True)
|
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)
|
insta = 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 = models.ImageField(default="hero.png", upload_to='heros')
|
||||||
hero_mobile = models.ImageField(default="hero-mobile.png", upload_to='heros')
|
hero_mobile = models.ImageField(default="hero-mobile.png", upload_to='heros')
|
||||||
|
|
||||||
|
@ -73,10 +74,10 @@ class Poll (models.Model):
|
||||||
location = models.OneToOneField(Location, on_delete=models.CASCADE)
|
location = models.OneToOneField(Location, on_delete=models.CASCADE)
|
||||||
|
|
||||||
ask_hi = models.BooleanField(default=True)
|
ask_hi = models.BooleanField(default=True)
|
||||||
hi_text = models.CharField(max_length=100, blank=True, null=True, default='What was the <span class="hi">Hi</span> of this we')
|
hi_text = models.CharField(max_length=100, blank=True, null=True, default='What was the <span class="hi">Hi</span> of this week?')
|
||||||
|
|
||||||
ask_lo = models.BooleanField(default=True)
|
ask_lo = models.BooleanField(default=True)
|
||||||
lo_text = models.CharField(max_length=100, blank=True, null=True, default='What was the <span class="lo">Lo</span> of this we')
|
lo_text = models.CharField(max_length=100, blank=True, null=True, default='What was the <span class="lo">Lo</span> of this week?')
|
||||||
|
|
||||||
ask_emotion = models.BooleanField(default=True)
|
ask_emotion = models.BooleanField(default=True)
|
||||||
emotion_text = models.CharField(max_length=100, 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?")
|
||||||
|
@ -90,11 +91,14 @@ class Poll (models.Model):
|
||||||
ask_question = models.BooleanField(default=False)
|
ask_question = models.BooleanField(default=False)
|
||||||
question_text = models.CharField(max_length=100, blank=True, null=True)
|
question_text = models.CharField(max_length=100, blank=True, null=True)
|
||||||
|
|
||||||
pub_date = models.DateTimeField('date published')
|
pub_date = models.DateTimeField('date published', blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.location.name}'s Poll"
|
return f"{self.location.name}'s Poll"
|
||||||
|
|
||||||
|
def __save__(self, *args, **kwargs):
|
||||||
|
self.pub_date = timezone.now()
|
||||||
|
super().save(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
EMOTION_CHOICES= [
|
EMOTION_CHOICES= [
|
||||||
|
|
|
@ -1 +1,35 @@
|
||||||
create.html
|
{% extends 'homepage/base.html' %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% block content %}
|
||||||
|
<style type="text/css">
|
||||||
|
html {
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<a href="/" class='btn btn-outline-secondary pull-left'>
|
||||||
|
Back
|
||||||
|
</a>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="text-center">
|
||||||
|
<h1 class="mt-5">Create your own HiLo!</h1>
|
||||||
|
<p class="lead">Create a HiLo for your area, and get your own customized page!</p>
|
||||||
|
</div>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
<fieldset class="form-group">
|
||||||
|
<legend class="border-bottom mb-4"> The new location </legend>
|
||||||
|
{{ locationForm|crispy}}
|
||||||
|
<br><br>
|
||||||
|
<legend class="border-bottom mb-4"> What questions would you like to ask? </legend>
|
||||||
|
{{ pollForm|crispy }}
|
||||||
|
</fieldset>
|
||||||
|
<div class="form-group">
|
||||||
|
<button type="submit" class="btn btn-outline-info">Submit</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -3,6 +3,7 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path ('', views.homepage, name="homepage"),
|
path ('', views.homepage, name="homepage"),
|
||||||
|
path ('create/', views.create, name="create"),
|
||||||
path ('<slug:slug>/', views.homepage),
|
path ('<slug:slug>/', views.homepage),
|
||||||
path ('<slug:slug>/results/', views.results)
|
path ('<slug:slug>/results/', views.results)
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.shortcuts import render, redirect
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.http import HttpResponseNotFound
|
from django.http import HttpResponseNotFound
|
||||||
from .forms import PollForm
|
from .forms import PollForm, CreatePollForm, LocationForm
|
||||||
from .models import Poll, Location, Answer
|
from .models import Poll, Location, Answer
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
@ -90,4 +90,27 @@ def results (request, slug="arlington"):
|
||||||
'answers':answers,
|
'answers':answers,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'homepage/results.html', context=context)
|
return render(request, 'homepage/results.html', context=context)
|
||||||
|
|
||||||
|
def create(request):
|
||||||
|
if request.method == "POST":
|
||||||
|
locationForm = LocationForm(request.POST)
|
||||||
|
pollForm = CreatePollForm(request.POST)
|
||||||
|
|
||||||
|
if locationForm.is_valid() and pollForm.is_valid():
|
||||||
|
location = locationForm.save()
|
||||||
|
poll = pollForm.save(commit=False)
|
||||||
|
poll.location = location
|
||||||
|
poll.save()
|
||||||
|
messages.success(request, "Your location has been created!")
|
||||||
|
return redirect(f'/{location.slug}/')
|
||||||
|
else:
|
||||||
|
locationForm = LocationForm()
|
||||||
|
pollForm = CreatePollForm()
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'locationForm': locationForm,
|
||||||
|
'pollForm': pollForm
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, 'homepage/create.html', context)
|
|
@ -1,6 +1,8 @@
|
||||||
argparse==1.4.0
|
argparse==1.4.0
|
||||||
django==3.1
|
django==3.1
|
||||||
django-cleanup==5.0.0
|
django-cleanup==5.0.0
|
||||||
|
django-crispy-forms==1.9.2
|
||||||
|
django-profanity-filter==0.2.1
|
||||||
django-widget-tweaks==1.4.8
|
django-widget-tweaks==1.4.8
|
||||||
pillow==7.2.0
|
pillow==7.2.0
|
||||||
pip-chill==1.0.0
|
pip-chill==1.0.0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user