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
1 merge request!179Code quality improvements
......@@ -2,4 +2,7 @@ from django.apps import AppConfig
class AkplanConfig(AppConfig):
"""
App configuration (default, only specifies name of the app)
"""
name = 'AKPlan'
# 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
:param hex: hex encoded color
......@@ -23,8 +23,7 @@ def rgb_to_hex(rgb):
"""
# Components need to be integers for hex to make sense
rgb = [int(x) for x in rgb]
return "#"+"".join(["0{0:x}".format(v) if v < 16 else
"{0:x}".format(v) for v in rgb])
return "#"+"".join([f"0{v:x}" if v < 16 else f"{v:x}" for v in rgb])
def linear_blend(start_hex, end_hex, position):
......
......@@ -11,6 +11,14 @@ register = template.Library()
@register.filter
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
if akslot.event.plan_hidden or (akslot.event.plan_published_at is not None
and akslot.event.plan_published_at > akslot.updated):
......@@ -25,9 +33,14 @@ def highlight_change_colors(akslot):
# Recent change? Calculate gradient blend between red and
recentness = seconds_since_update / settings.PLAN_MAX_HIGHLIGHT_UPDATE_SECONDS
return darken("#b71540", recentness)
# return linear_blend("#b71540", "#000000", recentness)
@register.simple_tag
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")
from datetime import timedelta
from django.conf import settings
from django.shortcuts import redirect
from django.urls import reverse_lazy
......@@ -11,6 +9,11 @@ from AKModel.metaviews.admin import FilterByEventSlugMixin
class PlanIndexView(FilterByEventSlugMixin, ListView):
"""
Default plan view
Shows two lists of current and upcoming AKs and a graphical full plan below
"""
model = AKSlot
template_name = "AKPlan/plan_index.html"
context_object_name = "akslots"
......@@ -60,6 +63,15 @@ class PlanIndexView(FilterByEventSlugMixin, ListView):
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"
def get(self, request, *args, **kwargs):
......@@ -92,22 +104,34 @@ class PlanScreenView(PlanIndexView):
class PlanRoomView(FilterByEventSlugMixin, DetailView):
"""
Plan view for a single room
"""
template_name = "AKPlan/plan_room.html"
model = Room
context_object_name = "room"
def get_context_data(self, *, object_list=None, **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')
return context
class PlanTrackView(FilterByEventSlugMixin, DetailView):
"""
Plan view for a single track
"""
template_name = "AKPlan/plan_track.html"
model = AKTrack
context_object_name = "track"
def get_context_data(self, *, object_list=None, **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
[MAIN]
ignore=tests.py, urls.py, migrations
load-plugins=
......@@ -41,7 +42,7 @@ ignore-signatures=yes
[BASIC]
# 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-names=i,j,k,a,e,ak,tz,_
......@@ -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
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