-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First model trials, setting up the basics (views.py, models.py). Toug…
…h part will be html templates and register dialogue.
- Loading branch information
Showing
12 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
Binary file added
BIN
+179 Bytes
bildungsfeiertag/bildungsfeiertag/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+2.29 KB
bildungsfeiertag/bildungsfeiertag/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.