commit 8948abe8e954746ff7dc2e93fba4a163d7485a66 Author: Kevin Alberts Date: Tue Dec 19 15:48:06 2017 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2647ccf --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +*.sqlite3 +*.db +isonzeinterndronken/local.py +*.pyc \ No newline at end of file diff --git a/dronken/__init__.py b/dronken/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dronken/admin.py b/dronken/admin.py new file mode 100644 index 0000000..bd4e379 --- /dev/null +++ b/dronken/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from dronken.models import * + +admin.site.register(City) +admin.site.register(Association) diff --git a/dronken/apps.py b/dronken/apps.py new file mode 100644 index 0000000..67cb292 --- /dev/null +++ b/dronken/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class DronkenConfig(AppConfig): + name = 'dronken' diff --git a/dronken/context_processors.py b/dronken/context_processors.py new file mode 100644 index 0000000..aba4c30 --- /dev/null +++ b/dronken/context_processors.py @@ -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 + } diff --git a/dronken/migrations/0001_initial.py b/dronken/migrations/0001_initial.py new file mode 100644 index 0000000..c8a929d --- /dev/null +++ b/dronken/migrations/0001_initial.py @@ -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()), + ], + ), + ] diff --git a/dronken/migrations/0002_association_city.py b/dronken/migrations/0002_association_city.py new file mode 100644 index 0000000..2643f03 --- /dev/null +++ b/dronken/migrations/0002_association_city.py @@ -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'), + ), + ] diff --git a/dronken/migrations/0003_auto_20171219_1418.py b/dronken/migrations/0003_auto_20171219_1418.py new file mode 100644 index 0000000..f1a7494 --- /dev/null +++ b/dronken/migrations/0003_auto_20171219_1418.py @@ -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), + ), + ] diff --git a/dronken/migrations/__init__.py b/dronken/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dronken/models.py b/dronken/models.py new file mode 100644 index 0000000..04f3b32 --- /dev/null +++ b/dronken/models.py @@ -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 diff --git a/dronken/tests.py b/dronken/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/dronken/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/dronken/urls.py b/dronken/urls.py new file mode 100644 index 0000000..8ad326a --- /dev/null +++ b/dronken/urls.py @@ -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('/', AssociationList.as_view(), name='association_list'), + path('//', AssociationDetail.as_view(), name='association'), +] diff --git a/dronken/views.py b/dronken/views.py new file mode 100644 index 0000000..2108705 --- /dev/null +++ b/dronken/views.py @@ -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}) diff --git a/isonzeinterndronken/__init__.py b/isonzeinterndronken/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/isonzeinterndronken/settings.py b/isonzeinterndronken/settings.py new file mode 100644 index 0000000..a974a95 --- /dev/null +++ b/isonzeinterndronken/settings.py @@ -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/' diff --git a/isonzeinterndronken/urls.py b/isonzeinterndronken/urls.py new file mode 100644 index 0000000..61903ed --- /dev/null +++ b/isonzeinterndronken/urls.py @@ -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')), +] diff --git a/isonzeinterndronken/wsgi.py b/isonzeinterndronken/wsgi.py new file mode 100644 index 0000000..f6af776 --- /dev/null +++ b/isonzeinterndronken/wsgi.py @@ -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() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..f69578d --- /dev/null +++ b/manage.py @@ -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) diff --git a/templates/association.html b/templates/association.html new file mode 100644 index 0000000..fb24bf2 --- /dev/null +++ b/templates/association.html @@ -0,0 +1,84 @@ + + + + + IsOnzeInternAlDronken.nl ~ {{ association.city }} ~ {{ association }} + {% if not debug %} + + + + {% endif %} + + + +
+ +

{{ association|safe }}?

+
+

{% if association.intern %}{{ association.intern|capfirst }}{% else %}De intern{% endif %}

+

is op dit moment:

+ {% if association.has_intern %} +

{{ association.get_state_display|upper }}

+
+

Update de staat van {% if association.intern %}{{ association.intern|capfirst }}{% else %}de intern{% endif %}:

+
+ {% csrf_token %} + {{ form.state }} +
+ {% else %} +

{{ association.short_name }} heeft helemaal geen intern!

+ {% endif %} +
+ + \ No newline at end of file diff --git a/templates/associations.html b/templates/associations.html new file mode 100644 index 0000000..229ce92 --- /dev/null +++ b/templates/associations.html @@ -0,0 +1,90 @@ + + + + + IsOnzeInternAlDronken.nl ~ {{ city }} + {% if not debug %} + + + + {% endif %} + + + +
+ + + +

Welke vereniging bedoel je?

+
+ + + {% for association in object_list %} + + + + + {% endfor %} + +
{{ association|safe }}{% if association.has_intern %}{{ association.state|upper }}{% else %}{{ association.short_name|safe|upper }} HEEFT GEEN INTERN!{% endif %}
+
+

Wil jij ook jouw vereniging/stad hier? Stuur een mailtje naar commissie[at]isonzeinterndronken.nl

+
+ + \ No newline at end of file diff --git a/templates/cities.html b/templates/cities.html new file mode 100644 index 0000000..d57cc4c --- /dev/null +++ b/templates/cities.html @@ -0,0 +1,86 @@ + + + + + IsOnzeInternAlDronken.nl ~ {{ city }} + {% if not debug %} + + + + {% endif %} + + + +
+

Welke stad bedoel je?

+
+
    + {% for city in object_list %} +
  • {{ city }}
  • + {% endfor %} +
+
+

Wil jij ook jouw vereniging/stad hier? Stuur een mailtje naar commissie[at]isonzeinterndronken.nl

+
+ + \ No newline at end of file