diff --git a/config/__pycache__/settings.cpython-311.pyc b/config/__pycache__/settings.cpython-311.pyc index dadfaa7..6b52506 100644 Binary files a/config/__pycache__/settings.cpython-311.pyc and b/config/__pycache__/settings.cpython-311.pyc differ diff --git a/config/__pycache__/urls.cpython-311.pyc b/config/__pycache__/urls.cpython-311.pyc index 139db10..480daeb 100644 Binary files a/config/__pycache__/urls.cpython-311.pyc and b/config/__pycache__/urls.cpython-311.pyc differ diff --git a/config/settings.py b/config/settings.py index 001b8c8..a7247c1 100644 --- a/config/settings.py +++ b/config/settings.py @@ -141,6 +141,9 @@ USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = BASE_DIR / 'staticfiles' +MEDIA_URL = '/media/' +MEDIA_ROOT = BASE_DIR / 'media' + STATICFILES_DIRS = [ BASE_DIR / 'static', diff --git a/config/urls.py b/config/urls.py index 5093d47..d60536e 100644 --- a/config/urls.py +++ b/config/urls.py @@ -15,9 +15,14 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import include, path +from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static urlpatterns = [ - path("admin/", admin.site.urls), path("", include("core.urls")), + path("admin/", admin.site.urls), ] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/core/__pycache__/admin.cpython-311.pyc b/core/__pycache__/admin.cpython-311.pyc index cd6f855..2bd112a 100644 Binary files a/core/__pycache__/admin.cpython-311.pyc and b/core/__pycache__/admin.cpython-311.pyc differ diff --git a/core/__pycache__/forms.cpython-311.pyc b/core/__pycache__/forms.cpython-311.pyc new file mode 100644 index 0000000..56356eb Binary files /dev/null and b/core/__pycache__/forms.cpython-311.pyc differ diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index 9aa598b..2d874a7 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index 1f807fa..e9609bd 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 6867ddf..4b92fcd 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/admin.py b/core/admin.py index 8c38f3f..3ebea38 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,3 +1,7 @@ from django.contrib import admin +from .models import Cliente, Portafoglio, Attivita, Documento -# Register your models here. +admin.site.register(Cliente) +admin.site.register(Portafoglio) +admin.site.register(Attivita) +admin.site.register(Documento) diff --git a/core/forms.py b/core/forms.py new file mode 100644 index 0000000..199bcaf --- /dev/null +++ b/core/forms.py @@ -0,0 +1,38 @@ +from django import forms +from .models import Cliente, Portafoglio, Attivita, Documento + +class ClienteForm(forms.ModelForm): + class Meta: + model = Cliente + exclude = ('Importo_Portafoglio_Attuale',) + widgets = { + 'Data_di_Nascita': forms.DateInput(attrs={'type': 'date'}), + } + +class PortafoglioForm(forms.ModelForm): + class Meta: + model = Portafoglio + fields = '__all__' + widgets = { + 'Data_Inizio': forms.DateInput(attrs={'type': 'date'}), + 'cliente': forms.HiddenInput(), + } + +class AttivitaForm(forms.ModelForm): + class Meta: + model = Attivita + fields = '__all__' + widgets = { + 'Data': forms.DateInput(attrs={'type': 'date'}), + 'Ora': forms.TimeInput(attrs={'type': 'time'}), + 'cliente': forms.HiddenInput(), + } + +class DocumentoForm(forms.ModelForm): + class Meta: + model = Documento + fields = '__all__' + widgets = { + 'Data_di_Scadenza': forms.DateInput(attrs={'type': 'date'}), + 'cliente': forms.HiddenInput(), + } diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 0000000..c852421 --- /dev/null +++ b/core/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 5.2.7 on 2025-10-25 16:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Cliente', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('Nome', models.CharField(max_length=100)), + ('Cognome', models.CharField(max_length=100)), + ('Codice_Fiscale', models.CharField(max_length=16, unique=True)), + ('Email', models.EmailField(max_length=254)), + ('Telefono', models.CharField(max_length=20)), + ('Data_di_Nascita', models.DateField()), + ('Lavoro', models.CharField(max_length=100)), + ('Stato', models.CharField(choices=[('Cliente', 'Cliente'), ('Prospect', 'Prospect'), ('Ex-Cliente', 'Ex-Cliente')], max_length=20)), + ('Categoria', models.CharField(choices=[('Privato', 'Privato'), ('Azienda', 'Azienda')], max_length=20)), + ('Importo_Portafoglio_Attuale', models.DecimalField(decimal_places=2, default=0.0, editable=False, max_digits=15)), + ('Scadenza_MIFID', models.DateField()), + ('Scadenza_Documento_Identita', models.DateField()), + ], + ), + ] diff --git a/core/migrations/0002_remove_cliente_scadenza_documento_identita_and_more.py b/core/migrations/0002_remove_cliente_scadenza_documento_identita_and_more.py new file mode 100644 index 0000000..2af4967 --- /dev/null +++ b/core/migrations/0002_remove_cliente_scadenza_documento_identita_and_more.py @@ -0,0 +1,61 @@ +# Generated by Django 5.2.7 on 2025-10-25 16:52 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='cliente', + name='Scadenza_Documento_Identita', + ), + migrations.RemoveField( + model_name='cliente', + name='Scadenza_MIFID', + ), + migrations.CreateModel( + name='Attivita', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('Data', models.DateField()), + ('Ora', models.TimeField(blank=True, null=True)), + ('Tipo', models.CharField(choices=[('Chiamata', 'Chiamata'), ('Riunione', 'Riunione'), ('Email', 'Email'), ('To-Do', 'To-Do'), ('Avviso Cedola', 'Avviso Cedola'), ('Scadenza Obbligazione', 'Scadenza Obbligazione'), ('Revisione Annuale', 'Revisione Annuale')], max_length=30)), + ('Stato', models.CharField(choices=[('Pianificato', 'Pianificato'), ('Completato', 'Completato')], default='Pianificato', max_length=20)), + ('Note', models.TextField(blank=True, null=True)), + ('cliente', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attivita', to='core.cliente')), + ], + ), + migrations.CreateModel( + name='Documento', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('Nome_Documento', models.CharField(max_length=100)), + ('Tipo', models.CharField(choices=[('Contratto', 'Contratto'), ('KYC', 'KYC'), ('Report', 'Report'), ('Altro', 'Altro')], max_length=20)), + ('Data_Caricamento', models.DateField(auto_now_add=True)), + ('Data_di_Scadenza', models.DateField(blank=True, null=True)), + ('File', models.FileField(upload_to='documenti/')), + ('Condivisibile', models.BooleanField(default=False)), + ('cliente', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documenti', to='core.cliente')), + ], + ), + migrations.CreateModel( + name='Portafoglio', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('Nome_Portafoglio', models.CharField(max_length=100)), + ('Profilo_di_Rischio', models.CharField(choices=[('Conservativo', 'Conservativo'), ('Bilanciato', 'Bilanciato'), ('Aggressivo', 'Aggressivo')], max_length=20)), + ('Composizione_Asset_Allocation', models.TextField(blank=True, null=True)), + ('Data_Inizio', models.DateField()), + ('Valore_Iniziale', models.DecimalField(decimal_places=2, max_digits=15)), + ('Valore_Corrente', models.DecimalField(decimal_places=2, max_digits=15)), + ('Note', models.TextField(blank=True, null=True)), + ('cliente', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='portafogli', to='core.cliente')), + ], + ), + ] diff --git a/core/migrations/__pycache__/0001_initial.cpython-311.pyc b/core/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..92357d7 Binary files /dev/null and b/core/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/core/migrations/__pycache__/0002_remove_cliente_scadenza_documento_identita_and_more.cpython-311.pyc b/core/migrations/__pycache__/0002_remove_cliente_scadenza_documento_identita_and_more.cpython-311.pyc new file mode 100644 index 0000000..446d7cc Binary files /dev/null and b/core/migrations/__pycache__/0002_remove_cliente_scadenza_documento_identita_and_more.cpython-311.pyc differ diff --git a/core/models.py b/core/models.py index 71a8362..69ef07e 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,86 @@ from django.db import models -# Create your models here. +class Cliente(models.Model): + STATO_CHOICES = [ + ('Cliente', 'Cliente'), + ('Prospect', 'Prospect'), + ('Ex-Cliente', 'Ex-Cliente'), + ] + CATEGORIA_CHOICES = [ + ('Privato', 'Privato'), + ('Azienda', 'Azienda'), + ] + + Nome = models.CharField(max_length=100) + Cognome = models.CharField(max_length=100) + Codice_Fiscale = models.CharField(max_length=16, unique=True) + Email = models.EmailField() + Telefono = models.CharField(max_length=20) + Data_di_Nascita = models.DateField() + Lavoro = models.CharField(max_length=100) + Stato = models.CharField(max_length=20, choices=STATO_CHOICES) + Categoria = models.CharField(max_length=20, choices=CATEGORIA_CHOICES) + Importo_Portafoglio_Attuale = models.DecimalField(max_digits=15, decimal_places=2, default=0.00, editable=False) + + def __str__(self): + return f"{self.Nome} {self.Cognome}" + +class Portafoglio(models.Model): + PROFILO_RISCHIO_CHOICES = [ + ('Conservativo', 'Conservativo'), + ('Bilanciato', 'Bilanciato'), + ('Aggressivo', 'Aggressivo'), + ] + cliente = models.ForeignKey(Cliente, on_delete=models.CASCADE, related_name='portafogli') + Nome_Portafoglio = models.CharField(max_length=100) + Profilo_di_Rischio = models.CharField(max_length=20, choices=PROFILO_RISCHIO_CHOICES) + Composizione_Asset_Allocation = models.TextField(blank=True, null=True) + Data_Inizio = models.DateField() + Valore_Iniziale = models.DecimalField(max_digits=15, decimal_places=2) + Valore_Corrente = models.DecimalField(max_digits=15, decimal_places=2) + Note = models.TextField(blank=True, null=True) + + def __str__(self): + return f"{self.Nome_Portafoglio} ({self.cliente})" + +class Attivita(models.Model): + TIPO_CHOICES = [ + ('Chiamata', 'Chiamata'), + ('Riunione', 'Riunione'), + ('Email', 'Email'), + ('To-Do', 'To-Do'), + ('Avviso Cedola', 'Avviso Cedola'), + ('Scadenza Obbligazione', 'Scadenza Obbligazione'), + ('Revisione Annuale', 'Revisione Annuale'), + ] + STATO_CHOICES = [ + ('Pianificato', 'Pianificato'), + ('Completato', 'Completato'), + ] + cliente = models.ForeignKey(Cliente, on_delete=models.CASCADE, related_name='attivita') + Data = models.DateField() + Ora = models.TimeField(blank=True, null=True) + Tipo = models.CharField(max_length=30, choices=TIPO_CHOICES) + Stato = models.CharField(max_length=20, choices=STATO_CHOICES, default='Pianificato') + Note = models.TextField(blank=True, null=True) + + def __str__(self): + return f"{self.Tipo} - {self.Data} - {self.cliente}" + +class Documento(models.Model): + TIPO_CHOICES = [ + ('Contratto', 'Contratto'), + ('KYC', 'KYC'), + ('Report', 'Report'), + ('Altro', 'Altro'), + ] + cliente = models.ForeignKey(Cliente, on_delete=models.CASCADE, related_name='documenti') + Nome_Documento = models.CharField(max_length=100) + Tipo = models.CharField(max_length=20, choices=TIPO_CHOICES) + Data_Caricamento = models.DateField(auto_now_add=True) + Data_di_Scadenza = models.DateField(blank=True, null=True) + File = models.FileField(upload_to='documenti/') # Placeholder, will be configured for S3 + Condivisibile = models.BooleanField(default=False) + + def __str__(self): + return f"{self.Nome_Documento} ({self.cliente})" \ No newline at end of file diff --git a/core/templates/base.html b/core/templates/base.html index 788576e..2e81fe0 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -6,6 +6,30 @@ {% block head %}{% endblock %} - {% block content %}{% endblock %} + + +
{% block content %} {% endblock %}
diff --git a/core/templates/core/article_detail.html b/core/templates/core/article_detail.html index 8820990..b129935 100644 --- a/core/templates/core/article_detail.html +++ b/core/templates/core/article_detail.html @@ -1,14 +1,151 @@ {% extends 'base.html' %} -{% block title %}{{ article.title }}{% endblock %} - {% block content %} -
-

{{ article.title }}

-

Published on {{ article.created_at|date:"F d, Y" }}

-
-
- {{ article.content|safe }} +
+
+
+

{{ object.Nome }} {{ object.Cognome }}

+
+
+

Codice Fiscale: {{ object.Codice_Fiscale }}

+

Email: {{ object.Email }}

+

Telefono: {{ object.Telefono }}

+

Data di Nascita: {{ object.Data_di_Nascita }}

+

Lavoro: {{ object.Lavoro }}

+

Stato: {{ object.Stato }}

+

Categoria: {{ object.Categoria }}

+

Importo Portafoglio Attuale: € {{ object.Importo_Portafoglio_Attuale }}

+
+ + + +
+
+ +
+ + + + + + + + + + + + + {% for portafoglio in portafogli %} + + + + + + + + + {% empty %} + + + + {% endfor %} + +
Nome PortafoglioProfilo di RischioValore InizialeValore CorrenteData InizioAzioni
{{ portafoglio.Nome_Portafoglio }}{{ portafoglio.Profilo_di_Rischio }}€ {{ portafoglio.Valore_Iniziale }}€ {{ portafoglio.Valore_Corrente }}{{ portafoglio.Data_Inizio }} + Modifica + Elimina +
Nessun portafoglio trovato.
+
+
+
+ +
+ + + + + + + + + + + + + {% for attivita_item in attivita %} + + + + + + + + + {% empty %} + + + + {% endfor %} + +
DataOraTipoStatoNoteAzioni
{{ attivita_item.Data }}{{ attivita_item.Ora|default_if_none:'' }}{{ attivita_item.Tipo }}{{ attivita_item.Stato }}{{ attivita_item.Note }} + Modifica + Elimina +
Nessuna attività trovata.
+
+
+
+ +
+ + + + + + + + + + + + + {% for documento in documenti %} + + + + + + + + + {% empty %} + + + + {% endfor %} + +
Nome DocumentoTipoData CaricamentoData di ScadenzaFileAzioni
{{ documento.Nome_Documento }}{{ documento.Tipo }}{{ documento.Data_Caricamento }}{{ documento.Data_di_Scadenza|default_if_none:'' }}Scarica + Modifica + Elimina +
Nessun documento trovato.
+
+
+
+ Torna alla lista
-{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/core/templates/core/attivita_confirm_delete.html b/core/templates/core/attivita_confirm_delete.html new file mode 100644 index 0000000..2983d44 --- /dev/null +++ b/core/templates/core/attivita_confirm_delete.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} +
+

Sei sicuro di voler eliminare l'attività "{{ object.Tipo }}" del {{ object.Data }}?

+
+ {% csrf_token %} + + Annulla +
+
+{% endblock %} \ No newline at end of file diff --git a/core/templates/core/attivita_form.html b/core/templates/core/attivita_form.html new file mode 100644 index 0000000..f554834 --- /dev/null +++ b/core/templates/core/attivita_form.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +
+

{% if object %}Modifica Attività{% else %}Aggiungi Attività{% endif %}

+
+ {% csrf_token %} + {{ form.as_p }} + + Annulla +
+
+{% endblock %} \ No newline at end of file diff --git a/core/templates/core/cliente_confirm_delete.html b/core/templates/core/cliente_confirm_delete.html new file mode 100644 index 0000000..ab215c8 --- /dev/null +++ b/core/templates/core/cliente_confirm_delete.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +
+

Delete Client

+

Are you sure you want to delete {{ object.Nome }} {{ object.Cognome }}?

+
+ {% csrf_token %} + + Cancel +
+
+{% endblock %} diff --git a/core/templates/core/cliente_form.html b/core/templates/core/cliente_form.html new file mode 100644 index 0000000..d79ae9f --- /dev/null +++ b/core/templates/core/cliente_form.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +
+

{% if form.instance.pk %}Edit Client{% else %}Add Client{% endif %}

+
+ {% csrf_token %} + {{ form.as_p }} + + Cancel +
+
+{% endblock %} diff --git a/core/templates/core/documento_confirm_delete.html b/core/templates/core/documento_confirm_delete.html new file mode 100644 index 0000000..4e40417 --- /dev/null +++ b/core/templates/core/documento_confirm_delete.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} +
+

Sei sicuro di voler eliminare il documento "{{ object.Nome_Documento }}"?

+
+ {% csrf_token %} + + Annulla +
+
+{% endblock %} \ No newline at end of file diff --git a/core/templates/core/documento_form.html b/core/templates/core/documento_form.html new file mode 100644 index 0000000..dfe2b83 --- /dev/null +++ b/core/templates/core/documento_form.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +
+

{% if object %}Modifica Documento{% else %}Aggiungi Documento{% endif %}

+
+ {% csrf_token %} + {{ form.as_p }} + + Annulla +
+
+{% endblock %} \ No newline at end of file diff --git a/core/templates/core/index.html b/core/templates/core/index.html index 0a3f404..e2e1b3f 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -1,154 +1,44 @@ -{% extends "base.html" %} - -{% block title %}{{ project_name }}{% endblock %} - -{% block head %} -{% if project_description %} - - - -{% endif %} -{% if project_image_url %} - - -{% endif %} - - - - -{% endblock %} +{% extends 'base.html' %} {% block content %} -
-
-

Analyzing your requirements and generating your app…

-
- Loading… +
+
+

Clienti

+ Add Client
-

AppWizzy AI is collecting your requirements and applying the first changes.

-

This page will refresh automatically as the plan is implemented.

-

- Runtime: Django {{ django_version }} · Python {{ python_version }} - — UTC {{ current_time|date:"Y-m-d H:i:s" }} -

-
-
-
- Page updated: {{ current_time|date:"Y-m-d H:i:s" }} (UTC) -
-{% endblock %} \ No newline at end of file +
+ + + + + + + + + + + + + + + {% for cliente in clienti %} + + + + + + + + + + + {% endfor %} + +
NomeCognomeCodice FiscaleEmailTelefonoStatoCategoriaActions
{{ cliente.Nome }}{{ cliente.Cognome }}{{ cliente.Codice_Fiscale }}{{ cliente.Email }}{{ cliente.Telefono }}{{ cliente.Stato }}{{ cliente.Categoria }} + Details + Edit + Delete +
+
+
+{% endblock %} diff --git a/core/templates/core/portafoglio_confirm_delete.html b/core/templates/core/portafoglio_confirm_delete.html new file mode 100644 index 0000000..e9eff12 --- /dev/null +++ b/core/templates/core/portafoglio_confirm_delete.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} +
+

Sei sicuro di voler eliminare il portafoglio "{{ object.Nome_Portafoglio }}"?

+
+ {% csrf_token %} + + Annulla +
+
+{% endblock %} \ No newline at end of file diff --git a/core/templates/core/portafoglio_form.html b/core/templates/core/portafoglio_form.html new file mode 100644 index 0000000..4421674 --- /dev/null +++ b/core/templates/core/portafoglio_form.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +
+

{% if object %}Modifica Portafoglio{% else %}Aggiungi Portafoglio{% endif %}

+
+ {% csrf_token %} + {{ form.as_p }} + + Annulla +
+
+{% endblock %} \ No newline at end of file diff --git a/core/urls.py b/core/urls.py index 6299e3d..af7b381 100644 --- a/core/urls.py +++ b/core/urls.py @@ -1,7 +1,40 @@ from django.urls import path - -from .views import home +from .views import ( + ClienteListView, + ClienteDetailView, + ClienteCreateView, + ClienteUpdateView, + ClienteDeleteView, + PortafoglioCreateView, + PortafoglioUpdateView, + PortafoglioDeleteView, + AttivitaCreateView, + AttivitaUpdateView, + AttivitaDeleteView, + DocumentoCreateView, + DocumentoUpdateView, + DocumentoDeleteView, +) urlpatterns = [ - path("", home, name="home"), -] + path('', ClienteListView.as_view(), name='cliente_list'), + path('cliente//', ClienteDetailView.as_view(), name='cliente_detail'), + path('cliente/new/', ClienteCreateView.as_view(), name='cliente_new'), + path('cliente//edit/', ClienteUpdateView.as_view(), name='cliente_edit'), + path('cliente//delete/', ClienteDeleteView.as_view(), name='cliente_delete'), + + # Portafoglio URLs + path('cliente//portafoglio/new/', PortafoglioCreateView.as_view(), name='portafoglio_new'), + path('portafoglio//edit/', PortafoglioUpdateView.as_view(), name='portafoglio_edit'), + path('portafoglio//delete/', PortafoglioDeleteView.as_view(), name='portafoglio_delete'), + + # Attivita URLs + path('cliente//attivita/new/', AttivitaCreateView.as_view(), name='attivita_new'), + path('attivita//edit/', AttivitaUpdateView.as_view(), name='attivita_edit'), + path('attivita//delete/', AttivitaDeleteView.as_view(), name='attivita_delete'), + + # Documento URLs + path('cliente//documento/new/', DocumentoCreateView.as_view(), name='documento_new'), + path('documento//edit/', DocumentoUpdateView.as_view(), name='documento_edit'), + path('documento//delete/', DocumentoDeleteView.as_view(), name='documento_delete'), +] \ No newline at end of file diff --git a/core/views.py b/core/views.py index c9aed12..afcb6bf 100644 --- a/core/views.py +++ b/core/views.py @@ -1,25 +1,141 @@ -import os -import platform +from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView +from django.urls import reverse_lazy, reverse +from .models import Cliente, Portafoglio, Attivita, Documento +from .forms import ClienteForm, PortafoglioForm, AttivitaForm, DocumentoForm +from django.shortcuts import get_object_or_404 -from django import get_version as django_version -from django.shortcuts import render -from django.utils import timezone +class ClienteListView(ListView): + model = Cliente + template_name = 'core/index.html' + context_object_name = 'clienti' +class ClienteDetailView(DetailView): + model = Cliente + template_name = 'core/article_detail.html' -def home(request): - """Render the landing screen with loader and environment details.""" - host_name = request.get_host().lower() - agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic" - now = timezone.now() + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + cliente = self.get_object() + context['portafogli'] = cliente.portafogli.all() + context['attivita'] = cliente.attivita.all() + context['documenti'] = cliente.documenti.all() + return context - context = { - "project_name": "New Style", - "agent_brand": agent_brand, - "django_version": django_version(), - "python_version": platform.python_version(), - "current_time": now, - "host_name": host_name, - "project_description": os.getenv("PROJECT_DESCRIPTION", ""), - "project_image_url": os.getenv("PROJECT_IMAGE_URL", ""), - } - return render(request, "core/index.html", context) +class ClienteCreateView(CreateView): + model = Cliente + template_name = 'core/cliente_form.html' + form_class = ClienteForm + success_url = reverse_lazy('cliente_list') + +class ClienteUpdateView(UpdateView): + model = Cliente + template_name = 'core/cliente_form.html' + form_class = ClienteForm + success_url = reverse_lazy('cliente_list') + +class ClienteDeleteView(DeleteView): + model = Cliente + template_name = 'core/cliente_confirm_delete.html' + success_url = reverse_lazy('cliente_list') + +# Portafoglio Views +class PortafoglioCreateView(CreateView): + model = Portafoglio + form_class = PortafoglioForm + template_name = 'core/portafoglio_form.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['cliente_pk'] = self.kwargs['cliente_pk'] + return context + + def form_valid(self, form): + cliente = get_object_or_404(Cliente, pk=self.kwargs['cliente_pk']) + form.instance.cliente = cliente + return super().form_valid(form) + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.kwargs['cliente_pk']}) + +class PortafoglioUpdateView(UpdateView): + model = Portafoglio + form_class = PortafoglioForm + template_name = 'core/portafoglio_form.html' + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.object.cliente.pk}) + +class PortafoglioDeleteView(DeleteView): + model = Portafoglio + template_name = 'core/portafoglio_confirm_delete.html' + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.object.cliente.pk}) + +# Attivita Views +class AttivitaCreateView(CreateView): + model = Attivita + form_class = AttivitaForm + template_name = 'core/attivita_form.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['cliente_pk'] = self.kwargs['cliente_pk'] + return context + + def form_valid(self, form): + cliente = get_object_or_404(Cliente, pk=self.kwargs['cliente_pk']) + form.instance.cliente = cliente + return super().form_valid(form) + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.kwargs['cliente_pk']}) + +class AttivitaUpdateView(UpdateView): + model = Attivita + form_class = AttivitaForm + template_name = 'core/attivita_form.html' + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.object.cliente.pk}) + +class AttivitaDeleteView(DeleteView): + model = Attivita + template_name = 'core/attivita_confirm_delete.html' + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.object.cliente.pk}) + +# Documento Views +class DocumentoCreateView(CreateView): + model = Documento + form_class = DocumentoForm + template_name = 'core/documento_form.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['cliente_pk'] = self.kwargs['cliente_pk'] + return context + + def form_valid(self, form): + cliente = get_object_or_404(Cliente, pk=self.kwargs['cliente_pk']) + form.instance.cliente = cliente + return super().form_valid(form) + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.kwargs['cliente_pk']}) + +class DocumentoUpdateView(UpdateView): + model = Documento + form_class = DocumentoForm + template_name = 'core/documento_form.html' + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.object.cliente.pk}) + +class DocumentoDeleteView(DeleteView): + model = Documento + template_name = 'core/documento_confirm_delete.html' + + def get_success_url(self): + return reverse('cliente_detail', kwargs={'pk': self.object.cliente.pk})