-
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.
Merge pull request #1 from kpoeppel/AddUserManagement
Add user management
- Loading branch information
Showing
9 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
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,4 @@ | ||
# the gitignore-file | ||
|
||
bildungsfeiertag/__pycache__/ | ||
bildungsfeiertag/db.sqlite |
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,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) |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BildungsfeiertagConfig(AppConfig): | ||
name = 'bildungsfeiertag' |
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,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) |
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 @@ | ||
`` |
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.