Skip to content
Merged
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
11 changes: 9 additions & 2 deletions django_blog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ init:
$(PYTHON) -m pip install --upgrade pip
pip install -r requirements.txt

init-dev: init
pip install -r requirements-dev.txt

fmt:
ruff format .

# Cria a estrutura do projeto
startproject:
python -m django startproject project
python -m django startproject app

run:
$(PYTHON) manage.py runserver

test:
$(PYTHON) manage.py test $(app-name)

# Cria a estrutura do projeto
# Criar uma django app
startapp:
@echo "Creating Django app: $(app-name)"
$(PYTHON) manage.py startapp $(app-name)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import os

from danilodias.settings import APP_SETTINGS_PAT

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', APP_SETTINGS_PAT)

application = get_asgi_application()
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
https://docs.djangoproject.com/en/5.2/ref/settings/
"""

import os
from pathlib import Path


APP_NAME = 'danilodias'

# 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/5.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-@--^j$fso41z4o2ulo!!gx$0bl48yra+j&ihk0_&pz9xrk7^qs'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = bool(int(os.getenv('DEBUG', 0))) # Buscar por variaveis de ambiente

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']


# Application definition
Expand All @@ -37,6 +40,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home.apps.HomeConfig',
]

MIDDLEWARE = [
Expand All @@ -49,7 +53,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'project.urls'
ROOT_URLCONF = f'{APP_NAME}.urls'

TEMPLATES = [
{
Expand All @@ -66,7 +70,7 @@
},
]

WSGI_APPLICATION = 'project.wsgi.application'
WSGI_APPLICATION = f'{APP_NAME}.wsgi.application'


# Database
Expand Down Expand Up @@ -104,7 +108,7 @@

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
TIME_ZONE = 'America/Sao_Paulo'

USE_I18N = True

Expand All @@ -120,3 +124,5 @@
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

APP_SETTINGS_PATH = f'{APP_NAME}.settings'
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
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
from django.urls import path, include


urlpatterns = [
path('admin/', admin.site.urls),
]
urlpatterns = [path('admin/', admin.site.urls), path('', include('home.urls'))]
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import os

from danilodias.settings import APP_SETTINGS_PATH

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', APP_SETTINGS_PATH)

application = get_wsgi_application()
Empty file added django_blog/home/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions django_blog/home/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions django_blog/home/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class HomeConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'home'
44 changes: 44 additions & 0 deletions django_blog/home/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 5.2.3 on 2025-06-18 20:41

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = []

operations = [
migrations.CreateModel(
name='Year',
fields=[
(
'id',
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
(
'name',
models.CharField(
default=2025,
max_length=4,
unique=True,
validators=[
django.core.validators.RegexValidator(
code='invalid_year',
message='O ano deve conter exatamente 4 dígitos numéricos.',
regex='^\\d{4}$',
)
],
),
),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(blank=True, null=True)),
],
),
]
Empty file.
34 changes: 34 additions & 0 deletions django_blog/home/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from datetime import datetime

from django.db import models
from django.utils import timezone

from validators.date import year_validator


class BaseModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(null=True, blank=True)

class Meta:
abstract = True

def save(self, *args, **kwargs):
if self.pk:
self.updated_at = timezone.now()
super().save(*args, **kwargs)


class Year(BaseModel):
name = models.CharField(
max_length=4,
unique=True,
validators=[year_validator], # Aplica o validador
default=datetime.now().year, # Define o ano atual como valor padrão
)

def __str__(self):
return str(self.name)

class Meta:
app_label = 'home'
3 changes: 3 additions & 0 deletions django_blog/home/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.
7 changes: 7 additions & 0 deletions django_blog/home/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name='index'),
]
7 changes: 7 additions & 0 deletions django_blog/home/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.shortcuts import render

from django.http import HttpResponse


def index(request):
return HttpResponse('Copyright © 2025 Danilo Dias .Dev - All rights reserved.')
9 changes: 6 additions & 3 deletions django_blog/manage.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

from danilodias.settings import APP_SETTINGS_PATH


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', APP_SETTINGS_PATH)
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
'available on your PYTHONPATH environment variable? Did you '
'forget to activate a virtual environment?'
) from exc
execute_from_command_line(sys.argv)

Expand Down
3 changes: 3 additions & 0 deletions django_blog/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r requirements.txt

ruff>=0.12.0
20 changes: 20 additions & 0 deletions django_blog/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
exclude = []

line-length = 120
indent-width = 4

target-version = "py313"

[lint]
select = ["E", "F", "B", "I", "UP", "N", "ANN", "ERA"]
ignore = ["E501"]
fixable = ["ALL"]
unfixable = []

[format]
quote-style = "single"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true
docstring-code-line-length = "dynamic"
7 changes: 7 additions & 0 deletions django_blog/validators/date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.core.validators import RegexValidator

year_validator = RegexValidator(
regex=r'^\d{4}$',
message='O ano deve conter exatamente 4 dígitos numéricos.',
code='invalid_year',
)
6 changes: 3 additions & 3 deletions django_study/announcements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.core.validators import MinValueValidator


# Create your models here.
class BaseModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(null=True, blank=True)
Expand All @@ -25,7 +24,7 @@ class User(BaseModel):
password = models.CharField(max_length=50)

class Meta:
app_label = 'announcements' #
app_label = 'announcements'


class Announcement(BaseModel):
Expand All @@ -35,6 +34,7 @@ class Announcement(BaseModel):
value = models.DecimalField(max_digits=10, decimal_places=2, validators=[MinValueValidator(0)])

class Meta:
app_label = 'announcements' #
app_label = 'announcements'