Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

[Mis en pause] Label financement #355

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fileignoreconfig:
- filename: dora/services/migrations/0110_fundinglabel.py
checksum: b04db85f9727ef213d715ce04cc4bf7f093e8e76ed3c6435a9d214d68b1f7226
- filename: dora/services/migrations/0111_service_funding_label.py
checksum: 1cb43c3e900ef7cc49bf25dec3b419d5b99e5581dea214eff89480cabfa8ee09
version: ""
24 changes: 24 additions & 0 deletions dora/services/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.admin import RelatedOnlyFieldListFilter
from django.contrib.gis import admin
from django.db.models import Count

from dora.core.admin import EnumAdmin

Expand All @@ -10,6 +11,7 @@
CoachOrientationMode,
ConcernedPublic,
Credential,
FundingLabel,
LocationKind,
Requirement,
SavedSearch,
Expand Down Expand Up @@ -146,6 +148,27 @@ class ServiceModelAdmin(admin.ModelAdmin):
raw_id_fields = ["structure", "model", "creator", "last_editor"]


class FundingLabelAdmin(admin.ModelAdmin):
list_display = [
"department",
"label",
"service_count"
]
search_fields = (
"department",
"label",
)
ordering = ["department"]

def get_queryset(self, request):
queryset = super().get_queryset(request)
queryset = queryset.annotate(service_count=Count("service"))
return queryset

def service_count(self, obj):
return obj.service_count


class CustomizableChoiceAdmin(admin.ModelAdmin):
list_display = ("name", "structure")
list_filter = [
Expand Down Expand Up @@ -192,6 +215,7 @@ class SavedSearchAdmin(admin.ModelAdmin):

admin.site.register(Service, ServiceAdmin)
admin.site.register(ServiceModel, ServiceModelAdmin)
admin.site.register(FundingLabel, FundingLabelAdmin)
admin.site.register(AccessCondition, CustomizableChoiceAdmin)
admin.site.register(ConcernedPublic, CustomizableChoiceAdmin)
admin.site.register(Requirement, CustomizableChoiceAdmin)
Expand Down
37 changes: 37 additions & 0 deletions dora/services/migrations/0110_fundinglabel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.15 on 2024-08-15 14:53

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("services", "0109_rename_orientation_mode_labels"),
]

operations = [
migrations.CreateModel(
name="FundingLabel",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"department",
models.CharField(
db_index=True, max_length=3, verbose_name="département"
),
),
("label", models.CharField(verbose_name="label")),
],
options={
"verbose_name": "label de financement",
"verbose_name_plural": "labels de financement",
},
),
]
23 changes: 23 additions & 0 deletions dora/services/migrations/0111_service_funding_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.15 on 2024-08-15 15:09

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("services", "0110_fundinglabel"),
]

operations = [
migrations.AddField(
model_name="service",
name="funding_label",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="services.fundinglabel",
),
),
]
19 changes: 19 additions & 0 deletions dora/services/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ class Meta:
verbose_name = "Source"


class FundingLabel(models.Model):
class Meta:
verbose_name = "label de financement"
verbose_name_plural = "labels de financement"

department = models.CharField(
max_length=3, db_index=True, verbose_name="département"
)
label = models.CharField(verbose_name="label")


class ServiceManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(is_model=False)
Expand Down Expand Up @@ -442,6 +453,14 @@ class Service(ModerationMixin, models.Model):
data_inclusion_id = models.TextField(blank=True, db_index=True)
data_inclusion_source = models.TextField(blank=True, db_index=True)

# Label financement
funding_label = models.ForeignKey(
FundingLabel,
on_delete=models.PROTECT,
blank=True,
null=True,
)

objects = ServiceManager()

class Meta:
Expand Down
1 change: 1 addition & 0 deletions dora/services/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _get_di_results(
lat=lat,
lon=lon,
)
print(set([r["service"]["source"] for r in raw_di_results if r]))
except requests.ConnectionError:
return []

Expand Down