diff --git a/core/settings.py b/core/settings.py index 6f62377..0a40a8f 100644 --- a/core/settings.py +++ b/core/settings.py @@ -1,47 +1,39 @@ -""" -Django settings for core project. - -Generated by 'django-admin startproject' using Django 4.1.2. - -For more information on this file, see -https://docs.djangoproject.com/en/4.1/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/4.1/ref/settings/ -""" - -import os, random, string +import os +import random +import string from pathlib import Path + from dotenv import load_dotenv from str2bool import str2bool -load_dotenv() # take environment variables from .env. +load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ - # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.environ.get('SECRET_KEY') if not SECRET_KEY: - SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 )) + SECRET_KEY = ''.join( + random.choice(string.ascii_lowercase) for i in range(32) + ) -# Enable/Disable DEBUG Mode DEBUG = str2bool(os.environ.get('DEBUG')) -#print(' DEBUG -> ' + str(DEBUG) ) -# Docker HOST ALLOWED_HOSTS = ['*'] -# Add here your deployment HOSTS -CSRF_TRUSTED_ORIGINS = ['http://localhost:8000', 'http://localhost:5085', 'http://127.0.0.1:8000', 'http://127.0.0.1:5085'] +CSRF_TRUSTED_ORIGINS = [ + 'http://localhost:8000', + 'http://localhost:5085', + 'http://127.0.0.1:8000', + 'http://127.0.0.1:5085', +] RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME') -if RENDER_EXTERNAL_HOSTNAME: +if RENDER_EXTERNAL_HOSTNAME: ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME) + # Application definition INSTALLED_APPS = [ @@ -52,8 +44,12 @@ "django.contrib.messages", "django.contrib.staticfiles", - 'theme_pixel', + # UI & Theme Apps + "theme_pixel", "home", + + # Custom Apps + "projects", ] MIDDLEWARE = [ @@ -69,12 +65,12 @@ ROOT_URLCONF = "core.urls" -HOME_TEMPLATES = os.path.join(BASE_DIR, 'templates') +TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates') TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [HOME_TEMPLATES], + "DIRS": [TEMPLATES_DIR], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -91,78 +87,55 @@ # Database -# https://docs.djangoproject.com/en/4.1/ref/settings/#databases - -DB_ENGINE = os.getenv('DB_ENGINE' , None) -DB_USERNAME = os.getenv('DB_USERNAME' , None) -DB_PASS = os.getenv('DB_PASS' , None) -DB_HOST = os.getenv('DB_HOST' , None) -DB_PORT = os.getenv('DB_PORT' , None) -DB_NAME = os.getenv('DB_NAME' , None) - -if DB_ENGINE and DB_NAME and DB_USERNAME: - DATABASES = { - 'default': { - 'ENGINE' : 'django.db.backends.' + DB_ENGINE, - 'NAME' : DB_NAME, - 'USER' : DB_USERNAME, - 'PASSWORD': DB_PASS, - 'HOST' : DB_HOST, - 'PORT' : DB_PORT, - }, - } -else: - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'db.sqlite3', - } + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', } +} + # Password validation -# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + "NAME": "django.contrib.auth.password_validation." + "UserAttributeSimilarityValidator", }, { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + "NAME": "django.contrib.auth.password_validation." + "MinimumLengthValidator", }, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + "NAME": "django.contrib.auth.password_validation." + "CommonPasswordValidator", }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + "NAME": "django.contrib.auth.password_validation." + "NumericPasswordValidator", }, ] # Internationalization -# https://docs.djangoproject.com/en/4.1/topics/i18n/ - -LANGUAGE_CODE = "en-us" - -TIME_ZONE = "UTC" +LANGUAGE_CODE = "pl-pl" +TIME_ZONE = "Europe/Warsaw" USE_I18N = True - USE_TZ = True # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/4.1/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') - -#if not DEBUG: -# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' - -# Default primary key field type -# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, "static"), +] DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" LOGIN_REDIRECT_URL = '/' +LOGOUT_REDIRECT_URL = '/login/' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' diff --git a/core/urls.py b/core/urls.py index 1e6b5a8..c526348 100644 --- a/core/urls.py +++ b/core/urls.py @@ -1,23 +1,10 @@ -"""core URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/4.1/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -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 include, path urlpatterns = [ + path('admin/', admin.site.urls), path('', include('home.urls')), - path("admin/", admin.site.urls), - path("", include('theme_pixel.urls')) -] + path('', include('theme_pixel.urls')), + # To jest kluczowa linia dla Twojej nowej aplikacji: + path('', include('projects.urls')), +] \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index e384063..dd11984 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/projects/__init__.py b/projects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/projects/admin.py b/projects/admin.py new file mode 100644 index 0000000..b666f36 --- /dev/null +++ b/projects/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import Client, Project + +admin.site.register(Client) +admin.site.register(Project) \ No newline at end of file diff --git a/projects/apps.py b/projects/apps.py new file mode 100644 index 0000000..4d48a27 --- /dev/null +++ b/projects/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ProjectsConfig(AppConfig): + name = 'projects' diff --git a/projects/migrations/0001_initial.py b/projects/migrations/0001_initial.py new file mode 100644 index 0000000..ef6b8e8 --- /dev/null +++ b/projects/migrations/0001_initial.py @@ -0,0 +1,38 @@ +# Generated by Django 4.2.9 on 2026-03-03 11:15 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Client', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ('company', models.CharField(blank=True, max_length=255)), + ('email', models.EmailField(max_length=254)), + ], + ), + migrations.CreateModel( + name='Project', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255)), + ('description', models.TextField(blank=True)), + ('deadline', models.DateField()), + ('status', models.CharField(choices=[('idea', 'Pomysł'), ('coding', 'W trakcie'), ('testing', 'Testowanie'), ('done', 'Zakończone')], default='idea', max_length=20)), + ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='projects', to='projects.client')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/projects/migrations/__init__.py b/projects/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/projects/models.py b/projects/models.py new file mode 100644 index 0000000..2e6e647 --- /dev/null +++ b/projects/models.py @@ -0,0 +1,40 @@ +from django.db import models +from django.contrib.auth.models import User + + +class Client(models.Model): + """Model przechowujący dane klientów freelancera.""" + name = models.CharField(max_length=255) + company = models.CharField(max_length=255, blank=True) + email = models.EmailField() + + def __str__(self): + return self.name + + +class Project(models.Model): + """Model przechowujący szczegóły projektów.""" + STATUS_CHOICES = [ + ('idea', 'Pomysł'), + ('coding', 'W trakcie'), + ('testing', 'Testowanie'), + ('done', 'Zakończone'), + ] + + user = models.ForeignKey(User, on_delete=models.CASCADE) + client = models.ForeignKey( + Client, + on_delete=models.CASCADE, + related_name='projects' + ) + title = models.CharField(max_length=255) + description = models.TextField(blank=True) + deadline = models.DateField() + status = models.CharField( + max_length=20, + choices=STATUS_CHOICES, + default='idea' + ) + + def __str__(self): + return self.title \ No newline at end of file diff --git a/projects/tests.py b/projects/tests.py new file mode 100644 index 0000000..de8bdc0 --- /dev/null +++ b/projects/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/projects/urls.py b/projects/urls.py new file mode 100644 index 0000000..64c5a98 --- /dev/null +++ b/projects/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('my-projects/', views.project_list, name='project_list'), +] \ No newline at end of file diff --git a/projects/views.py b/projects/views.py new file mode 100644 index 0000000..f625638 --- /dev/null +++ b/projects/views.py @@ -0,0 +1,14 @@ +from django.shortcuts import render +from django.contrib.auth.decorators import login_required +from .models import Project + + +@login_required(login_url="/login/") +def project_list(request): + """Widok listy projektów przypisanych do użytkownika.""" + projects = Project.objects.filter(user=request.user) + context = { + 'projects': projects, + 'segment': 'projects', + } + return render(request, 'projects/projects_list.html', context) \ No newline at end of file diff --git a/templates/projects/projects_list.html b/templates/projects/projects_list.html new file mode 100644 index 0000000..e8ccaf8 --- /dev/null +++ b/templates/projects/projects_list.html @@ -0,0 +1,29 @@ + + +
+{{ project.description }}
+ {{ project.get_status_display }} +Brak projektów. Dodaj je w panelu admina!
+ {% endfor %} +