From cd8471036ce5123a85bb42fb36041d3646c5c32d Mon Sep 17 00:00:00 2001 From: moanos Date: Mon, 23 Jun 2025 18:38:15 +0200 Subject: [PATCH] feat: Add initial support for contacts --- src/fellchensammlung/api/serializers.py | 1 - .../management/commands/export_contacts.py | 1 + .../templates/fellchensammlung/contacts.vcf | 9 +++++++++ src/fellchensammlung/tools/admin.py | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/fellchensammlung/templates/fellchensammlung/contacts.vcf diff --git a/src/fellchensammlung/api/serializers.py b/src/fellchensammlung/api/serializers.py index 85e629a..435140c 100644 --- a/src/fellchensammlung/api/serializers.py +++ b/src/fellchensammlung/api/serializers.py @@ -116,7 +116,6 @@ class RescueOrgeGeoJSONSerializer(serializers.ModelSerializer): return None - class AnimalCreateSerializer(serializers.ModelSerializer): class Meta: model = Animal diff --git a/src/fellchensammlung/management/commands/export_contacts.py b/src/fellchensammlung/management/commands/export_contacts.py index dad20f6..dc26b7e 100644 --- a/src/fellchensammlung/management/commands/export_contacts.py +++ b/src/fellchensammlung/management/commands/export_contacts.py @@ -1,4 +1,5 @@ from django.core.management import BaseCommand + from fellchensammlung.tools.admin import export_orgs_as_vcf diff --git a/src/fellchensammlung/templates/fellchensammlung/contacts.vcf b/src/fellchensammlung/templates/fellchensammlung/contacts.vcf new file mode 100644 index 0000000..ca97ba6 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/contacts.vcf @@ -0,0 +1,9 @@ +{% for contact in contacts %} +BEGIN:VCARD +VERSION:4.0 +N:{{contact.name}};;;; +TEL;TYPE=work:{{ contact.phone_number }} +{% if contact.email %}EMAIL:{{ contact.email }} +{% endif %}REV:{{ current_time|date:'Ymd' }}T{{ current_time|date:'His' }}T +END:VCARD +{% endfor %} \ No newline at end of file diff --git a/src/fellchensammlung/tools/admin.py b/src/fellchensammlung/tools/admin.py index 22a387b..c205755 100644 --- a/src/fellchensammlung/tools/admin.py +++ b/src/fellchensammlung/tools/admin.py @@ -4,6 +4,7 @@ from django.utils import timezone from datetime import timedelta from django_super_deduper.merge import MergedModelInstance +from django.template.loader import render_to_string from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log, \ AdoptionNoticeNotification @@ -116,4 +117,10 @@ def dedup_locations(): def export_orgs_as_vcf(): rescue_orgs = RescueOrganization.objects.filter(phone_number__isnull=False) + result = render_to_string(template_name="fellchensammlung/contacts.vcf", + context={"contacts": rescue_orgs, "current_time": timezone.now()}) + filename = "contacts.vcf" + with open(filename, "w") as f: + f.write(result) + print(f"Wrote {len(rescue_orgs)} contacts to {filename}")