191 lines
11 KiB
HTML
191 lines
11 KiB
HTML
{% extends 'base.html' %}
|
|
|
|
{% block title %}CSV Import - Stiftungsverwaltung{% endblock %}
|
|
|
|
{% block content %}
|
|
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1><i class="fas fa-file-csv text-primary"></i> CSV Import</h1>
|
|
<a href="{% url 'stiftung:csv_import_list' %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-list"></i> Import-Verlauf
|
|
</a>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-8">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-primary text-white">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-upload"></i> Neue CSV-Datei importieren
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="post" enctype="multipart/form-data">
|
|
{% csrf_token %}
|
|
|
|
<div class="mb-3">
|
|
<label for="import_type" class="form-label">
|
|
<strong>Import-Typ *</strong>
|
|
</label>
|
|
<select name="import_type" id="import_type" class="form-select" required>
|
|
<option value="">Bitte wählen...</option>
|
|
{% for value, label in import_types %}
|
|
<option value="{{ value }}">{{ label }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
<div class="form-text">Wählen Sie den Typ der zu importierenden Daten aus.</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="csv_file" class="form-label">
|
|
<strong>CSV-Datei *</strong>
|
|
</label>
|
|
<input type="file" name="csv_file" id="csv_file"
|
|
class="form-control" accept=".csv" required>
|
|
<div class="form-text">Nur CSV-Dateien werden unterstützt.</div>
|
|
</div>
|
|
|
|
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
|
<a href="{% url 'stiftung:home' %}" class="btn btn-outline-secondary me-md-2">
|
|
<i class="fas fa-times"></i> Abbrechen
|
|
</a>
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-upload"></i> Import starten
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-4">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-info text-white">
|
|
<h6 class="card-title mb-0">
|
|
<i class="fas fa-info-circle"></i> Import-Informationen
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<h6>Destinatäre Import:</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Vorname, Nachname</li>
|
|
<li><strong>Optionale Felder:</strong> E-Mail, Telefon, IBAN, Straße, PLZ, Ort, Notizen, Geburtsdatum, Familienzweig, Berufsgruppe, Ausbildungsstand, Institution, Projektbeschreibung, Jährliches_Einkommen, Finanzielle_Notlage, Aktiv</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
</ul>
|
|
|
|
<hr>
|
|
|
|
<h6>Pächter Import:</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Vorname, Nachname</li>
|
|
<li><strong>Optionale Felder:</strong> E-Mail, Telefon, IBAN, Straße, PLZ, Ort, Personentyp, Notizen, Geburtsdatum, Pachtnummer, Pachtbeginn_Erste, Pachtende_Letzte, Pachtzins_Aktuell, Landwirtschaftliche_Ausbildung, Berufserfahrung_Jahre, Spezialisierung, Aktiv</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
</ul>
|
|
|
|
<hr>
|
|
|
|
<h6>Ländereien Import:</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Lfd_Nr, Gemeinde, Gemarkung, Flur, Flurstück</li>
|
|
<li><strong>Optionale Felder:</strong> EW_Nummer, Amtsgericht, Größe_qm, Grünland_qm, Acker_qm, Wald_qm, Sonstiges_qm, Verpachtete_Gesamtfläche_qm, Verp_Fläche_aktuell_qm, Aktiv, Notizen</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
</ul>
|
|
|
|
<hr>
|
|
|
|
<h6>Personen Import (Legacy):</h6>
|
|
<ul class="list-unstyled small">
|
|
<li><strong>Pflichtfelder:</strong> Vorname, Nachname</li>
|
|
<li><strong>Optionale Felder:</strong> E-Mail, Telefon, IBAN, Adresse, Notizen, Geburtsdatum, Familienzweig, Aktiv</li>
|
|
<li><strong>Format:</strong> UTF-8 CSV mit Komma oder Semikolon als Trennzeichen</li>
|
|
<li><strong>Hinweis:</strong> Nur für Legacy-Daten, neue Daten sollten als Destinatäre oder Pächter importiert werden</li>
|
|
</ul>
|
|
|
|
<div class="alert alert-warning mt-3">
|
|
<i class="fas fa-exclamation-triangle"></i>
|
|
<strong>Hinweis:</strong> Bestehende Datensätze werden aktualisiert, wenn sie anhand der eindeutigen Felder gefunden werden.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm mt-3">
|
|
<div class="card-header bg-success text-white">
|
|
<h6 class="card-title mb-0">
|
|
<i class="fas fa-download"></i> CSV-Vorlagen herunterladen
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="d-grid gap-2">
|
|
<a href="#" class="btn btn-outline-success btn-sm" onclick="downloadTemplate('destinataere')">
|
|
<i class="fas fa-download"></i> Destinatäre-Vorlage
|
|
</a>
|
|
<a href="#" class="btn btn-outline-success btn-sm" onclick="downloadTemplate('paechter')">
|
|
<i class="fas fa-download"></i> Pächter-Vorlage
|
|
</a>
|
|
<a href="#" class="btn btn-outline-success btn-sm" onclick="downloadTemplate('laendereien')">
|
|
<i class="fas fa-download"></i> Ländereien-Vorlage
|
|
</a>
|
|
<a href="#" class="btn btn-outline-secondary btn-sm" onclick="downloadTemplate('personen')">
|
|
<i class="fas fa-download"></i> Personen-Vorlage (Legacy)
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
function downloadTemplate(type) {
|
|
let headers, filename, exampleRow;
|
|
|
|
if (type === 'destinataere') {
|
|
headers = ['Vorname', 'Nachname', 'Familienzweig', 'E-Mail', 'Telefon', 'IBAN', 'Straße', 'PLZ', 'Ort', 'Geburtsdatum', 'Berufsgruppe', 'Ausbildungsstand', 'Institution', 'Projektbeschreibung', 'Jährliches_Einkommen', 'Finanzielle_Notlage', 'Notizen', 'Aktiv'];
|
|
filename = 'destinataere_vorlage.csv';
|
|
exampleRow = 'Max,Mustermann,hauptzweig,max@email.com,0123456789,DE12345678901234567890,Musterstraße 1,12345,Musterstadt,01.01.1990,student,Abitur,Universität Musterstadt,Studium der Informatik,15000,false,Beispiel Notiz,true';
|
|
} else if (type === 'paechter') {
|
|
headers = ['Vorname', 'Nachname', 'E-Mail', 'Telefon', 'IBAN', 'Straße', 'PLZ', 'Ort', 'Personentyp', 'Geburtsdatum', 'Pachtnummer', 'Pachtbeginn_Erste', 'Pachtende_Letzte', 'Pachtzins_Aktuell', 'Landwirtschaftliche_Ausbildung', 'Berufserfahrung_Jahre', 'Spezialisierung', 'Notizen', 'Aktiv'];
|
|
filename = 'paechter_vorlage.csv';
|
|
exampleRow = 'Hans,Bauer,hans@email.com,0123456789,DE12345678901234567890,Bauernhof 1,12345,Bauerndorf,natuerlich,01.01.1980,P001,01.01.2020,31.12.2029,5000,true,15,Ackerbau,Beispiel Notiz,true';
|
|
} else if (type === 'laendereien') {
|
|
headers = ['Lfd_Nr', 'EW_Nummer', 'Amtsgericht', 'Gemeinde', 'Gemarkung', 'Flur', 'Flurstück', 'Größe_qm', 'Grünland_qm', 'Acker_qm', 'Wald_qm', 'Sonstiges_qm', 'Verpachtete_Gesamtfläche_qm', 'Verp_Fläche_aktuell_qm', 'Aktiv', 'Notizen'];
|
|
filename = 'laendereien_vorlage.csv';
|
|
exampleRow = 'L001,EW001,Amtsgericht Musterstadt,Musterstadt,Mustergemarkung,1,123,10000,5000,3000,1500,500,8000,8000,true,Beispiel Notiz';
|
|
} else if (type === 'personen') {
|
|
headers = ['Vorname', 'Nachname', 'Familienzweig', 'E-Mail', 'Telefon', 'IBAN', 'Adresse', 'Geburtsdatum', 'Notizen', 'Aktiv'];
|
|
filename = 'personen_legacy_vorlage.csv';
|
|
exampleRow = 'Beispiel,Beispiel,hauptzweig,beispiel@email.com,0123456789,DE12345678901234567890,Beispielstraße 1,01.01.1990,Beispiel Notiz,true';
|
|
}
|
|
|
|
// Create CSV content
|
|
const csvContent = headers.join(',') + '\n' + exampleRow;
|
|
|
|
// Create download link
|
|
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
|
const link = document.createElement('a');
|
|
const url = URL.createObjectURL(blob);
|
|
link.setAttribute('href', url);
|
|
link.setAttribute('download', filename);
|
|
link.style.visibility = 'hidden';
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
}
|
|
|
|
// File validation
|
|
document.getElementById('csv_file').addEventListener('change', function(e) {
|
|
const file = e.target.files[0];
|
|
if (file && !file.name.toLowerCase().endsWith('.csv')) {
|
|
alert('Bitte wählen Sie eine gültige CSV-Datei aus.');
|
|
this.value = '';
|
|
}
|
|
});
|
|
</script>
|
|
{% endblock %}
|