Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(overview): made website overview for tv in workshop #623

Closed
wants to merge 15 commits into from
Empty file added overview/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions overview/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class OverviewConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "overview"
23 changes: 23 additions & 0 deletions overview/static/overview/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body {
background-color: #4E4B46;
overflow: hidden;
}

.panel h3 {
padding: 5px;
padding: 5px;
}

.panel div {
font-size: 20px;
}

.panel {
margin: 30px;
}

#rule-body {
font-size: 1.40rem;
height: 60rem;
overflow: hidden;
}
15 changes: 15 additions & 0 deletions overview/templates/overview/events.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ul class="collection with-header card-panel">
<li class="collection-header">
<p class="flow-text"><a class="hs-gray-text">Siste arrangementer</a></p>
</li>
{% for event in event_list %}
<li class="collection-item">
{% if event.time_start > current_time %}
<span class="badge white-text hs-green">{{ event.time_start|date:"d.m.Y" }}</span>
{% else %}
<span class="secondary-content badge line-through">{{ event.time_start|date:"d.m.Y" }}</span>
{% endif %}
<a class="title">{{ event.title }}</a>
</li>
{% endfor %}
</ul>
11 changes: 11 additions & 0 deletions overview/templates/overview/news.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<ul class="collection with-header card-panel">
<li class="collection-header">
<p class="flow-text"><a class="hs-gray-text">Siste nytt</a></p>
</li>
{% for article in article_list %}
<li class="collection-item ">
<span class="secondary-content badge" href="#!">{{ article.pub_date|date:"d.m.Y" }}</span>
<a class="">{{ article.title }}</a>
</li>
{% endfor %}
</ul>
53 changes: 53 additions & 0 deletions overview/templates/overview/overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% load static %}
<head>
<title>Hackerspace NTNU</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Google Icons -->
<link href="https://fonts.googleapis.com/css?family=Montserrat:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900|Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i" rel="stylesheet">
<!-- Legg til Materialize JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Lokale stylesheets etter materialize, for å override farger etc -->
<link rel="stylesheet" type="text/css" href="{% static "website/css/style.css" %}">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{% static 'news/css/news_style.css' %}">

<link rel="stylesheet" type="text/css" href="{% static 'overview/css/style.css' %}">
</head>

<body>
<main>
<div class="row">
{% if rule %}
<div class="col s6">
{% else %}
<div class="col s12">
{% endif %}
<div class="row">
<div class="col s6">
<div class="panel">
{% include 'overview/news.html' %}
</div>
</div>
<div class="col s6">
<div class="panel">
{% include 'overview/events.html' %}
</div>
</div>
</div>
<div class="row">
{% include 'overview/watchlist.html' %}
</div>
</div>
{% if rule %}
<div class="col s6">
<div class="">
{% include 'overview/rules.html' %}
</div>
</div>
{% endif %}
</main>
</body>


10 changes: 10 additions & 0 deletions overview/templates/overview/rules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="white card-panel panel">
<div class="">
<h3><b>{{ rule.title }}</b></h3>
</div>
<div class="container">
<div id="rule-body">
{{ rule.body | safe }}
</div>
</div>
</div>
20 changes: 20 additions & 0 deletions overview/templates/overview/watchlist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="card-panel panel">
<h3 class=""><b>Vakthavende - {{ weekday }}</b></h3>
{% for time, shift in shifts.items %}
<div class="center-align"><b>{{ time }}</b></div>
<hr>
<div>
{% if shift.watchers.count > 0 %}
<div class="row center-align">
{% for user in shift.watchers.all %}
<div class="col s12 m6 l3 center-align">{{ user.first_name }} {{ user.last_name }}</div>
{% endfor %}
</div>
{% else %}
<p>Ingen på vakt!</p>
{% endif %}
</div>
{% empty %}
<h5 id="no-time-slots">Ingen vakter satt for i dag</h5>
{% endfor %}
</div>
9 changes: 9 additions & 0 deletions overview/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from . import views

app_name = "overview"

urlpatterns = [
path("", views.OverviewView.as_view(), name="overview"),
]
67 changes: 67 additions & 0 deletions overview/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from datetime import datetime

from django.utils import timezone
from django.views.generic import TemplateView

from news.models import Article, Event
from watchlist.models import ShiftSlot
from website.models import Rule

WEEKDAYS = ["Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag"]


class OverviewView(TemplateView):
template_name = "overview/overview.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

# Get the 5 events closest to starting
event_list = list(
Event.objects.filter(
time_start__gt=timezone.now(),
draft=False,
internal=False,
).order_by("time_start")[:5]
)

# Add expired events if we couldn't fill the 5 slots
if len(event_list) < 5:
to_fill = 5 - len(event_list)
expired_events = Event.objects.filter(
time_start__lte=timezone.now(),
internal=False,
draft=False,
).order_by("-time_start")[:to_fill]
event_list += list(expired_events)

current_time = datetime.now()

# Get five published articles
article_list = Article.objects.filter(draft=False, internal=False).order_by(
"-pub_date"
)[:5]

# Get shifts from today
valid_shifts = ShiftSlot.objects.filter(
weekday=current_time.weekday()
).order_by("start")

shift_dict = {}
for shift in valid_shifts:
row_header = "{} -\n{}".format(
shift.start.strftime("%H:%M"), shift.end.strftime("%H:%M")
)
shift_dict[row_header] = shift

context = {
"article_list": article_list,
"event_list": event_list,
"current_time": current_time,
"shifts": shift_dict,
"today": current_time.weekday(),
"weekday": WEEKDAYS[current_time.weekday()],
"rule": Rule.objects.filter(id=9).first(),
}

return context
1 change: 1 addition & 0 deletions website/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"social_django",
"inventory",
"watchlist",
"overview",
"projectarchive",
]

Expand Down
1 change: 1 addition & 0 deletions website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
path("inventory/", include("inventory.urls")),
path("vaktliste/", include("watchlist.urls")),
path("intranet/", IntranetView.as_view(), name="intranet"),
path("overview/", include("overview.urls")),
path("projectarchive/", include("projectarchive.urls"), name="projectarchive"),
]

Expand Down