diff --git a/bildungsfeiertag/bildungsfeiertag/__pycache__/__init__.cpython-36.pyc b/bildungsfeiertag/bildungsfeiertag/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..89a02ae Binary files /dev/null and b/bildungsfeiertag/bildungsfeiertag/__pycache__/__init__.cpython-36.pyc differ diff --git a/bildungsfeiertag/bildungsfeiertag/__pycache__/models.cpython-36.pyc b/bildungsfeiertag/bildungsfeiertag/__pycache__/models.cpython-36.pyc new file mode 100644 index 0000000..c4d7b1e Binary files /dev/null and b/bildungsfeiertag/bildungsfeiertag/__pycache__/models.cpython-36.pyc differ diff --git a/bildungsfeiertag/bildungsfeiertag/__pycache__/settings.cpython-36.pyc b/bildungsfeiertag/bildungsfeiertag/__pycache__/settings.cpython-36.pyc new file mode 100644 index 0000000..c20cd9a Binary files /dev/null and b/bildungsfeiertag/bildungsfeiertag/__pycache__/settings.cpython-36.pyc differ diff --git a/bildungsfeiertag/bildungsfeiertag/__pycache__/urls.cpython-36.pyc b/bildungsfeiertag/bildungsfeiertag/__pycache__/urls.cpython-36.pyc new file mode 100644 index 0000000..f6bf17e Binary files /dev/null and b/bildungsfeiertag/bildungsfeiertag/__pycache__/urls.cpython-36.pyc differ diff --git a/bildungsfeiertag/bildungsfeiertag/__pycache__/views.cpython-36.pyc b/bildungsfeiertag/bildungsfeiertag/__pycache__/views.cpython-36.pyc new file mode 100644 index 0000000..815d8b1 Binary files /dev/null and b/bildungsfeiertag/bildungsfeiertag/__pycache__/views.cpython-36.pyc differ diff --git a/bildungsfeiertag/bildungsfeiertag/admin.py b/bildungsfeiertag/bildungsfeiertag/admin.py new file mode 100644 index 0000000..ed435e7 --- /dev/null +++ b/bildungsfeiertag/bildungsfeiertag/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin +from django.db import models +from .models import * + +admin.site.register(Site) +admin.site.register(Room) +admin.site.register(Talk) +admin.site.register(Vote) diff --git a/bildungsfeiertag/bildungsfeiertag/models.py b/bildungsfeiertag/bildungsfeiertag/models.py new file mode 100644 index 0000000..ef150c9 --- /dev/null +++ b/bildungsfeiertag/bildungsfeiertag/models.py @@ -0,0 +1,67 @@ +import docupy +from datetime import datetime +from django.db import models +import bildungsfeiertag.settings as settings + + +class Site(models.Model): + name = models.CharField(max_length=100) + address = models.TextField() + image = models.CharField(max_length=128) + + def __str__(self): + return "{}".format(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(settings.AUTH_USER_MODEL, + 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( + settings.AUTH_USER_MODEL, + 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) diff --git a/bildungsfeiertag/bildungsfeiertag/settings.py b/bildungsfeiertag/bildungsfeiertag/settings.py index f62e607..b08c9fc 100644 --- a/bildungsfeiertag/bildungsfeiertag/settings.py +++ b/bildungsfeiertag/bildungsfeiertag/settings.py @@ -20,7 +20,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 @@ -37,6 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'material' ] MIDDLEWARE = [ @@ -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': [ @@ -103,7 +104,7 @@ # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'de-de' TIME_ZONE = 'UTC' diff --git a/bildungsfeiertag/bildungsfeiertag/templates/base.html b/bildungsfeiertag/bildungsfeiertag/templates/base.html new file mode 100644 index 0000000..e69de29 diff --git a/bildungsfeiertag/bildungsfeiertag/urls.py b/bildungsfeiertag/bildungsfeiertag/urls.py index f8ddf72..7c16270 100644 --- a/bildungsfeiertag/bildungsfeiertag/urls.py +++ b/bildungsfeiertag/bildungsfeiertag/urls.py @@ -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 +import bildungsfeiertag.views as views + urlpatterns = [ - path('admin/', admin.site.urls), + path(r"admin/", admin.site.urls), + path(r"", views.index) ] diff --git a/bildungsfeiertag/bildungsfeiertag/views.py b/bildungsfeiertag/bildungsfeiertag/views.py new file mode 100644 index 0000000..adbec26 --- /dev/null +++ b/bildungsfeiertag/bildungsfeiertag/views.py @@ -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() +}) diff --git a/bildungsfeiertag/db.sqlite3 b/bildungsfeiertag/db.sqlite3 new file mode 100644 index 0000000..6d151bb Binary files /dev/null and b/bildungsfeiertag/db.sqlite3 differ