Compare commits
5 Commits
4f5f12473d
...
feat/balan
Author | SHA1 | Date | |
---|---|---|---|
64d9bbbad2
|
|||
9156142c04
|
|||
c090b611e2
|
|||
9d33377ac1
|
|||
72ad6ec081
|
3
.env.template
Normal file
3
.env.template
Normal file
@ -0,0 +1,3 @@
|
||||
DJANGO_SECRET_KEY=
|
||||
DJANGO_ENV=prod
|
||||
DJANGO_HOSTS=localhost,127.0.0.1
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
__pycache__
|
||||
db.sqlite3
|
||||
/db.sqlite3
|
||||
/.env
|
||||
|
12
.idea/dataSources.xml
generated
12
.idea/dataSources.xml
generated
@ -1,20 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="db" uuid="77a8092c-4d7c-43f6-806c-af3a9c288eeb">
|
||||
<data-source source="LOCAL" name="Django default" uuid="5554f55f-0dda-4059-8562-7321c41658f9">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<imported>true</imported>
|
||||
<remarks>$PROJECT_DIR$/TimeDispatcher/settings.py</remarks>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/db.sqlite3</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<libraries>
|
||||
<library>
|
||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0.jar</url>
|
||||
</library>
|
||||
<library>
|
||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar</url>
|
||||
</library>
|
||||
</libraries>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
2
.idea/discord.xml
generated
2
.idea/discord.xml
generated
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="ASK" />
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
<option name="applicationTheme" value="default" />
|
||||
<option name="iconsTheme" value="default" />
|
||||
|
6
.idea/httpClient.xml
generated
Normal file
6
.idea/httpClient.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="HttpClientEndpointsTabState">
|
||||
<option name="requestToText" value="<CachedHttpClientTabRequests> <entry key="da376d1083f024ef0956ab871581b6fa09ce0fda" value="###&#10;POST http://localhost:8000/projects/{{id}}/set_parent/" /> </CachedHttpClientTabRequests>" />
|
||||
</component>
|
||||
</project>
|
99
.idea/icon.svg
generated
Normal file
99
.idea/icon.svg
generated
Normal file
@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="64"
|
||||
height="64"
|
||||
viewBox="0 0 64 64"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
sodipodi:docname="logo.svg"
|
||||
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
showgrid="true"
|
||||
inkscape:zoom="11.559708"
|
||||
inkscape:cx="31.012894"
|
||||
inkscape:cy="41.047749"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1016"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="27"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1">
|
||||
<inkscape:grid
|
||||
id="grid1"
|
||||
units="px"
|
||||
originx="0"
|
||||
originy="0"
|
||||
spacingx="1"
|
||||
spacingy="1"
|
||||
empcolor="#0099e5"
|
||||
empopacity="0.30196078"
|
||||
color="#0099e5"
|
||||
opacity="0.14901961"
|
||||
empspacing="8"
|
||||
enabled="true"
|
||||
visible="true" />
|
||||
</sodipodi:namedview>
|
||||
<defs
|
||||
id="defs1">
|
||||
<inkscape:path-effect
|
||||
effect="fillet_chamfer"
|
||||
id="path-effect3"
|
||||
is_visible="true"
|
||||
lpeversion="1"
|
||||
nodesatellites_param="F,0,1,1,0,2,0,1 @ F,0,1,1,0,2,0,1 @ F,0,1,1,0,2,0,1 @ F,0,1,1,0,2,0,1 @ F,0,1,1,0,2,0,1 @ F,0,0,1,0,2,0,1 @ F,0,1,1,0,2,0,1 @ F,0,1,1,0,2,0,1"
|
||||
radius="0"
|
||||
unit="px"
|
||||
method="auto"
|
||||
mode="F"
|
||||
chamfer_steps="1"
|
||||
flexible="false"
|
||||
use_knot_distance="true"
|
||||
apply_no_radius="true"
|
||||
apply_with_radius="true"
|
||||
only_selected="false"
|
||||
hide_knots="false" />
|
||||
</defs>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<g
|
||||
id="g4">
|
||||
<path
|
||||
style="fill:#69c935;fill-opacity:1;stroke-width:6;stroke-linecap:square;stroke:none"
|
||||
d="m 8,10 v 4 a 2,2 45 0 0 2,2 h 7 a 2,2 45 0 1 2,2 v 36 a 2,2 45 0 0 2,2 h 4 a 2,2 135 0 0 2,-2 V 18 a 2,2 135 0 1 2,-2 h 7 a 2,2 135 0 0 2,-2 V 10 A 2,2 45 0 0 36,8 H 10 a 2,2 135 0 0 -2,2 z"
|
||||
id="path1"
|
||||
sodipodi:nodetypes="ccccccccc"
|
||||
inkscape:path-effect="#path-effect3"
|
||||
inkscape:original-d="m 8,8 v 8 h 11 v 40 h 8 V 16 H 38 V 8 Z" />
|
||||
<g
|
||||
id="g3"
|
||||
style="stroke:#61ba31;stroke-opacity:1;fill:none">
|
||||
<path
|
||||
id="path2"
|
||||
style="fill:none;stroke:#61ba31;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
|
||||
d="M 44.834929,13.274537 C 51.52452,17.296808 56,24.625752 56,33 56,45.702549 45.702549,56 33,56"
|
||||
sodipodi:nodetypes="csc" />
|
||||
<path
|
||||
style="fill:none;stroke:#61ba31;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 44,47 33,33 38,26"
|
||||
id="path3" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.2 KiB |
87
README.md
Normal file
87
README.md
Normal file
@ -0,0 +1,87 @@
|
||||
# Time Dispatcher
|
||||
|
||||
### Table of contents
|
||||
<!-- TOC -->
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Installation](#installation)
|
||||
* [Run the app](#run-the-app)
|
||||
* [Production](#production)
|
||||
* [Development](#development)
|
||||
* [Updating](#updating)
|
||||
<!-- TOC -->
|
||||
|
||||
---
|
||||
|
||||
**Time Dispatcher** is a QoL tool to help you track, analyze and allocate your time spent on various projects.
|
||||
Here is a list of the main features available :
|
||||
- Import tasks, projects and time imputations from CSV (compatible with [Super Productivity](https://github.com/johannesjo/super-productivity))
|
||||
- Create parents to group multiple projects
|
||||
- Track your clock-ins / -outs and/or remote work
|
||||
- Mark each parent as either productive or not, i.e. whether its projects take a share of the "clocked" time
|
||||
- Automatically compute the time that should be reported as spent on each productive parent (for example to input in SageX)
|
||||
- View your monthly working times in a nice table or in a summarized form on the dashboard
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Python 3+
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository
|
||||
```shell
|
||||
git clone https://git.kb28.ch/HEL/TimeDispatcher.git
|
||||
```
|
||||
2. Go inside the project directory
|
||||
```shell
|
||||
cd TimeDispatcher/
|
||||
```
|
||||
3. Install the Python requirements
|
||||
```shell
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
4. Apply the database migrations
|
||||
```shell
|
||||
python manage.py migrate
|
||||
```
|
||||
5. Set the appropriate settings in the `.env` file:
|
||||
1. Copy `.env.template` to `.env`
|
||||
```shell
|
||||
cp .env.template .env
|
||||
```
|
||||
2. Fill in the settings
|
||||
- `DJANGO_SECRET_KEY`: The secret key used by Django.
|
||||
This is a long random string.
|
||||
For example, it can be generated using Python with
|
||||
```python
|
||||
import secrets
|
||||
secrets.token_urlsafe(64)
|
||||
```
|
||||
- `DJANGO_ENV`: Current environment, either `prod` or `dev`
|
||||
- `DJANGO_HOSTS`: Comma-separated list of allowed hosts used by Django
|
||||
|
||||
## Run the app
|
||||
### Production
|
||||
1. Start the Uvicorn server
|
||||
```shell
|
||||
python main.py
|
||||
```
|
||||
2. Open [the app](http://localhost:8000/) in your browser
|
||||
|
||||
### Development
|
||||
1. Start the Django server
|
||||
```shell
|
||||
python manage.py runserver
|
||||
```
|
||||
2. Open [the app](http://localhost:8000/) in your browser
|
||||
|
||||
## Updating
|
||||
(Before updating to a new version, it is recommended to back up the database file, i.e. `db.sqlite3`)
|
||||
|
||||
To update to a new version:
|
||||
1. Download the new sources
|
||||
- from the [release page](https://git.kb28.ch/HEL/TimeDispatcher/releases)
|
||||
- or pull the new version with git
|
||||
2. Run the database migrations:
|
||||
```shell
|
||||
python manage.py migrate
|
||||
```
|
3
TimeDispatcher/config.py
Normal file
3
TimeDispatcher/config.py
Normal file
@ -0,0 +1,3 @@
|
||||
class Config:
|
||||
# Number of hours in an off-day
|
||||
WORKING_HOURS_PER_OFF_DAY = 8.2
|
@ -1,8 +1,10 @@
|
||||
from TimeDispatcher.settings import APP_VERSION
|
||||
from TimeDispatcher.config import Config
|
||||
from TimeDispatcher.settings import APP_VERSION, DEBUG
|
||||
|
||||
|
||||
def version(request):
|
||||
return {
|
||||
"debug": DEBUG,
|
||||
"version": APP_VERSION
|
||||
}
|
||||
|
||||
@ -15,4 +17,11 @@ def navbar_links(request):
|
||||
{'view': 'parents', 'label': 'Parents'},
|
||||
{'view': 'import', 'label': 'Import'},
|
||||
]
|
||||
}
|
||||
|
||||
def app_config(request):
|
||||
return {
|
||||
"config": {
|
||||
"WORKING_HOURS_PER_OFF_DAY": Config.WORKING_HOURS_PER_OFF_DAY
|
||||
}
|
||||
}
|
@ -9,25 +9,28 @@ https://docs.djangoproject.com/en/5.1/topics/settings/
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/5.1/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
APP_VERSION = "0.0.1"
|
||||
APP_VERSION = "0.1.0"
|
||||
|
||||
load_dotenv(BASE_DIR / ".env", override=True)
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-^*x5i_#=$9kuj6k^v0cy5dqefmzo%j*i&0w93i%!zmgsa_z)2z'
|
||||
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = os.environ.get("DJANGO_ENV", "dev").lower() != "prod"
|
||||
|
||||
ALLOWED_HOSTS = ["localhost", "192.168.2.68"]
|
||||
ALLOWED_HOSTS = list(map(lambda h: h.strip(), os.environ.get("DJANGO_HOSTS", "localhost,127.0.0.1").split(",")))
|
||||
|
||||
|
||||
# Application definition
|
||||
@ -57,8 +60,7 @@ ROOT_URLCONF = 'TimeDispatcher.urls'
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [BASE_DIR / 'templates']
|
||||
,
|
||||
'DIRS': [BASE_DIR / 'templates'],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
@ -66,8 +68,9 @@ TEMPLATES = [
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'context_processors.version',
|
||||
'context_processors.navbar_links'
|
||||
'TimeDispatcher.context_processors.app_config',
|
||||
'TimeDispatcher.context_processors.version',
|
||||
'TimeDispatcher.context_processors.navbar_links'
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -111,7 +114,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = 'Europe/Zurich'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
@ -121,7 +124,12 @@ USE_TZ = True
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
||||
|
||||
|
||||
STATICFILES_DIRS = [
|
||||
BASE_DIR / "dispatcher" / "static"
|
||||
]
|
||||
STATIC_URL = 'static/'
|
||||
_STATIC_ROOT = BASE_DIR / "dispatcher" / "static"
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||
|
@ -14,9 +14,10 @@ Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path, register_converter
|
||||
from django.urls import path, register_converter, re_path
|
||||
from django.views.static import serve
|
||||
|
||||
from TimeDispatcher import settings
|
||||
from TimeDispatcher.converters import DateConverter, YearMonthConverter
|
||||
from dispatcher import views
|
||||
|
||||
@ -41,3 +42,6 @@ urlpatterns = [
|
||||
path("clockings/<date:date>/", views.set_clocking, name="set_clocking"),
|
||||
path("sagex/<int:id>/<year_month:month>/", views.set_real_sagex, name="set_real_sagex"),
|
||||
]
|
||||
|
||||
if not settings.DEBUG:
|
||||
urlpatterns.append(re_path(r"^static/(?P<path>.*)$", serve, {"document_root": settings._STATIC_ROOT}))
|
@ -1,6 +1,16 @@
|
||||
from django.apps import AppConfig
|
||||
from django.utils.autoreload import autoreload_started
|
||||
|
||||
from TimeDispatcher.settings import BASE_DIR
|
||||
|
||||
|
||||
def watchdog(sender, **kwargs):
|
||||
sender.watch_dir(BASE_DIR, ".env")
|
||||
|
||||
|
||||
class DispatcherConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'dispatcher'
|
||||
|
||||
def ready(self):
|
||||
autoreload_started.connect(watchdog)
|
||||
|
@ -53,3 +53,20 @@ class RealSageXHours(models.Model):
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=["parent", "date"], name="unique_monthly_sagex")
|
||||
]
|
||||
|
||||
|
||||
class FullTimeMonthlyHours(models.Model):
|
||||
date = models.DateField(unique=True)
|
||||
hours = models.DurationField(default=timedelta)
|
||||
|
||||
|
||||
class EmploymentRate:
|
||||
rate = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
start_date = models.DateField()
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(fields=["start_date"])
|
||||
]
|
||||
|
||||
|
||||
|
@ -77,6 +77,12 @@ footer .sep {
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
footer .debug {
|
||||
margin-right: auto;
|
||||
font-style: italic;
|
||||
color: #ffb33d;
|
||||
}
|
||||
|
||||
main {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
|
20
dispatcher/static/error.css
Normal file
20
dispatcher/static/error.css
Normal file
@ -0,0 +1,20 @@
|
||||
.wrapper {
|
||||
margin: auto;
|
||||
max-width: 25em;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2em;
|
||||
}
|
||||
|
||||
.desc {
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.url {
|
||||
font-family: monospace;
|
||||
background-color: rgba(255, 255, 255, 0.11);
|
||||
padding: 0.1em 0.4em;
|
||||
border-radius: 4px;
|
||||
}
|
@ -267,7 +267,8 @@ def set_clocking(request, date: datetime.date):
|
||||
clocking.out_pm = request.POST.get("out_pm", clocking.out_pm) or None
|
||||
remote = request.POST.get("remote", clocking.remote) or None
|
||||
if remote is not None:
|
||||
remote = str_to_timedelta(remote)
|
||||
if isinstance(remote, str):
|
||||
remote = str_to_timedelta(remote)
|
||||
else:
|
||||
remote = timedelta()
|
||||
clocking.remote = remote
|
||||
@ -307,4 +308,4 @@ def set_real_sagex(request, id, month: datetime.date):
|
||||
return JsonResponse({
|
||||
"status": "success",
|
||||
"sagex": RealSageXHoursSerializer(entry).data
|
||||
})
|
||||
})
|
||||
|
16
main.py
Normal file
16
main.py
Normal file
@ -0,0 +1,16 @@
|
||||
import uvicorn
|
||||
|
||||
from TimeDispatcher.asgi import application
|
||||
|
||||
|
||||
def main():
|
||||
uvicorn.run(
|
||||
application,
|
||||
host="127.0.0.1",
|
||||
port=8000,
|
||||
workers=1
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,2 +1,4 @@
|
||||
Django~=5.1.5
|
||||
djangorestframework~=3.15.2
|
||||
djangorestframework~=3.15.2
|
||||
python-dotenv~=1.0.1
|
||||
uvicorn~=0.34.0
|
13
templates/404.html
Normal file
13
templates/404.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% block title %}404 Not Found{% endblock %}
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="{% static "error.css" %}">
|
||||
{% endblock %}
|
||||
{% block footer %}{% endblock %}
|
||||
{% block main %}
|
||||
<div class="wrapper">
|
||||
<h1 class="title">Page not found</h1>
|
||||
<p class="desc">Oops, page <span class="url">{{ request.path }}</span> could not be found. Go back to <a href="{% url "dashboard" %}">Dashboard</a></p>
|
||||
</div>
|
||||
{% endblock %}
|
@ -6,6 +6,9 @@
|
||||
<title>{% block title %}Title{% endblock %}</title>
|
||||
<link rel="shortcut icon" href="{% static "logo.svg" %}" type="image/x-svg">
|
||||
<link rel="stylesheet" href="{% static "base.css" %}">
|
||||
<script type="application/javascript">
|
||||
const Config = {{ config|safe }}
|
||||
</script>
|
||||
<script src="{% static "base.js" %}"></script>
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
@ -22,6 +25,7 @@
|
||||
{% block main %}{% endblock %}
|
||||
</main>
|
||||
<footer>
|
||||
{% if debug %}<span class="debug">Debug</span>{% endif %}
|
||||
<span><i>Time Dispatcher v{{ version }}</i></span>
|
||||
<span class="sep"></span>
|
||||
<span><a href="https://git.kb28.ch/HEL/TimeDispatcher" target="_blank">Gitea</a></span>
|
||||
|
Reference in New Issue
Block a user