Skip to content

Commit

Permalink
Merge pull request #1 from kpoeppel/AddUserManagement
Browse files Browse the repository at this point in the history
Add user management
  • Loading branch information
kpoeppel authored Mar 28, 2019
2 parents 86f796d + 7edcf80 commit 2f939d2
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# the gitignore-file

bildungsfeiertag/__pycache__/
bildungsfeiertag/db.sqlite
7 changes: 7 additions & 0 deletions bildungsfeiertag/bildungsfeiertag/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from . import models

admin.site.register(models.Site)
admin.site.register(models.Room)
admin.site.register(models.Talk)
admin.site.register(models.Vote)
5 changes: 5 additions & 0 deletions bildungsfeiertag/bildungsfeiertag/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BildungsfeiertagConfig(AppConfig):
name = 'bildungsfeiertag'
68 changes: 68 additions & 0 deletions bildungsfeiertag/bildungsfeiertag/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import docupy
from datetime import datetime
from django.db import models
from django.contrib.auth.models import User


class Site(models.Model):
name = models.CharField(max_length=100)
address = models.TextField()
image = models.CharField(max_length=128)

def __str__(self):
return "{}".format(self.name)


class Room(models.Model):
site = models.ForeignKey('Site',
on_delete=models.CASCADE)
name = models.CharField(max_length=100)
seats = models.PositiveIntegerField()

def __str__(self):
return "Room {}".format(self.name)


class Talk(models.Model):
title = models.TextField()
date = models.DateField()
description = models.TextField()
room = models.ForeignKey('Room',
on_delete=models.CASCADE)
speaker = models.ForeignKey(User,
on_delete=models.CASCADE)
duration = models.DurationField()
time = models.TimeField()
accepted = models.BooleanField()
image = models.CharField(max_length=128)

def __str__(self):
return "\"{}\" by {}".format(self.title, self.speaker.name)


class Vote(models.Model):
talk = models.OneToOneField(
Talk,
on_delete=models.CASCADE,
)
user = models.OneToOneField(
User,
on_delete=models.CASCADE,
)


class MediaFile(models.Model):
def create_filename(instance, filename):
extension = "." + filename.split(".")[-1] if "." in filename else ""
return datetime.strftime(datetime.now(), "%Y%m%d-%H%M%S") + extension

def media_lookup():
return {
media.name: media.mediafile.url for media in MediaFile.objects.all()
}

name = models.TextField(primary_key=True)
mediafile = models.FileField(upload_to=create_filename)

def __str__(self):
return "MediaFile ({})".format(self.name)
14 changes: 8 additions & 6 deletions bildungsfeiertag/bildungsfeiertag/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""

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__)))

Expand All @@ -20,7 +19,7 @@
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!83t*9=be*x3+i_oe^cd$_p5&b##$5ti)!#^+qoi209j9d%^d3'
SECRET_KEY = '_-ijxz1hdg4cw&#fhd!i__%cniv#26vukzco#^vcc)lp%bj-6_'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -31,12 +30,14 @@
# Application definition

INSTALLED_APPS = [
'bildungsfeiertag.apps.BildungsfeiertagConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'material'
]

MIDDLEWARE = [
Expand All @@ -54,7 +55,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -99,13 +100,12 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'de-de'

TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Berlin'

USE_I18N = True

Expand All @@ -118,3 +118,5 @@
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
1 change: 1 addition & 0 deletions bildungsfeiertag/bildungsfeiertag/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``
10 changes: 8 additions & 2 deletions bildungsfeiertag/bildungsfeiertag/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.urls import path, include
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path
from django.conf import settings
from . import views


urlpatterns = [
path('admin/', admin.site.urls),
path(r"admin/", admin.site.urls),
path(r"", views.index)
]
60 changes: 60 additions & 0 deletions bildungsfeiertag/bildungsfeiertag/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
from django.shortcuts import render
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.db import IntegrityError
from .models import Site, Room, Talk, Vote, MediaFile


def index(request):
return render(request, "index.html")


def overview(request):
sites = Site.objects.all()
return render(request, "overview.html")


def site(request, id):
site = get_object_or_404(Site, id=id)
rooms = Room.objects.filter(site=site)
talks = [Talk.objects.filter(room=room) for room in rooms]
return render(request, "site.html", {"site": site,
"rooms": rooms,
"talks": talks})


def talk(request, id):
if request.method == "POST":
talk = get_object_or_404(Talk, id=id)
return render(request, "talk.html", {"talk": talk})


def room(request, id):
room = get_object_or_404(Room, id=id)
talks = Talk.objects.filter(room=room).order_by("time")
return render(request, "room.html", {"room": room, "talks": talks})


def media(request):
if request.method == "POST":
if "delete" in request.POST:
media = MediaFile.objects.get(name=request.POST["name"])
try:
os.remove(media.mediafile.path)
except FileNotFoundError: pass
media.delete()
return redirect("/media/")
try:
MediaFile.objects.create(
name=request.POST["name"], mediafile=request.FILES["file"]
)
except IntegrityError:
return render(request, "media.html", {
"error": "There is already media with that name",
"media": MediaFile.objects.all()
})
return redirect("/media/")
return render(request, "media.html", {
"media": MediaFile.objects.all()
})
Binary file added bildungsfeiertag/db.sqlite3
Binary file not shown.

0 comments on commit 2f939d2

Please sign in to comment.