Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 44 additions & 71 deletions core/settings.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -52,8 +44,12 @@
"django.contrib.messages",
"django.contrib.staticfiles",

'theme_pixel',
# UI & Theme Apps
"theme_pixel",
"home",

# Custom Apps
"projects",
]

MIDDLEWARE = [
Expand All @@ -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": [
Expand All @@ -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'
23 changes: 5 additions & 18 deletions core/urls.py
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

path('', include('projects.urls')),
]
Binary file modified db.sqlite3
Binary file not shown.
Empty file added projects/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions projects/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Client, Project

admin.site.register(Client)
admin.site.register(Project)
5 changes: 5 additions & 0 deletions projects/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ProjectsConfig(AppConfig):
name = 'projects'
38 changes: 38 additions & 0 deletions projects/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
Empty file added projects/migrations/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions projects/models.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions projects/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Comment on lines +1 to +3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brak testów

6 changes: 6 additions & 0 deletions projects/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('my-projects/', views.project_list, name='project_list'),
]
14 changes: 14 additions & 0 deletions projects/views.py
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 29 additions & 0 deletions templates/projects/projects_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Moje Projekty</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-5">
<h1 class="mb-4">Lista Projektów Freelancera</h1>
<div class="row">
{% for project in projects %}
<div class="col-md-4 mb-3">
<div class="card shadow-sm">
<div class="card-body">
<h5 class="card-title">{{ project.title }}</h5>
<h6 class="card-subtitle mb-2 text-muted">Klient: {{ project.client.name }}</h6>
<p class="card-text">{{ project.description }}</p>
<span class="badge bg-primary">{{ project.get_status_display }}</span>
</div>
</div>
</div>
{% empty %}
<p>Brak projektów. Dodaj je w panelu admina!</p>
{% endfor %}
</div>
<a href="/admin" class="btn btn-secondary mt-3">Przejdź do Admina</a>
</div>
</body>
</html>