diff --git a/Finanzas/finanzas/accounts/.gitignore b/Finanzas/finanzas/accounts/.gitignore new file mode 100644 index 0000000..62616c7 --- /dev/null +++ b/Finanzas/finanzas/accounts/.gitignore @@ -0,0 +1 @@ +migrations/ diff --git a/Finanzas/finanzas/accounts/__init__.py b/Finanzas/finanzas/accounts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Finanzas/finanzas/accounts/admin.py b/Finanzas/finanzas/accounts/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/Finanzas/finanzas/accounts/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Finanzas/finanzas/accounts/apps.py b/Finanzas/finanzas/accounts/apps.py new file mode 100644 index 0000000..3e3c765 --- /dev/null +++ b/Finanzas/finanzas/accounts/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AccountsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'accounts' diff --git a/Finanzas/finanzas/accounts/models.py b/Finanzas/finanzas/accounts/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/Finanzas/finanzas/accounts/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/Finanzas/finanzas/accounts/tests.py b/Finanzas/finanzas/accounts/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/Finanzas/finanzas/accounts/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Finanzas/finanzas/accounts/urls.py b/Finanzas/finanzas/accounts/urls.py new file mode 100644 index 0000000..532af83 --- /dev/null +++ b/Finanzas/finanzas/accounts/urls.py @@ -0,0 +1,8 @@ +# accounts/urls.py +from django.urls import path +from django.contrib.auth import views as auth_views + +urlpatterns = [ + path('login/', auth_views.LoginView.as_view(), name='login'), + path('logout/', auth_views.LogoutView.as_view(), name='logout'), +] diff --git a/Finanzas/finanzas/accounts/views.py b/Finanzas/finanzas/accounts/views.py new file mode 100644 index 0000000..2536b37 --- /dev/null +++ b/Finanzas/finanzas/accounts/views.py @@ -0,0 +1 @@ +from django.shortcuts import render diff --git a/Finanzas/finanzas/apuntes/__init__.py b/Finanzas/finanzas/apuntes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Finanzas/finanzas/apuntes/admin.py b/Finanzas/finanzas/apuntes/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/Finanzas/finanzas/apuntes/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/Finanzas/finanzas/apuntes/apps.py b/Finanzas/finanzas/apuntes/apps.py new file mode 100644 index 0000000..a6b5f1b --- /dev/null +++ b/Finanzas/finanzas/apuntes/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApuntesConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'apuntes' diff --git a/Finanzas/finanzas/apuntes/forms.py b/Finanzas/finanzas/apuntes/forms.py new file mode 100644 index 0000000..44918a6 --- /dev/null +++ b/Finanzas/finanzas/apuntes/forms.py @@ -0,0 +1,52 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm, UserChangeForm + +from .models import Cuentas, Apuntes, ReyMotaUser, Tipos + + +class CuentasForm(forms.ModelForm): + class Meta: + model = Cuentas + fields = ['nombre', 'saldo_inicial', 'tipo'] + + nombre = forms.CharField( + widget=forms.TextInput(attrs={'class': 'form-control'})) + saldo_inicial = forms.DecimalField( + widget=forms.TextInput(attrs={'class': 'form-control'})) + tipo = forms.ModelChoiceField( + queryset=Tipos.objects.all(), + widget=forms.TextInput(attrs={'class': 'form-control'})) + + +class ApuntesForm(forms.ModelForm): + class Meta: + model = Apuntes + fields = ['fecha', 'cta_origen', 'cta_destino', 'importe'] + + fecha = forms.DateField( + widget=forms.DateInput(attrs={'type': 'date', 'class': 'form-control'})) + + cta_origen = forms.ModelChoiceField( + queryset=Cuentas.objects.all(), + widget=forms.Select(attrs={'class': 'form-control'})) + + cta_destino = forms.ModelChoiceField( + queryset=Cuentas.objects.all(), + widget=forms.Select(attrs={'class': 'form-control'})) + + importe = forms.DecimalField( + widget=forms.NumberInput(attrs={'class': 'form-control'})) + +class ReyMotaUserCreationForm(UserCreationForm): + + class Meta: + model = ReyMotaUser + fields = ("email", "nombre", "foto") + labels = {'email': 'Dirección de correo'} + + +class ReyMotaUserChangeForm(UserChangeForm): + + class Meta: + model = ReyMotaUser + fields = ("email", "foto") diff --git a/Finanzas/finanzas/apuntes/managers.py b/Finanzas/finanzas/apuntes/managers.py new file mode 100644 index 0000000..0b8128d --- /dev/null +++ b/Finanzas/finanzas/apuntes/managers.py @@ -0,0 +1,34 @@ +from django.contrib.auth.base_user import BaseUserManager +from django.utils.translation import gettext_lazy as _ + + +class ReyMotaUserManager(BaseUserManager): + """ + ReyMota user model manager where email is the unique identifiers + for authentication instead of usernames. + """ + def create_user(self, email, password, **extra_fields): + """ + Create and save a user with the given email and password. + """ + if not email: + raise ValueError(_("The Email must be set")) + email = self.normalize_email(email) + user = self.model(email=email, **extra_fields) + user.set_password(password) + user.save() + return user + + def create_superuser(self, email, password, **extra_fields): + """ + Create and save a SuperUser with the given email and password. + """ + extra_fields.setdefault("is_staff", True) + extra_fields.setdefault("is_superuser", True) + extra_fields.setdefault("is_active", True) + + if extra_fields.get("is_staff") is not True: + raise ValueError(_("Superuser must have is_staff=True.")) + if extra_fields.get("is_superuser") is not True: + raise ValueError(_("Superuser must have is_superuser=True.")) + return self.create_user(email, password, **extra_fields) diff --git a/Finanzas/finanzas/apuntes/migrations/0001_initial.py b/Finanzas/finanzas/apuntes/migrations/0001_initial.py new file mode 100644 index 0000000..ec3fccd --- /dev/null +++ b/Finanzas/finanzas/apuntes/migrations/0001_initial.py @@ -0,0 +1,66 @@ +# Generated by Django 5.1 on 2024-09-02 14:10 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='Cuentas', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nombre', models.TextField(max_length=20)), + ('saldo_inicial', models.DecimalField(decimal_places=2, max_digits=10)), + ('saldo_actual', models.DecimalField(decimal_places=2, max_digits=10)), + ], + ), + migrations.CreateModel( + name='Tipos', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('tipo', models.TextField(max_length=10)), + ], + ), + migrations.CreateModel( + name='ReyMotaUser', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')), + ('foto', models.ImageField(blank=True, default='profile_images/default.jpg', upload_to='profile_images')), + ('is_staff', models.BooleanField(default=False)), + ('is_active', models.BooleanField(default=True)), + ('nombre', models.CharField(blank=True, max_length=200, null=True)), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Apuntes', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('fecha', models.DateField()), + ('importe', models.DecimalField(decimal_places=2, max_digits=10)), + ('cta_destino', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='destino', to='apuntes.cuentas')), + ('cta_origen', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='origen', to='apuntes.cuentas')), + ], + ), + migrations.AddField( + model_name='cuentas', + name='tipo', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='apuntes.tipos'), + ), + ] diff --git a/Finanzas/finanzas/apuntes/migrations/__init__.py b/Finanzas/finanzas/apuntes/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Finanzas/finanzas/apuntes/models.py b/Finanzas/finanzas/apuntes/models.py new file mode 100644 index 0000000..9380de2 --- /dev/null +++ b/Finanzas/finanzas/apuntes/models.py @@ -0,0 +1,37 @@ +from django.db import models +from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin +from django.utils.translation import gettext_lazy as _ + +from .managers import ReyMotaUserManager + +# Create your models here. + +class ReyMotaUser(AbstractBaseUser, PermissionsMixin): + email = models.EmailField(_("email address"), unique=True) + foto = models.ImageField(upload_to="profile_images", default="profile_images/default.jpg", blank=True) + is_staff = models.BooleanField(default=False) + is_active = models.BooleanField(default=True) + nombre = models.CharField(max_length=200, blank=True, null=True) + + USERNAME_FIELD = "email" + REQUIRED_FIELDS = [] + + objects = ReyMotaUserManager() + + def __str__(self): + return self.email + +class Tipos(models.Model): + tipo = models.TextField(max_length=10) + +class Cuentas(models.Model): + nombre = models.TextField(max_length=20) + saldo_inicial = models.DecimalField(max_digits=10, decimal_places=2) + saldo_actual = models.DecimalField(max_digits=10, decimal_places=2) + tipo = models.ForeignKey(Tipos, on_delete=models.CASCADE) + +class Apuntes(models.Model): + fecha = models.DateField() + cta_origen = models.ForeignKey(Cuentas, on_delete=models.CASCADE, related_name='origen') + cta_destino = models.ForeignKey(Cuentas, on_delete=models.CASCADE, related_name='destino') + importe = models.DecimalField(max_digits=10, decimal_places=2) diff --git a/Finanzas/finanzas/apuntes/templates/404.html b/Finanzas/finanzas/apuntes/templates/404.html new file mode 100644 index 0000000..6fc7ab0 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/404.html @@ -0,0 +1,14 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

404
Página no encontrada

+
+ Lo siento, no hemos podido encontrar la página que buscas. +
+ Ir a la página de inicio +
+ +{% endblock %} + diff --git a/Finanzas/finanzas/apuntes/templates/_branding.html b/Finanzas/finanzas/apuntes/templates/_branding.html new file mode 100644 index 0000000..69bda9b --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/_branding.html @@ -0,0 +1,8 @@ +{% load static %} + +{% load filtros_de_entorno %} + +
+ + +
diff --git a/Finanzas/finanzas/apuntes/templates/_cabecera.html b/Finanzas/finanzas/apuntes/templates/_cabecera.html new file mode 100644 index 0000000..3759aed --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/_cabecera.html @@ -0,0 +1,142 @@ +{% load static %} + +
+
+
+
+
+ + + +
+ +
+ +
+
+
+
+ +
+
+
+ × + + {% include "_branding.html" %} + + +
+
+ +
diff --git a/Finanzas/finanzas/apuntes/templates/_footer.html b/Finanzas/finanzas/apuntes/templates/_footer.html new file mode 100644 index 0000000..eed4e66 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/_footer.html @@ -0,0 +1,10 @@ + + +
+ (c) Celestino Rey +
+ \ No newline at end of file diff --git a/Finanzas/finanzas/apuntes/templates/_head.html b/Finanzas/finanzas/apuntes/templates/_head.html new file mode 100644 index 0000000..f05a4fa --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/_head.html @@ -0,0 +1,23 @@ +{% load static %} + + + + + Registro de vehículos y sus apuntes + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Finanzas/finanzas/apuntes/templates/apuntes/detalle_apunte.html b/Finanzas/finanzas/apuntes/templates/apuntes/detalle_apunte.html new file mode 100644 index 0000000..a6a190b --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/apuntes/detalle_apunte.html @@ -0,0 +1,32 @@ + +{% extends 'base.html' %} + +{% block content %} +
+
+
+
+
+

{{ apunte.fecha }}

+ +
    +
  • {{ apunte.cuenta.matricula }}
  • +
  • |
  • +
  • {{ apunte.kms }} kms
  • +
  • |
  • +
  • {{ apunte.litros }} litros
  • +
  • |
  • +
  • {{ apunte.importe }} €
  • +
  • |
  • +
  • {{ apunte.kmsrecorridos }} kms. recorridos
  • +
  • |
  • +
  • {{ apunte.consumo }} litros/100 kms
  • +
  • |
  • +
  • {{ apunte.precioxlitro }} €/litros
  • +
+
+ +
+
+
+{% endblock %} diff --git a/Finanzas/finanzas/apuntes/templates/apuntes/detalle_cuenta.html b/Finanzas/finanzas/apuntes/templates/apuntes/detalle_cuenta.html new file mode 100644 index 0000000..15cb2b9 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/apuntes/detalle_cuenta.html @@ -0,0 +1,72 @@ +{% extends 'base.html' %} + +{% block content %} +
+
+
+
+
+ {% if cuenta.foto %} +

{{ cuenta.matricula}}

+ {% else %} +

No hay imágen disponible

+ {% endif %} +
+
+

{{ cuenta.matricula }}

+ +
    +
  • {{ cuenta.matricula }}
  • +
+
+
+
+
+ + {% if apuntes %} + + + + + + + + + + + + + + + {% for apunte in apuntes %} + + + + + + + + + + + {% endfor %} + +
FechaKilómetrosLitrosImporteDescuentoPrecio por litroKms recorridosConsumo/100 kms
{{ apunte.fecha }}{{ apunte.kms }}{{ apunte.litros }}{{ apunte.importe }}{{ apunte.descuento }}{{ apunte.precioxlitro }}{{ apunte.kmsrecorridos }}{{ apunte.consumo }}
+ {% else %} +

No se han encontrado apuntes para este cuenta

+ {% endif %} +
+
+ + +
+{% endblock %} + diff --git a/Finanzas/finanzas/apuntes/templates/apuntes/form_apunte.html b/Finanzas/finanzas/apuntes/templates/apuntes/form_apunte.html new file mode 100644 index 0000000..147f8b2 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/apuntes/form_apunte.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} + +{% block content %} +
+

{% if form.instance.pk %}Editar apunte{% else %}Nuevo apunte{% endif %}

+
+
+ {% csrf_token %} + {{ form.as_p }} +
+ +
+
+ {{ form.media }} +
+
+{% endblock %} diff --git a/Finanzas/finanzas/apuntes/templates/apuntes/form_cuenta.html b/Finanzas/finanzas/apuntes/templates/apuntes/form_cuenta.html new file mode 100644 index 0000000..f5905a2 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/apuntes/form_cuenta.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} + +{% block content %} +
+ +

{% if form.instance.pk %}Editar vehículo{% else %}Nuevo vehículo{% endif %}

+
+
+ {% csrf_token %} + {{ form.as_p }} +
+ +
+
+
+
+{% endblock %} diff --git a/Finanzas/finanzas/apuntes/templates/apuntes/index.html b/Finanzas/finanzas/apuntes/templates/apuntes/index.html new file mode 100644 index 0000000..aa914de --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/apuntes/index.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} + +{% block content %} + +
+ +

Introducción

+ + +
+ +{% endblock %} diff --git a/Finanzas/finanzas/apuntes/templates/apuntes/lista_apuntes.html b/Finanzas/finanzas/apuntes/templates/apuntes/lista_apuntes.html new file mode 100644 index 0000000..23a2c60 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/apuntes/lista_apuntes.html @@ -0,0 +1,57 @@ + +{% extends 'base.html' %} + +{% block content %} +
+
+
+

apuntes

+
+
+
+
+
+ +
+
+
+ + +
+
+ + + + + + + + + + + + + + + {% for apunte in apuntes %} + + + + + + + + + + + + + + + {% endfor %} +
FechaCuentaKilómetrosLitrosImporteDescuentoPrecio por litroKms recorridosConsumo/100 kms
{{ apunte.fecha }}{{ apunte.cuenta.matricula }}{{ apunte.kms }}{{ apunte.litros }}{{ apunte.importe }} €{{ apunte.descuento }} €{{ apunte.precioxlitro }} €{{ apunte.kmsrecorridos }}{{ apunte.consumo }}
+
+
+{% endblock %} diff --git a/Finanzas/finanzas/apuntes/templates/apuntes/lista_cuentas.html b/Finanzas/finanzas/apuntes/templates/apuntes/lista_cuentas.html new file mode 100644 index 0000000..d5ffb05 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/apuntes/lista_cuentas.html @@ -0,0 +1,65 @@ +{% extends 'base.html' %} + +{% block content %} +
+ +
+
+

Cuentas

+
+
+
+
+
+ +
+
+
+ +
+ {% for cuenta in cuentas %} +
+
+
+

{{ cuenta.matricula}}

+ +
+ +
+ +
+
+
+ {% endfor %} +
+
+{% endblock %} diff --git a/Finanzas/finanzas/apuntes/templates/base.html b/Finanzas/finanzas/apuntes/templates/base.html new file mode 100644 index 0000000..9087edd --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/base.html @@ -0,0 +1,34 @@ +{% load static %} + +{% include "_head.html" %} + + + {% include "_cabecera.html" %} + +
+ +
+ {% block content %}{% endblock %} +
+ + {% include "_footer.html" %} + +
+ + + + + + + + + + + + + + + + + + diff --git a/Finanzas/finanzas/apuntes/templates/fotoperfil b/Finanzas/finanzas/apuntes/templates/fotoperfil new file mode 100644 index 0000000..8f26812 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/fotoperfil @@ -0,0 +1,5 @@ +{% if user.is_authenticated %} + + {% else %} + + {% endif %} \ No newline at end of file diff --git a/Finanzas/finanzas/apuntes/templates/login.html b/Finanzas/finanzas/apuntes/templates/login.html new file mode 100644 index 0000000..4eaabed --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/login.html @@ -0,0 +1,89 @@ +{% load i18n static %} + +{% include "_head.html" %} + + +
+
+
+
+ {% include "_branding.html" %} +

Entrar en Finanzas

+ + {% if form.errors and not form.non_field_errors %} +

+ {% blocktranslate count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %} +

+ {% endif %} + + {% if form.non_field_errors %} + {% for error in form.non_field_errors %} +

+ {{ error }} +

+ {% endfor %} + {% endif %} + +
+ {% if user.is_authenticated %} +

+ {% blocktranslate trimmed %} + You are authenticated as {{ username }}, but are not authorized to + access this page. Would you like to login to a different account? + {% endblocktranslate %} +

+ {% endif %} + + +
+
+ {% include "_footer.html" %} +
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+ + + diff --git a/Finanzas/finanzas/apuntes/templates/registration/logged_out.html b/Finanzas/finanzas/apuntes/templates/registration/logged_out.html new file mode 100644 index 0000000..61938f5 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/registration/logged_out.html @@ -0,0 +1,7 @@ +{% block title %}Logged out{% endblock %} +{% block content %} + +Logged out +You have been successfully logged out. You can log-in again. + +{% endblock %} \ No newline at end of file diff --git a/Finanzas/finanzas/apuntes/templates/registration/login.html b/Finanzas/finanzas/apuntes/templates/registration/login.html new file mode 100644 index 0000000..4eaabed --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/registration/login.html @@ -0,0 +1,89 @@ +{% load i18n static %} + +{% include "_head.html" %} + + +
+
+
+
+ {% include "_branding.html" %} +

Entrar en Finanzas

+ + {% if form.errors and not form.non_field_errors %} +

+ {% blocktranslate count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %} +

+ {% endif %} + + {% if form.non_field_errors %} + {% for error in form.non_field_errors %} +

+ {{ error }} +

+ {% endfor %} + {% endif %} + +
+ {% if user.is_authenticated %} +

+ {% blocktranslate trimmed %} + You are authenticated as {{ username }}, but are not authorized to + access this page. Would you like to login to a different account? + {% endblocktranslate %} +

+ {% endif %} + + +
+
+ {% include "_footer.html" %} +
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+ + + diff --git a/Finanzas/finanzas/apuntes/templates/registration/logout.html b/Finanzas/finanzas/apuntes/templates/registration/logout.html new file mode 100644 index 0000000..fa8a841 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/registration/logout.html @@ -0,0 +1,10 @@ + + + + Cerrar Sesión + + +

Has cerrado sesión con éxito

+ Iniciar sesión nuevamente + + diff --git a/Finanzas/finanzas/apuntes/templates/registration/signup.html b/Finanzas/finanzas/apuntes/templates/registration/signup.html new file mode 100644 index 0000000..d86ba8b --- /dev/null +++ b/Finanzas/finanzas/apuntes/templates/registration/signup.html @@ -0,0 +1,67 @@ + +{% include "_head.html" %} + + +
+
+
+
+ {% include "_branding.html" %} +

Registrarse en Finanzas

+ +
+ + + +
¿Ya tienes una cuenta? Entra
+
+ + + +
+ + {% include "_footer.html" %} + +
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+ + + + + diff --git a/Finanzas/finanzas/apuntes/templatetags/__init__.py b/Finanzas/finanzas/apuntes/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Finanzas/finanzas/apuntes/templatetags/filtros_de_entorno.py b/Finanzas/finanzas/apuntes/templatetags/filtros_de_entorno.py new file mode 100644 index 0000000..4a6a015 --- /dev/null +++ b/Finanzas/finanzas/apuntes/templatetags/filtros_de_entorno.py @@ -0,0 +1,9 @@ +import os +from django import template + +register = template.Library() + + +@register.filter +def muestra_version(clave): + return os.getenv(clave, '') diff --git a/Finanzas/finanzas/apuntes/tests.py b/Finanzas/finanzas/apuntes/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/Finanzas/finanzas/apuntes/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Finanzas/finanzas/apuntes/urls.py b/Finanzas/finanzas/apuntes/urls.py new file mode 100644 index 0000000..31d6c10 --- /dev/null +++ b/Finanzas/finanzas/apuntes/urls.py @@ -0,0 +1,17 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('cuentas/', views.lista_cuentas, name='lista_cuentas'), + path('cuentas/nuevo/', views.nueva_cuenta, name='nueva_cuenta'), + path('cuentas//', views.detalle_cuenta, name='detalle_cuenta'), + path('cuentas//editar/', views.editar_cuenta, name='editar_cuenta'), + path('cuentas//eliminar/', views.eliminar_cuenta, name='eliminar_cuenta'), + + path('apuntes/', views.lista_apuntes, name='lista_apuntes'), + path('apuntes/nuevo/', views.nuevo_apunte, name='nuevo_apunte'), + path('apuntes//', views.detalle_apunte, name='detalle_apunte'), + path('apuntes//editar/', views.editar_apunte, name='editar_apunte'), + path('apuntes//eliminar/', views.eliminar_apunte, name='eliminar_apunte'), +] diff --git a/Finanzas/finanzas/apuntes/views.py b/Finanzas/finanzas/apuntes/views.py new file mode 100644 index 0000000..c5e9c17 --- /dev/null +++ b/Finanzas/finanzas/apuntes/views.py @@ -0,0 +1,145 @@ +from django.shortcuts import render +from django.contrib.auth.decorators import login_required +from django.shortcuts import render, get_object_or_404, redirect + +# Create your views here. +from .models import Cuentas, Apuntes +from .forms import CuentasForm, ApuntesForm + +@login_required +def principal(request): + cuentas = Cuentas.objects.all() + apuntes = Apuntes.objects.all() + + return render(request, 'apuntes/index.html', {'cuentas': cuentas, 'apuntes': apuntes}) + + +# Vistas para los cuentas +@login_required +def lista_cuentas(request): + cuentas = Cuentas.objects.all() + return render(request, 'apuntes/lista_cuentas.html', {'cuentas': cuentas}) + + +@login_required +def detalle_cuenta(request, cuenta_id): + cuenta = get_object_or_404(Cuentas, pk=cuenta_id) + + apuntes = Apuntes.objects.filter(cuenta=cuenta_id) + + return render(request, 'apuntes/detalle_cuenta.html', {'cuenta': cuenta, 'apuntes': apuntes}) + + +@login_required +def nueva_cuenta(request): + if request.method == 'POST': + form = CuentasForm(request.POST, request.FILES) + if form.is_valid(): + form.save() + return redirect('lista_cuentas') + else: + form = CuentasForm() + return render(request, 'apuntes/form_cuenta.html', {'form': form}) + + +@login_required +def editar_cuenta(request, cuenta_id): + cuenta = get_object_or_404(Cuentas, pk=cuenta_id) + if request.method == 'POST': + form = CuentasForm(request.POST, request.FILES, instance=cuenta) + if form.is_valid(): + form.save() + return redirect('lista_cuentas') + else: + form = CuentasForm(instance=cuenta) + return render(request, 'apuntes/form_cuenta.html', {'form': form}) + + +@login_required +def eliminar_cuenta(request, cuenta_id): + cuenta = get_object_or_404(Cuentas, pk=cuenta_id) + cuenta.delete() + return redirect('lista_cuentas') + + +# Vistas para los apuntes +@login_required +def lista_apuntes(request): + apuntes = Apuntes.objects.all() + return render(request, 'apuntes/lista_apuntes.html', {'apuntes': apuntes}) + + +@login_required +def detalle_apunte(request, apunte_id): + apunte = get_object_or_404(Apuntes, pk=apunte_id) + return render(request, 'apuntes/detalle_apunte.html', {'apunte': apunte}) + + +@login_required +def nuevo_apunte(request): + + cuentas = Cuentas.objects.all() # vamos a ver si hay vehículos dados de alta + + if cuentas: + if request.method == 'POST': + form = ApuntesForm(request.POST, request.FILES) + if form.is_valid(): + instancia = form.save(commit=False) + + aplica_descuento = form.cleaned_data['aplica_descuento'] + + if aplica_descuento: + instancia.descuento = float(instancia.importe) * 0.03 + else: + instancia.descuento = 0.0 + + instancia.importe = float(instancia.importe) - instancia.descuento + + if instancia.litros > 0: + instancia.precioxlitro = round(instancia.importe / float(instancia.litros), 2) + else: + instancia.precioxlitro = 0 + + # lee todos los apuntes del vehículo + # apuntes = Apuntes.query.filter_by(cuenta_id=cuenta_id).all() + + if Apuntes.objects.filter(cuenta_id=instancia.cuenta): + apuntes = Apuntes.objects.filter(cuenta_id=instancia.cuenta).order_by('-fecha')[0] + + instancia.kmsrecorridos = instancia.kms - apuntes.kms + + if instancia.kmsrecorridos > 0: + instancia.consumo = round(instancia.litros * 100 / instancia.kmsrecorridos, 2) + else: + instancia.kmsrecorridos = 0 + instancia.consumo = 0 + + instancia.save() + + return redirect('lista_apuntes') + else: + form = ApuntesForm() + return render(request, 'apuntes/form_apunte.html', {'form': form}) + else: + return render(request, 'apuntes/index.html') + + +@login_required +def editar_apunte(request, apunte_id): + apunte = get_object_or_404(Apuntes, pk=apunte_id) + + if request.method == 'POST': + form = ApuntesForm(request.POST, request.FILES, instance=apunte) + if form.is_valid(): + form.save() + return redirect('lista_apuntes') + else: + form = ApuntesForm(instance=apunte) + return render(request, 'apuntes/form_apunte.html', {'form': form}) + + +@login_required +def eliminar_apunte(request, apunte_id): + apunte = Apuntes.objects.get(pk=apunte_id) + apunte.delete() + return redirect('lista_apuntes') diff --git a/Finanzas/finanzas/db.sqlite3 b/Finanzas/finanzas/db.sqlite3 new file mode 100644 index 0000000..86494ba Binary files /dev/null and b/Finanzas/finanzas/db.sqlite3 differ diff --git a/Finanzas/finanzas/finanzas/__init__.py b/Finanzas/finanzas/finanzas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Finanzas/finanzas/finanzas/asgi.py b/Finanzas/finanzas/finanzas/asgi.py new file mode 100644 index 0000000..6647f88 --- /dev/null +++ b/Finanzas/finanzas/finanzas/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for finanzas project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'finanzas.settings') + +application = get_asgi_application() diff --git a/Finanzas/finanzas/finanzas/settings.py b/Finanzas/finanzas/finanzas/settings.py new file mode 100644 index 0000000..312293d --- /dev/null +++ b/Finanzas/finanzas/finanzas/settings.py @@ -0,0 +1,141 @@ +""" +Django settings for finanzas project. + +Generated by 'django-admin startproject' using Django 5.1. + +For more information on this file, see +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/ +""" + +from pathlib import Path + +# 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.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-vu#zk4g8pj-qoov#8^i$&s8n_ipp2r3h+o$z1w(1%d=6+i@erm' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + 'apuntes', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'finanzas.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'finanzas.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.1/topics/i18n/ + +LANGUAGE_CODE = 'es-es' + +TIME_ZONE = 'Europe/Madrid' + +USE_I18N = True + +USE_TZ = True +I18N = True +L10N = True +DECIMAL_SEPARATOR = ',' +THOUSAND_SEPARATOR = '.' + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.1/howto/static-files/ + +STATIC_URL = 'static/' +STATIC_ROOT = BASE_DIR / "staticfiles" + +# Default primary key field type +# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +LOGIN_URL = '/accounts/login/' +LOGIN_REDIRECT_URL = 'principal' +LOGOUT_REDIRECT_URL = 'principal' + +AUTH_USER_MODEL = "apuntes.ReyMotaUser" + +MEDIA_ROOT = BASE_DIR / "mediafiles" +MEDIA_URL = '/media/' + +if DEBUG is False: + CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS").split(" ") diff --git a/Finanzas/finanzas/finanzas/urls.py b/Finanzas/finanzas/finanzas/urls.py new file mode 100644 index 0000000..6b5d00a --- /dev/null +++ b/Finanzas/finanzas/finanzas/urls.py @@ -0,0 +1,35 @@ +""" +URL configuration for finanzas project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.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 path, include +from django.conf.urls.static import static +from django.conf import settings +from django.views.generic.base import TemplateView # new + +urlpatterns = [ + path('obreros/', admin.site.urls), + + path('apuntes/', include('apuntes.urls')), + + path("accounts/", include("accounts.urls")), # new + + path("accounts/", include("django.contrib.auth.urls")), + + path("", TemplateView.as_view(template_name="apuntes/index.html"), + name="principal"), # new +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + diff --git a/Finanzas/finanzas/finanzas/wsgi.py b/Finanzas/finanzas/finanzas/wsgi.py new file mode 100644 index 0000000..f64f301 --- /dev/null +++ b/Finanzas/finanzas/finanzas/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for finanzas project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'finanzas.settings') + +application = get_wsgi_application() diff --git a/Finanzas/finanzas/manage.py b/Finanzas/finanzas/manage.py new file mode 100755 index 0000000..7fc3cf5 --- /dev/null +++ b/Finanzas/finanzas/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'finanzas.settings') + 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?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/Finanzas/finanzas/mediafiles/profile_images/default.jpg b/Finanzas/finanzas/mediafiles/profile_images/default.jpg new file mode 100644 index 0000000..c3d6ff4 Binary files /dev/null and b/Finanzas/finanzas/mediafiles/profile_images/default.jpg differ diff --git a/Finanzas/finanzas/mediafiles/profile_images/gravatar-tino.jpeg b/Finanzas/finanzas/mediafiles/profile_images/gravatar-tino.jpeg new file mode 100644 index 0000000..98ef9b0 Binary files /dev/null and b/Finanzas/finanzas/mediafiles/profile_images/gravatar-tino.jpeg differ diff --git a/Finanzas/finanzas/mediafiles/profile_images/gravatar-tino_jqB0Vq4.jpeg b/Finanzas/finanzas/mediafiles/profile_images/gravatar-tino_jqB0Vq4.jpeg new file mode 100644 index 0000000..98ef9b0 Binary files /dev/null and b/Finanzas/finanzas/mediafiles/profile_images/gravatar-tino_jqB0Vq4.jpeg differ diff --git a/Finanzas/finanzas/mediafiles/vehiculos/bmw.jpg b/Finanzas/finanzas/mediafiles/vehiculos/bmw.jpg new file mode 100644 index 0000000..88723ad Binary files /dev/null and b/Finanzas/finanzas/mediafiles/vehiculos/bmw.jpg differ diff --git a/Finanzas/finanzas/mediafiles/vehiculos/bmw.png b/Finanzas/finanzas/mediafiles/vehiculos/bmw.png new file mode 100644 index 0000000..e6e2c25 Binary files /dev/null and b/Finanzas/finanzas/mediafiles/vehiculos/bmw.png differ diff --git a/Finanzas/finanzas/mediafiles/vehiculos/bmw_yVyuq4g.jpg b/Finanzas/finanzas/mediafiles/vehiculos/bmw_yVyuq4g.jpg new file mode 100644 index 0000000..88723ad Binary files /dev/null and b/Finanzas/finanzas/mediafiles/vehiculos/bmw_yVyuq4g.jpg differ