Initial commit

This commit is contained in:
Kevin Alberts 2017-12-19 15:48:06 +01:00
commit 8948abe8e9
21 changed files with 621 additions and 0 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.idea
*.sqlite3
*.db
isonzeinterndronken/local.py
*.pyc

0
dronken/__init__.py Normal file
View file

5
dronken/admin.py Normal file
View file

@ -0,0 +1,5 @@
from django.contrib import admin
from dronken.models import *
admin.site.register(City)
admin.site.register(Association)

5
dronken/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class DronkenConfig(AppConfig):
name = 'dronken'

View file

@ -0,0 +1,8 @@
from django.conf import settings
def environment(request):
""" Template context processor to add debug variable to tempate context. """
return {
'debug': settings.DEBUG
}

View file

@ -0,0 +1,35 @@
# Generated by Django 2.0 on 2017-12-19 12:53
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Association',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('slug', models.CharField(max_length=255)),
('intern', models.CharField(max_length=255)),
('state', models.CharField(choices=[('ja', 'Ja'), ('nee', 'Nee'), ('brak', 'Brak')], max_length=255)),
('has_intern', models.BooleanField()),
('enabled', models.BooleanField()),
],
),
migrations.CreateModel(
name='City',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('slug', models.CharField(max_length=255)),
('enabled', models.BooleanField()),
],
),
]

View file

@ -0,0 +1,19 @@
# Generated by Django 2.0 on 2017-12-19 12:58
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dronken', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='association',
name='city',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='dronken.City'),
),
]

View file

@ -0,0 +1,24 @@
# Generated by Django 2.0 on 2017-12-19 14:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dronken', '0002_association_city'),
]
operations = [
migrations.AddField(
model_name='association',
name='short_name',
field=models.CharField(default='', max_length=255),
preserve_default=False,
),
migrations.AlterField(
model_name='association',
name='state',
field=models.CharField(choices=[('dronken', 'Dronken'), ('nuchter', 'Nuchter'), ('brak', 'Brak')], max_length=255),
),
]

View file

30
dronken/models.py Normal file
View file

@ -0,0 +1,30 @@
from django.db import models
class City(models.Model):
name = models.CharField(max_length=255)
slug = models.CharField(max_length=255)
enabled = models.BooleanField()
def __str__(self):
return self.name
class Association(models.Model):
STATES = (
('dronken', 'Dronken'),
('nuchter', 'Nuchter'),
('brak', 'Brak')
)
name = models.CharField(max_length=255)
short_name = models.CharField(max_length=255)
slug = models.CharField(max_length=255)
intern = models.CharField(max_length=255)
state = models.CharField(choices=STATES, max_length=255)
city = models.ForeignKey(to=City, on_delete=models.SET_NULL, blank=True, null=True)
has_intern = models.BooleanField()
enabled = models.BooleanField()
def __str__(self):
return self.name

3
dronken/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

11
dronken/urls.py Normal file
View file

@ -0,0 +1,11 @@
from django.urls import path
from dronken.views import *
app_name = 'dronken'
urlpatterns = [
path('', CityList.as_view(), name='city_list'),
path('<city>/', AssociationList.as_view(), name='association_list'),
path('<city>/<slug>/', AssociationDetail.as_view(), name='association'),
]

38
dronken/views.py Normal file
View file

@ -0,0 +1,38 @@
from django import forms
from django.urls import reverse_lazy
from django.views.generic import ListView, UpdateView
from dronken.models import City, Association
class CityList(ListView):
template_name = 'cities.html'
model = City
class AssociationList(ListView):
template_name = 'associations.html'
model = Association
def get_queryset(self):
c = City.objects.get(slug=self.kwargs['city'])
return Association.objects.filter(city=c)
class DrunkUpdateForm(forms.ModelForm):
state = forms.CharField(
widget=forms.Select(choices=Association.STATES),
)
class Meta:
model = Association
fields = ['state']
class AssociationDetail(UpdateView):
template_name = 'association.html'
model = Association
form_class = DrunkUpdateForm
def get_success_url(self):
return reverse_lazy('dronken:association_list', kwargs={'city': self.get_object().city.slug})

View file

View file

@ -0,0 +1,123 @@
"""
Django settings for isonzeinterndronken project.
Generated by 'django-admin startproject' using Django 2.0.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!_pns0*0-*8dxr_*it5=#^249%pfrf@gdvza-++cgdcp4x$=c7'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dronken'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'isonzeinterndronken.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'dronken.context_processors.environment',
],
},
},
]
WSGI_APPLICATION = 'isonzeinterndronken.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'

View file

@ -0,0 +1,24 @@
"""isonzeinterndronken URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from dronken.views import *
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('dronken.urls')),
]

View file

@ -0,0 +1,16 @@
"""
WSGI config for isonzeinterndronken project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "isonzeinterndronken.settings")
application = get_wsgi_application()

15
manage.py Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "isonzeinterndronken.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

View file

@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IsOnzeInternAlDronken.nl ~ {{ association.city }} ~ {{ association }}</title>
{% if not debug %}
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.isonzeinterndronken.nl"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
var u = "//piwik.kuro.network/";
_paq.push(['setTrackerUrl', u + 'piwik.php']);
_paq.push(['setSiteId', '5']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = u + 'piwik.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<!-- End Piwik Code -->
{% endif %}
<style type="text/css">
html, body {
height: 100%;
font-family: OpenSans, Verdana, sans-serif;
}
div {
text-align: center;
top: 50%;
position: relative;
transform: translateY(-50%);
}
h1 {
font-size: 60px;
padding-top: 30px;
}
h2 {
font-size: 40px;
padding: 0px;
margin: 0px;
}
h3 {
font-size: 30px;
padding: 0px;
margin: 0px;
}
.line {
margin-top: 2em;
margin-bottom: 2em;
}
</style>
</head>
<body>
<div>
<a href="{% url 'dronken:association_list' association.city.slug %}"><button>Back</button></a>
<h2>{{ association|safe }}?</h2>
<hr class="line" />
<h2>{% if association.intern %}{{ association.intern|capfirst }}{% else %}De intern{% endif %}</h2>
<h2>is op dit moment:</h2>
{% if association.has_intern %}
<h1>{{ association.get_state_display|upper }}</h1>
<hr class="line"/>
<p>Update de staat van {% if association.intern %}{{ association.intern|capfirst }}{% else %}de intern{% endif %}:</p>
<form method="post">
{% csrf_token %}
{{ form.state }} <input type="submit" value="Update!" />
</form>
{% else %}
<h1>{{ association.short_name }} heeft helemaal geen intern!</h1>
{% endif %}
</div>
</body>
</html>

View file

@ -0,0 +1,90 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IsOnzeInternAlDronken.nl ~ {{ city }}</title>
{% if not debug %}
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.isonzeinterndronken.nl"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
var u = "//piwik.kuro.network/";
_paq.push(['setTrackerUrl', u + 'piwik.php']);
_paq.push(['setSiteId', '5']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = u + 'piwik.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<!-- End Piwik Code -->
{% endif %}
<style type="text/css">
html, body {
height: 90%;
font-family: OpenSans, Verdana, sans-serif;
}
div {
text-align: center;
top: 50%;
position: relative;
transform: translateY(-50%);
}
h1 {
font-size: 60px;
padding-top: 30px;
}
h2 {
font-size: 40px;
padding: 0px;
margin: 0px;
}
h3 {
font-size: 30px;
padding: 0px;
margin: 0px;
}
table {
width: 100%;
}
.line {
margin-top: 2em;
margin-bottom: 2em;
}
</style>
</head>
<body>
<div>
<a href="{% url 'dronken:city_list' %}">
<button>Back</button>
</a>
<h2>Welke vereniging bedoel je?</h2>
<hr class="line"/>
<table align="center">
<tbody>
{% for association in object_list %}
<tr>
<td><b><a href="{% url 'dronken:association' association.city.slug association.slug %}">{{ association|safe }}</a></b></td>
<td><b>{% if association.has_intern %}{{ association.state|upper }}{% else %}{{ association.short_name|safe|upper }} HEEFT GEEN INTERN!{% endif %}</b></td>
</tr>
{% endfor %}
</tbody>
</table>
<hr class="line"/>
<p>Wil jij ook jouw vereniging/stad hier? Stuur een mailtje naar commissie[at]isonzeinterndronken.nl</p>
</div>
</body>
</html>

86
templates/cities.html Normal file
View file

@ -0,0 +1,86 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IsOnzeInternAlDronken.nl ~ {{ city }}</title>
{% if not debug %}
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.isonzeinterndronken.nl"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
var u = "//piwik.kuro.network/";
_paq.push(['setTrackerUrl', u + 'piwik.php']);
_paq.push(['setSiteId', '5']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = u + 'piwik.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<!-- End Piwik Code -->
{% endif %}
<style type="text/css">
html, body {
height: 90%;
font-family: OpenSans, Verdana, sans-serif;
}
div {
text-align: center;
top: 50%;
position: relative;
transform: translateY(-50%);
}
h1 {
font-size: 60px;
padding-top: 30px;
}
h2 {
font-size: 40px;
padding: 0px;
margin: 0px;
}
h3 {
font-size: 30px;
padding: 0px;
margin: 0px;
}
table {
width: 100%;
}
ul {
list-style-type: none;
}
.line {
margin-top: 2em;
margin-bottom: 2em;
}
</style>
</head>
<body>
<div>
<h2>Welke stad bedoel je?</h2>
<hr class="line"/>
<ul>
{% for city in object_list %}
<li><b><a href="{% url 'dronken:association_list' city.slug %}">{{ city }}</a></b></li>
{% endfor %}
</ul>
<hr class="line"/>
<p>Wil jij ook jouw vereniging/stad hier? Stuur een mailtje naar commissie[at]isonzeinterndronken.nl</p>
</div>
</body>
</html>