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

2021 Release #2

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pre-commit = "*"

[packages]
uwsgi = "*"
django = "==2.2.10"
django = "==3.2.9"
cssselect = "==1.0.3"
dateutils = "==0.6.6"
markdown = "==3.0.1"
Expand Down
501 changes: 287 additions & 214 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ First clone the repository from BitBucket and switch to the new directory::

Next, create a virtual environment and install all of the requirements::

(iticket)$ pip shell
(iticket)$ pipenv install --dev
(gingerhouse)$ pip shell
(gingerhouse)$ pipenv install --dev

Now, create a local settings file and set your DJANGO_SETTINGS_MODULE to use it:::

Expand Down
9 changes: 8 additions & 1 deletion gingerhouse/houses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@


from gingerhouse.houses.models import Category, GingerHouse, Vote
from gingerhouse.photos.models import Photo


class CategoryAdmin(admin.ModelAdmin):
list_display = ("name",)


class PhotoAdminInline(admin.TabularInline):
model = Photo
extra = 3


class GingerHouseAdmin(admin.ModelAdmin):
list_display = ("name", "vote_count")

inlines = [PhotoAdminInline]

def vote_count(self, obj):
return obj.vote_set.all().count()

Expand Down
6 changes: 3 additions & 3 deletions gingerhouse/houses/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def __init__(self, *args, **kwargs):

def clean(self):
cleaned_data = self.cleaned_data
# is there a vote with this email to same house category?
# is there a vote with this email on this entry already?
email = cleaned_data.get("email")
already_voted = Vote.objects.filter(email=email, ginger_house__category=self.ginger_house.category).exists()
already_voted = Vote.objects.filter(email=email, ginger_house=self.ginger_house).exists()
if already_voted:
raise forms.ValidationError("You have already voted in this category")
raise forms.ValidationError("You have already voted for this entry")
return cleaned_data
25 changes: 25 additions & 0 deletions gingerhouse/houses/migrations/0003_remove_image_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.9 on 2021-12-01 23:15

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('houses', '0002_auto_20201205_1227'),
]

operations = [
migrations.AlterModelOptions(
name='category',
options={'verbose_name_plural': 'Categories'},
),
migrations.AlterModelOptions(
name='gingerhouse',
options={'ordering': ['-category__name']},
),
migrations.RemoveField(
model_name='gingerhouse',
name='image',
),
]
20 changes: 8 additions & 12 deletions gingerhouse/houses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Category(models.Model):
"""Categories are used to limit voting and present entries in groupings"""
name = models.CharField(max_length=255)

class Meta:
verbose_name_plural = "Categories"

Expand All @@ -21,21 +21,18 @@ class GingerHouse(models.Model):
category = models.ForeignKey('Category', on_delete=models.CASCADE)
display_address = models.TextField(blank=True)
model_address = models.TextField(blank=True)
image = models.ImageField(
verbose_name="Ginger house image",
upload_to='uploads/',
max_length=255,
blank=True,
null=True,
help_text="Ginger house image. Horizontal format, cropped to 812x680 px.",
)


class Meta:
ordering = ["-category__name", ]

def __str__(self):
return self.name


@property
def primary_image(self):
image = self.photo_set.filter(is_primary=True).first()
return image

def get_absolute_url(self):
return reverse("houses:detail", kwargs={"pk": self.id})

Expand All @@ -46,4 +43,3 @@ class Vote(models.Model):

def __str__(self):
return "{} - {} - {}".format(self.email, self.ginger_house.category.name, self.ginger_house.name)

16 changes: 14 additions & 2 deletions gingerhouse/houses/views.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
from random import shuffle

from django.db.models import OuterRef, Subquery, ImageField
from django.shortcuts import redirect, reverse
from django.views.generic import ListView, DetailView, FormView

from gingerhouse.houses.forms import VoteForm
from gingerhouse.houses.models import GingerHouse, Vote
from gingerhouse.photos.models import Photo


class HousesListView(ListView):
model = GingerHouse
template_name = 'houses/index.html'

def get_queryset(self):
qs = super().get_queryset().order_by('name')
qs = qs.annotate(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

image=Subquery(Photo.objects.filter(house=OuterRef("id"), is_primary=True)[:1].values("image"),
output_field=ImageField())
)
return qs


class HouseDetailView(DetailView):
model = GingerHouse
template_name = 'houses/detail.html'
context_object_name = "house"

def get_context_data(self, **kwargs):
ctx = super(HouseDetailView, self).get_context_data(**kwargs)
ctx["form"] = VoteForm(ginger_house=ctx["object"])
Expand All @@ -24,7 +36,7 @@ def get_context_data(self, **kwargs):
class VoteView(FormView):
template_name = 'houses/detail.html'
form_class = VoteForm

def get_ginger_house(self):
ginger_house_id = self.kwargs.get("ginger_house_id")
ginger_house = GingerHouse.objects.get(pk=ginger_house_id)
Expand Down
Empty file added gingerhouse/photos/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions gingerhouse/photos/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.2.9 on 2021-12-01 23:16

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('houses', '0003_remove_image_field'),
]

operations = [
migrations.CreateModel(
name='Image',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(blank=True, help_text='Ginger house image. Horizontal format, cropped to 812x680 px.', max_length=255, null=True, upload_to='uploads/', verbose_name='Ginger house image')),
('is_primary', models.BooleanField(default=False)),
('description', models.TextField(blank=True)),
('house', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='houses.gingerhouse')),
],
),
]
18 changes: 18 additions & 0 deletions gingerhouse/photos/migrations/0002_rename_image_photo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.9 on 2021-12-01 23:46

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('houses', '0003_remove_image_field'),
('photos', '0001_initial'),
]

operations = [
migrations.RenameModel(
old_name='Image',
new_name='Photo',
),
]
Empty file.
21 changes: 21 additions & 0 deletions gingerhouse/photos/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import models


class Photo(models.Model):
house = models.ForeignKey("houses.GingerHouse", null=True, blank=False, on_delete=models.SET_NULL)
image = models.ImageField(
verbose_name="Ginger house image",
upload_to='uploads/',
max_length=255,
blank=True,
null=True,
help_text="Ginger house image. Horizontal format, cropped to 812x680 px.",
)
is_primary = models.BooleanField(default=False)
description = models.TextField(blank=True)

class Meta:
ordering = ("house__id", "is_primary")

def __str__(self):
return self.description
6 changes: 4 additions & 2 deletions gingerhouse/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)

# Application definition

INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
Expand All @@ -33,7 +32,8 @@
'django.contrib.humanize',
'django.contrib.sitemaps',
# local apps
'gingerhouse.houses'
'gingerhouse.houses',
'gingerhouse.photos',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -205,3 +205,5 @@
SECURE_BROWSER_XSS_FILTER = True
CSRF_COOKIE_HTTPONLY = True
X_FRAME_OPTIONS = 'DENY'

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
16 changes: 7 additions & 9 deletions gingerhouse/settings/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@

MEDIA_ROOT = '/storage/media/'

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '%(CACHE_HOST)s' % os.environ,
}
}
# CACHES = {
# 'default': {
# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
# 'LOCATION': '%(CACHE_HOST)s' % os.environ,
# }
# }

EMAIL_HOST = os.environ.get('EMAIL_HOST', 'localhost')
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER', '')
Expand All @@ -99,9 +99,7 @@

SESSION_COOKIE_HTTPONLY = True

ALLOWED_HOSTS = ['gingerhouse.tworock.io', 'homesfortheholidays-2020.com',
'www.homesfortheholidays-2020.com', 'homesfortheholidays2020.com',
'www.homesfortheholidays2020.com', ]
ALLOWED_HOSTS = ['gingerhouse.tworock.io', 'homesfortheholidays2021.com', 'www.homesfortheholidays2021.com', ]

# Use template caching on deployed servers
for backend in TEMPLATES:
Expand Down
3 changes: 1 addition & 2 deletions gingerhouse/static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
--small-border-radius: .5rem;
}


body {
background-color: var(--tan);
color: var(--brown);
Expand Down Expand Up @@ -331,4 +330,4 @@ i.fa-map-marker-alt::after {
-webkit-box-shadow: 3px 3px 5px 6px #ccc; /* Safari 3-4, iOS 4.0.2 - 4.2, Android 2.3+ */
-moz-box-shadow: 3px 3px 5px 6px #ccc; /* Firefox 3.5 - 3.6 */
box-shadow: 3px 3px 5px 6px #ccc; /* Opera 10.5, IE 9, Firefox 4+, Chrome 6+, iOS 5 */
}
}
Binary file added gingerhouse/static/img/HHFTH_FB-Banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions gingerhouse/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% load static from staticfiles %}
{% load static %}
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}Homes For The Holidays - 2020 - Historic Hillsborugh Gingerbread House Competition</title>
<title>{% block title %}{% endblock %}Homes For The Holidays - 2021 - Historic Hillsborugh Gingerbread House Competition</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="{% block meta-description %}{% endblock %}Vote for your favorite gingerbread recreations of Historic Hillsborough structures!">
<meta property="og:image" content="{% static 'img/HFTH_Social_Banner.jpg' %}">
<meta name="twitter:image" content="{% static 'img/HFTH_Social_Banner.jpg' %}">
<meta name="description" content="{% block meta-description %}{% endblock %}Vote for your favorite gingerbread recreations of iconic structures on display in Hillsborough, NC!">
<meta property="og:image" content="{% static 'img/HHFTH_FB-Banner.jpg' %}">
<meta name="twitter:image" content="{% static 'img/HHFTH_FB-Banner.jpg' %}">
<meta name="author" content="{% block meta-author %}{% endblock %}">
<meta name="keywords" content="{% block meta-keywords %}{% endblock %}">
{% block extra-meta %}{% endblock %}
Expand Down
Loading