Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 72def373e3 | |||
| a50cadc873 | |||
| 551057b067 | |||
| ad7ddbe887 | |||
| d6b7cdfe6a | |||
| 56286c2fd9 | |||
| ba4f6ad65d | |||
| ed7041ae40 | |||
| fa948a98e2 | |||
| e8a5091dfd | |||
| a0ee6ecd14 | |||
| d6c9aa3db3 | |||
| 9751d19401 | |||
| cda9adb986 | |||
| e7e7fd118d | |||
| 132b1e1722 | |||
| 7f557a3247 | |||
| 8cf1a55161 | |||
| 61a04e5040 | |||
| e5a0caa8b6 | |||
| 25e6088355 | |||
| 8ec391ccde | |||
| 3b007f324f | |||
| 6e003009fa | |||
| 69578f1dba | |||
| 3eb81b343c | |||
| ce5aac0e89 | |||
| c534f500ad | |||
| 63c6b645c3 | |||
| b16cb367d3 | |||
| 503233d323 | |||
| b50ab06a22 | |||
| cda339a336 | |||
| 541a73ce36 | |||
| 8932eeefbf | |||
| 80e5e2a422 | |||
| a686bccd54 | |||
| 6be67a9100 | |||
| bee360dfbb | |||
| a20a61be82 | |||
| b9675385aa | |||
| c33def1124 | |||
| 52dfa51af2 | |||
| a02617f8d2 | |||
| 53b4e89347 | |||
| df0579dd86 | |||
| 1022a44f12 | |||
| bb697d92c6 |
+2
-1
@@ -7,4 +7,5 @@ __pycache__/
|
|||||||
*.pyc
|
*.pyc
|
||||||
tienda/__pycache__/
|
tienda/__pycache__/
|
||||||
proyecto/__pycache__/
|
proyecto/__pycache__/
|
||||||
media
|
media
|
||||||
|
staticfiles
|
||||||
|
|||||||
Vendored
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"python.REPL.enableREPLSmartSend": false
|
"python.REPL.enableREPLSmartSend": false,
|
||||||
|
"makefile.configureOnOpen": false
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# AGENTS.md - Django Tienda Project
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make test # Run tests
|
||||||
|
python manage.py runserver # Dev server
|
||||||
|
python manage.py migrate # Migrations
|
||||||
|
python manage.py collectstatic # Static files (production)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- **Redis**: `redis://127.0.0.1:6379/1` (Linux: `sudo systemctl start redis-server`)
|
||||||
|
- **PostgreSQL**: Default. Set `POSTGRES_ENABLED=False` for SQLite
|
||||||
|
- **Environment**: Copy `.env.example` to `.env`
|
||||||
|
|
||||||
|
## Quirks
|
||||||
|
|
||||||
|
1. **Migrations**: If `makemigrations` fails with error 130, check `tienda/migrations/` - file often created anyway
|
||||||
|
2. **Test DB**: Always uses SQLite (hardcoded)
|
||||||
|
3. **App URL**: `http://localhost:8000/tienda/` (not `/`)
|
||||||
|
4. **Admin**: `/admin/`
|
||||||
|
5. **User Model**: Use `tienda.User` for queries
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
- `proyecto/` - Django settings, URLs, WSGI/ASGI
|
||||||
|
- `tienda/` - Main app (models, views, admin, templates)
|
||||||
|
- Templates extend `tienda/templates/tienda/base.html`
|
||||||
|
|
||||||
|
## Shipping
|
||||||
|
|
||||||
|
Only Almería province, Spain (04xxx). Country: "España".
|
||||||
|
|
||||||
|
## External Services
|
||||||
|
|
||||||
|
- **Payment**: Stripe + PayPal (via .env)
|
||||||
|
- **Storage**: S3 - set `S3_ENABLE=True`
|
||||||
|
- **Email**: SMTP (see .env.example)
|
||||||
|
- **Async**: Celery + Redis
|
||||||
|
|
||||||
|
## Deploy
|
||||||
|
|
||||||
|
- Push to `origin` and `github` after changes
|
||||||
|
- GitHub Actions updates `ghcr.io/dsaub/proyecto-mvc:development`
|
||||||
|
- SSH: `debian@172.16.14.221` (requires VPN - skip if unavailable)
|
||||||
|
- Stack: `/home/debian/composes/mvc/mvc.yml` on swarm
|
||||||
|
- Timeout: 1 minute max when updating services
|
||||||
|
- Docker job requires Test job to pass first
|
||||||
|
|
||||||
|
## Other
|
||||||
|
|
||||||
|
- **Repo**: https://github.com/dsaub/proyecto-final
|
||||||
|
- **Python**: 3.14, use `.venv` virtualenv
|
||||||
|
- **GIT**: origin → git.elordenador.org, github → GitHub
|
||||||
|
- **Docs**: `.github/copilot-instructions.md`, `docs/`
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
from .celery import app as celery_app
|
from .celery import app as celery
|
||||||
__all__ = ('celery_app',)
|
__all__ = ('celery',)
|
||||||
+6
-1
@@ -1,8 +1,13 @@
|
|||||||
from celery import Celery
|
from celery import Celery
|
||||||
import os
|
import os
|
||||||
|
import django
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings')
|
||||||
|
django.setup()
|
||||||
|
|
||||||
app = Celery('proyecto')
|
app = Celery('proyecto')
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proyecto.settings')
|
|
||||||
app.config_from_object('django.conf:settings', namespace="CELERY")
|
app.config_from_object('django.conf:settings', namespace="CELERY")
|
||||||
|
|
||||||
|
user_options = {}
|
||||||
|
|
||||||
app.autodiscover_tasks()
|
app.autodiscover_tasks()
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
from jinja2 import Environment
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.templatetags.static import static
|
|
||||||
|
|
||||||
def environment(**options):
|
|
||||||
env = Environment(**options)
|
|
||||||
env.globals.update({
|
|
||||||
'static': static,
|
|
||||||
'url': reverse,
|
|
||||||
})
|
|
||||||
return env
|
|
||||||
+12
-9
@@ -14,6 +14,7 @@ import logging
|
|||||||
import os, sys
|
import os, sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
DEV_ENV = (sys.argv[1] == 'runserver')
|
||||||
|
|
||||||
RUNNING_TESTS = any(arg in {'test', 'pytest'} for arg in sys.argv) or 'PYTEST_CURRENT_TEST' in os.environ
|
RUNNING_TESTS = any(arg in {'test', 'pytest'} for arg in sys.argv) or 'PYTEST_CURRENT_TEST' in os.environ
|
||||||
|
|
||||||
@@ -101,6 +102,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'django.forms',
|
||||||
'compressor',
|
'compressor',
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -136,14 +138,6 @@ TEMPLATES = [
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
'BACKEND': 'django.template.backends.jinja2.Jinja2',
|
|
||||||
'DIRS': [BASE_DIR / 'templates/jinja2'],
|
|
||||||
'APP_DIRS': True,
|
|
||||||
'OPTIONS': {
|
|
||||||
'environment': 'proyecto.jinja2.environment',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'proyecto.wsgi.application'
|
WSGI_APPLICATION = 'proyecto.wsgi.application'
|
||||||
@@ -216,6 +210,8 @@ USE_TZ = True
|
|||||||
|
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||||
|
COMPRESS_ROOT = STATIC_ROOT
|
||||||
|
COMPRESS_URL = STATIC_URL
|
||||||
STATICFILES_DIRS = [
|
STATICFILES_DIRS = [
|
||||||
BASE_DIR / 'tienda' / 'static',
|
BASE_DIR / 'tienda' / 'static',
|
||||||
]
|
]
|
||||||
@@ -427,4 +423,11 @@ CELERY_RESULT_SERIALIZER = 'json'
|
|||||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||||
|
|
||||||
USE_X_FORWARDED_HOST = True
|
USE_X_FORWARDED_HOST = True
|
||||||
SECURE_REFERER_POLICY = "strict-origin-when-cross-origin"
|
SECURE_REFERER_POLICY = "strict-origin-when-cross-origin"
|
||||||
|
|
||||||
|
from django.forms.renderers import TemplatesSetting
|
||||||
|
|
||||||
|
class CustomFormRenderer(TemplatesSetting):
|
||||||
|
form_template_name = "tienda/form_snippet.html"
|
||||||
|
|
||||||
|
FORM_RENDERER = "proyecto.settings.CustomFormRenderer"
|
||||||
+27
-22
@@ -1,46 +1,51 @@
|
|||||||
amqp==5.3.1
|
amqp==5.3.1
|
||||||
asgiref==3.11.0
|
asgiref==3.11.1
|
||||||
billiard==4.2.4
|
billiard==4.2.4
|
||||||
celery==5.6.2
|
boto3==1.43.5
|
||||||
certifi==2026.1.4
|
botocore==1.43.5
|
||||||
|
celery==5.6.3
|
||||||
|
certifi==2026.4.22
|
||||||
cffi==2.0.0
|
cffi==2.0.0
|
||||||
charset-normalizer==3.4.4
|
charset-normalizer==3.4.7
|
||||||
click==8.3.1
|
click==8.3.3
|
||||||
click-didyoumean==0.3.1
|
click-didyoumean==0.3.1
|
||||||
click-plugins==1.1.1.2
|
click-plugins==1.1.1.2
|
||||||
click-repl==0.3.0
|
click-repl==0.3.0
|
||||||
cryptography==46.0.7
|
cryptography==48.0.0
|
||||||
Django==6.0.4
|
defusedxml==0.7.1
|
||||||
|
Django==6.0.5
|
||||||
django-appconf==1.2.0
|
django-appconf==1.2.0
|
||||||
django-redis==5.4.0
|
django-redis==6.0.0
|
||||||
|
django-storages==1.14.6
|
||||||
django_compressor==4.6.0
|
django_compressor==4.6.0
|
||||||
django-storages[boto3]==1.14.6
|
fonttools==4.62.1
|
||||||
gunicorn==25.1.0
|
fpdf2==2.8.7
|
||||||
idna==3.11
|
gunicorn==26.0.0
|
||||||
Jinja2==3.1.6
|
idna==3.13
|
||||||
|
|
||||||
|
jmespath==1.1.0
|
||||||
kombu==5.6.2
|
kombu==5.6.2
|
||||||
MarkupSafe==3.0.3
|
MarkupSafe==3.0.3
|
||||||
packaging==26.0
|
packaging==26.2
|
||||||
paypalrestsdk==1.13.3
|
paypalrestsdk==1.13.3
|
||||||
pillow==12.2.0
|
pillow==12.2.0
|
||||||
boto3==1.42.97
|
|
||||||
prompt_toolkit==3.0.52
|
prompt_toolkit==3.0.52
|
||||||
|
psycopg2-binary==2.9.12
|
||||||
pycparser==3.0
|
pycparser==3.0
|
||||||
pyOpenSSL==26.0.0
|
pyOpenSSL==26.2.0
|
||||||
python-dateutil==2.9.0.post0
|
python-dateutil==2.9.0.post0
|
||||||
rcssmin==1.2.2
|
rcssmin==1.2.2
|
||||||
redis==5.2.1
|
redis==7.4.0
|
||||||
requests==2.33.0
|
requests==2.33.1
|
||||||
rjsmin==1.2.5
|
rjsmin==1.2.5
|
||||||
|
s3transfer==0.17.0
|
||||||
six==1.17.0
|
six==1.17.0
|
||||||
sqlparse==0.5.5
|
sqlparse==0.5.5
|
||||||
stripe==14.3.0
|
stripe==15.1.0
|
||||||
typing_extensions==4.15.0
|
typing_extensions==4.15.0
|
||||||
tzdata==2025.3
|
tzdata==2026.2
|
||||||
tzlocal==5.3.1
|
tzlocal==5.3.1
|
||||||
urllib3==2.6.3
|
urllib3==2.6.3
|
||||||
vine==5.1.0
|
vine==5.1.0
|
||||||
wcwidth==0.6.0
|
wcwidth==0.7.0
|
||||||
whitenoise==6.12.0
|
whitenoise==6.12.0
|
||||||
fpdf2==2.8.7
|
|
||||||
psycopg2-binary==2.9.11
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+60
-3
@@ -1,17 +1,74 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Category, Image, Product, Cart, CartItem, Order, OrderItem, OrderMessage, StockReservation, StockReservationItem, User, VerificationCode, SavedPaymentMethod
|
from .models import Category, Image, Product, Cart, CartItem, Order, OrderItem, OrderMessage, StockReservation, StockReservationItem, User, VerificationCode, SavedPaymentMethod
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
from django.urls import path
|
||||||
|
from django.contrib import messages
|
||||||
|
from . import tasks
|
||||||
|
|
||||||
admin.site.register(Category)
|
admin.site.register(Category)
|
||||||
admin.site.register(Image)
|
admin.site.register(Image)
|
||||||
admin.site.register(User)
|
|
||||||
admin.site.register(VerificationCode)
|
admin.site.register(VerificationCode)
|
||||||
|
|
||||||
|
@admin.register(User)
|
||||||
|
class UserAdmin(admin.ModelAdmin):
|
||||||
|
search_fields = ('username',)
|
||||||
|
actions = ['banear_usuario_action', 'desbanear_usuario_action']
|
||||||
|
def has_change_permission(self, request, obj = ...):
|
||||||
|
return super().has_change_permission(request, obj)
|
||||||
|
|
||||||
|
def banear_usuario_action(self, request, queryset):
|
||||||
|
usuarios_baneados = 0
|
||||||
|
for user in queryset:
|
||||||
|
user: User = user
|
||||||
|
# Desactiva usuario
|
||||||
|
if user.registration_status == User.RegisterStatus.BANNED:
|
||||||
|
continue
|
||||||
|
|
||||||
|
user.is_active = False
|
||||||
|
user.registration_status = User.RegisterStatus.BANNED
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
# Enviar task a Worker
|
||||||
|
tasks.banear_usuario.delay(user.email)
|
||||||
|
|
||||||
|
# Borrar productos
|
||||||
|
Product.objects.filter(creator=user).delete()
|
||||||
|
usuarios_baneados+=1
|
||||||
|
self.message_user(
|
||||||
|
request,
|
||||||
|
f"Se ha(n) baneado {usuarios_baneados} usuario(s) correctamente.",
|
||||||
|
level=messages.SUCCESS
|
||||||
|
)
|
||||||
|
def desbanear_usuario_action(self, request, queryset):
|
||||||
|
user_desbaneados = 0
|
||||||
|
for user in queryset:
|
||||||
|
user: User = user
|
||||||
|
if user.registration_status != User.RegisterStatus.BANNED:
|
||||||
|
continue
|
||||||
|
|
||||||
|
user.is_active = True
|
||||||
|
user.registration_status = User.RegisterStatus.ACTIVE
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
tasks.desbanear_usuario.delay(user.email)
|
||||||
|
|
||||||
|
user_desbaneados -= 1
|
||||||
|
self.message_user(
|
||||||
|
request,
|
||||||
|
f"Se ha(n) desbaneado {user_desbaneados} usuario(s)",
|
||||||
|
level=messages.SUCCESS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
banear_usuario_action.short_description = "Banear usuarios seleccionados"
|
||||||
|
desbanear_usuario_action.short_description = "Desbanear usuarios seleccionados"
|
||||||
|
|
||||||
@admin.register(Product)
|
@admin.register(Product)
|
||||||
class ProductAdmin(admin.ModelAdmin):
|
class ProductAdmin(admin.ModelAdmin):
|
||||||
list_display = ('id', 'name', 'price', 'stock', 'category', 'creator')
|
list_display = ('id', 'sku', 'name', 'price', 'stock', 'category', 'creator')
|
||||||
search_fields = ('name', 'creator__username', 'creator__email')
|
search_fields = ('name', 'sku', 'creator__username', 'creator__email')
|
||||||
list_filter = ('category',)
|
list_filter = ('category',)
|
||||||
class CartItemInline(admin.TabularInline):
|
class CartItemInline(admin.TabularInline):
|
||||||
model = CartItem
|
model = CartItem
|
||||||
|
|||||||
+354
@@ -0,0 +1,354 @@
|
|||||||
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from .models import Category
|
||||||
|
|
||||||
|
|
||||||
|
class ProductForm(forms.Form):
|
||||||
|
name = forms.CharField(
|
||||||
|
label="Nombre del Producto",
|
||||||
|
max_length=200,
|
||||||
|
required = True,
|
||||||
|
widget=forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'placeholder': 'Ej: iPhone 15 Pro Max'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
briefdesc = forms.CharField(
|
||||||
|
label="Descripción Breve",
|
||||||
|
max_length=250,
|
||||||
|
required = True,
|
||||||
|
widget = forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'placeholder': 'Una descripción corta para mostrar en las tarjetas de producto'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
description = forms.CharField(
|
||||||
|
widget=forms.Textarea(attrs={"rows": "5", "class": "form-control"}),
|
||||||
|
max_length=5000,
|
||||||
|
label="Descripción completa",
|
||||||
|
required = True
|
||||||
|
)
|
||||||
|
price = forms.FloatField(
|
||||||
|
label="Precio (en €)",
|
||||||
|
required = True,
|
||||||
|
widget = forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'placeholder': '15.99'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
stock = forms.IntegerField(
|
||||||
|
label="Stock Disponible",
|
||||||
|
required = True,
|
||||||
|
widget = forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
category = forms.ModelChoiceField(
|
||||||
|
queryset=Category.objects.all(),
|
||||||
|
label="Categoría",
|
||||||
|
required=True,
|
||||||
|
widget=forms.Select(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
|
||||||
|
primary_image = forms.ImageField(
|
||||||
|
label="Imagen Principal",
|
||||||
|
required = False,
|
||||||
|
widget = forms.ClearableFileInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'accept': 'image/*'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ProductEditForm(forms.Form):
|
||||||
|
name = forms.CharField(
|
||||||
|
label="Nombre del Producto",
|
||||||
|
max_length=200,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Ej: iPhone 15 Pro Max'})
|
||||||
|
)
|
||||||
|
briefdesc = forms.CharField(
|
||||||
|
label="Descripción Breve",
|
||||||
|
max_length=250,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Una descripción corta'})
|
||||||
|
)
|
||||||
|
description = forms.CharField(
|
||||||
|
widget=forms.Textarea(attrs={"rows": "5", "class": "form-control"}),
|
||||||
|
max_length=5000,
|
||||||
|
label="Descripción completa",
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
price = forms.FloatField(
|
||||||
|
label="Precio (en €)",
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '15.99'})
|
||||||
|
)
|
||||||
|
stock = forms.IntegerField(
|
||||||
|
label="Stock Disponible",
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
category = forms.ModelChoiceField(
|
||||||
|
queryset=Category.objects.all(),
|
||||||
|
label="Categoría",
|
||||||
|
required=True,
|
||||||
|
widget=forms.Select(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
primary_image = forms.ImageField(
|
||||||
|
label="Imagen Principal (opcional)",
|
||||||
|
required=False,
|
||||||
|
widget=forms.ClearableFileInput(attrs={'class': 'form-control', 'accept': 'image/*'})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SecondaryImageForm(forms.Form):
|
||||||
|
image = forms.ImageField(
|
||||||
|
label="Seleccionar Imagen",
|
||||||
|
required = True,
|
||||||
|
widget = forms.ClearableFileInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'accept': 'image/*'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
alt = forms.CharField(
|
||||||
|
label="Texto Alternativo",
|
||||||
|
max_length=255,
|
||||||
|
required = False,
|
||||||
|
widget = forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'placeholder': 'Descripción opcional de la imagen'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class UserLoginForm(forms.Form):
|
||||||
|
email = forms.EmailField(
|
||||||
|
label = "Correo Electrónico",
|
||||||
|
max_length=255,
|
||||||
|
required = True,
|
||||||
|
widget = forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'placeholder': 'Correo Electronico de tu cuenta...'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
password = forms.CharField(
|
||||||
|
label="Contraseña",
|
||||||
|
max_length = 255,
|
||||||
|
required = True,
|
||||||
|
widget = forms.PasswordInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control',
|
||||||
|
'placeholder': 'Contraseña del usuario'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
remember = forms.BooleanField(
|
||||||
|
required = False,
|
||||||
|
label = "Recuerdame",
|
||||||
|
widget = forms.CheckboxInput(attrs={'class': 'form-check-input'})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class UserRegisterForm(forms.Form):
|
||||||
|
name = forms.CharField(
|
||||||
|
label = "Nombre Completo",
|
||||||
|
max_length = 255,
|
||||||
|
required = True,
|
||||||
|
widget = forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
email = forms.EmailField(
|
||||||
|
label = "Correo Electrónico",
|
||||||
|
max_length = 255,
|
||||||
|
required = True,
|
||||||
|
widget = forms.TextInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
password = forms.CharField(
|
||||||
|
label = "Contraseña",
|
||||||
|
max_length = 255,
|
||||||
|
required = True,
|
||||||
|
widget = forms.PasswordInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
password_confirm = forms.CharField(
|
||||||
|
label = "Verificar Contraseña",
|
||||||
|
max_length = 255,
|
||||||
|
required = True,
|
||||||
|
widget = forms.PasswordInput(
|
||||||
|
attrs = {
|
||||||
|
'class': 'form-control'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
terms = forms.BooleanField(
|
||||||
|
required = True,
|
||||||
|
label = "Acepto los terminos y condiciones",
|
||||||
|
widget = forms.CheckboxInput(attrs={'class': 'form-check-input'})
|
||||||
|
)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super().clean()
|
||||||
|
password = cleaned_data.get("password")
|
||||||
|
password_confirm = cleaned_data.get("password_confirm")
|
||||||
|
if password and password_confirm and password != password_confirm:
|
||||||
|
raise ValidationError("Las contraseñas no coinciden.")
|
||||||
|
|
||||||
|
|
||||||
|
class EditProfileForm(forms.Form):
|
||||||
|
first_name = forms.CharField(
|
||||||
|
label="Nombre",
|
||||||
|
max_length=150,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
last_name = forms.CharField(
|
||||||
|
label="Apellidos",
|
||||||
|
max_length=150,
|
||||||
|
required=False,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
email = forms.EmailField(
|
||||||
|
label="Correo Electrónico",
|
||||||
|
max_length=254,
|
||||||
|
required=True,
|
||||||
|
widget=forms.EmailInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ChangePasswordForm(forms.Form):
|
||||||
|
current_password = forms.CharField(
|
||||||
|
label="Contraseña Actual",
|
||||||
|
max_length=128,
|
||||||
|
required=True,
|
||||||
|
widget=forms.PasswordInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
new_password = forms.CharField(
|
||||||
|
label="Nueva Contraseña",
|
||||||
|
max_length=128,
|
||||||
|
required=True,
|
||||||
|
widget=forms.PasswordInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
confirm_password = forms.CharField(
|
||||||
|
label="Confirmar Nueva Contraseña",
|
||||||
|
max_length=128,
|
||||||
|
required=True,
|
||||||
|
widget=forms.PasswordInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super().clean()
|
||||||
|
new_password = cleaned_data.get("new_password")
|
||||||
|
confirm_password = cleaned_data.get("confirm_password")
|
||||||
|
if new_password and confirm_password and new_password != confirm_password:
|
||||||
|
raise ValidationError("Las contraseñas no coinciden.")
|
||||||
|
if new_password and len(new_password) < 8:
|
||||||
|
raise ValidationError("La contraseña debe tener al menos 8 caracteres.")
|
||||||
|
|
||||||
|
|
||||||
|
class ShippingAddressForm(forms.Form):
|
||||||
|
full_name = forms.CharField(
|
||||||
|
label="Nombre Completo",
|
||||||
|
max_length=255,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Juan Pérez García'})
|
||||||
|
)
|
||||||
|
address_line_1 = forms.CharField(
|
||||||
|
label="Dirección",
|
||||||
|
max_length=255,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Calle Mayor 123'})
|
||||||
|
)
|
||||||
|
address_line_2 = forms.CharField(
|
||||||
|
label="Dirección (línea 2)",
|
||||||
|
max_length=255,
|
||||||
|
required=False,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Piso, puerta, etc.'})
|
||||||
|
)
|
||||||
|
city = forms.CharField(
|
||||||
|
label="Población",
|
||||||
|
max_length=100,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Almería'})
|
||||||
|
)
|
||||||
|
postal_code = forms.CharField(
|
||||||
|
label="Código Postal",
|
||||||
|
max_length=5,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '04001'})
|
||||||
|
)
|
||||||
|
country = forms.CharField(
|
||||||
|
label="País",
|
||||||
|
max_length=100,
|
||||||
|
required=False,
|
||||||
|
initial="España",
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'readonly': True})
|
||||||
|
)
|
||||||
|
phone = forms.CharField(
|
||||||
|
label="Teléfono",
|
||||||
|
max_length=20,
|
||||||
|
required=True,
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': '612 345 678'})
|
||||||
|
)
|
||||||
|
is_default = forms.BooleanField(
|
||||||
|
label="Establecer como dirección predeterminada",
|
||||||
|
required=False,
|
||||||
|
widget=forms.CheckboxInput(attrs={'class': 'form-check-input'})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ResetPasswordForm(forms.Form):
|
||||||
|
email = forms.EmailField(
|
||||||
|
label="Correo Electrónico",
|
||||||
|
max_length=254,
|
||||||
|
required=True,
|
||||||
|
widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'tu@email.com'})
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ResetPasswordPhase2Form(forms.Form):
|
||||||
|
password = forms.CharField(
|
||||||
|
label="Nueva Contraseña",
|
||||||
|
max_length=128,
|
||||||
|
required=True,
|
||||||
|
widget=forms.PasswordInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
verify_password = forms.CharField(
|
||||||
|
label="Confirmar Contraseña",
|
||||||
|
max_length=128,
|
||||||
|
required=True,
|
||||||
|
widget=forms.PasswordInput(attrs={'class': 'form-control'})
|
||||||
|
)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
cleaned_data = super().clean()
|
||||||
|
password = cleaned_data.get("password")
|
||||||
|
verify_password = cleaned_data.get("verify_password")
|
||||||
|
if password and verify_password and password != verify_password:
|
||||||
|
raise ValidationError("Las contraseñas no coinciden.")
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 6.0.4 on 2026-05-05 07:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tienda', '0006_alter_category_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='product',
|
||||||
|
name='sku',
|
||||||
|
field=models.CharField(blank=True, max_length=50, null=True, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 6.0.4 on 2026-05-07 08:14
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tienda', '0007_add_product_sku'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='product',
|
||||||
|
name='briefdesc',
|
||||||
|
field=models.TextField(default='', max_length=250),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='product',
|
||||||
|
name='description',
|
||||||
|
field=models.TextField(default='', max_length=5000),
|
||||||
|
),
|
||||||
|
]
|
||||||
+30
-3
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import unicodedata
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User, AbstractUser
|
from django.contrib.auth.models import User, AbstractUser
|
||||||
from django.utils.crypto import get_random_string
|
from django.utils.crypto import get_random_string
|
||||||
@@ -83,8 +84,9 @@ class Image(models.Model):
|
|||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
name = models.CharField(max_length=200, default="")
|
name = models.CharField(max_length=200, default="")
|
||||||
description = models.TextField(default = "")
|
sku = models.CharField(max_length=50, unique=True, blank=True, null=True)
|
||||||
briefdesc = models.TextField(default = "")
|
description = models.TextField(default = "", max_length=5000)
|
||||||
|
briefdesc = models.TextField(default = "", max_length=250)
|
||||||
price = models.FloatField(default = 0)
|
price = models.FloatField(default = 0)
|
||||||
stock = models.PositiveIntegerField(default=0)
|
stock = models.PositiveIntegerField(default=0)
|
||||||
category = models.ForeignKey(Category, on_delete=models.CASCADE)
|
category = models.ForeignKey(Category, on_delete=models.CASCADE)
|
||||||
@@ -106,6 +108,7 @@ class Product(models.Model):
|
|||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {
|
return {
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
|
"sku": self.sku,
|
||||||
"description": self.description,
|
"description": self.description,
|
||||||
"briefdesc": self.briefdesc,
|
"briefdesc": self.briefdesc,
|
||||||
"price": self.price,
|
"price": self.price,
|
||||||
@@ -342,8 +345,32 @@ class ShippingAddress(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.full_name} - {self.city}"
|
return f"{self.full_name} - {self.city}"
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.conf import settings
|
||||||
|
from .vars import ALMERIA_POSTAL_CODE_PREFIX, ALMERIA_MUNICIPALITIES_DISPLAY
|
||||||
|
from .views import _normalize_location_text
|
||||||
|
|
||||||
|
postal_code = (self.postal_code or "").strip()
|
||||||
|
city = (self.city or "").strip()
|
||||||
|
|
||||||
|
almeria_prefix = getattr(settings, 'POSTGRES_ENABLED', False) and "04" or ALMERIA_POSTAL_CODE_PREFIX
|
||||||
|
|
||||||
|
if len(postal_code) != 5 or not postal_code.isdigit() or not postal_code.startswith(almeria_prefix):
|
||||||
|
raise ValidationError({
|
||||||
|
'postal_code': 'Solo realizamos envíos en la provincia de Almería (código postal 04xxx).'
|
||||||
|
})
|
||||||
|
|
||||||
|
normalized_city = _normalize_location_text(city)
|
||||||
|
normalized_municipalities = {_normalize_location_text(m) for m in ALMERIA_MUNICIPALITIES_DISPLAY}
|
||||||
|
|
||||||
|
if normalized_city not in normalized_municipalities:
|
||||||
|
raise ValidationError({
|
||||||
|
'city': 'El pueblo/ciudad debe pertenecer a la provincia de Almería.'
|
||||||
|
})
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
# Si se marca como predeterminada, desmarcar las demás del usuario
|
self.full_clean()
|
||||||
if self.is_default:
|
if self.is_default:
|
||||||
ShippingAddress.objects.filter(user=self.user, is_default=True).update(is_default=False)
|
ShippingAddress.objects.filter(user=self.user, is_default=True).update(is_default=False)
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|||||||
@@ -315,5 +315,6 @@ p.price {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.texto-ajustado {
|
.texto-ajustado {
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: break-word;
|
||||||
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-6
@@ -11,14 +11,32 @@ from .models import User, VerificationCode
|
|||||||
@shared_task
|
@shared_task
|
||||||
def enviar_correo_bienvenida(email_usuario: str, nombre_usuario: str):
|
def enviar_correo_bienvenida(email_usuario: str, nombre_usuario: str):
|
||||||
html_content = render_to_string(
|
html_content = render_to_string(
|
||||||
'emails/welcome.html',
|
'tienda/emails/welcome.html',
|
||||||
{
|
{
|
||||||
"name": nombre_usuario
|
"name": nombre_usuario
|
||||||
},
|
},
|
||||||
using='jinja2'
|
|
||||||
)
|
)
|
||||||
send_hemail(email_usuario, "Inicio de Sesión correcto", html_content, "Has iniciado sesión...")
|
send_hemail(email_usuario, "Inicio de Sesión correcto", html_content, "Has iniciado sesión...")
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def banear_usuario(email_usuario: str):
|
||||||
|
html_content = render_to_string(
|
||||||
|
'tienda/emails/ban.html',
|
||||||
|
{
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
send_hemail(email_usuario, "Cuenta Bloqueada", html_content, "Tu cuenta ha sido bloqueada...")
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def desbanear_usuario(email_usuario: str):
|
||||||
|
html_content = render_to_string(
|
||||||
|
'tienda/emails/unban.html',
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
|
||||||
|
send_hemail(email_usuario, "Cuenta Desbloqueada", html_content, "Tu cuenta ha sido desbloqueada...")
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def enviar_correo_confirmacion(id: int):
|
def enviar_correo_confirmacion(id: int):
|
||||||
usuario = User.objects.get(id=id)
|
usuario = User.objects.get(id=id)
|
||||||
@@ -33,7 +51,11 @@ def enviar_correo_confirmacion(id: int):
|
|||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def enviar_correo_recuperacion(email: str):
|
def enviar_correo_recuperacion(email: str):
|
||||||
usuario = User.objects.get(email=email)
|
usuario: User | None
|
||||||
|
try:
|
||||||
|
usuario = User.objects.get(email=email)
|
||||||
|
except User.DoesNotExist as e:
|
||||||
|
usuario = None
|
||||||
if usuario is not None:
|
if usuario is not None:
|
||||||
ver_code = VerificationCode.objects.create(
|
ver_code = VerificationCode.objects.create(
|
||||||
code_mode = VerificationCode.VerificationModes.RESET_PASSWORD,
|
code_mode = VerificationCode.VerificationModes.RESET_PASSWORD,
|
||||||
@@ -42,18 +64,18 @@ def enviar_correo_recuperacion(email: str):
|
|||||||
)
|
)
|
||||||
ver_code.save()
|
ver_code.save()
|
||||||
html_content = render_to_string(
|
html_content = render_to_string(
|
||||||
'emails/reset_pass.html',
|
'tienda/emails/reset_pass.html',
|
||||||
{
|
{
|
||||||
"name": usuario.get_full_name(),
|
"name": usuario.get_full_name(),
|
||||||
"domain": settings.DOMAIN,
|
"domain": settings.DOMAIN,
|
||||||
"protocol": settings.PROTOCOL,
|
"protocol": settings.PROTOCOL,
|
||||||
"code": ver_code.code
|
"code": ver_code.code
|
||||||
},
|
},
|
||||||
using='jinja2'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
send_hemail(email, "Reset de Contraseña", html_content, "Estas reseteando la contraseña...")
|
send_hemail(email, "Reset de Contraseña", html_content, "Estas reseteando la contraseña...")
|
||||||
|
else:
|
||||||
|
print("User does not exist, Cancelling TASK.")
|
||||||
|
|
||||||
# Purchased items should be a list of dictionary, the dictionary must follow this tags: amount, product name, price (each)
|
# Purchased items should be a list of dictionary, the dictionary must follow this tags: amount, product name, price (each)
|
||||||
@shared_task
|
@shared_task
|
||||||
|
|||||||
@@ -13,74 +13,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="POST" enctype="multipart/form-data">
|
<form method="POST" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{{ form }}
|
||||||
<!-- Nombre del producto -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="name" class="form-label">Nombre del Producto <span class="text-danger">*</span></label>
|
|
||||||
<input type="text" class="form-control" id="name" name="name" required maxlength="200"
|
|
||||||
placeholder="Ej: iPhone 15 Pro Max">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Descripción breve -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="briefdesc" class="form-label">Descripción Breve</label>
|
|
||||||
<input type="text" class="form-control" id="briefdesc" name="briefdesc" maxlength="250"
|
|
||||||
placeholder="Una descripción corta para mostrar en las tarjetas de producto">
|
|
||||||
<div class="form-text">Opcional. Se mostrará en las vistas de listado de productos.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Descripción completa -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="description" class="form-label">Descripción Completa <span class="text-danger">*</span></label>
|
|
||||||
<textarea class="form-control" id="description" name="description" rows="5" required
|
|
||||||
placeholder="Describe tu producto en detalle..."></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Precio -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="price" class="form-label">Precio <span class="text-danger">*</span></label>
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-text">€</span>
|
|
||||||
<input type="number" class="form-control" id="price" name="price" required
|
|
||||||
min="0" step="0.01" placeholder="0.00">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Stock -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="stock" class="form-label">Stock disponible <span class="text-danger">*</span></label>
|
|
||||||
<input type="number" class="form-control" id="stock" name="stock" required
|
|
||||||
min="0" step="1" placeholder="0">
|
|
||||||
<div class="form-text">Cantidad máxima que podrán comprar los clientes.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Categoría -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="category" class="form-label">Categoría <span class="text-danger">*</span></label>
|
|
||||||
<select class="form-select" id="category" name="category" required>
|
|
||||||
<option value="" selected disabled>Selecciona una categoría</option>
|
|
||||||
{% for category in categories %}
|
|
||||||
<option value="{{ category.id }}">{{ category.name }}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Imagen principal -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="primary_image" class="form-label">Imagen Principal</label>
|
|
||||||
<input type="file" class="form-control" id="primary_image" name="primary_image"
|
|
||||||
accept="image/*">
|
|
||||||
<div class="form-text">Opcional. Esta será la imagen destacada del producto.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Imágenes secundarias -->
|
|
||||||
<div class="mb-4">
|
|
||||||
<label for="secondary_images" class="form-label">Imágenes Secundarias</label>
|
|
||||||
<input type="file" class="form-control" id="secondary_images" name="secondary_images"
|
|
||||||
accept="image/*" multiple>
|
|
||||||
<div class="form-text">Opcional. Puedes seleccionar múltiples imágenes adicionales.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Botones -->
|
<!-- Botones -->
|
||||||
<div class="d-flex justify-content-end gap-2">
|
<div class="d-flex justify-content-end gap-2">
|
||||||
<a href="{% url 'mis_productos' %}" class="btn btn-secondary">Cancelar</a>
|
<a href="{% url 'mis_productos' %}" class="btn btn-secondary">Cancelar</a>
|
||||||
|
|||||||
@@ -21,52 +21,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="mb-3">
|
{{ form.as_p }}
|
||||||
<label for="full_name" class="form-label">Nombre Completo *</label>
|
|
||||||
<input type="text" class="form-control" id="full_name" name="full_name" value="{{ direccion.full_name|default:'' }}" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="address_line_1" class="form-label">Dirección *</label>
|
|
||||||
<input type="text" class="form-control" id="address_line_1" name="address_line_1" value="{{ direccion.address_line_1|default:'' }}" placeholder="Calle, número, piso, puerta" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="address_line_2" class="form-label">Dirección (línea 2)</label>
|
|
||||||
<input type="text" class="form-control" id="address_line_2" name="address_line_2" value="{{ direccion.address_line_2|default:'' }}" placeholder="Edificio, bloque, etc. (opcional)">
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-6 mb-3">
|
|
||||||
<label for="city" class="form-label">Ciudad/Pueblo (Almería) *</label>
|
|
||||||
<input type="text" class="form-control" id="city" name="city" value="{{ direccion.city|default:'' }}" list="almeria-towns" autocomplete="off" required>
|
|
||||||
<datalist id="almeria-towns">
|
|
||||||
{% for town in almeria_municipalities %}
|
|
||||||
<option value="{{ town }}"></option>
|
|
||||||
{% endfor %}
|
|
||||||
</datalist>
|
|
||||||
<div class="form-text">Selecciona o escribe un municipio de la provincia de Almería.</div>
|
|
||||||
<div class="invalid-feedback" id="city-validation-message">
|
|
||||||
El pueblo/ciudad debe pertenecer a la provincia de Almería.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-6 mb-3">
|
|
||||||
<label for="postal_code" class="form-label">Código Postal *</label>
|
|
||||||
<input type="text" class="form-control" id="postal_code" name="postal_code" value="{{ direccion.postal_code|default:'' }}" pattern="04[0-9]{3}" maxlength="5" placeholder="04XXX" required>
|
|
||||||
<div class="form-text">Solo aceptamos códigos postales de Almería (04xxx).</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="country" class="form-label">País *</label>
|
|
||||||
<input type="text" class="form-control" id="country" name="country" value="España" readonly>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="phone" class="form-label">Teléfono *</label>
|
|
||||||
<input type="tel" class="form-control" id="phone" name="phone" value="{{ direccion.phone|default:'' }}" placeholder="+34 600 000 000" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3 form-check">
|
|
||||||
<input type="checkbox" class="form-check-input" id="is_default" name="is_default" {% if direccion.is_default %}checked{% endif %}>
|
|
||||||
<label class="form-check-label" for="is_default">
|
|
||||||
Establecer como dirección predeterminada
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="d-flex gap-2">
|
<div class="d-flex gap-2">
|
||||||
<button type="submit" class="btn btn-primary">{% if direccion %}Actualizar{% else %}Crear{% endif %} Dirección</button>
|
<button type="submit" class="btn btn-primary">{% if direccion %}Actualizar{% else %}Crear{% endif %} Dirección</button>
|
||||||
<a href="{% url 'direcciones_usuario' %}" class="btn btn-secondary">Cancelar</a>
|
<a href="{% url 'direcciones_usuario' %}" class="btn btn-secondary">Cancelar</a>
|
||||||
@@ -80,7 +35,6 @@
|
|||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
const cityInput = document.getElementById('city');
|
const cityInput = document.getElementById('city');
|
||||||
const cityValidationMessage = document.getElementById('city-validation-message');
|
|
||||||
const form = cityInput ? cityInput.form : null;
|
const form = cityInput ? cityInput.form : null;
|
||||||
|
|
||||||
if (!cityInput || !form) {
|
if (!cityInput || !form) {
|
||||||
@@ -123,8 +77,6 @@
|
|||||||
cityInput.setCustomValidity('El pueblo/ciudad debe pertenecer a la provincia de Almería.');
|
cityInput.setCustomValidity('El pueblo/ciudad debe pertenecer a la provincia de Almería.');
|
||||||
cityInput.classList.add('is-invalid');
|
cityInput.classList.add('is-invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
cityValidationMessage.textContent = cityInput.validationMessage || 'El pueblo/ciudad debe pertenecer a la provincia de Almería.';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cityInput.addEventListener('input', validateTown);
|
cityInput.addEventListener('input', validateTown);
|
||||||
|
|||||||
@@ -37,18 +37,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="mb-3">
|
{{ form.as_p }}
|
||||||
<label for="first_name" class="form-label">Nombre</label>
|
|
||||||
<input type="text" class="form-control" id="first_name" name="first_name" value="{{ user.first_name }}" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="last_name" class="form-label">Apellidos</label>
|
|
||||||
<input type="text" class="form-control" id="last_name" name="last_name" value="{{ user.last_name }}">
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="email" class="form-label">Correo Electrónico</label>
|
|
||||||
<input type="email" class="form-control" id="email" name="email" value="{{ user.email }}" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="username" class="form-label">Nombre de Usuario</label>
|
<label for="username" class="form-label">Nombre de Usuario</label>
|
||||||
<input type="text" class="form-control" id="username" value="{{ user.username }}" disabled>
|
<input type="text" class="form-control" id="username" value="{{ user.username }}" disabled>
|
||||||
@@ -69,19 +58,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="POST" action="{% url 'cambiar_contrasena' %}">
|
<form method="POST" action="{% url 'cambiar_contrasena' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="mb-3">
|
{{ password_form.as_p }}
|
||||||
<label for="current_password" class="form-label">Contraseña Actual</label>
|
|
||||||
<input type="password" class="form-control" id="current_password" name="current_password" required>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="new_password" class="form-label">Nueva Contraseña</label>
|
|
||||||
<input type="password" class="form-control" id="new_password" name="new_password" required>
|
|
||||||
<small class="text-muted">Mínimo 8 caracteres</small>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="confirm_password" class="form-label">Confirmar Nueva Contraseña</label>
|
|
||||||
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-warning">Cambiar Contraseña</button>
|
<button type="submit" class="btn btn-warning">Cambiar Contraseña</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,67 +13,9 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="POST" enctype="multipart/form-data">
|
<form method="POST" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
<!-- Nombre del producto -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="name" class="form-label">Nombre del Producto <span class="text-danger">*</span></label>
|
|
||||||
<input type="text" class="form-control" id="name" name="name" required maxlength="200"
|
|
||||||
value="{{ producto.name }}" placeholder="Ej: iPhone 15 Pro Max">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Descripción breve -->
|
<!-- Imágenes secundarias (no incluidas en el form) -->
|
||||||
<div class="mb-3">
|
|
||||||
<label for="briefdesc" class="form-label">Descripción Breve</label>
|
|
||||||
<input type="text" class="form-control" id="briefdesc" name="briefdesc" maxlength="250"
|
|
||||||
value="{{ producto.briefdesc }}" placeholder="Una descripción corta para mostrar en las tarjetas de producto">
|
|
||||||
<div class="form-text">Opcional. Se mostrará en las vistas de listado de productos.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Descripción completa -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="description" class="form-label">Descripción Completa <span class="text-danger">*</span></label>
|
|
||||||
<textarea class="form-control" id="description" name="description" rows="5" required
|
|
||||||
placeholder="Describe tu producto en detalle...">{{ producto.description }}</textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Precio -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="price" class="form-label">Precio <span class="text-danger">*</span></label>
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-text">€</span>
|
|
||||||
<input type="number" class="form-control" id="price" name="price" required
|
|
||||||
min="0" step="0.01" value="{{ producto.price }}" placeholder="0.00">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Stock -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="stock" class="form-label">Stock disponible <span class="text-danger">*</span></label>
|
|
||||||
<input type="number" class="form-control" id="stock" name="stock" required
|
|
||||||
min="0" step="1" value="{{ producto.stock }}" placeholder="0">
|
|
||||||
<div class="form-text">Cantidad máxima que podrán comprar los clientes.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Categoría -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="category" class="form-label">Categoría <span class="text-danger">*</span></label>
|
|
||||||
<select class="form-select" id="category" name="category" required>
|
|
||||||
<option value="" disabled>Selecciona una categoría</option>
|
|
||||||
{% for category in categories %}
|
|
||||||
<option value="{{ category.id }}" {% if producto.category.id == category.id %}selected{% endif %}>{{ category.name }}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Imagen principal -->
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="primary_image" class="form-label">Imagen Principal</label>
|
|
||||||
<input type="file" class="form-control" id="primary_image" name="primary_image"
|
|
||||||
accept="image/*">
|
|
||||||
<div class="form-text">Opcional. Si subes una nueva, reemplazará la actual.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Imágenes secundarias -->
|
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<label for="secondary_images" class="form-label">Imágenes Secundarias</label>
|
<label for="secondary_images" class="form-label">Imágenes Secundarias</label>
|
||||||
<input type="file" class="form-control" id="secondary_images" name="secondary_images"
|
<input type="file" class="form-control" id="secondary_images" name="secondary_images"
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="padding: 20px;">
|
||||||
|
<table width="600" border="0" cellspacing="0" cellpadding="0" style="border: 1px solid #eeeeee; background-color: #ffffff;">
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="background-color: #007bff; padding: 40px;">
|
||||||
|
<h1 style="color: #ffffff; font-family: sans-serif; margin: 0;">Su cuenta ha sido bloqueada</h1>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="padding: 40px">
|
||||||
|
<svg fill="#FF0000" width="128px" height="128px" viewBox="-3.2 -3.2 38.40 38.40" version="1.1" xmlns="http://www.w3.org/2000/svg" stroke="#FF0000" stroke-width="0.00032"><g id="SVGRepo_bgCarrier" stroke-width="0" transform="translate(6.4,6.4), scale(0.6)"><rect x="-3.2" y="-3.2" width="38.40" height="38.40" rx="19.2" fill="#1a5fb4" strokewidth="0"></rect></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="1.152"> <title>alert</title> <path d="M14.611 18.856c-0.346 0.352-0.52 0.782-0.52 1.292 0 0.551 0.197 1.014 0.59 1.389 0.363 0.346 0.799 0.519 1.309 0.519 0.521 0 0.971-0.188 1.346-0.566s0.562-0.828 0.562-1.35c0-0.504-0.182-0.943-0.545-1.318-0.363-0.381-0.801-0.571-1.311-0.571-0.567-0.001-1.044 0.201-1.431 0.605v0zM14.391 10.788c-0.299 0.451-0.447 1.011-0.447 1.679 0 0.545 0.092 1.146 0.276 1.802s0.435 1.271 0.751 1.846c0.428 0.779 0.76 1.169 0.994 1.169 0.24 0 0.557-0.305 0.949-0.914 0.346-0.539 0.622-1.152 0.83-1.841s0.312-1.332 0.312-1.93c0-0.902-0.244-1.6-0.73-2.092-0.363-0.375-0.805-0.563-1.326-0.563-0.703 0-1.24 0.282-1.609 0.844v0z"></path> </g><g id="SVGRepo_iconCarrier"> <title>alert</title> <path d="M14.611 18.856c-0.346 0.352-0.52 0.782-0.52 1.292 0 0.551 0.197 1.014 0.59 1.389 0.363 0.346 0.799 0.519 1.309 0.519 0.521 0 0.971-0.188 1.346-0.566s0.562-0.828 0.562-1.35c0-0.504-0.182-0.943-0.545-1.318-0.363-0.381-0.801-0.571-1.311-0.571-0.567-0.001-1.044 0.201-1.431 0.605v0zM14.391 10.788c-0.299 0.451-0.447 1.011-0.447 1.679 0 0.545 0.092 1.146 0.276 1.802s0.435 1.271 0.751 1.846c0.428 0.779 0.76 1.169 0.994 1.169 0.24 0 0.557-0.305 0.949-0.914 0.346-0.539 0.622-1.152 0.83-1.841s0.312-1.332 0.312-1.93c0-0.902-0.244-1.6-0.73-2.092-0.363-0.375-0.805-0.563-1.326-0.563-0.703 0-1.24 0.282-1.609 0.844v0z"></path> </g></svg>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 30px; font-family: sans-serif; line-height: 1.5; color: #444444;">
|
||||||
|
<p>Lamentamos informarle de que el equipo de moderación ha tomado acciones en su cuenta</p>
|
||||||
|
<p>Su cuenta ha sido bloqueada indefinidamente y sus productos han sido eliminados de la tienda.</p>
|
||||||
|
<p>Si desea apelar, por favor, contacte con Soporte Técnico</p>
|
||||||
|
<p></p>
|
||||||
|
<p style="color: gray;">Este email ha sido enviado automaticamente, no responda a este correo.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
+1
-1
@@ -18,4 +18,4 @@
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
+1
-1
@@ -24,4 +24,4 @@
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="padding: 20px;">
|
||||||
|
<table width="600" border="0" cellspacing="0" cellpadding="0" style="border: 1px solid #eeeeee; background-color: #ffffff;">
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="background-color: #007bff; padding: 40px;">
|
||||||
|
<h1 style="color: #ffffff; font-family: sans-serif; margin: 0;">Su cuenta ha sido desbloqueada</h1>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" style="padding: 40px">
|
||||||
|
<svg fill="#FF0000" width="128px" height="128px" viewBox="-3.2 -3.2 38.40 38.40" version="1.1" xmlns="http://www.w3.org/2000/svg" stroke="#FF0000" stroke-width="0.00032"><g id="SVGRepo_bgCarrier" stroke-width="0" transform="translate(6.4,6.4), scale(0.6)"><rect x="-3.2" y="-3.2" width="38.40" height="38.40" rx="19.2" fill="#1a5fb4" strokewidth="0"></rect></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="1.152"> <title>alert</title> <path d="M14.611 18.856c-0.346 0.352-0.52 0.782-0.52 1.292 0 0.551 0.197 1.014 0.59 1.389 0.363 0.346 0.799 0.519 1.309 0.519 0.521 0 0.971-0.188 1.346-0.566s0.562-0.828 0.562-1.35c0-0.504-0.182-0.943-0.545-1.318-0.363-0.381-0.801-0.571-1.311-0.571-0.567-0.001-1.044 0.201-1.431 0.605v0zM14.391 10.788c-0.299 0.451-0.447 1.011-0.447 1.679 0 0.545 0.092 1.146 0.276 1.802s0.435 1.271 0.751 1.846c0.428 0.779 0.76 1.169 0.994 1.169 0.24 0 0.557-0.305 0.949-0.914 0.346-0.539 0.622-1.152 0.83-1.841s0.312-1.332 0.312-1.93c0-0.902-0.244-1.6-0.73-2.092-0.363-0.375-0.805-0.563-1.326-0.563-0.703 0-1.24 0.282-1.609 0.844v0z"></path> </g><g id="SVGRepo_iconCarrier"> <title>alert</title> <path d="M14.611 18.856c-0.346 0.352-0.52 0.782-0.52 1.292 0 0.551 0.197 1.014 0.59 1.389 0.363 0.346 0.799 0.519 1.309 0.519 0.521 0 0.971-0.188 1.346-0.566s0.562-0.828 0.562-1.35c0-0.504-0.182-0.943-0.545-1.318-0.363-0.381-0.801-0.571-1.311-0.571-0.567-0.001-1.044 0.201-1.431 0.605v0zM14.391 10.788c-0.299 0.451-0.447 1.011-0.447 1.679 0 0.545 0.092 1.146 0.276 1.802s0.435 1.271 0.751 1.846c0.428 0.779 0.76 1.169 0.994 1.169 0.24 0 0.557-0.305 0.949-0.914 0.346-0.539 0.622-1.152 0.83-1.841s0.312-1.332 0.312-1.93c0-0.902-0.244-1.6-0.73-2.092-0.363-0.375-0.805-0.563-1.326-0.563-0.703 0-1.24 0.282-1.609 0.844v0z"></path> </g></svg>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 30px; font-family: sans-serif; line-height: 1.5; color: #444444;">
|
||||||
|
<p>Hemos aceptado la apelación del previo baneo de su cuenta</p>
|
||||||
|
<p>Su cuenta ha sido desbloqueada y ya puede entrar, pero los productos seguirán eliminados, por lo que deberá recrearlos para seguir vendiendolos</p>
|
||||||
|
<p>Muchas gracias por su paciencia</p>
|
||||||
|
<p></p>
|
||||||
|
<p style="color: gray;">Este email ha sido enviado automaticamente, no responda a este correo.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
@@ -23,4 +23,4 @@
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{% for field in form %}
|
||||||
|
<div class="mb-3">
|
||||||
|
{{ field.errors }}
|
||||||
|
{{ field.label_tag }} {{ field }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
{% extends "tienda/base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row mt-4 mb-5">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<div>
|
||||||
|
<h2>Gestionar Imágenes</h2>
|
||||||
|
<p class="text-muted mb-0">Producto: <strong>{{ producto.name }}</strong></p>
|
||||||
|
</div>
|
||||||
|
<a href="{% url 'mis_productos' %}" class="btn btn-outline-secondary">← Volver a Mis Productos</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">Imagen Principal</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{% if producto.primary_image %}
|
||||||
|
<img src="{{ producto.primary_image.image.url }}" alt="{{ producto.primary_image.alt|default:producto.name }}" class="rounded" style="width: 200px; height: 200px; object-fit: cover;">
|
||||||
|
<p class="mt-2 text-muted mb-0">Esta imagen no se puede cambiar desde aquí.</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-muted">No hay imagen principal asignada.</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header d-flex justify-content-between align-items-center">
|
||||||
|
<h5 class="mb-0">Imágenes Secundarias</h5>
|
||||||
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#agregarImagenModal">
|
||||||
|
➕ Agregar Imagen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{% if secondary_images %}
|
||||||
|
<div class="row">
|
||||||
|
{% for img in secondary_images %}
|
||||||
|
<div class="col-md-3 col-sm-4 col-6 mb-3">
|
||||||
|
<div class="card">
|
||||||
|
<img src="{{ img.image.url }}" alt="{{ img.alt|default:producto.name }}" class="card-img-top" style="height: 180px; object-fit: cover;">
|
||||||
|
<div class="card-body p-2">
|
||||||
|
<form method="POST" action="{% url 'eliminar_imagen_secundaria' producto.id img.id %}" onsubmit="return confirm('¿Seguro que quieres eliminar esta imagen?');">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit" class="btn btn-outline-danger btn-sm w-100">🗑 Eliminar</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-muted text-center py-4">No hay imágenes secundarias. ¡Agrega una!</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="agregarImagenModal" tabindex="-1" aria-labelledby="agregarImagenModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="agregarImagenModalLabel">Agregar Imagen Secundaria</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<form method="POST" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="modal-body">
|
||||||
|
{{ form }}
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Subir Imagen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -12,22 +12,7 @@
|
|||||||
<form method="post" action="{% url 'login' %}">
|
<form method="post" action="{% url 'login' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<div class="mb-3">
|
{{ form }}
|
||||||
<label for="loginEmail" class="form-label">Correo Electrónico</label>
|
|
||||||
<input type="email" class="form-control" id="loginEmail" name="email" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="loginPassword" class="form-label">Contraseña</label>
|
|
||||||
<input type="password" class="form-control" id="loginPassword" name="password" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3 form-check">
|
|
||||||
<input type="checkbox" class="form-check-input" id="rememberMe" name="remember">
|
|
||||||
<label class="form-check-label" for="rememberMe">
|
|
||||||
Recordarme
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-grid gap-2">
|
<div class="d-grid gap-2">
|
||||||
<button type="submit" class="btn btn-primary">Iniciar Sesión</button>
|
<button type="submit" class="btn btn-primary">Iniciar Sesión</button>
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
<td class="text-end">{{ producto.stock }}</td>
|
<td class="text-end">{{ producto.stock }}</td>
|
||||||
<td class="text-end">
|
<td class="text-end">
|
||||||
<div class="d-flex justify-content-end gap-2">
|
<div class="d-flex justify-content-end gap-2">
|
||||||
|
<a href="{% url 'gestionar_imagenes' producto.id %}" class="btn btn-outline-secondary btn-sm">Gestionar Imágenes</a>
|
||||||
<a href="{% url 'editar_producto' producto.id %}" class="btn btn-outline-primary btn-sm">Editar</a>
|
<a href="{% url 'editar_producto' producto.id %}" class="btn btn-outline-primary btn-sm">Editar</a>
|
||||||
<form method="POST" action="{% url 'borrar_producto' producto.id %}" onsubmit="return confirm('¿Seguro que quieres borrar este producto?');">
|
<form method="POST" action="{% url 'borrar_producto' producto.id %}" onsubmit="return confirm('¿Seguro que quieres borrar este producto?');">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|||||||
@@ -12,33 +12,7 @@
|
|||||||
<form method="post" action="{% url 'register' %}">
|
<form method="post" action="{% url 'register' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<div class="mb-3">
|
{{ form }}
|
||||||
<label for="registerName" class="form-label">Nombre Completo</label>
|
|
||||||
<input type="text" class="form-control" id="registerName" name="name" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="registerEmail" class="form-label">Correo Electrónico</label>
|
|
||||||
<input type="email" class="form-control" id="registerEmail" name="email" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="registerPassword" class="form-label">Contraseña</label>
|
|
||||||
<input type="password" class="form-control" id="registerPassword" name="password" required>
|
|
||||||
<div class="form-text">La contraseña debe tener al menos 8 caracteres.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="registerPasswordConfirm" class="form-label">Confirmar Contraseña</label>
|
|
||||||
<input type="password" class="form-control" id="registerPasswordConfirm" name="password_confirm" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3 form-check">
|
|
||||||
<input type="checkbox" class="form-check-input" id="acceptTerms" name="terms" required>
|
|
||||||
<label class="form-check-label" for="acceptTerms">
|
|
||||||
Acepto los <a href="{% url 'terminos' %}" target="_blank">términos y condiciones</a>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-grid gap-2">
|
<div class="d-grid gap-2">
|
||||||
<button type="submit" class="btn btn-primary">Crear Cuenta</button>
|
<button type="submit" class="btn btn-primary">Crear Cuenta</button>
|
||||||
|
|||||||
@@ -11,11 +11,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="post" action="{% url 'reset_password' %}">
|
<form method="post" action="{% url 'reset_password' %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
<div class="mb-3">
|
|
||||||
<label for="loginEmail" class="form-label">Correo Electrónico</label>
|
|
||||||
<input type="email" class="form-control" id="loginEmail" name="email" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-grid gap-2">
|
<div class="d-grid gap-2">
|
||||||
<button type="submit" class="btn btn-primary">Recuperar contraseña</button>
|
<button type="submit" class="btn btn-primary">Recuperar contraseña</button>
|
||||||
|
|||||||
@@ -11,16 +11,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="post" action="{% url 'reset_password_phase2' code %}">
|
<form method="post" action="{% url 'reset_password_phase2' code %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
<div class="mb-3">
|
|
||||||
<label for="password" class="form-label">Contraseña</label>
|
|
||||||
<input type="password" class="form-control" id="password" name="password" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="verify_password" class="form-label">Verificar contraseña</label>
|
|
||||||
<input type="password" class="form-control" id="verify_password" name="verify_password" required>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="d-grid gap-2">
|
<div class="d-grid gap-2">
|
||||||
<button type="submit" class="btn btn-primary">Recuperar contraseña</button>
|
<button type="submit" class="btn btn-primary">Recuperar contraseña</button>
|
||||||
|
|||||||
+181
@@ -14,6 +14,7 @@ from .models import (
|
|||||||
StockReservation, StockReservationItem, Cart, CartItem,
|
StockReservation, StockReservationItem, Cart, CartItem,
|
||||||
Order, OrderItem, OrderMessage, SavedPaymentMethod, ShippingAddress
|
Order, OrderItem, OrderMessage, SavedPaymentMethod, ShippingAddress
|
||||||
)
|
)
|
||||||
|
from .forms import UserRegisterForm, UserLoginForm, EditProfileForm, ChangePasswordForm, ShippingAddressForm, ResetPasswordForm, ResetPasswordPhase2Form
|
||||||
from .vars import VAT_RATE, TRANSACTION_CODE_PREFIX
|
from .vars import VAT_RATE, TRANSACTION_CODE_PREFIX
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
@@ -22,6 +23,185 @@ import random
|
|||||||
# ==================== USER MODEL TESTS ====================
|
# ==================== USER MODEL TESTS ====================
|
||||||
class UserModelTests(TestCase):
|
class UserModelTests(TestCase):
|
||||||
"""Tests exhaustivos para el modelo User."""
|
"""Tests exhaustivos para el modelo User."""
|
||||||
|
|
||||||
|
|
||||||
|
class FormTests(TestCase):
|
||||||
|
"""Tests para formularios Django."""
|
||||||
|
|
||||||
|
def test_user_register_form_terms_required(self):
|
||||||
|
"""El campo terms debe ser obligatorio."""
|
||||||
|
form = UserRegisterForm(data={
|
||||||
|
"name": "Test User",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123",
|
||||||
|
"password_confirm": "password123",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("terms", form.errors)
|
||||||
|
|
||||||
|
def test_user_register_form_terms_off_not_checked(self):
|
||||||
|
"""Si terms está en off (None/false), debe fallar."""
|
||||||
|
form = UserRegisterForm(data={
|
||||||
|
"name": "Test User",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123",
|
||||||
|
"password_confirm": "password123",
|
||||||
|
"terms": False,
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("terms", form.errors)
|
||||||
|
|
||||||
|
def test_user_register_form_terms_on(self):
|
||||||
|
"""Si terms está marcado, el formulario debe ser válido."""
|
||||||
|
form = UserRegisterForm(data={
|
||||||
|
"name": "Test User",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123",
|
||||||
|
"password_confirm": "password123",
|
||||||
|
"terms": True,
|
||||||
|
})
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_user_register_form_passwords_mismatch(self):
|
||||||
|
"""Las contraseñas deben coincidir."""
|
||||||
|
form = UserRegisterForm(data={
|
||||||
|
"name": "Test User",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123",
|
||||||
|
"password_confirm": "different_password",
|
||||||
|
"terms": True,
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("__all__", form.errors)
|
||||||
|
|
||||||
|
def test_user_register_form_empty_fields(self):
|
||||||
|
"""Los campos obligatorios no pueden estar vacíos."""
|
||||||
|
form = UserRegisterForm(data={})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("name", form.errors)
|
||||||
|
self.assertIn("email", form.errors)
|
||||||
|
self.assertIn("password", form.errors)
|
||||||
|
self.assertIn("password_confirm", form.errors)
|
||||||
|
|
||||||
|
def test_user_login_form_valid(self):
|
||||||
|
"""Login con datos válidos."""
|
||||||
|
form = UserLoginForm(data={
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "password123",
|
||||||
|
})
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_user_login_form_missing_email(self):
|
||||||
|
"""Email es obligatorio en login."""
|
||||||
|
form = UserLoginForm(data={
|
||||||
|
"password": "password123",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("email", form.errors)
|
||||||
|
|
||||||
|
def test_user_login_form_invalid_email_format(self):
|
||||||
|
"""Email debe tener formato válido."""
|
||||||
|
form = UserLoginForm(data={
|
||||||
|
"email": "not-an-email",
|
||||||
|
"password": "password123",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("email", form.errors)
|
||||||
|
|
||||||
|
def test_edit_profile_form_valid(self):
|
||||||
|
"""Formulario de edición de perfil válido."""
|
||||||
|
form = EditProfileForm(data={
|
||||||
|
"first_name": "Juan",
|
||||||
|
"last_name": "Pérez",
|
||||||
|
"email": "juan@example.com",
|
||||||
|
})
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_edit_profile_form_missing_email(self):
|
||||||
|
"""Email es obligatorio en perfil."""
|
||||||
|
form = EditProfileForm(data={
|
||||||
|
"first_name": "Juan",
|
||||||
|
"last_name": "Pérez",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("email", form.errors)
|
||||||
|
|
||||||
|
def test_change_password_form_passwords_mismatch(self):
|
||||||
|
"""Las nuevas contraseñas deben coincidir."""
|
||||||
|
form = ChangePasswordForm(data={
|
||||||
|
"current_password": "oldpass123",
|
||||||
|
"new_password": "newpass123",
|
||||||
|
"confirm_password": "differentpass",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("__all__", form.errors)
|
||||||
|
|
||||||
|
def test_change_password_form_short_password(self):
|
||||||
|
"""La nueva contraseña debe tener al menos 8 caracteres."""
|
||||||
|
form = ChangePasswordForm(data={
|
||||||
|
"current_password": "oldpass123",
|
||||||
|
"new_password": "short",
|
||||||
|
"confirm_password": "short",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("__all__", form.errors)
|
||||||
|
|
||||||
|
def test_shipping_address_form_valid(self):
|
||||||
|
"""Dirección con datos válidos."""
|
||||||
|
form = ShippingAddressForm(data={
|
||||||
|
"full_name": "Juan Pérez",
|
||||||
|
"address_line_1": "Calle Mayor 123",
|
||||||
|
"city": "Almería",
|
||||||
|
"postal_code": "04001",
|
||||||
|
"country": "España",
|
||||||
|
"phone": "612345678",
|
||||||
|
})
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_shipping_address_form_missing_required_fields(self):
|
||||||
|
"""Campos obligatorios no pueden estar vacíos."""
|
||||||
|
form = ShippingAddressForm(data={})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("full_name", form.errors)
|
||||||
|
self.assertIn("address_line_1", form.errors)
|
||||||
|
self.assertIn("city", form.errors)
|
||||||
|
self.assertIn("postal_code", form.errors)
|
||||||
|
self.assertIn("phone", form.errors)
|
||||||
|
|
||||||
|
def test_reset_password_form_valid_email(self):
|
||||||
|
"""Formulario de recuperación de contraseña."""
|
||||||
|
form = ResetPasswordForm(data={
|
||||||
|
"email": "test@example.com",
|
||||||
|
})
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_reset_password_form_invalid_email(self):
|
||||||
|
"""Email inválido."""
|
||||||
|
form = ResetPasswordForm(data={
|
||||||
|
"email": "not-an-email",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("email", form.errors)
|
||||||
|
|
||||||
|
def test_reset_password_phase2_form_valid(self):
|
||||||
|
"""Cambio de contraseña válido."""
|
||||||
|
form = ResetPasswordPhase2Form(data={
|
||||||
|
"password": "newpass123",
|
||||||
|
"verify_password": "newpass123",
|
||||||
|
})
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_reset_password_phase2_form_mismatch(self):
|
||||||
|
"""Las contraseñas deben coincidir."""
|
||||||
|
form = ResetPasswordPhase2Form(data={
|
||||||
|
"password": "newpass123",
|
||||||
|
"verify_password": "different",
|
||||||
|
})
|
||||||
|
self.assertFalse(form.is_valid())
|
||||||
|
self.assertIn("__all__", form.errors)
|
||||||
|
|
||||||
|
|
||||||
|
# ==================== ENDPOINT VIEW TESTS ====================
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.user_data = {
|
self.user_data = {
|
||||||
@@ -1455,6 +1635,7 @@ class EndpointViewTests(TestCase):
|
|||||||
"email": "nuevo@example.com",
|
"email": "nuevo@example.com",
|
||||||
"password": self.password,
|
"password": self.password,
|
||||||
"password_confirm": self.password,
|
"password_confirm": self.password,
|
||||||
|
"terms": "on",
|
||||||
})
|
})
|
||||||
self.assertEqual(register_response.status_code, 302)
|
self.assertEqual(register_response.status_code, 302)
|
||||||
confirm_delay.assert_called_once()
|
confirm_delay.assert_called_once()
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ urlpatterns = [
|
|||||||
path("venta/crear-producto/", views.crear_producto, name="crear_producto"),
|
path("venta/crear-producto/", views.crear_producto, name="crear_producto"),
|
||||||
path("venta/editar-producto/<int:id>/", views.editar_producto, name="editar_producto"),
|
path("venta/editar-producto/<int:id>/", views.editar_producto, name="editar_producto"),
|
||||||
path("venta/borrar-producto/<int:id>/", views.borrar_producto, name="borrar_producto"),
|
path("venta/borrar-producto/<int:id>/", views.borrar_producto, name="borrar_producto"),
|
||||||
|
path("venta/gestionar-imagenes/<int:id>/", views.gestionar_imagenes, name="gestionar_imagenes"),
|
||||||
|
path("venta/gestionar-imagenes/<int:product_id>/eliminar/<int:image_id>/", views.eliminar_imagen_secundaria, name="eliminar_imagen_secundaria"),
|
||||||
# Carrito
|
# Carrito
|
||||||
path("cart/", views.view_cart, name="view_cart"),
|
path("cart/", views.view_cart, name="view_cart"),
|
||||||
path("cart/add/<int:product_id>/", views.add_to_cart, name="add_to_cart"),
|
path("cart/add/<int:product_id>/", views.add_to_cart, name="add_to_cart"),
|
||||||
|
|||||||
+411
-409
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user