Initial commit
This commit is contained in:
		
						commit
						8948abe8e9
					
				
					 21 changed files with 621 additions and 0 deletions
				
			
		
							
								
								
									
										0
									
								
								dronken/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								dronken/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										5
									
								
								dronken/admin.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								dronken/admin.py
									
										
									
									
									
										Normal 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
									
								
							
							
						
						
									
										5
									
								
								dronken/apps.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
from django.apps import AppConfig
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DronkenConfig(AppConfig):
 | 
			
		||||
    name = 'dronken'
 | 
			
		||||
							
								
								
									
										8
									
								
								dronken/context_processors.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								dronken/context_processors.py
									
										
									
									
									
										Normal 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
 | 
			
		||||
    }
 | 
			
		||||
							
								
								
									
										35
									
								
								dronken/migrations/0001_initial.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								dronken/migrations/0001_initial.py
									
										
									
									
									
										Normal 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()),
 | 
			
		||||
            ],
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										19
									
								
								dronken/migrations/0002_association_city.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								dronken/migrations/0002_association_city.py
									
										
									
									
									
										Normal 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'),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										24
									
								
								dronken/migrations/0003_auto_20171219_1418.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								dronken/migrations/0003_auto_20171219_1418.py
									
										
									
									
									
										Normal 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),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										0
									
								
								dronken/migrations/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								dronken/migrations/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										30
									
								
								dronken/models.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								dronken/models.py
									
										
									
									
									
										Normal 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
									
								
							
							
						
						
									
										3
									
								
								dronken/tests.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
from django.test import TestCase
 | 
			
		||||
 | 
			
		||||
# Create your tests here.
 | 
			
		||||
							
								
								
									
										11
									
								
								dronken/urls.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								dronken/urls.py
									
										
									
									
									
										Normal 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
									
								
							
							
						
						
									
										38
									
								
								dronken/views.py
									
										
									
									
									
										Normal 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})
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue