Compare commits
	
		
			3 Commits
		
	
	
		
			64f5668dde
			...
			fix-csrf
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 615d4e59c6 | |||
| 83f075e49d | |||
| d3682368b4 | 
@ -1,5 +1 @@
 | 
				
			|||||||
src/web/static/*
 | 
					src/web/static/*
 | 
				
			||||||
.venv
 | 
					 | 
				
			||||||
.githooks
 | 
					 | 
				
			||||||
.vscode
 | 
					 | 
				
			||||||
node_modules
 | 
					 | 
				
			||||||
							
								
								
									
										12
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								CHANGELOG.md
									
									
									
									
									
								
							@ -1,14 +1,4 @@
 | 
				
			|||||||
## 0.2.1 / 2023-01-13 16:53+01:00
 | 
					## Unreleased
 | 
				
			||||||
 | 
					 | 
				
			||||||
* List number of sessions when filtering on session list
 | 
					 | 
				
			||||||
* Start sessions of last purchase from list (https://git.kucharczyk.xyz/lukas/timetracker/issues/19)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## 0.2.0 / 2023-01-09 22:42+01:00
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
* Show playtime total on session list (https://git.kucharczyk.xyz/lukas/timetracker/issues/6)
 | 
					 | 
				
			||||||
* Make formatting durations more robust, change default duration display to "X hours" (https://git.kucharczyk.xyz/lukas/timetracker/issues/26)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## 0.1.4 / 2023-01-08 15:45+01:00
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Fix collectstaticfiles causing error when restarting container (https://git.kucharczyk.xyz/lukas/timetracker/issues/23)
 | 
					* Fix collectstaticfiles causing error when restarting container (https://git.kucharczyk.xyz/lukas/timetracker/issues/23)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,7 @@ RUN npm install && \
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
FROM python:3.10.9-alpine
 | 
					FROM python:3.10.9-alpine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ENV VERSION_NUMBER 0.2.1
 | 
					ENV VERSION_NUMBER 0.1.2-3-g83f075e
 | 
				
			||||||
ENV PROD 1
 | 
					ENV PROD 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RUN apk add \
 | 
					RUN apk add \
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							@ -20,7 +20,7 @@ migrate: makemigrations
 | 
				
			|||||||
	poetry run python src/web/manage.py migrate
 | 
						poetry run python src/web/manage.py migrate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dev: migrate sethookdir
 | 
					dev: migrate sethookdir
 | 
				
			||||||
	poetry run python src/web/manage.py runserver
 | 
						poetry run python src/web/manage.py runserver_plus
 | 
				
			||||||
 | 
					
 | 
				
			||||||
caddy:
 | 
					caddy:
 | 
				
			||||||
	caddy run --watch
 | 
						caddy run --watch
 | 
				
			||||||
@ -44,7 +44,7 @@ shell:
 | 
				
			|||||||
	poetry run python src/web/manage.py shell
 | 
						poetry run python src/web/manage.py shell
 | 
				
			||||||
 | 
					
 | 
				
			||||||
collectstatic:
 | 
					collectstatic:
 | 
				
			||||||
	poetry run python src/web/manage.py collectstatic --clear --no-input
 | 
						poetry run python src/web/manage.py collectstatic -c --no-input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
poetry.lock: pyproject.toml
 | 
					poetry.lock: pyproject.toml
 | 
				
			||||||
	poetry install
 | 
						poetry install
 | 
				
			||||||
@ -56,7 +56,7 @@ sethookdir:
 | 
				
			|||||||
	git config core.hooksPath .githooks
 | 
						git config core.hooksPath .githooks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
date:
 | 
					date:
 | 
				
			||||||
	poetry run python -c 'import datetime; from zoneinfo import ZoneInfo; print(datetime.datetime.isoformat(datetime.datetime.now(ZoneInfo("Europe/Prague")), timespec="minutes", sep=" "))'
 | 
						python3 -c 'import datetime; from zoneinfo import ZoneInfo; print(datetime.datetime.isoformat(datetime.datetime.now(ZoneInfo("Europe/Prague")), timespec="minutes", sep=" "))'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cleanstatic:
 | 
					cleanstatic:
 | 
				
			||||||
	rm -r src/web/static/*
 | 
						rm -r src/web/static/*
 | 
				
			||||||
 | 
				
			|||||||
@ -10,4 +10,4 @@ poetry run python src/web/manage.py collectstatic --clear --no-input
 | 
				
			|||||||
echo "Starting server"
 | 
					echo "Starting server"
 | 
				
			||||||
caddy start
 | 
					caddy start
 | 
				
			||||||
cd src/web || exit
 | 
					cd src/web || exit
 | 
				
			||||||
poetry run python -m gunicorn --bind 0.0.0.0:8001 web.asgi:application -k uvicorn.workers.UvicornWorker --access-logfile - --error-logfile -
 | 
					poetry run python -m gunicorn --bind 0.0.0.0:8001 web.asgi:application -k uvicorn.workers.UvicornWorker
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
[tool.poetry]
 | 
					[tool.poetry]
 | 
				
			||||||
name = "timetracker"
 | 
					name = "timetracker"
 | 
				
			||||||
version = "0.2.1"
 | 
					version = "0.1.2"
 | 
				
			||||||
description = "A simple time tracker."
 | 
					description = "A simple time tracker."
 | 
				
			||||||
authors = ["Lukáš Kucharczyk <lukas@kucharczyk.xyz>"]
 | 
					authors = ["Lukáš Kucharczyk <lukas@kucharczyk.xyz>"]
 | 
				
			||||||
license = "GPL"
 | 
					license = "GPL"
 | 
				
			||||||
 | 
				
			|||||||
@ -8,17 +8,8 @@ def now() -> datetime:
 | 
				
			|||||||
    return datetime.now(ZoneInfo(settings.TIME_ZONE))
 | 
					    return datetime.now(ZoneInfo(settings.TIME_ZONE))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _safe_timedelta(duration: timedelta | int | None):
 | 
					 | 
				
			||||||
    if duration == None:
 | 
					 | 
				
			||||||
        return timedelta(0)
 | 
					 | 
				
			||||||
    elif isinstance(duration, int):
 | 
					 | 
				
			||||||
        return timedelta(seconds=duration)
 | 
					 | 
				
			||||||
    elif isinstance(duration, timedelta):
 | 
					 | 
				
			||||||
        return duration
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def format_duration(
 | 
					def format_duration(
 | 
				
			||||||
    duration: timedelta | int | None, format_string: str = "%H hours"
 | 
					    duration: timedelta, format_string: str = "%H hours %m minutes"
 | 
				
			||||||
) -> str:
 | 
					) -> str:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Format timedelta into the specified format_string.
 | 
					    Format timedelta into the specified format_string.
 | 
				
			||||||
@ -27,28 +18,19 @@ def format_duration(
 | 
				
			|||||||
    - %m minutes
 | 
					    - %m minutes
 | 
				
			||||||
    - %s seconds
 | 
					    - %s seconds
 | 
				
			||||||
    - %r total seconds
 | 
					    - %r total seconds
 | 
				
			||||||
    Values don't change into higher units if those units are missing
 | 
					 | 
				
			||||||
    from the formatting string. For example:
 | 
					 | 
				
			||||||
    - 61 seconds as "%s" = 61 seconds
 | 
					 | 
				
			||||||
    - 61 seconds as "%m %s" = 1 minutes 1 seconds"
 | 
					 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    minute_seconds = 60
 | 
					    minute_seconds = 60
 | 
				
			||||||
    hour_seconds = 60 * minute_seconds
 | 
					    hour_seconds = 60 * minute_seconds
 | 
				
			||||||
    day_seconds = 24 * hour_seconds
 | 
					    day_seconds = 24 * hour_seconds
 | 
				
			||||||
    duration = _safe_timedelta(duration)
 | 
					    if not isinstance(duration, timedelta):
 | 
				
			||||||
    # we don't need float
 | 
					        duration = timedelta(seconds=duration)
 | 
				
			||||||
    seconds_total = int(duration.total_seconds())
 | 
					    seconds_total = int(duration.total_seconds())
 | 
				
			||||||
    # timestamps where end is before start
 | 
					    # timestamps where end is before start
 | 
				
			||||||
    if seconds_total < 0:
 | 
					    if seconds_total < 0:
 | 
				
			||||||
        seconds_total = 0
 | 
					        seconds_total = 0
 | 
				
			||||||
    days = hours = minutes = seconds = 0
 | 
					    days, remainder = divmod(seconds_total, day_seconds)
 | 
				
			||||||
    remainder = seconds = seconds_total
 | 
					    hours, remainder = divmod(remainder, hour_seconds)
 | 
				
			||||||
    if "%d" in format_string:
 | 
					    minutes, seconds = divmod(remainder, minute_seconds)
 | 
				
			||||||
        days, remainder = divmod(seconds_total, day_seconds)
 | 
					 | 
				
			||||||
    if "%H" in format_string:
 | 
					 | 
				
			||||||
        hours, remainder = divmod(remainder, hour_seconds)
 | 
					 | 
				
			||||||
    if "%m" in format_string:
 | 
					 | 
				
			||||||
        minutes, seconds = divmod(remainder, minute_seconds)
 | 
					 | 
				
			||||||
    literals = {
 | 
					    literals = {
 | 
				
			||||||
        "%d": str(days),
 | 
					        "%d": str(days),
 | 
				
			||||||
        "%H": str(hours),
 | 
					        "%H": str(hours),
 | 
				
			||||||
 | 
				
			|||||||
@ -1,21 +0,0 @@
 | 
				
			|||||||
# Generated by Django 4.1.5 on 2023-01-09 14:49
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import datetime
 | 
					 | 
				
			||||||
from django.db import migrations, models
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Migration(migrations.Migration):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    dependencies = [
 | 
					 | 
				
			||||||
        ("tracker", "0003_alter_session_duration_manual_and_more"),
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    operations = [
 | 
					 | 
				
			||||||
        migrations.AlterField(
 | 
					 | 
				
			||||||
            model_name="session",
 | 
					 | 
				
			||||||
            name="duration_manual",
 | 
					 | 
				
			||||||
            field=models.DurationField(
 | 
					 | 
				
			||||||
                blank=True, default=datetime.timedelta(0), null=True
 | 
					 | 
				
			||||||
            ),
 | 
					 | 
				
			||||||
        ),
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
@ -1,34 +0,0 @@
 | 
				
			|||||||
# Generated by Django 4.1.5 on 2023-01-09 17:43
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from django.db import migrations
 | 
					 | 
				
			||||||
from datetime import timedelta
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def set_duration_calculated_none_to_zero(apps, schema_editor):
 | 
					 | 
				
			||||||
    Session = apps.get_model("tracker", "Session")
 | 
					 | 
				
			||||||
    for session in Session.objects.all():
 | 
					 | 
				
			||||||
        if session.duration_calculated == None:
 | 
					 | 
				
			||||||
            session.duration_calculated = timedelta(0)
 | 
					 | 
				
			||||||
            session.save()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def revert_set_duration_calculated_none_to_zero(apps, schema_editor):
 | 
					 | 
				
			||||||
    Session = apps.get_model("tracker", "Session")
 | 
					 | 
				
			||||||
    for session in Session.objects.all():
 | 
					 | 
				
			||||||
        if session.duration_calculated == timedelta(0):
 | 
					 | 
				
			||||||
            session.duration_calculated = None
 | 
					 | 
				
			||||||
            session.save()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Migration(migrations.Migration):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    dependencies = [
 | 
					 | 
				
			||||||
        ("tracker", "0004_alter_session_duration_manual"),
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    operations = [
 | 
					 | 
				
			||||||
        migrations.RunPython(
 | 
					 | 
				
			||||||
            set_duration_calculated_none_to_zero,
 | 
					 | 
				
			||||||
            revert_set_duration_calculated_none_to_zero,
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
@ -1,34 +0,0 @@
 | 
				
			|||||||
# Generated by Django 4.1.5 on 2023-01-09 18:04
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from django.db import migrations
 | 
					 | 
				
			||||||
from datetime import timedelta
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def set_duration_manual_none_to_zero(apps, schema_editor):
 | 
					 | 
				
			||||||
    Session = apps.get_model("tracker", "Session")
 | 
					 | 
				
			||||||
    for session in Session.objects.all():
 | 
					 | 
				
			||||||
        if session.duration_manual == None:
 | 
					 | 
				
			||||||
            session.duration_manual = timedelta(0)
 | 
					 | 
				
			||||||
            session.save()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def revert_set_duration_manual_none_to_zero(apps, schema_editor):
 | 
					 | 
				
			||||||
    Session = apps.get_model("tracker", "Session")
 | 
					 | 
				
			||||||
    for session in Session.objects.all():
 | 
					 | 
				
			||||||
        if session.duration_manual == timedelta(0):
 | 
					 | 
				
			||||||
            session.duration_manual = None
 | 
					 | 
				
			||||||
            session.save()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Migration(migrations.Migration):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    dependencies = [
 | 
					 | 
				
			||||||
        ("tracker", "0005_auto_20230109_1843"),
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    operations = [
 | 
					 | 
				
			||||||
        migrations.RunPython(
 | 
					 | 
				
			||||||
            set_duration_manual_none_to_zero,
 | 
					 | 
				
			||||||
            revert_set_duration_manual_none_to_zero,
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
    ]
 | 
					 | 
				
			||||||
@ -3,9 +3,7 @@ from datetime import datetime, timedelta
 | 
				
			|||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
from zoneinfo import ZoneInfo
 | 
					from zoneinfo import ZoneInfo
 | 
				
			||||||
from common.util.time import format_duration
 | 
					from common.util.time import format_duration
 | 
				
			||||||
from django.db.models import Sum, F
 | 
					from django.db.models import Sum
 | 
				
			||||||
from django.db.models import Manager
 | 
					 | 
				
			||||||
from typing import Any
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Game(models.Model):
 | 
					class Game(models.Model):
 | 
				
			||||||
@ -34,58 +32,69 @@ class Platform(models.Model):
 | 
				
			|||||||
        return self.name
 | 
					        return self.name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SessionQuerySet(models.QuerySet):
 | 
					 | 
				
			||||||
    def total_duration(self):
 | 
					 | 
				
			||||||
        result = self.aggregate(
 | 
					 | 
				
			||||||
            duration=Sum(F("duration_calculated") + F("duration_manual"))
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        return format_duration(result["duration"])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Session(models.Model):
 | 
					class Session(models.Model):
 | 
				
			||||||
    purchase = models.ForeignKey("Purchase", on_delete=models.CASCADE)
 | 
					    purchase = models.ForeignKey("Purchase", on_delete=models.CASCADE)
 | 
				
			||||||
    timestamp_start = models.DateTimeField()
 | 
					    timestamp_start = models.DateTimeField()
 | 
				
			||||||
    timestamp_end = models.DateTimeField(blank=True, null=True)
 | 
					    timestamp_end = models.DateTimeField(blank=True, null=True)
 | 
				
			||||||
    duration_manual = models.DurationField(blank=True, null=True, default=timedelta(0))
 | 
					    duration_manual = models.DurationField(blank=True, null=True)
 | 
				
			||||||
    duration_calculated = models.DurationField(blank=True, null=True)
 | 
					    duration_calculated = models.DurationField(blank=True, null=True)
 | 
				
			||||||
    note = models.TextField(blank=True, null=True)
 | 
					    note = models.TextField(blank=True, null=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    objects = SessionQuerySet.as_manager()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        mark = ", manual" if self.duration_manual != None else ""
 | 
					        mark = ", manual" if self.duration_manual != None else ""
 | 
				
			||||||
        return f"{str(self.purchase)} {str(self.timestamp_start.date())} ({self.duration_formatted()}{mark})"
 | 
					        return f"{str(self.purchase)} {str(self.timestamp_start.date())} ({self.duration_any()}{mark})"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def finish_now(self):
 | 
					    def finish_now(self):
 | 
				
			||||||
        self.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE))
 | 
					        self.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def start_now():
 | 
					 | 
				
			||||||
        self.timestamp_start = datetime.now(ZoneInfo(settings.TIME_ZONE))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def duration_seconds(self) -> timedelta:
 | 
					    def duration_seconds(self) -> timedelta:
 | 
				
			||||||
        manual = timedelta(0)
 | 
					        if self.duration_manual == None:
 | 
				
			||||||
        calculated = timedelta(0)
 | 
					            if self.timestamp_end == None or self.timestamp_start == None:
 | 
				
			||||||
        if not self.duration_manual in (None, 0, timedelta(0)):
 | 
					                return timedelta(0)
 | 
				
			||||||
            manual = self.duration_manual
 | 
					            else:
 | 
				
			||||||
        if self.timestamp_end != None and self.timestamp_start != None:
 | 
					                value = self.timestamp_end - self.timestamp_start
 | 
				
			||||||
            calculated = self.timestamp_end - self.timestamp_start
 | 
					        else:
 | 
				
			||||||
        return timedelta(seconds=(manual + calculated).total_seconds())
 | 
					            value = self.duration_manual
 | 
				
			||||||
 | 
					        return timedelta(seconds=value.total_seconds())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def duration_formatted(self) -> str:
 | 
					    def duration_formatted(self) -> str:
 | 
				
			||||||
        result = format_duration(self.duration_seconds(), "%H:%m")
 | 
					        result = format_duration(self.duration_seconds(), "%H:%m")
 | 
				
			||||||
        return result
 | 
					        return result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    def duration_any(self):
 | 
				
			||||||
    def duration_sum(self) -> str:
 | 
					        return (
 | 
				
			||||||
        return Session.objects.all().total_duration()
 | 
					            self.duration_formatted()
 | 
				
			||||||
 | 
					            if self.duration_manual == None
 | 
				
			||||||
 | 
					            else self.duration_manual
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @staticmethod
 | 
				
			||||||
    def last(self) -> Manager[Any]:
 | 
					    def calculated_sum() -> timedelta:
 | 
				
			||||||
        return Session.objects.all().order_by("timestamp_start")[:-1]
 | 
					        calculated_sum_query = Session.objects.all().aggregate(
 | 
				
			||||||
 | 
					            Sum("duration_calculated")
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        calculated_sum = (
 | 
				
			||||||
 | 
					            timedelta(0)
 | 
				
			||||||
 | 
					            if calculated_sum_query["duration_calculated__sum"] == None
 | 
				
			||||||
 | 
					            else calculated_sum_query["duration_calculated__sum"]
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        return calculated_sum
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @staticmethod
 | 
				
			||||||
 | 
					    def manual_sum() -> timedelta:
 | 
				
			||||||
 | 
					        manual_sum_query = Session.objects.all().aggregate(Sum("duration_manual"))
 | 
				
			||||||
 | 
					        manual_sum = (
 | 
				
			||||||
 | 
					            timedelta(0)
 | 
				
			||||||
 | 
					            if manual_sum_query["duration_manual__sum"] == None
 | 
				
			||||||
 | 
					            else manual_sum_query["duration_manual__sum"]
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        return manual_sum
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @staticmethod
 | 
				
			||||||
 | 
					    def total_sum() -> timedelta:
 | 
				
			||||||
 | 
					        return Session.manual_sum() + Session.calculated_sum()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def save(self, *args, **kwargs):
 | 
					    def save(self, *args, **kwargs):
 | 
				
			||||||
        if self.timestamp_start != None and self.timestamp_end != None:
 | 
					        if self.timestamp_start != None and self.timestamp_end != None:
 | 
				
			||||||
            self.duration_calculated = self.timestamp_end - self.timestamp_start
 | 
					            self.duration_calculated = self.timestamp_end - self.timestamp_start
 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            self.duration_calculated = timedelta(0)
 | 
					 | 
				
			||||||
        super(Session, self).save(*args, **kwargs)
 | 
					        super(Session, self).save(*args, **kwargs)
 | 
				
			||||||
 | 
				
			|||||||
@ -683,66 +683,34 @@ select {
 | 
				
			|||||||
  width: 100%;
 | 
					  width: 100%;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.\!container {
 | 
					 | 
				
			||||||
  width: 100% !important;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@media (min-width: 640px) {
 | 
					@media (min-width: 640px) {
 | 
				
			||||||
  .container {
 | 
					  .container {
 | 
				
			||||||
    max-width: 640px;
 | 
					    max-width: 640px;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  .\!container {
 | 
					 | 
				
			||||||
    max-width: 640px !important;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@media (min-width: 768px) {
 | 
					@media (min-width: 768px) {
 | 
				
			||||||
  .container {
 | 
					  .container {
 | 
				
			||||||
    max-width: 768px;
 | 
					    max-width: 768px;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  .\!container {
 | 
					 | 
				
			||||||
    max-width: 768px !important;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@media (min-width: 1024px) {
 | 
					@media (min-width: 1024px) {
 | 
				
			||||||
  .container {
 | 
					  .container {
 | 
				
			||||||
    max-width: 1024px;
 | 
					    max-width: 1024px;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  .\!container {
 | 
					 | 
				
			||||||
    max-width: 1024px !important;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@media (min-width: 1280px) {
 | 
					@media (min-width: 1280px) {
 | 
				
			||||||
  .container {
 | 
					  .container {
 | 
				
			||||||
    max-width: 1280px;
 | 
					    max-width: 1280px;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  .\!container {
 | 
					 | 
				
			||||||
    max-width: 1280px !important;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@media (min-width: 1536px) {
 | 
					@media (min-width: 1536px) {
 | 
				
			||||||
  .container {
 | 
					  .container {
 | 
				
			||||||
    max-width: 1536px;
 | 
					    max-width: 1536px;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  .\!container {
 | 
					 | 
				
			||||||
    max-width: 1536px !important;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.visible {
 | 
					 | 
				
			||||||
  visibility: visible;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.collapse {
 | 
					 | 
				
			||||||
  visibility: collapse;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.static {
 | 
					.static {
 | 
				
			||||||
@ -753,26 +721,6 @@ select {
 | 
				
			|||||||
  position: fixed;
 | 
					  position: fixed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.\!fixed {
 | 
					 | 
				
			||||||
  position: fixed !important;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.absolute {
 | 
					 | 
				
			||||||
  position: absolute;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.relative {
 | 
					 | 
				
			||||||
  position: relative;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.sticky {
 | 
					 | 
				
			||||||
  position: sticky;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.\!sticky {
 | 
					 | 
				
			||||||
  position: sticky !important;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.left-2 {
 | 
					.left-2 {
 | 
				
			||||||
  left: 0.5rem;
 | 
					  left: 0.5rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -802,42 +750,10 @@ select {
 | 
				
			|||||||
  display: block;
 | 
					  display: block;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.inline-block {
 | 
					 | 
				
			||||||
  display: inline-block;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.inline {
 | 
					 | 
				
			||||||
  display: inline;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.flex {
 | 
					.flex {
 | 
				
			||||||
  display: flex;
 | 
					  display: flex;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.table {
 | 
					 | 
				
			||||||
  display: table;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.table-caption {
 | 
					 | 
				
			||||||
  display: table-caption;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.table-cell {
 | 
					 | 
				
			||||||
  display: table-cell;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.contents {
 | 
					 | 
				
			||||||
  display: contents;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.hidden {
 | 
					 | 
				
			||||||
  display: none;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.\!hidden {
 | 
					 | 
				
			||||||
  display: none !important;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.h-5 {
 | 
					.h-5 {
 | 
				
			||||||
  height: 1.25rem;
 | 
					  height: 1.25rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -870,10 +786,6 @@ select {
 | 
				
			|||||||
  max-width: 1024px;
 | 
					  max-width: 1024px;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.resize {
 | 
					 | 
				
			||||||
  resize: both;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.flex-col {
 | 
					.flex-col {
 | 
				
			||||||
  flex-direction: column;
 | 
					  flex-direction: column;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -906,12 +818,6 @@ select {
 | 
				
			|||||||
  align-self: center;
 | 
					  align-self: center;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.truncate {
 | 
					 | 
				
			||||||
  overflow: hidden;
 | 
					 | 
				
			||||||
  text-overflow: ellipsis;
 | 
					 | 
				
			||||||
  white-space: nowrap;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.whitespace-nowrap {
 | 
					.whitespace-nowrap {
 | 
				
			||||||
  white-space: nowrap;
 | 
					  white-space: nowrap;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -920,16 +826,12 @@ select {
 | 
				
			|||||||
  border-radius: 0.25rem;
 | 
					  border-radius: 0.25rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.rounded-lg {
 | 
					 | 
				
			||||||
  border-radius: 0.5rem;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.rounded-xl {
 | 
					.rounded-xl {
 | 
				
			||||||
  border-radius: 0.75rem;
 | 
					  border-radius: 0.75rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.border {
 | 
					.rounded-lg {
 | 
				
			||||||
  border-width: 1px;
 | 
					  border-radius: 0.5rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.border-gray-200 {
 | 
					.border-gray-200 {
 | 
				
			||||||
@ -1011,28 +913,20 @@ select {
 | 
				
			|||||||
  line-height: 1rem;
 | 
					  line-height: 1rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.text-base {
 | 
					 | 
				
			||||||
  font-size: 1rem;
 | 
					 | 
				
			||||||
  line-height: 1.5rem;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.text-lg {
 | 
					.text-lg {
 | 
				
			||||||
  font-size: 1.125rem;
 | 
					  font-size: 1.125rem;
 | 
				
			||||||
  line-height: 1.75rem;
 | 
					  line-height: 1.75rem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.text-base {
 | 
				
			||||||
 | 
					  font-size: 1rem;
 | 
				
			||||||
 | 
					  line-height: 1.5rem;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.font-semibold {
 | 
					.font-semibold {
 | 
				
			||||||
  font-weight: 600;
 | 
					  font-weight: 600;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.uppercase {
 | 
					 | 
				
			||||||
  text-transform: uppercase;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.lowercase {
 | 
					 | 
				
			||||||
  text-transform: lowercase;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.text-white {
 | 
					.text-white {
 | 
				
			||||||
  --tw-text-opacity: 1;
 | 
					  --tw-text-opacity: 1;
 | 
				
			||||||
  color: rgb(255 255 255 / var(--tw-text-opacity));
 | 
					  color: rgb(255 255 255 / var(--tw-text-opacity));
 | 
				
			||||||
@ -1048,39 +942,16 @@ select {
 | 
				
			|||||||
  color: rgb(248 113 113 / var(--tw-text-opacity));
 | 
					  color: rgb(248 113 113 / var(--tw-text-opacity));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.shadow-md {
 | 
					 | 
				
			||||||
  --tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
 | 
					 | 
				
			||||||
  --tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);
 | 
					 | 
				
			||||||
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.shadow {
 | 
					.shadow {
 | 
				
			||||||
  --tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
 | 
					  --tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
 | 
				
			||||||
  --tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
 | 
					  --tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
 | 
				
			||||||
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
 | 
					  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.blur {
 | 
					.shadow-md {
 | 
				
			||||||
  --tw-blur: blur(8px);
 | 
					  --tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
 | 
				
			||||||
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
 | 
					  --tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);
 | 
				
			||||||
}
 | 
					  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
 | 
				
			||||||
 | 
					 | 
				
			||||||
.invert {
 | 
					 | 
				
			||||||
  --tw-invert: invert(100%);
 | 
					 | 
				
			||||||
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.\!invert {
 | 
					 | 
				
			||||||
  --tw-invert: invert(100%) !important;
 | 
					 | 
				
			||||||
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow) !important;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.filter {
 | 
					 | 
				
			||||||
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.\!filter {
 | 
					 | 
				
			||||||
  filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow) !important;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.transition {
 | 
					.transition {
 | 
				
			||||||
 | 
				
			|||||||
@ -3,18 +3,12 @@
 | 
				
			|||||||
{% block title %}Sessions{% endblock title %}
 | 
					{% block title %}Sessions{% endblock title %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% block content %}
 | 
					{% block content %}
 | 
				
			||||||
 | 
					    {% if purchase %}
 | 
				
			||||||
        <div class="text-center text-xl mb-4 dark:text-slate-400">
 | 
					        <div class="text-center text-xl mb-4 dark:text-slate-400">
 | 
				
			||||||
            <a href="{% url 'start_session' dataset.last.purchase.id %}">
 | 
					 | 
				
			||||||
                <button type="button" title="Track last tracked" class="py-1 px-2 bg-green-600 hover:bg-green-700 focus:ring-green-500 focus:ring-offset-blue-200 text-white transition ease-in duration-200 text-center text-base font-semibold shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 rounded-lg ">
 | 
					 | 
				
			||||||
                    New session of {{ dataset.last.purchase }}
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
            </a>
 | 
					 | 
				
			||||||
            {% if purchase %}
 | 
					 | 
				
			||||||
            <h1>Listing sessions only for purchase "{{ purchase }}"</h1>
 | 
					            <h1>Listing sessions only for purchase "{{ purchase }}"</h1>
 | 
				
			||||||
            <h2>Total playtime: {{ total_duration }} over {{ dataset.count }} sessions.</h2>
 | 
					 | 
				
			||||||
            <a class="dark:text-white hover:underline" href="{% url 'list_sessions' %}">View all sessions</a>
 | 
					            <a class="dark:text-white hover:underline" href="{% url 'list_sessions' %}">View all sessions</a>
 | 
				
			||||||
            {% endif %}
 | 
					 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					    {% endif %}
 | 
				
			||||||
    <div id="session-table" class="gap-4 shadow rounded-xl max-w-screen-lg mx-auto dark:bg-slate-700 p-2 justify-center">
 | 
					    <div id="session-table" class="gap-4 shadow rounded-xl max-w-screen-lg mx-auto dark:bg-slate-700 p-2 justify-center">
 | 
				
			||||||
        <div class="dark:border-white dark:text-slate-300 text-lg">Name</div>
 | 
					        <div class="dark:border-white dark:text-slate-300 text-lg">Name</div>
 | 
				
			||||||
        <div class="dark:border-white dark:text-slate-300 text-lg text-center">Start</div>
 | 
					        <div class="dark:border-white dark:text-slate-300 text-lg text-center">Start</div>
 | 
				
			||||||
 | 
				
			|||||||
@ -12,11 +12,6 @@ urlpatterns = [
 | 
				
			|||||||
        views.update_session,
 | 
					        views.update_session,
 | 
				
			||||||
        name="update_session",
 | 
					        name="update_session",
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
    path(
 | 
					 | 
				
			||||||
        "start-session/<int:purchase_id>",
 | 
					 | 
				
			||||||
        views.start_session,
 | 
					 | 
				
			||||||
        name="start_session",
 | 
					 | 
				
			||||||
    ),
 | 
					 | 
				
			||||||
    path(
 | 
					    path(
 | 
				
			||||||
        "delete_session/by-id/<int:session_id>",
 | 
					        "delete_session/by-id/<int:session_id>",
 | 
				
			||||||
        views.delete_session,
 | 
					        views.delete_session,
 | 
				
			||||||
 | 
				
			|||||||
@ -40,12 +40,6 @@ def update_session(request, session_id=None):
 | 
				
			|||||||
    return redirect("list_sessions")
 | 
					    return redirect("list_sessions")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def start_session(request, purchase_id=None):
 | 
					 | 
				
			||||||
    session = SessionForm({"purchase": purchase_id, "timestamp_start": now_with_tz()})
 | 
					 | 
				
			||||||
    session.save()
 | 
					 | 
				
			||||||
    return redirect("list_sessions")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def delete_session(request, session_id=None):
 | 
					def delete_session(request, session_id=None):
 | 
				
			||||||
    session = Session.objects.get(id=session_id)
 | 
					    session = Session.objects.get(id=session_id)
 | 
				
			||||||
    session.delete()
 | 
					    session.delete()
 | 
				
			||||||
@ -62,11 +56,10 @@ def list_sessions(request, purchase_id=None):
 | 
				
			|||||||
        dataset = Session.objects.all().order_by("timestamp_start")
 | 
					        dataset = Session.objects.all().order_by("timestamp_start")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for session in dataset:
 | 
					    for session in dataset:
 | 
				
			||||||
        if session.timestamp_end == None and session.duration_manual.seconds == 0:
 | 
					        if session.timestamp_end == None and session.duration_manual == None:
 | 
				
			||||||
            session.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE))
 | 
					            session.timestamp_end = datetime.now(ZoneInfo(settings.TIME_ZONE))
 | 
				
			||||||
            session.unfinished = True
 | 
					            session.unfinished = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    context["total_duration"] = dataset.total_duration()
 | 
					 | 
				
			||||||
    context["dataset"] = dataset
 | 
					    context["dataset"] = dataset
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return render(request, "list_sessions.html", context)
 | 
					    return render(request, "list_sessions.html", context)
 | 
				
			||||||
@ -112,6 +105,12 @@ def add_platform(request):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def index(request):
 | 
					def index(request):
 | 
				
			||||||
    context = {}
 | 
					    context = {}
 | 
				
			||||||
    context["total_duration"] = Session().duration_sum
 | 
					    if Session.objects.count() == 0:
 | 
				
			||||||
 | 
					        duration: str = ""
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        context["total_duration"] = format_duration(
 | 
				
			||||||
 | 
					            Session.total_sum(),
 | 
				
			||||||
 | 
					            "%H hours %m minutes",
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
    context["title"] = "Index"
 | 
					    context["title"] = "Index"
 | 
				
			||||||
    return render(request, "index.html", context)
 | 
					    return render(request, "index.html", context)
 | 
				
			||||||
 | 
				
			|||||||
@ -18,40 +18,15 @@ class FormatDurationTest(unittest.TestCase):
 | 
				
			|||||||
        result = format_duration(delta, "%H hours")
 | 
					        result = format_duration(delta, "%H hours")
 | 
				
			||||||
        self.assertEqual(result, "1 hours")
 | 
					        self.assertEqual(result, "1 hours")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_overflow_hours(self):
 | 
					 | 
				
			||||||
        delta = timedelta(hours=25)
 | 
					 | 
				
			||||||
        result = format_duration(delta, "%H hours")
 | 
					 | 
				
			||||||
        self.assertEqual(result, "25 hours")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_overflow_hours_into_days(self):
 | 
					 | 
				
			||||||
        delta = timedelta(hours=25)
 | 
					 | 
				
			||||||
        result = format_duration(delta, "%d days, %H hours")
 | 
					 | 
				
			||||||
        self.assertEqual(result, "1 days, 1 hours")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_only_minutes(self):
 | 
					    def test_only_minutes(self):
 | 
				
			||||||
        delta = timedelta(minutes=34)
 | 
					        delta = timedelta(minutes=34)
 | 
				
			||||||
        result = format_duration(delta, "%m minutes")
 | 
					        result = format_duration(delta, "%m minutes")
 | 
				
			||||||
        self.assertEqual(result, "34 minutes")
 | 
					        self.assertEqual(result, "34 minutes")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_only_overflow_minutes(self):
 | 
					 | 
				
			||||||
        delta = timedelta(minutes=61)
 | 
					 | 
				
			||||||
        result = format_duration(delta, "%m minutes")
 | 
					 | 
				
			||||||
        self.assertEqual(result, "61 minutes")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_overflow_minutes_into_hours(self):
 | 
					 | 
				
			||||||
        delta = timedelta(minutes=61)
 | 
					 | 
				
			||||||
        result = format_duration(delta, "%H hours, %m minutes")
 | 
					 | 
				
			||||||
        self.assertEqual(result, "1 hours, 1 minutes")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_only_overflow_seconds(self):
 | 
					    def test_only_overflow_seconds(self):
 | 
				
			||||||
        delta = timedelta(seconds=61)
 | 
					        delta = timedelta(seconds=61)
 | 
				
			||||||
        result = format_duration(delta, "%s seconds")
 | 
					        result = format_duration(delta, "%s seconds")
 | 
				
			||||||
        self.assertEqual(result, "61 seconds")
 | 
					        self.assertEqual(result, "1 seconds")
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_overflow_seconds_into_minutes(self):
 | 
					 | 
				
			||||||
        delta = timedelta(seconds=61)
 | 
					 | 
				
			||||||
        result = format_duration(delta, "%m minutes, %s seconds")
 | 
					 | 
				
			||||||
        self.assertEqual(result, "1 minutes, 1 seconds")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_only_rawseconds(self):
 | 
					    def test_only_rawseconds(self):
 | 
				
			||||||
        delta = timedelta(seconds=5690)
 | 
					        delta = timedelta(seconds=5690)
 | 
				
			||||||
@ -81,12 +56,3 @@ class FormatDurationTest(unittest.TestCase):
 | 
				
			|||||||
        delta = timedelta(hours=-2)
 | 
					        delta = timedelta(hours=-2)
 | 
				
			||||||
        result = format_duration(delta, "%H hours")
 | 
					        result = format_duration(delta, "%H hours")
 | 
				
			||||||
        self.assertEqual(result, "0 hours")
 | 
					        self.assertEqual(result, "0 hours")
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_none(self):
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            format_duration(None)
 | 
					 | 
				
			||||||
        except TypeError as exc:
 | 
					 | 
				
			||||||
            assert False, f"format_duration(None) raised an exception {exc}"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def test_number(self):
 | 
					 | 
				
			||||||
        self.assertEqual(format_duration(3600, "%H hour"), "1 hour")
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user