Skip to content
Snippets Groups Projects
Commit c642abca authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Improve documentation and resolve quality issues for AKPlan

Add comments
Remove unused imports
Simplify statements
Improve linting configuration
parent a2853bb1
No related branches found
No related tags found
No related merge requests found
...@@ -2,4 +2,7 @@ from django.apps import AppConfig ...@@ -2,4 +2,7 @@ from django.apps import AppConfig
class AkplanConfig(AppConfig): class AkplanConfig(AppConfig):
"""
App configuration (default, only specifies name of the app)
"""
name = 'AKPlan' name = 'AKPlan'
# gradients based on http://bsou.io/posts/color-gradients-with-python # gradients based on http://bsou.io/posts/color-gradients-with-python
def hex_to_rgb(hex): def hex_to_rgb(hex): #pylint: disable=redefined-builtin
""" """
Convert hex color to RGB color code Convert hex color to RGB color code
:param hex: hex encoded color :param hex: hex encoded color
...@@ -23,8 +23,7 @@ def rgb_to_hex(rgb): ...@@ -23,8 +23,7 @@ def rgb_to_hex(rgb):
""" """
# Components need to be integers for hex to make sense # Components need to be integers for hex to make sense
rgb = [int(x) for x in rgb] rgb = [int(x) for x in rgb]
return "#"+"".join(["0{0:x}".format(v) if v < 16 else return "#"+"".join([f"0{v:x}" if v < 16 else f"{v:x}" for v in rgb])
"{0:x}".format(v) for v in rgb])
def linear_blend(start_hex, end_hex, position): def linear_blend(start_hex, end_hex, position):
......
...@@ -11,6 +11,14 @@ register = template.Library() ...@@ -11,6 +11,14 @@ register = template.Library()
@register.filter @register.filter
def highlight_change_colors(akslot): def highlight_change_colors(akslot):
"""
Adjust color to highlight recent changes if needed
:param akslot: akslot to determine color for
:type akslot: AKSlot
:return: color that should be used (either default color of the category or some kind of red)
:rtype: str
"""
# Do not highlight in preview mode or when changes occurred before the plan was published # Do not highlight in preview mode or when changes occurred before the plan was published
if akslot.event.plan_hidden or (akslot.event.plan_published_at is not None if akslot.event.plan_hidden or (akslot.event.plan_published_at is not None
and akslot.event.plan_published_at > akslot.updated): and akslot.event.plan_published_at > akslot.updated):
...@@ -25,9 +33,14 @@ def highlight_change_colors(akslot): ...@@ -25,9 +33,14 @@ def highlight_change_colors(akslot):
# Recent change? Calculate gradient blend between red and # Recent change? Calculate gradient blend between red and
recentness = seconds_since_update / settings.PLAN_MAX_HIGHLIGHT_UPDATE_SECONDS recentness = seconds_since_update / settings.PLAN_MAX_HIGHLIGHT_UPDATE_SECONDS
return darken("#b71540", recentness) return darken("#b71540", recentness)
# return linear_blend("#b71540", "#000000", recentness)
@register.simple_tag @register.simple_tag
def timestamp_now(tz): def timestamp_now(tz):
"""
Get the current timestamp for the given timezone
:param tz: timezone to be used for the timestamp
:return: current timestamp in given timezone
"""
return date_format(datetime.now().astimezone(tz), "c") return date_format(datetime.now().astimezone(tz), "c")
from datetime import timedelta
from django.conf import settings from django.conf import settings
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse_lazy from django.urls import reverse_lazy
...@@ -11,6 +9,11 @@ from AKModel.metaviews.admin import FilterByEventSlugMixin ...@@ -11,6 +9,11 @@ from AKModel.metaviews.admin import FilterByEventSlugMixin
class PlanIndexView(FilterByEventSlugMixin, ListView): class PlanIndexView(FilterByEventSlugMixin, ListView):
"""
Default plan view
Shows two lists of current and upcoming AKs and a graphical full plan below
"""
model = AKSlot model = AKSlot
template_name = "AKPlan/plan_index.html" template_name = "AKPlan/plan_index.html"
context_object_name = "akslots" context_object_name = "akslots"
...@@ -60,6 +63,15 @@ class PlanIndexView(FilterByEventSlugMixin, ListView): ...@@ -60,6 +63,15 @@ class PlanIndexView(FilterByEventSlugMixin, ListView):
class PlanScreenView(PlanIndexView): class PlanScreenView(PlanIndexView):
"""
Plan view optimized for screens and projectors
This again shows current and upcoming AKs as well as a graphical plan,
but no navigation elements and trys to use the available space as best as possible
such that no scrolling is needed.
The view contains a frontend functionality for auto-reload.
"""
template_name = "AKPlan/plan_wall.html" template_name = "AKPlan/plan_wall.html"
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
...@@ -92,22 +104,34 @@ class PlanScreenView(PlanIndexView): ...@@ -92,22 +104,34 @@ class PlanScreenView(PlanIndexView):
class PlanRoomView(FilterByEventSlugMixin, DetailView): class PlanRoomView(FilterByEventSlugMixin, DetailView):
"""
Plan view for a single room
"""
template_name = "AKPlan/plan_room.html" template_name = "AKPlan/plan_room.html"
model = Room model = Room
context_object_name = "room" context_object_name = "room"
def get_context_data(self, *, object_list=None, **kwargs): def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs) context = super().get_context_data(object_list=object_list, **kwargs)
# Restrict AKSlot list to the given room
# while joining AK, room and category information to reduce the amount of necessary SQL queries
context["slots"] = AKSlot.objects.filter(room=context['room']).select_related('ak', 'ak__category', 'ak__track') context["slots"] = AKSlot.objects.filter(room=context['room']).select_related('ak', 'ak__category', 'ak__track')
return context return context
class PlanTrackView(FilterByEventSlugMixin, DetailView): class PlanTrackView(FilterByEventSlugMixin, DetailView):
"""
Plan view for a single track
"""
template_name = "AKPlan/plan_track.html" template_name = "AKPlan/plan_track.html"
model = AKTrack model = AKTrack
context_object_name = "track" context_object_name = "track"
def get_context_data(self, *, object_list=None, **kwargs): def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs) context = super().get_context_data(object_list=object_list, **kwargs)
context["slots"] = AKSlot.objects.filter(event=self.event, ak__track=context['track']).select_related('ak', 'room', 'ak__category') # Restrict AKSlot list to given track
# while joining AK, room and category information to reduce the amount of necessary SQL queries
context["slots"] = AKSlot.objects.\
filter(event=self.event, ak__track=context['track']).\
select_related('ak', 'room', 'ak__category')
return context return context
[MAIN] [MAIN]
ignore=tests.py, urls.py, migrations ignore=tests.py, urls.py, migrations
load-plugins= load-plugins=
...@@ -41,7 +42,7 @@ ignore-signatures=yes ...@@ -41,7 +42,7 @@ ignore-signatures=yes
[BASIC] [BASIC]
# Regular expression matching correct module names # Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|(AK[A-Z][a-z0-9_]+))$ module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|((tags_)*AK[A-Z][a-z0-9_]+))$
# Good variable names which should always be accepted, separated by a comma # Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,a,e,ak,tz,_ good-names=i,j,k,a,e,ak,tz,_
...@@ -66,3 +67,8 @@ generated-members=objects,DoesNotExist,id,pk,_meta,base_fields,context ...@@ -66,3 +67,8 @@ generated-members=objects,DoesNotExist,id,pk,_meta,base_fields,context
# List of method names used to declare (i.e. assign) instance attributes # List of method names used to declare (i.e. assign) instance attributes
defining-attr-methods=__init__,__new__,setUp defining-attr-methods=__init__,__new__,setUp
[DESIGN]
max-parents=15
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment